51 #include <Epetra_MpiComm.h> 53 #include <Epetra_SerialComm.h> 59 #include <Teuchos_ParameterList.hpp> 70 #include <lifev/bc_interface/3D/bc/BCInterface3D.hpp> 71 #include <lifev/bc_interface/core/solver/EmptyPhysicalSolver.hpp> 77 #include <lifev/core/mesh/MeshLoadingUtility.hpp> 83 #include <lifev/core/fem/GradientRecovery.hpp> 84 #include <lifev/core/fem/BCManage.hpp> 89 #include <lifev/core/algorithm/LinearSolver.hpp> 90 #include <lifev/core/algorithm/PreconditionerML.hpp> 95 #include <lifev/eta/fem/ETFESpace.hpp> 96 #include <lifev/eta/expression/Integrate.hpp> 102 #include <lifev/core/filter/ExporterHDF5.hpp> 109 #include <lifev/electrophysiology/util/HeartUtility.hpp> 117 using namespace LifeV;
153 fespacePtr_Type fespace,
154 vectorPtr_Type vector,
156 std::string outputName,
157 std::string hdf5name);
171 int main (
int argc,
char** argv )
179 MPI_Init (&argc, &argv);
180 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
182 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm);
185 typedef BCHandler bc_Type;
186 typedef std::shared_ptr< bc_Type > bcPtr_Type;
188 typedef EmptyPhysicalSolver<VectorEpetra> physicalSolver_Type;
189 typedef BCInterface3D< bc_Type, physicalSolver_Type > bcInterface_Type;
191 typedef std::shared_ptr< bcInterface_Type > bcInterfacePtr_Type;
192 typedef MeshUtility::MeshTransformer<mesh_Type> meshTransformer_Type;
203 GetPot commandLine ( argc, argv );
204 std::string problemFolder = commandLine.follow (
"Output", 2,
"-o",
"--output" );
206 if ( problemFolder.compare (
"./") )
208 problemFolder +=
"/";
210 if ( Comm->MyPID() == 0 )
212 mkdir ( problemFolder.c_str(), 0777 );
226 GetPot command_line (argc, argv);
227 const std::string data_file_name = command_line.follow (
"data", 2,
"-f",
"--file");
228 GetPot dataFile (data_file_name);
235 std::string meshName = dataFile (
"problem/space_discretization/mesh_file",
"" );
236 std::string meshPath = dataFile (
"problem/space_discretization/mesh_dir",
"./" );
246 meshPtr_Type meshPart (
new mesh_Type ( Comm ) );
247 MeshUtility::loadMesh (meshPart, meshName, meshPath);
260 std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > uSpace
261 (
new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (meshPart, &feTetraP1, Comm) );
263 fespacePtr_Type uFESpace (
new FESpace< mesh_Type, MapEpetra > (meshPart,
"P1", 1, Comm) );
265 fespacePtr_Type vectorFESpace (
new FESpace< mesh_Type, MapEpetra > (meshPart,
"P1", 3, Comm) );
272 std::shared_ptr<matrix_Type> systemMatrix (
new matrix_Type ( uSpace->map() ) );
274 *systemMatrix *= 0.0;
276 using namespace ExpressionAssembly;
279 integrate ( elements (uSpace->mesh() ),
283 dot ( grad (phi_i) , grad (phi_j) )
288 systemMatrix->globalAssemble();
309 bcInterfacePtr_Type BC (
new bcInterface_Type() );
311 BC->fillHandler ( data_file_name,
"problem" );
312 BC->handler()->bcUpdate ( *uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() );
322 typedef LifeV::Preconditioner basePrec_Type;
323 typedef std::shared_ptr<basePrec_Type> basePrecPtr_Type;
324 typedef LifeV::PreconditionerIfpack prec_Type;
325 typedef std::shared_ptr<prec_Type> precPtr_Type;
327 prec_Type* precRawPtr;
328 basePrecPtr_Type precPtr;
329 precRawPtr =
new prec_Type;
330 precRawPtr->setDataFromGetPot ( dataFile,
"prec" );
331 precPtr.reset ( precRawPtr );
342 Teuchos::ParameterList solverList;
343 createListFromGetPot (solverList, dataFile);
345 LinearSolver linearSolver;
346 linearSolver.setCommunicator (Comm);
347 linearSolver.setParameters ( solverList );
348 linearSolver.setPreconditioner ( precPtr );
354 vectorPtr_Type rhs (
new vector_Type ( uSpace -> map() ) );
356 rhs -> globalAssemble();
362 bcManage ( *systemMatrix, *rhs, *uSpace->mesh(), uSpace->dof(), *BC -> handler(), uFESpace->feBd(), 1.0, 0.0 );
372 vectorPtr_Type solution (
new vector_Type ( uFESpace -> map() ) );
375 linearSolver.setOperator (systemMatrix);
376 linearSolver.setRightHandSide (rhs);
377 linearSolver.solve (solution);
383 ExporterHDF5< mesh_Type > exporter;
384 exporter.setMeshProcId ( meshPart, Comm -> MyPID() );
385 exporter.setPostDir (problemFolder);
386 exporter.setPrefix (
"Potential");
387 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"potential", uFESpace, solution, UInt (0) );
388 exporter.postProcess (0);
389 exporter.closeFile();
398 vectorPtr_Type sx (
new vector_Type ( uSpace -> map() ) );
399 vectorPtr_Type sy (
new vector_Type ( uSpace -> map() ) );
400 vectorPtr_Type sz (
new vector_Type ( uSpace -> map() ) );
402 *sx = GradientRecovery::ZZGradient (uSpace, *solution, 0);
403 *sy = GradientRecovery::ZZGradient (uSpace, *solution, 1);
404 *sz = GradientRecovery::ZZGradient (uSpace, *solution, 2);
412 vectorPtr_Type rbSheet (
new vector_Type ( vectorFESpace -> map() ) );
413 vectorPtr_Type rbFiber (
new vector_Type ( vectorFESpace -> map() ) );
414 vectorPtr_Type projection (
new vector_Type ( vectorFESpace -> map() ) );
431 int n = (*rbSheet).epetraVector().MyLength();
443 for (
int l (0); l < d; l++)
445 int i = (*rbSheet).blockMap().GID (l);
446 int j = (*rbSheet).blockMap().GID (l + d);
447 int k = (*rbSheet).blockMap().GID (l + 2 * d);
449 (*rbSheet) [i] = (*sx) [i];
450 (*rbSheet) [j] = (*sy) [i];
451 (*rbSheet) [k] = (*sz) [i];
454 ElectrophysiologyUtility::normalize (*rbSheet);
462 Real cx = dataFile (
"problem/centerline_x", 0.0);
463 Real cy = dataFile (
"problem/centerline_y", 0.0);
464 Real cz = dataFile (
"problem/centerline_z", 1.0);
477 for (
int l (0); l < d; l++)
479 int i = (*rbSheet).blockMap().GID (l);
480 int j = (*rbSheet).blockMap().GID (l + d);
481 int k = (*rbSheet).blockMap().GID (l + 2 * d);
483 Real cdot = cx * (*rbSheet) [i] + cy * (*rbSheet) [j] + cz * (*rbSheet) [k];
485 (*projection) [i] = cx - cdot * (*rbSheet) [i];
486 (*projection) [j] = cy - cdot * (*rbSheet) [j];
487 (*projection) [k] = cz - cdot * (*rbSheet) [k];
490 ElectrophysiologyUtility::normalize (*projection);
507 for (
int l (0); l < d; l++)
509 int i = (*rbSheet).blockMap().GID (l);
510 int j = (*rbSheet).blockMap().GID (l + d);
511 int k = (*rbSheet).blockMap().GID (l + 2 * d);
513 (*rbFiber) [i] = (*rbSheet) [j] * (*projection) [k] - (*rbSheet) [k] * (*projection) [j];
514 (*rbFiber) [j] = (*rbSheet) [k] * (*projection) [i] - (*rbSheet) [i] * (*projection) [k];
515 (*rbFiber) [k] = (*rbSheet) [i] * (*projection) [j] - (*rbSheet) [j] * (*projection) [i];
518 ElectrophysiologyUtility::normalize (*rbFiber);
532 Real epi_angle = dataFile (
"problem/epi_angle", -60.0);
533 Real endo_angle = dataFile (
"problem/endo_angle", 60.0);
535 for (
int l (0); l < d; l++)
537 int i = (*rbSheet).blockMap().GID (l);
538 int j = (*rbSheet).blockMap().GID (l + d);
539 int k = (*rbSheet).blockMap().GID (l + 2 * d);
552 Real p = 3.14159265358979;
553 Real teta1 = p * epi_angle / 180;
554 Real teta2 = p * endo_angle / 180;
555 Real m = (teta1 - teta2 );
559 teta = m * (*solution) [i] + q;
568 Real s01 = (*rbSheet) [i];
569 Real s02 = (*rbSheet) [j];
570 Real s03 = (*rbSheet) [k];
571 Real f01 = (*rbFiber) [i];
572 Real f02 = (*rbFiber) [j];
573 Real f03 = (*rbFiber) [k];
583 Real sa = std::sin (teta);
584 Real sa2 = 2.0 * std::sin (0.5 * teta) * std::sin (0.5 * teta);
596 Real R11 = 1.0 + sa * W11 + sa2 * ( s01 * s01 - 1.0 );
597 Real R12 = 0.0 + sa * W12 + sa2 * ( s01 * s02 );
598 Real R13 = 0.0 + sa * W13 + sa2 * ( s01 * s03 );
599 Real R21 = 0.0 + sa * W21 + sa2 * ( s02 * s01 );
600 Real R22 = 1.0 + sa * W22 + sa2 * ( s02 * s02 - 1.0 );
601 Real R23 = 0.0 + sa * W23 + sa2 * ( s02 * s03 );
602 Real R31 = 0.0 + sa * W31 + sa2 * ( s03 * s01 );
603 Real R32 = 0.0 + sa * W32 + sa2 * ( s03 * s02 );
604 Real R33 = 1.0 + sa * W33 + sa2 * ( s03 * s03 - 1.0 );
610 (*rbFiber) [i] = R11 * f01 + R12 * f02 + R13 * f03;
611 (*rbFiber) [j] = R21 * f01 + R22 * f02 + R23 * f03;
612 (*rbFiber) [k] = R31 * f01 + R32 * f02 + R33 * f03;
627 std::string outputFiberFileName = dataFile (
"problem/output_fiber_filename",
"FiberDirection");
628 std::string fiberHDF5Name = dataFile (
"problem/hdf5_fiber_name",
"fibers");
630 std::string outputSheetsFileName = dataFile (
"problem/output_sheets_filename",
"SheetsDirection");
631 std::string sheetsHDF5Name = dataFile (
"problem/hdf5_sheets_name",
"sheets");
633 exportVectorField (Comm, meshPart, vectorFESpace, rbFiber, problemFolder, outputFiberFileName, fiberHDF5Name );
634 exportVectorField (Comm, meshPart, vectorFESpace, rbSheet, problemFolder, outputSheetsFileName, sheetsHDF5Name );
635 exportVectorField (Comm, meshPart, vectorFESpace, projection, problemFolder,
"Projection",
"projection" );
643 Real normS = rbSheet-> norm2();
644 Real normF = rbFiber-> norm2();
650 Real err = std::abs (normF - normS) / std::abs (normS);
651 std::cout << std::setprecision (20) <<
"\nError: " << err <<
"\nFiber Norm: " << normF <<
"\n";
652 std::cout << std::setprecision (20) <<
"Sheet Norm: " << normS <<
"\n";
667 void createListFromGetPot (Teuchos::ParameterList& solverList,
const GetPot& dataFile)
669 std::string solverName = dataFile (
"problem/solver/solver_name",
"AztecOO");
670 std::string solver = dataFile (
"problem/solver/solver",
"gmres");
671 std::string conv = dataFile (
"problem/solver/conv",
"rhs");
672 std::string scaling = dataFile (
"problem/solver/scaling",
"none");
673 std::string output = dataFile (
"problem/solver/output",
"all");
674 Int maxIter = dataFile (
"problem/solver/max_iter", 200);
675 Int maxIterForReuse = dataFile (
"problem/solver/max_iter_reuse", 250);
676 Int kspace = dataFile (
"problem/solver/kspace", 100);
677 Int orthog = dataFile (
"problem/solver/orthog", 0);
678 Int auxvec = dataFile (
"problem/solver/aux_vec", 0);
679 double tol = dataFile (
"problem/solver/tol", 1e-10);
680 bool reusePreconditioner = dataFile (
"problem/solver/reuse",
true);
681 bool quitOnFailure = dataFile (
"problem/solver/quit",
false);
682 bool silent = dataFile (
"problem/solver/silent",
false);
684 solverList.set (
"Solver Type", solverName);
685 solverList.set (
"Maximum Iterations", maxIter);
686 solverList.set (
"Max Iterations For Reuse", maxIterForReuse);
687 solverList.set (
"Reuse Preconditioner", reusePreconditioner);
688 solverList.set (
"Quit On Failure", quitOnFailure);
689 solverList.set (
"Silent", silent);
690 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"solver", solver);
691 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"conv", conv);
692 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"scaling", scaling);
693 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"output", output);
694 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"tol", tol);
695 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"max_iter", maxIter);
696 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"kspace", kspace);
697 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"orthog", orthog);
698 solverList.sublist (
"Solver: Operator List").sublist (
"Trilinos: AztecOO List").set (
"aux_vec", auxvec);;
702 void exportVectorField (std::shared_ptr<Epetra_Comm> comm,
704 fespacePtr_Type fespace,
705 vectorPtr_Type vector,
707 std::string outputName,
708 std::string hdf5name)
710 ExporterHDF5< mesh_Type > exporter;
711 exporter.setMeshProcId ( mesh, comm -> MyPID() );
712 exporter.setPostDir (postDir);
713 exporter.setPrefix (outputName);
714 exporter.addVariable ( ExporterData<mesh_Type>::VectorField, hdf5name, fespace, vector, UInt (0) );
715 exporter.postProcess (0);
716 exporter.closeFile();
VectorEpetra - The Epetra Vector format Wrapper.
int main(int argc, char **argv)
Real fzero(const Real &, const Real &, const Real &, const Real &, const ID &)
MatrixEpetra< Real > matrix_Type
void createListFromGetPot(Teuchos::ParameterList &solverList, const GetPot &dataFile)
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
std::shared_ptr< mesh_Type > meshPtr_Type
std::shared_ptr< fespace_Type > fespacePtr_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
FESpace< mesh_Type, MapEpetra > fespace_Type
double Real
Generic real data.
std::shared_ptr< matrix_Type > matrixPtr_Type
RegionMesh< LinearTetra > mesh_Type
void exportVectorField(std::shared_ptr< Epetra_Comm > comm, meshPtr_Type mesh, fespacePtr_Type fespace, vectorPtr_Type vector, std::string postDir, std::string outputName, std::string hdf5name)
std::shared_ptr< vector_Type > vectorPtr_Type