43 #pragma GCC diagnostic ignored "-Wunused-variable" 44 #pragma GCC diagnostic ignored "-Wunused-parameter" 46 #include <Epetra_ConfigDefs.h> 49 #include <Epetra_MpiComm.h> 51 #include <Epetra_SerialComm.h> 55 #pragma GCC diagnostic warning "-Wunused-variable" 56 #pragma GCC diagnostic warning "-Wunused-parameter" 61 #include <lifev/core/array/VectorSmall.hpp> 63 #include <lifev/core/array/VectorEpetra.hpp> 64 #include <lifev/core/array/MatrixEpetra.hpp> 65 #include <lifev/core/array/MapEpetra.hpp> 66 #include <lifev/core/mesh/MeshData.hpp> 67 #include <lifev/core/mesh/MeshPartitioner.hpp> 68 #include <lifev/core/filter/ExporterEnsight.hpp> 69 #include <lifev/core/filter/ExporterHDF5.hpp> 70 #include <lifev/core/filter/ExporterEmpty.hpp> 72 #include <lifev/core/algorithm/LinearSolver.hpp> 73 #include <lifev/electrophysiology/examples/example_bidomain/ElectroETABidomainSolver.hpp> 75 #include <lifev/core/filter/ExporterEnsight.hpp> 77 #include <lifev/core/filter/ExporterHDF5.hpp> 79 #include <lifev/core/filter/ExporterEmpty.hpp> 81 #include <lifev/electrophysiology/solver/IonicModels/IonicMinimalModel.hpp> 82 #include <lifev/core/fem/BCManage.hpp> 83 #include <lifev/core/LifeV.hpp> 85 #include <Teuchos_RCP.hpp> 86 #include <Teuchos_ParameterList.hpp> 87 #include "Teuchos_XMLParameterListHelpers.hpp" 90 using namespace LifeV;
95 Real pacingSite_X = 0.0;
96 Real pacingSite_Y = 0.0;
97 Real pacingSite_Z = 0.0;
98 Real stimulusRadius = 0.15;
100 if ( std::abs ( x - pacingSite_X ) <= stimulusRadius && std::abs ( z - pacingSite_Z ) <= stimulusRadius && std::abs ( y - pacingSite_Y ) <= stimulusRadius)
113 Real pacingSite_X = 0.0;
114 Real pacingSite_Y = 0.0;
115 Real pacingSite_Z = 0.0;
116 Real stimulusRadius = 0.15;
117 Real stimulusValue = 10.0;
121 if ( std::abs ( x - pacingSite_X ) <= stimulusRadius && std::abs ( z - pacingSite_Z ) <= stimulusRadius && std::abs ( y - pacingSite_Y ) <= stimulusRadius)
123 returnValue1 = stimulusValue;
148 MPI_Init (&argc, &argv);
149 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
150 if ( Comm->MyPID() == 0 )
152 std::cout <<
"% using MPI" << std::endl;
161 typedef RegionMesh<LinearTetra> mesh_Type;
162 typedef std::function < Real (
const Real& ,
166 const ID& ) > function_Type;
169 typedef std::shared_ptr< bidomainSolver_Type > bidomainSolverPtr_Type;
171 typedef std::shared_ptr<vector_Type> vectorPtr_Type;
173 LifeChrono chronoinitialsettings;
175 if ( Comm->MyPID() == 0 )
177 chronoinitialsettings.start();
186 if ( Comm->MyPID() == 0 )
188 std::cout <<
"Importing parameters list...";
190 Teuchos::ParameterList bidomainList = * ( Teuchos::getParametersFromXmlFile (
"BidomainSolverParamList.xml" ) );
191 if ( Comm->MyPID() == 0 )
193 std::cout <<
" Done!" << std::endl;
202 if ( Comm->MyPID() == 0 )
204 std::cout <<
"Building Constructor for Minimal Model with parameters ... ";
206 std::shared_ptr<IonicMinimalModel> model (
new IonicMinimalModel() );
207 if ( Comm->MyPID() == 0 )
209 std::cout <<
" Done!" << std::endl;
217 std::string meshName = bidomainList.get (
"mesh_name",
"lid16.mesh");
218 std::string meshPath = bidomainList.get (
"mesh_path",
"./");
232 if ( Comm->MyPID() == 0 )
234 std::cout <<
"Building bidomain Solvers... ";
237 bidomainSolverPtr_Type splitting (
new bidomainSolver_Type ( meshName, meshPath, dataFile, model ) );
238 if ( Comm->MyPID() == 0 )
240 std::cout <<
" Splitting solver done... ";
248 if ( Comm->MyPID() == 0 )
250 std::cout <<
"\nInitializing potential: " ;
254 function_Type pacing = &PacingProtocol;
255 splitting -> initializePotential();
266 * ( splitting -> globalSolution().at (1) ) = 1.0;
267 * ( splitting -> globalSolution().at (2) ) = 1.0;
268 * ( splitting -> globalSolution().at (3) ) = 0.021553043080281;
270 if ( Comm->MyPID() == 0 )
272 std::cout <<
"Done! \n" ;
278 splitting -> setParameters ( bidomainList );
284 if ( Comm->MyPID() == 0 )
286 std::cout <<
"-- Reading bc ..";
289 std::shared_ptr<LifeV::BCHandler> bcs (
new LifeV::BCHandler() );
291 LifeV::BCFunctionBase zero (bcDirichletZero);
293 std::vector<LifeV::ID> compx (1, 0), compy (1, 1), compz (1, 2);
294 bcs->addBC (
"boundaryDirichletZero", 600, LifeV::Essential, LifeV::Full, zero, 3);
298 bcs->bcUpdate ( *splitting->localMeshPtr(), splitting->feSpacePtr()->feBd(), splitting->feSpacePtr()->dof() );
300 if ( Comm->MyPID() == 0 )
302 std::cout <<
" Done!" << std::endl;
309 if ( Comm->MyPID() == 0 )
311 std::cout <<
"\nImporting fibers: " ;
314 std::shared_ptr<FESpace< mesh_Type, MapEpetra > > Space3D
315 (
new FESpace< mesh_Type, MapEpetra > ( splitting -> localMeshPtr(),
"P1", 3, splitting -> commPtr() ) );
317 std::shared_ptr<VectorEpetra> fiber (
new VectorEpetra ( Space3D -> map() ) );
318 std::string nm = bidomainList.get (
"fiber_file",
"FiberDirection") ;
319 ElectrophysiologyUtility::setupFibers ( *fiber, 0.0, 0.0, 1.0 );
320 splitting -> setFiberPtr (fiber);
322 if ( Comm->MyPID() == 0 )
324 std::cout <<
"Done! \n" ;
329 if ( Comm->MyPID() == 0 )
331 std::cout <<
"\nSetup operators: " ;
335 splitting -> setupMassMatrix();
336 splitting -> setupStiffnessMatrix();
337 splitting -> setupGlobalMatrix();
338 if ( Comm->MyPID() == 0 )
340 std::cout <<
"Done! \n" ;
346 ExporterHDF5< RegionMesh <LinearTetra> > exporterSplitting;
348 splitting -> setupExporter ( exporterSplitting, bidomainList.get (
"OutputFile",
"Splitting") );
350 splitting -> exportSolution ( exporterSplitting, 0);
355 if ( Comm->MyPID() == 0 )
357 std::cout <<
"\nstart solving: " ;
360 bidomainSolver_Type::vectorPtr_Type dtVec (
new VectorEpetra ( splitting->feSpacePtr() -> map(), LifeV::Unique ) );
361 ExporterHDF5<mesh_Type> Exp;
362 Exp.setMeshProcId ( splitting -> localMeshPtr(), splitting -> commPtr() -> MyPID() );
363 Exp.setPrefix (bidomainList.get (
"OutputTimeSteps",
"TimeSteps") );
364 Exp.addVariable ( ExporterData<mesh_Type>::ScalarField,
"dt", splitting->feSpacePtr(), dtVec, UInt (0) );
366 Real dt = bidomainList.get (
"timeStep", 0.1);
367 Real TF = bidomainList.get (
"endTime", 150.0);
368 Int iter = bidomainList.get (
"saveStep", 1.0) / dt;
369 Int meth = bidomainList.get (
"meth", 1 );
370 Real dt_min = dt / 50.0;
378 Real stimulusStart = 0.0;
379 Real stimulusStop = 2.0;
381 for (
Real t = 0.0; t < TF; )
384 if ( (t >= stimulusStart ) && (t <= stimulusStop + dt) )
386 splitting -> setAppliedCurrentFromFunctionIntra ( pacing );
391 splitting -> initializeAppliedCurrentIntra();
404 splitting->solveOneReactionStepFE( );
408 timeReac += chrono.globalDiff ( *Comm );
410 (*splitting->rhsPtrUnique() ) *= 0.0;
411 splitting->updateRhs();
418 splitting->solveOneDiffusionStepBE();
420 timeDiff += chrono.globalDiff ( *Comm );
424 splitting -> exportSolution (exporterSplitting, t);
428 nodes = dtVec->epetraVector().MyLength();
429 j = dtVec->blockMap().GID (0);
430 dt_min = (*dtVec) [j];
431 for (
int i = 1; i < nodes; i++)
433 j = dtVec->blockMap().GID (i);
434 if (dt_min > (*dtVec) [j])
436 dt_min = (*dtVec) [j];
444 if ( Comm->MyPID() == 0 )
446 std::cout <<
"\n\n\nActual time : " << t << std::endl << std::endl << std::endl;
451 Real normSolution = ( ( splitting -> globalSolution().at (0) )->norm2() );
452 if ( Comm->MyPID() == 0 )
454 std::cout <<
"2-norm of potential solution: " << normSolution << std::endl;
457 exporterSplitting.closeFile();
464 splitting -> exportFiberDirection();
467 if ( Comm->MyPID() == 0 )
469 chronoinitialsettings.stop();
470 std::cout <<
"\n\n\nTotal lapsed time : " << chronoinitialsettings.diff() << std::endl;
471 std::cout <<
"Diffusion time : " << timeDiff << std::endl;
472 std::cout <<
"Reaction time : " << timeReac << std::endl;
473 std::cout <<
"\nThank you for using ETA_bidomainSolver.\nI hope to meet you again soon!\n All the best for your simulation :P\n " ;
475 MPI_Barrier (MPI_COMM_WORLD);
480 if (std::abs (normSolution - 14.182) > 1e-4 )
482 returnValue = EXIT_FAILURE;
486 returnValue = EXIT_SUCCESS;
488 return ( returnValue );
VectorEpetra - The Epetra Vector format Wrapper.
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
int main(int argc, char **argv)
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
static Real bcDirichletOne(const Real &, const Real &, const Real &, const Real &, const LifeV::ID &)
IonicModel - This class implements an ionic model.
int32_type Int
Generic integer data.
static Real bcDirichletZero(const Real &, const Real &, const Real &, const Real &, const LifeV::ID &)
ExporterHDF5< mesh_Type > hdf5IOFile_Type
double Real
Generic real data.
Real smoothing(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real PacingProtocol(const Real &, const Real &x, const Real &y, const Real &z, const ID &)