CEPS  24.01
Cardiac ElectroPhysiology Simulator
FEStaticSolver.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
32 
35 
37  AbstractStaticPdeSolver(problem),
38  m_fe(ceps::runtimeCast<FiniteElements*>(problem->getSpatialDiscretization()))
39 {}
40 
42 {}
43 
44 void
46 {
47  CEPS_SAYS_NOENDL(" Assembling the linear system...");
48 
49  // Firstly assemble what is needed
51 
52  // Build LHS
53  m_lhs->finalize();
54  m_opMat->copy(*m_lhs);
55  m_lhs->add(*m_bcMat, 1.0, false);
56 
57  // Build RHS
58  m_rhs->zero();
60 
61  // 1. Compute source terms F and add M.F to right hand side
62  if (m_hasRegSrc)
63  {
65  regSrc->zero();
66 
67  for (auto src : m_problem->getSourceTermManager()->asVector())
68  if (src->hasOption(CepsSourceTermFlag::Default) or src->hasOption(CepsSourceTermFlag::Stimulation))
69  addFieldValuesTo(*src, regSrc.get(), 0.);
70 
71  tmp->mult(*(m_fe->getMassMatrix()), *regSrc);
72  m_rhs->add(*tmp);
73  }
74 
75  // 2. "Laplace" source terms
76  if (m_hasLapSrc)
77  {
79  lapSrc->zero();
80 
81  for (auto src : m_problem->getSourceTermManager()->asVector())
82  if (src->hasOption(CepsSourceTermFlag::Laplace))
83  addFieldValuesTo(*src, lapSrc.get(), 0.);
84 
85  tmp->mult(*m_lapSrcMat, *lapSrc);
86  m_rhs->add(*tmp);
87  }
88 
89  // 3. The neuman and robin boundary conditions
90  m_rhs->add(*m_bcVec);
91 
92  // Then apply Dirichlet BCs (put 1 on diagonal in the matrix, and the corresponding value into the
93  // vector)
95  bc.second->applyAsDirichlet(m_lhs, m_rhs);
96 
97  m_rhs->finalize();
98  m_lhs->finalize();
99 
100  CEPS_SAYS_INLINE(" Done");
101 
102  // Solve
103  CEPS_SAYS_NOENDL(" Solving linear system...");
105  CEPS_SAYS_INLINE(" Done");
106 }
@ Laplace
A source term that multiplies grad phi (for FE)
@ Default
Simply add the source term.
@ Stimulation
Apply cardiac specific treatment before adding.
#define CEPS_SAYS_NOENDL(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_SAYS_INLINE(message)
Writes a message in the debug log and in the terminal (stdio).
std::shared_ptr< DistributedVector > DVecPtr
Short typedef for pointer on distributed vector.
void addFieldValuesTo(ScalarField< _SupportType > &f, DistributedVector *vec, CepsReal t=0.)
Add values to a distributed vector. Exclusive to scalar fields. Field data may be evaluated on the fl...
DVecPtr newDofVector() const
Get a new vector from the factory.
SourceTermManager * getSourceTermManager() const
Get boundary condition manager.
BoundaryConditionManager * getBoundaryConditionManager() const
Get boundary condition manager.
DMatPtr m_lhs
Left hand side of the system.
DVecPtr m_rhs
Right hand side of the system.
DMatPtr m_bcMat
Matrix of boundary conditions.
CepsBool m_hasRegSrc
Flag telling if there are regular source terms.
AbstractDiscretization * m_discretization
Link to PDE discretization.
LinearSystem * m_linearSystem
Linear system.
DMatPtr m_opMat
Matrix of operator.
DVecPtr m_bcVec
Vector of boundary conditions.
CepsBool m_hasLapSrc
Flag telling if there are Delta f source terms.
AbstractPdeProblem * m_problem
Link to PDE to solve.
DMatPtr m_lapSrcMat
Matrix used for laplace source terms.
Astract Problem which does not depend on time.
Base class for solving PDE with no time dependance.
void updateAssemblers() override
Update assemblers and recompute everything is needed.
DHVecPtr m_solution
The actual vector with the solution.
Manager * getDirichletBCs() const
Get the manager for Dirichlet conditions.
FEStaticSolver()=delete
Deleted constructor.
void assembleAndSolve() override
Main routine used during solving, assemble the system and solve it.
FiniteElements * m_fe
Geometry and reference FE.
~FEStaticSolver() override
Destructor.
Holds all finite elements corresponding to each geometrical element.
DMatPtr getMassMatrix() const
Pointer on mass matrix.
virtual void solve(DVecPtr solution)
Solve current linear system. Calls the solver's method.
Definition: PETScKSP.cpp:54
CepsVector< ScalarSourceTerm * > asVector() const
Get a vector of all source terms.
A namespace for all utility methods.
_Derived runtimeCast(_Base x)
Perform a runtime cast between base type and derived type if we can.
Definition: CepsMemory.hpp:94