CEPS  24.01
Cardiac ElectroPhysiology Simulator
PacemakerBidomainProblem.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
33 
37 
40  m_problem(problem)
41 {}
42 
45 {
46  PacemakerBidomainProblem* pb = ceps::runtimeCast<PacemakerBidomainProblem*>(m_problem);
47 
48  if (args.unknownId == pb->getVCetsUnknown()->getIdentifier())
49  {
50  auto Am = pb->getAm()->getFunctor()->eval(args);
51  auto Cm = pb->getCm()->getFunctor()->eval(args);
53 
54  return res / (Am * Cm);
55  }
56  return 0.0;
57 }
58 
60  ExtendedBidomainProblem (g, params),
61  AbstractPacemakerProblem(g, params)
62 {
63  setProblemName("Extended Bidomain connected to a Pacemaker");
64 
65  if (ceps::isValidPtr(params))
67 }
68 
69 void
71 {
72  v0->zero();
74 
75  // auto QCetsDof = m_discr->getDegreesOfFreedomForUnknown(m_unknowns[4])[0];
76  // if (QCetsDof->getOwner() == ceps::getRank())
77  // {
78  // v0->getLocalData();
79  // (*v0)[QCetsDof->getGlobalIndex()] = m_pmkCets * m_stimAmplitude;
80  // v0->releaseLocalData();
81  // }
82 }
83 
84 void
86 {
88  addUnknown(UnknownsName::ue, getWholeDomainAttributes()); // ue is defined everywhere
90 
91  // the 0D unknowns "potential"
95 
96  // and the 0D unknowns
104  // sigma_e U_e.gradN is integrated on the cathode to get the current
107 }
108 
109 void
111 {}
112 
113 void
115 {
117 
118  m_functions->addEntry("capaChargeFunc", ceps::getNew<PowerSupply>(this));
120  "__power_supply capaChargeFunc UNKNOWN " //
121  + ceps::toString(getVCetsUnknown()->getIdentifier())
122  );
123 }
124 
125 void
127 {
128  if (ceps::isProfiling())
129  getProfiler()->start("whole", "solving the bidomain problem");
130 
132 
133  // Solve the static problem
134  if (m_parameters->isActiveOption("compute electric field"))
135  {
136  auto spb = ceps::getNew<FluxAnodeCathodeProblem>(m_geom, m_parameters);
137  auto dico = spb->getFunctionDictionary();
138  dico->deleteTensor("physCoeffSigma");
139  dico->add("sigma_i", m_sigmaIOptions);
140  dico->add("sigma_e", m_sigmaEOptions);
141  dico->add("physCoeffSigma", "OPERATOR sigma_i + sigma_e");
142  spb->setOutputFileBase(spb->getOutputFileBase() + "_elec_field");
143  spb->initializeEquation();
144 
145  FluxAnodeCathodeSolver ssolver(spb);
146  ssolver.solve();
147  ceps::destroyObject(spb);
148  }
149 
150  PacemakerBidomainSolver solver(this);
151 
152  solver.solve();
153 
154  if (hasAnalyticSolution())
155  m_errors = solver.getErrors();
156 
157  if (ceps::isProfiling())
158  getProfiler()->stop("whole");
159 }
160 
163 {
164  return getAnode()->getAttributes();
165 }
166 
169 {
170  return getCathode()->getAttributes();
171 }
172 
173 Unknown*
175 {
177 }
178 
179 Unknown*
181 {
183 }
184 
185 Unknown*
187 {
189 }
190 
191 Unknown*
193 {
195 }
196 
197 void
199 {
200  // enforce no anodal and cathodal stimulation for surrounded bidomain problem
201  m_biElecStimOpts = "";
202 
203  return;
204 }
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
CepsReal eval(CepsStandardArgs args) override
Evaluation of function.
Common elements of problems with a pacemaker.
CepsBool hasAnalyticSolution() const
Tells if there is an analytic or reference solution.
void setProblemName(const CepsString &name)
Set the name of the problem.
SourceTermManager * m_sourceTerms
All source terms.
void addUnknown(const CepsString &label, CepsSet< CepsAttribute > attrs={}, CepsLocationFlag flag=CepsLocationFlag::Point, const CepsString &unit="")
Register a new unknown.
void addZeroDUnknown(CepsString label, const CepsString &unit="")
Register a new unknown, defined outside of geometry.
void addUnknownInteraction(CepsString label1, CepsString label2, CepsSet< CepsAttribute > attrs={})
Register interaction between unknowns. Also sets the interaction within Unknown instances label1 and ...
Unknown * getUnknown(const CepsString &label) const
Get an unknown by its name.
InputParameters * m_parameters
Input file data.
Geometry * m_geom
Link to geometry on which the pb is defined.
FunctionDictionary * m_functions
Collection of custom functions.
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > m_errors
Will store Linf, L1 and L2 relative errors.
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > getErrors() const
Gets the currently computed errors. First index selects absolute(0) or relative(1) second index selec...
void getInitialCondition(DHVecPtr v) const override
asks each ionic model to fill the parts of the Vm vector with its initial value, fill ue with same va...
CepsString m_sigmaIOptions
Options for intracellular conductivity.
CepsString m_sigmaEOptions
Options for extracellulat conductivity.
const CepsSet< CepsAttribute > & getTissueAttributes() const
All attributes that localize tissue.
ScalarField< DegreeOfFreedom > * getCm() const
Link to Cm coefficient.
void initializeEquation() override
Initializes all the elements of the PDE from options.
ScalarField< DegreeOfFreedom > * getAm() const
Link to Am coefficient.
void defineSourceTerms() override
For cardiac problem, only calls initializeStimulation. Can be overriden.
void solve() override
Performs all iterations of the PDE solver.
Profiler * getProfiler() const
Access to profiler.
Definition: CepsObject.cpp:46
Bidomain equation with extracardiac medium main class.
CepsSet< CepsAttribute > getWholeDomainAttributes() const
Get all attributes: tissue and extracardiac.
CepsString m_biElecStimOpts
Anodal and cathodal stimulation parameters, disabled if empty.
Solver for a Poisson equation with Neumann BC (using 0 mean constraint)
void solve() override
Solve and postprocess.
void addEntry(const CepsString &label, ScalarEntry func)
Ads an entry to the map of scalar functions.
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
ParallelRCElectrode * getCathode() const
Ptr to cathode object.
ParallelRCElectrode * getAnode() const
Ptr to anode object.
Reads and stores simulation configuration.
CepsBool isActiveOption(const keyType &key) const
Tells if key exists in configuration and is of "1","YES","ON" or "TRUE".
PowerSupply(PacemakerBidomainProblem *problem)
constructor
CepsReal eval(CepsStandardArgs args) final
Evaluation function.
Bidomain equation with extracardiac medium and connected to a pacemaker main class.
CepsSet< CepsAttribute > getAnodeAttributes() const override
Get cathode attributes if set.
void setupWithParameters(InputParameters *params) override
Sets options from the parameters.
Unknown * getUAnodeUnknown() const override
Link to the Up unknown of the problem.
void defineSourceTerms() override
Define the source terms.
Unknown * getVCetsUnknown() const override
Link to the VCets unknown of the problem.
Unknown * getUCathodeUnknown() const override
Link to the Um unknown of the problem.
CepsSet< CepsAttribute > getCathodeAttributes() const override
Get cathode attributes if set.
PacemakerBidomainProblem(Geometry *g, InputParameters *=nullptr)
Constructor from geometry and possibly parameters.
Unknown * getVCtsUnknown() const override
Link to the VCts unknown of the problem.
void defineUnknowns() override
Transmembrane voltage (mV), Extracellular potential (mV) and both potential of the pacemaker.
void defineBoundaryConditions() override
Define the boundary conditions.
void run() override
Run the simulation.
void getInitialCondition(DHVecPtr v0) const override
Zero and fill with initial conditions for vm and ue, and put QCets to Cets*AmpStim.
Solves pacemaker bidomain problem with FBE, SBDF RK or CN schemes.
void stop(CepsString lbl)
Stops the measure of a labeled chronometer.
void start(CepsString lbl, CepsString dspl="")
Creates or continue a labeled chronometer.
void add(const CepsString &params, CepsBool computeSupport=false)
Add a source term from parameters.
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
Definition: Unknown.hpp:45
CepsUnknownIndex getIdentifier() const
Get the identifier of the unknown.
Definition: Unknown.cpp:82
CepsSet< CepsAttribute > & getAttributes()
Returns the attributes of the entity.
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
Definition: CepsString.hpp:409
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:257
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116
Structure used to pass arguments to SAFunc (see pde directory) The flags of the SAFunc allows extract...
Definition: CepsTypes.hpp:239
CepsUnknownIndex unknownId
unknown index
Definition: CepsTypes.hpp:247
static constexpr const char * VCts
Voltage on reserve capacitor.
static constexpr const char * ue
Extracellular and extracardiac potential.
static constexpr const char * UCathode
Potential of cathode (device side)
static constexpr const char * VCets
Voltage on tank capacitor.
static constexpr const char * UAnode
Potential of anode (device side)
static constexpr const char * vm
Transmebrane voltage.