CEPS  24.01
Cardiac ElectroPhysiology Simulator
PacemakerPoissonSolver.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  HeatSolver (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 u on anode (mV)", &m_meanOfPotentialOnAnode);
55  m_timeWriter->addCustomData("Mean of u on cathode (mV)", &m_meanOfPotentialOnCathode);
57  }
58 }
59 
60 // void
61 // PacemakerPoissonSolver::setupWithParameters(InputParameters* params)
62 // {
63 // }
64 
65 void
67 {
68  auto pb = getPacemakerPoissonProblem();
69 
70  auto opAsb = ceps::getNew<FEPacemakerPoissonAssembler>(pb, m_fe);
71  opAsb->setKForUnknown(pb->getUFieldUnknown(), pb->getDiffusionTensor());
72  m_opAsb = opAsb;
73 
74  m_bcAsb = ceps::getNew<FEDivKGradBCAssembler>(m_fe);
75 }
76 
79 {
80  return ceps::runtimeCast<PacemakerPoissonProblem*>(getTimedProblem());
81 }
82 
83 void
85 {
86  CepsReal time = m_timeStepper->getTime();
87  // CepsReal previous = m_timeStepper->getTimeStep();
88  CepsReal dt = getRequiredTimeStep(time,getPacemakerPoissonProblem()->getTimeStep());
89 
90  if (not ceps::equals(m_timeStepper->getTimeStep(), dt))
92 
94 
95  // Compute additionnal values
96  auto pb = getPacemakerPoissonProblem();
97  auto anode = pb->getAnode();
98  auto cathode = pb->getCathode();
99  auto u = pb->getUFieldUnknown();
100  m_current = getPacemakerCurrent(m_uNp1, m_fe, time + dt);
101  m_Vcroco = getAlligatorVoltage(m_uNp1, m_fe, time + dt);
104  m_phase = static_cast<CepsReal>(pb->getPhase(time + dt));
105 }
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
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
Main routine used during solving, assemble the system depending on the scheme and solve the linear sy...
FiniteElements * m_fe
Geometry and reference FE.
Solve heat equation.
Definition: HeatSolver.hpp:39
Bidomain equation with extracardiac medium and connected to a pacemaker main class.
void assembleAndSolve() override
Main routine used during solving, assemble the system depending on the scheme and solve the linear sy...
PacemakerPoissonSolver(PacemakerPoissonProblem *problem)
Constructor from problem.
PacemakerPoissonProblem * getPacemakerPoissonProblem() const
Converts own pointer to abstract pde problem to cardiac problem.
void initializeAssemblers() override
Sets the assemblers.
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
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