CEPS  24.01
Cardiac ElectroPhysiology Simulator
AbstractTimedPdeProblem.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
34 
35 
37  Geometry* geom,
38  InputParameters* params
39 ):
40  AbstractPdeProblem(geom,params),
41  m_pdeStartTime(0.),
42  m_pdeEndTime(1.),
43  m_pdeTimeStep(0.1),
44  m_pdeSnapshotTime(0.1)
45 {
46  if (m_parameters)
48 }
49 
50 void
52 {
53  setTimes(params->getReal("pde start time",m_pdeStartTime),
54  params->getReal("pde end time" ,m_pdeEndTime ),
55  params->getReal("pde time step" ,m_pdeTimeStep ));
56  setSnapshotTime(params->getReal("output period",m_pdeSnapshotTime));
57 }
58 
61 {
62  return m_pdeStartTime;
63 }
64 
67 {
68  return m_pdeEndTime;
69 }
70 
73 {
74  return m_pdeTimeStep;
75 }
76 
77 void
79 {
80  m_pdeStartTime = std::min(tStart,tEnd);
81  m_pdeEndTime = std::max(tStart,tEnd);
82  m_pdeTimeStep = std::fabs(dt);
84  "Pde time step must be strictly positive"
85  );
86 }
87 
90 {
91  return m_pdeSnapshotTime;
92 }
93 
94 void
96 {
97  m_pdeSnapshotTime = std::abs(time);
99  "Pde output periodicity is lower than time step, output will be set to 1 per time step"
100  );
102  CEPS_ABORT_IF(ceps::equals(time,0.),
103  "Pde output periodicity must be strictly positive"
104  );
105 }
106 
107 void
109 {
110  m_initialCondition = nullptr;
111 }
112 
113 void
115 {
116  v->zero();
119 }
120 
121 void
123 {
125  this->defineInitialCondition();
126 }
127 
130 {
131  return m_errors;
132 }
133 
134 CepsBool
136 {
137  if (not hasAnalyticSolution())
138  return false;
139  if (m_refSolFiles.empty())
140  return true;
142  return std::abs(tt-std::round(tt)) < 1.e-3;
143 }
#define CEPS_WARNS_IF(condition, message)
If condition is true, writes a warning in the debug log and in the terminal (stderr).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
CepsArray< _Type, 2U > CepsArray2
C++ array, 2 elements.
Definition: CepsTypes.hpp:162
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
void evaluateFunctionOnDofs(ceps::Function< CepsReal(CepsStandardArgs)> *func, DHVecPtr v, CepsReal t=0.) const
Fills vector v with values of function func at owned and halo dofs and time t.
Base class for creating PDEs to solve.
CepsBool hasAnalyticSolution() const
Tells if there is an analytic or reference solution.
CepsString m_refSolFiles
base name of reference solution file, if any
AbstractDiscretization * m_discr
Discretization method (eg FE for now)
CepsReal m_refSolSnapDt
reference solution output period
InputParameters * m_parameters
Input file data.
virtual void initializeEquation()
Initializes equations (unknowns, bc, source term) and creates the spatial discretization This method ...
void setTimes(CepsReal tStart, CepsReal tEnd, CepsReal dt)
Define the start and end times, also time step.
CepsReal m_pdeTimeStep
Time Step for the PDE.
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > getErrors() const
Get the errors.
virtual void getInitialCondition(DHVecPtr v) const
Build vector from function pointed by m_initialCondition.
CepsReal getTimeStep() const
pde time step
AbstractTimedPdeProblem(Geometry *geom, InputParameters *params=nullptr)
Constructor with geometry and optional parameters.
CepsReal m_pdeStartTime
Initial time.
ScalarFunction * m_initialCondition
Function defining the initial condition, which is 0 if pointer is null.
void setupWithParameters(InputParameters *params) override
Set attributes from input file. Parameters are passed as arguments in case one wants to use other par...
void setSnapshotTime(CepsReal st)
Periodicity of outputs, in time units.
CepsReal getEndTime() const override
pde end time
void initializeEquation() override
Initializes equations (unknowns, bc, source term) and creates the spatial discretization This method ...
CepsReal getStartTime() const override
pde start time
CepsReal m_pdeSnapshotTime
Periodicity of outputs.
CepsBool canComputeErrorAtTime(CepsReal t) const
Tells if either analytic solution or reference solution has a snapshot at time t.
CepsReal getSnapshotTime() const override
Periodicity of outputs, in time units.
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > m_errors
Will store Linf, L1 and L2 relative errors.
virtual void defineInitialCondition()
Sets the pointer on function for initial guess. Here it is set to nullptr, so it will be 0.
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
Reads and stores simulation configuration.
CepsReal getReal(const keyType &key) const
Reads a floating point value from configuration.
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
Definition: CepsVector.hpp:464
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
Definition: CepsVector.hpp:448
CepsBool equals(CepsReal a, CepsReal b, CepsReal error=1.0)
CepsReal equality up to machine precision.
Definition: Precision.hpp:54