39 #ifndef _MONODOMAINSOLVER_H_    40 #define _MONODOMAINSOLVER_H_    42 #include <lifev/core/array/MatrixElemental.hpp>    43 #include <lifev/core/array/VectorElemental.hpp>    44 #include <lifev/core/fem/AssemblyElemental.hpp>    45 #include <lifev/core/fem/Assembly.hpp>    46 #include <lifev/core/fem/BCManage.hpp>    47 #include <lifev/core/algorithm/SolverAztecOO.hpp>    48 #include <lifev/core/array/MapEpetra.hpp>    49 #include <lifev/core/array/MatrixEpetra.hpp>    50 #include <lifev/core/array/VectorEpetra.hpp>    51 #include <lifev/core/fem/SobolevNorms.hpp>    52 #include <lifev/core/fem/GeometricMap.hpp>    53 #include <lifev/heart/solver/HeartMonodomainData.hpp>    54 #include <lifev/core/util/LifeChrono.hpp>    55 #include <boost/shared_ptr.hpp>    56 #include <lifev/core/fem/FESpace.hpp>    57 #include <lifev/heart/solver/HeartStiffnessFibers.hpp>    58 #include <lifev/core/fem/TimeAdvanceBDF.hpp>    65 template < 
typename Mesh,
    66          typename SolverType = LifeV::SolverAztecOO >
   113                             BCHandler& bcHandler,
   114                             std::shared_ptr<Epetra_Comm>& comm);
   299 template<
typename Mesh, 
typename SolverType>
   304                         std::shared_ptr<Epetra_Comm>&              comm ) :
   334         std::stringstream MyPID;
   335         ifstream fibers (M_data.fibersFile().c_str() );
   337         std::cout << 
"fiber_file: " <<  M_data.fibersFile().c_str() << std::endl;
   338         UInt NumGlobalElements = M_localMapVector.map (Repeated)->NumGlobalElements();
   339         std::vector<Real> fiber_global_vector (NumGlobalElements);
   341         for ( 
UInt i = 0; i < NumGlobalElements; ++i)
   343             fibers >> fiber_global_vector[i];
   345         UInt NumMyElements = M_localMapVector.map (Repeated)->NumMyElements();
   346         for (
UInt j = 0; j < NumMyElements; ++j)
   348             UInt ig = M_localMapVector.map (Repeated)->MyGlobalElements() [j];
   349             M_fiberVector[ig] = fiber_global_vector[ig];
   351         std::cout << std::endl;
   352         fiber_global_vector.clear();
   357 template<
typename Mesh, 
typename SolverType>
   361     M_diagonalize = dataFile 
( "electric/space_discretization/diagonalize",  1. 
);
   365     M_linearSolver.setCommunicator (M_comm);
   371     std::string precType = dataFile ( 
"electric/prec/prectype", 
"Ifpack");
   373     M_preconditioner.reset ( PRECFactory::instance().createObject ( precType ) );
   374     ASSERT (M_preconditioner.get() != 0, 
"monodomainSolver : Preconditioner not set");
   380 template<
typename Mesh, 
typename SolverType>
   383     M_massMatrix.reset  ( 
new matrix_Type (M_localMap) );
   384     M_stiffnessMatrix.reset ( 
new matrix_Type (M_localMap) );
   388         std::cout << 
"  f-  Computing constant matrices ...        ";
   393     LifeChrono chronoDer;
   394     LifeChrono chronoStiff;
   395     LifeChrono chronoMass;
   398     LifeChrono chronoStiffAssemble;
   399     LifeChrono chronoMassAssemble;
   400     LifeChrono chronoZero;
   409     for ( 
UInt iVol = 0; iVol < 
M_uFESpace.mesh()->numVolumes(); iVol++ )
   413         M_stiffnessElementaryMatrix.zero();
   414         M_massElementaryMatrix.zero();
   425                     stiff ( M_data.longitudinalConductivity(),
   426                             M_data.transversalConductivity(),
   428                             M_stiffnessElementaryMatrix,
   436                     AssemblyElemental::stiff ( M_data.diffusivity(), M_stiffnessElementaryMatrix,  M_uFESpace.fe(), 0, 0 );
   444                     stiff ( M_data.reducedConductivitySphere(),
   445                             M_data.longitudinalConductivity(),
   446                             M_data.transversalConductivity(),
   448                             M_stiffnessElementaryMatrix,
   450                             M_uFESpace.dof(), 0, 0);
   454                     stiff ( M_data.reducedConductivitySphere(),
   455                             M_data.diffusivity(), M_stiffnessElementaryMatrix,
   466                     stiff ( M_data.reducedConductivityCylinder(),
   467                             M_data.longitudinalConductivity(),
   468                             M_data.transversalConductivity(),
   470                             M_stiffnessElementaryMatrix,
   478                     stiff ( M_data.reducedConductivityCylinder(),
   479                             M_data.diffusivity(),
   480                             M_stiffnessElementaryMatrix,
   491                     stiff ( M_data.reducedConductivityBox(),
   492                             M_data.longitudinalConductivity(),
   493                             M_data.transversalConductivity(),
   495                             M_stiffnessElementaryMatrix,
   503                     stiff ( M_data.reducedConductivityBox(),
   504                             M_data.diffusivity(),
   505                             M_stiffnessElementaryMatrix,
   516         AssemblyElemental::mass ( 1., M_massElementaryMatrix, M_uFESpace.fe(), 0, 0 );
   520         chronoStiffAssemble.start();
   521         assembleMatrix ( *M_stiffnessMatrix,
   522                          M_stiffnessElementaryMatrix,
   529         chronoStiffAssemble.stop();
   532         chronoMassAssemble.start();
   533         assembleMatrix ( *M_massMatrix,
   534                          M_massElementaryMatrix,
   541         chronoMassAssemble.stop();
   552         std::cout << 
"done in " << chrono.diff() << 
" s.\n" << std::flush;
   557         std::cout << 
"  f-  Finalizing the matrices     ...        " << std::flush;
   561     M_stiffnessMatrix->globalAssemble();
   562     M_massMatrix->globalAssemble();
   566     M_matrNoBC.reset (
new matrix_Type (M_localMap, M_stiffnessMatrix->meanNumEntries() ) );
   570     *M_matrNoBC += *M_stiffnessMatrix;
   572     *M_matrNoBC += *M_massMatrix * massCoefficient;
   574     M_matrNoBC->globalAssemble();
   579         std::cout << 
"done in " << chrono.diff() << 
" s." << std::endl;
   583         std::cout << 
"partial times:  \n"   584                   << 
" Der            " << chronoDer.diffCumul() << 
" s.\n"   585                   << 
" Zero           " << chronoZero.diffCumul() << 
" s.\n"   586                   << 
" Stiff          " << chronoStiff.diffCumul() << 
" s.\n"   587                   << 
" Stiff Assemble " << chronoStiffAssemble.diffCumul() << 
" s.\n"   588                   << 
" Mass           " << chronoMass.diffCumul() << 
" s.\n"   589                   << 
" Mass Assemble  " << chronoMassAssemble.diffCumul() << 
" s.\n"   594 template<
typename Mesh, 
typename SolverType>
   608 template<
typename Mesh, 
typename SolverType>
   620 template<
typename Mesh, 
typename SolverType>
   630 template<
typename Mesh, 
typename SolverType>
   639         std::cout << 
"  f-  Updating mass term and right hand side... "   651         std::cout << 
"done in " << chrono.diff() << 
" s.\n"  << std::flush;
   662         std::cout << 
"  f-  Copying the matrices ...                 "   667     M_matrNoBC.reset (
new matrix_Type (M_localMap, M_stiffnessMatrix->meanNumEntries() ) );
   669     *M_matrNoBC += *M_stiffnessMatrix;
   671     *M_matrNoBC += *M_massMatrix * alpha;
   675     if (M_verbose) std::cout << 
"done in " << chrono.diff() << 
" s.\n"   681     M_matrNoBC->globalAssemble();
   685 template<
typename Mesh, 
typename SolverType>
   693         std::cout << 
"  f-  Updating right hand side... "   705         std::cout << 
"done in " << chrono.diff() << 
" s.\n"  << std::flush;
   712 template<
typename Mesh, 
typename SolverType>
   725         std::cout << 
"done in " << chrono.diff() << 
" s.\n"   730     if (M_verbose) std::cout << 
"  f-  Applying boundary conditions ...         "   735     applyBoundaryConditions ( *matrFull, rhsFull, bch);
   743         std::cout << 
"done in " << chrono.diff() << 
" s.\n" << std::flush;
   747     solveSystem ( matrFull, rhsFull );
   756 template<
typename Mesh, 
typename SolverType>
   764         std::cout << 
"  f-  Setting up the solver ...                ";
   768     M_linearSolver.setMatrix (*matrFull);
   772         std::cout << 
"done in " << chrono.diff() << 
" s.\n"   781             std::cout << 
"  f-  Computing the precond ...                ";
   793             std::cout << 
"done in " << chrono.diff() << 
" s.\n";
   794             std::cout << 
"Estimated condition number = " << condest << 
"\n" <<  std::flush;
   803             std::cout << 
"f-  Reusing  precond ...                \n" <<  std::flush;
   812         std::cout << 
"f-  Solving system ...                                ";
   821         std::cout << 
"\ndone in " << chrono.diff()
   822                   << 
" s. ( " << numIter << 
"  iterations. ) \n"   838 template<
typename Mesh, 
typename SolverType>
   845     if ( !BCh.bcUpdateDone() )
   858         matrix.diagonalize ( 1 * 
dim_u(),
 virtual void updatePDESystem(vector_Type &sourceVec)
Updates time dependent parts of PDE system. 
 
virtual void buildSystem()
Builds time independent parts of PDE system. 
 
vector_Type M_fiberVector
Local fibers vector. 
 
double operator()(const char *VarName, const double &Default) const
 
const Real & volumeSurfaceRatio() const
Chi. 
 
HeartMonodomainSolver(const data_type &dataType, FESpace< Mesh, MapEpetra > &uFESpace, BCHandler &bcHandler, std::shared_ptr< Epetra_Comm > &comm)
Constructor. 
 
SolverType::vector_type vector_Type
 
std::function< Real(Real const  &, Real const  &, Real const  &, Real const  &, ID const  &) > source_Type
 
void initialize(const vector_Type &)
 
FESpace - Short description here please! 
 
MatrixElemental M_massElementaryMatrix
 
HeartMonodomainData data_type
 
matrixPtr_Type M_stiffnessMatrix
Stiff matrix: D*stiff. 
 
const data_type & M_data
Data. 
 
preconditioner_Type M_preconditioner
 
const vector_Type & residual() const
Returns the local residual vector. 
 
bool M_verbose
Boolean that indicates if output is sent to cout. 
 
int32_type Int
Generic integer data. 
 
void setBC(BCHandler &BCh_u)
Setting of the boundary conditions. 
 
vector_Type M_rhsNoBC
Right hand side for the PDE. 
 
SolverType::matrix_type matrix_Type
 
void resetPreconditioner()
 
MapEpetra M_localMapVector
 
Epetra_Import const  & importer()
Getter for the Epetra_Import. 
 
SolverType M_linearSolver
Solver. 
 
vector_Type M_residual
residual 
 
std::shared_ptr< bcHandlerRaw_Type > bcHandler_Type
 
BCHandler bcHandlerRaw_Type
 
const vector_Type & solutionTransmembranePotential() const
Returns the local solution vector. 
 
virtual void updatePDESystem(Real alpha, vector_Type &sourceVec)
Updates time dependent parts of PDE system. 
 
void initialize(const source_Type &)
Initialize. 
 
bool M_recomputeMatrix
Boolean that indicates if the matrix has to be recomputed. 
 
virtual void PDEiterate(bcHandlerRaw_Type &bch)
Updates sources, bc treatment and solve the monodomain system. 
 
matrixPtr_Type M_matrNoBC
 
void postProcessing(bool _writeMesh=false)
Postprocessing. 
 
double Real
Generic real data. 
 
const Real & membraneCapacitance() const
Cm. 
 
virtual void setup(const GetPot &dataFile)
Sets up the system solver. 
 
int operator()(const char *VarName, int Default) const
 
const Int & heartDiffusionFactor() const
 
SolverType::prec_type preconditioner_Type
 
BCHandler * M_BChandlerElectric
Monodomain BC. 
 
FESpace< Mesh, MapEpetra > & M_uFESpace
u FE space 
 
void solveSystem(matrixPtr_Type matrFull, vector_Type &rhsFull)
Solves PDE system. 
 
void applyBoundaryConditions(matrix_Type &matrix, vector_Type &rhs, bcHandlerRaw_Type &BCh)
Apply BC. 
 
void initialize(const Function &)
 
bool operator()(const char *VarName, bool Default) const
 
matrixPtr_Type M_massMatrix
mass matrix 
 
const vector_Type & fiberVector() const
 
FESpace< Mesh, MapEpetra > & potentialFESpace()
Returns u FE space. 
 
const std::shared_ptr< Epetra_Comm > M_comm
MPI communicator. 
 
Int M_maxIteration
Integer storing the max number of solver iteration with prec recomputing. 
 
MatrixElemental M_stiffnessElementaryMatrix
Elementary matrices. 
 
vector_Type M_solutionTransmembranePotential
Global solution _u. 
 
SolverType::prec_raw_type preconditionerRaw_Type
 
virtual ~HeartMonodomainSolver()
Destructor. 
 
bool M_resetPreconditioner
 
std::shared_ptr< matrix_Type > matrixPtr_Type
 
uint32_type UInt
generic unsigned integer (used mainly for addressing) 
 
bool M_updated
Boolean that indicates if the matrix is updated for the current iteration. 
 
bool M_reusePreconditioner
Boolean that indicates if the precond has to be recomputed.