CEPS  24.01
Cardiac ElectroPhysiology Simulator
PacemakerPoissonProblem.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 {}
41 
44 {
45  PacemakerPoissonProblem* pb = ceps::runtimeCast<PacemakerPoissonProblem*>(m_problem);
46 
47  if (args.unknownId == pb->getVCetsUnknown()->getIdentifier())
49  return 0.0;
50 }
51 
53  HeatProblem(g, params),
54  AbstractPacemakerProblem(g, params)
55 {
56  setProblemName("Poisson connected to a Pacemaker");
57 
58  if (ceps::isValidPtr(params))
60 }
61 
62 void
64 {
65  v0->zero();
67 
68  // auto QCetsDof = m_discr->getDegreesOfFreedomForUnknown(m_unknowns[4])[0];
69  // if (QCetsDof->getOwner() == ceps::getRank())
70  // {
71  // v0->getLocalData();
72  // (*v0)[QCetsDof->getGlobalIndex()] = m_pmkCets * m_stimAmplitude;
73  // v0->releaseLocalData();
74  // }
75 }
76 
77 void
79 {
80  addUnknown(UnknownsName::u, {CepsUniversal}); // ue is defined everywhere
81 
82  // the 0D unknowns "potential"
85 
86  // and the 0D unknowns
89 
96 
99 }
100 
101 void
103 {}
104 
105 void
107 {
109 
110  m_functions->addEntry("capaChargeFunc", ceps::getNew<PowerSupply>(this));
112  "__power_supply capaChargeFunc UNKNOWN " //
113  + ceps::toString(getVCetsUnknown()->getIdentifier())
114  );
115 }
116 
117 void
119 {
120  if (ceps::isProfiling())
121  getProfiler()->start("whole", "solving the bidomain problem");
122 
124 
125  // Solve the static problem
126  if (m_parameters->isActiveOption("compute electric field"))
127  {
128  auto spb = ceps::getNew<FluxAnodeCathodeProblem>(m_geom,m_parameters);
129  spb->getFunctionDictionary()->deleteTensor("physCoeffSigma");
130  spb->getFunctionDictionary()->addConstant("physCoeffSigma", m_k);
131  spb->setOutputFileBase(spb->getOutputFileBase() + "_elec_field");
132  spb->initializeEquation();
133 
134  FluxAnodeCathodeSolver ssolver(spb);
135  ssolver.solve();
136  ceps::destroyObject(spb);
137  }
138 
139  PacemakerPoissonSolver solver(this);
140 
141  solver.solve();
142 
143  if (hasAnalyticSolution())
144  m_errors = solver.getErrors();
145 
146  if (ceps::isProfiling())
147  getProfiler()->stop("whole");
148 }
149 
152 {
153  return getAnode()->getAttributes();
154 }
155 
158 {
159  return getCathode()->getAttributes();
160 }
161 
162 Unknown*
164 {
165  return getUnknown(UnknownsName::u);
166 }
167 
168 Unknown*
170 {
172 }
173 
174 Unknown*
176 {
178 }
179 
180 Unknown*
182 {
184 }
185 
186 Unknown*
188 {
190 }
191 
192 void
194 {
195  return;
196 }
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
constexpr CepsAttribute CepsUniversal
This attribute means "everywhere".
Definition: CepsTypes.hpp:232
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.
virtual void getInitialCondition(DHVecPtr v) const
Build vector from function pointed by m_initialCondition.
void initializeEquation() override
Initializes equations (unknowns, bc, source term) and creates the spatial discretization This method ...
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > m_errors
Will store Linf, L1 and L2 relative errors.
void solve() override
Solves the all PDE (all iterations)
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > getErrors() const
Gets the currently computed errors. First index selects absolute(0) or relative(1) second index selec...
Profiler * getProfiler() const
Access to profiler.
Definition: CepsObject.cpp:46
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
Heat PDE, single unknown, constant diffusion coeff 1, homogeneous Neumann (no BC defined)
Definition: HeatProblem.hpp:36
CepsMathTensor m_k
Diffusion tensor.
Definition: HeatProblem.hpp:73
void defineSourceTerms() override
Lists the unknowns of the problem (one here)
Definition: HeatProblem.cpp:56
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(PacemakerPoissonProblem *problem)
constructor
CepsReal eval(CepsStandardArgs args) final
Evaluation function.
Bidomain equation with extracardiac medium and connected to a pacemaker main class.
Unknown * getVCtsUnknown() const override
Link to the VCts unknown of the problem.
Unknown * getUFieldUnknown() const
Link to the u unknown of the problem.
Unknown * getVCetsUnknown() const override
Link to the VCets unknown of the problem.
void run() override
Run the simulation.
Unknown * getUCathodeUnknown() const override
Link to the Um unknown of the problem.
void getInitialCondition(DHVecPtr v0) const override
Zero and fill with initial conditions for vm and ue, and put QCets to Cets*AmpStim.
void defineSourceTerms() override
Define the source terms.
CepsSet< CepsAttribute > getAnodeAttributes() const
Get cathode attributes if set.
void defineBoundaryConditions() override
Define the boundary conditions.
void defineUnknowns() override
Transmembrane voltage (mV), Extracellular potential (mV) and both potential of the pacemaker.
CepsSet< CepsAttribute > getCathodeAttributes() const
Get cathode attributes if set.
void setupWithParameters(InputParameters *params) override
Sets options from the parameters.
PacemakerPoissonProblem(Geometry *g, InputParameters *=nullptr)
Constructor from geometry and possibly parameters.
Unknown * getUAnodeUnknown() const override
Link to the Up unknown of the problem.
Solves pacemaker poisson 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 * UAnode
Potential of anode (device side)
static constexpr const char * VCts
Voltage on reserve capacitor.
static constexpr const char * u
Potential in computational domain.
static constexpr const char * UCathode
Potential of cathode (device side)
static constexpr const char * VCets
Voltage on tank capacitor.