CEPS  24.01
Cardiac ElectroPhysiology Simulator
PacemakerBidomainSolver.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 
39 
41  ExtendedBidomainSolver (problem),
42  AbstractPacemakerSolver(problem,problem->getParameters())
43 {
44  // renew the time stepper with a variable one
46  m_timeStepper = ceps::getNew<VariableTimeStepper>(
47  problem->getStartTime(), problem->getEndTime(), problem->getTimeStep()
48  );
49 
51  {
52  m_timeWriter->addCustomData("Current I (uA)", &m_current);
53  m_timeWriter->addCustomData("Measured voltage (mV)", &m_Vcroco);
54  m_timeWriter->addCustomData("Mean of ue on anode (mV)", &m_meanOfPotentialOnAnode);
55  m_timeWriter->addCustomData("Mean of ue on cathode (mV)", &m_meanOfPotentialOnCathode);
57  }
58 }
59 
60 void
62 {
63  auto pbpb = getPacemakerBidomainProblem();
64  m_opAsb = ceps::getNew<FEPacemakerBidomainAssembler>(pbpb, m_fe);
65  m_bcAsb = ceps::getNew<FECardiacBCAssembler>(pbpb,CepsSet<CepsAttribute>({CepsUniversal}),m_fe);
66 }
67 
70 {
71  return ceps::runtimeCast<PacemakerBidomainProblem*>(getTimedProblem());
72 }
73 
74 void
76 {
77 
78  CepsReal time = m_timeStepper->getTime();
79  CepsReal previous = m_timeStepper->getTimeStep();
80  CepsReal dt = getRequiredTimeStep(time,getPacemakerBidomainProblem()->getTimeStep());
81 
82  if (not ceps::equals(previous,dt))
84 
86 
87  // Compute addition values
88  auto pb = getPacemakerBidomainProblem();
89  auto anode = pb->getAnode();
90  auto cathode = pb->getCathode();
91  auto ue = pb->getUeUnknown();
93  m_Vcroco = getAlligatorVoltage(m_uNp1, m_fe, time + dt);
96  m_phase = static_cast<CepsReal>(pb->getPhase(time));
97  #ifdef CEPS_DEBUG_ENABLED
98  ceps::checkNanOrInf(m_current ,"pacemaker current" );
99  ceps::checkNanOrInf(m_Vcroco ,"voltage between clips" );
100  ceps::checkNanOrInf(m_meanOfPotentialOnAnode ,"mean anode potential" );
101  ceps::checkNanOrInf(m_meanOfPotentialOnCathode,"mean cathode potential");
102  #endif
103 }
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
Solves pacemaker bidomain problem with FBE, SBDF RK or CN schemes.
CepsReal getPacemakerCurrent(DHVecPtr sol, AbstractDiscretization *disc, CepsReal time) const
Compute the current pacemaker current I in uA.
CepsReal m_Vcroco
Register for measured voltage.
CepsReal m_meanOfPotentialOnAnode
Register for an integral value on anode.
CepsReal getMeanOnElectrodeOf(DHVecPtr sol, Unknown *u, FiniteElements *fe, ParallelRCElectrode *e) const
Integrate the unknown u on the electrode e.
CepsReal getAlligatorVoltage(DHVecPtr sol, AbstractDiscretization *disc, CepsReal time) const
Compute the alligator voltage in mV.
CepsReal m_phase
Which phase of pulse delivery.
CepsReal m_meanOfPotentialOnCathode
Register for an integral value on cathode.
CepsReal m_current
Register for pacemaker current in uA.
CepsReal getRequiredTimeStep(CepsReal t, CepsReal defTimeStep=1E12) const
Get the required time step for this time (phase deduced from the time)
AbstractAssembler * m_bcAsb
Assembler for Robin and Neumann BCs.
TimeWriter * m_timeWriter
Writer for time dependant data (even for static problems...)
AbstractAssembler * m_opAsb
Assembler for the operator matrix.
CepsReal getTimeStep() const
pde time step
CepsReal getEndTime() const override
pde end time
CepsReal getStartTime() const override
pde start time
TimeStepper * m_timeStepper
Monitors time evolution.
AbstractTimedPdeProblem * getTimedProblem() const
Returns a pointer with the appropriate type of pb.
DHVecPtr m_uNp1
Vectors of unknowns at time t^n+1.
void assembleAndSolve() override
Performs one iteration of the solver.
Solves bidomain extended problem with FBE, SBDF RK or CN schemes.
FiniteElements * m_fe
Geometry and reference FE.
Bidomain equation with extracardiac medium and connected to a pacemaker main class.
PacemakerBidomainProblem * getPacemakerBidomainProblem() const
Converts own pointer to abstract pde problem to cardiac problem.
void assembleAndSolve() override
Main routine used during solving, assemble the system depending on the scheme and solve the linear sy...
void initializeAssemblers() override
Sets the assemblers.
PacemakerBidomainSolver(PacemakerBidomainProblem *problem)
Constructor from problem.
CepsReal getTimeStep() const
Time step.
Definition: TimeStepper.cpp:95
virtual CepsReal getTime()
current simulation time
virtual void setTimeStep(CepsReal timeStep)
Set time step.
Definition: TimeStepper.cpp:76
void addCustomData(const CepsString &name, CepsReal *data)
Add a custom data to be written in the outputfile. Custom data cannot be added after header has been ...
Definition: TimeWriter.cpp:72
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
void checkNanOrInf(CepsReal v, CepsString message="")
Stops if value is NaN or infty.
CepsBool equals(CepsReal a, CepsReal b, CepsReal error=1.0)
CepsReal equality up to machine precision.
Definition: Precision.hpp:54
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116