CEPS  24.01
Cardiac ElectroPhysiology Simulator
BilayerMonodomainProblem.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
32 
34  CardiacProblem(g,params),
35  m_couplingStr (200.),
36  m_couplingAttrs ({}),
37  m_couplingAttrNeg(false),
38  m_sigmaIOptions2 ("CONSTANT 1. 1. 1."),
39  m_sigmaEOptions2 ("CONSTANT 1. 1. 1."),
40  m_fibersOptions2 (""),
41  m_sigmaI2 (nullptr),
42  m_sigmaE2 (nullptr)
43 {
44  setProblemName("Bilayer Monodomain");
45 
46  if(ceps::isValidPtr(params))
48 
49  CEPS_SAYS(
50  "Bilayer model: elements " << (m_couplingAttrNeg ? "without":"with") <<
51  " attribute " << m_couplingAttrs << " will be coupled,\n" <<
52  "adding the equality " << m_couplingStr << "(u1-u2) = 0 to the original equation."
53  );
54 }
55 
56 void
58 {
61 }
62 
65 {
66  return {getTMVUnknown1(), getTMVUnknown2()};
67 }
68 
71 {
72  return getTMVUnknowns();
73 }
74 
75 Unknown*
77 {
79 }
80 
81 Unknown*
83 {
85 }
86 
89 {
90  return m_sigmaI2;
91 }
92 
95 {
96  return m_sigmaE2;
97 }
98 
99 void
101 {
102  if (ceps::isProfiling())
103  getProfiler()->start("whole","performing whole simulation (BilayerMonodomainProblem)");
104 
106 
107  BilayerMonodomainSolver solver(this);
108 
109  solver.solve();
110 
111  if (hasAnalyticSolution())
112  m_errors = solver.getErrors();
113 
114  if (ceps::isProfiling())
115  getProfiler()->stop("whole");
116 
117 }
118 
119 CepsReal
121 {
122  return m_couplingStr;
123 }
124 
127 {
128  return m_couplingAttrs;
129 }
130 
131 CepsBool
133 {
134  return m_couplingAttrNeg;
135 }
136 
137 void
139 {
140  // Creates reference sigmaI and sigmaE,
141  // then reorient sigmaI and sigmaE for first layer
145  m_sigmaI,
146  m_sigmaE,
148  );
149  // Second layer
153  m_sigmaI2,
154  m_sigmaE2,
156  "2"
157  );
158 
159 }
160 
161 void
163 {
164 
165  // Conductivities and fibers
169  ))
170  {
171  if (params->hasKey("sigma i layer "+v[2]))
172  m_sigmaIOptions = params->getString("sigma i layer "+v[2],v[0]);
173  else
174  m_sigmaIOptions = params->getString("intracellular conductivity layer "+v[2],v[0]);
175  if (params->hasKey("sigma e layer "+v[2]))
176  m_sigmaEOptions = params->getString("sigma e layer "+v[2],v[1]);
177  else
178  m_sigmaEOptions = params->getString("extracellular conductivity layer "+v[2],v[1]);
179  }
180 
181  m_fibersOptions = params->getString("fibers layer 1",m_fibersOptions2);
182  m_fibersOptions2 = params->getString("fibers layer 2",m_fibersOptions2);
183 
184  // Coupling
185  m_couplingStr = params->getReal("coupling strength",m_couplingStr);
186 
187  CepsVector<CepsString> ws = ceps::split(params->getString("coupling attribute"));
188  m_couplingAttrNeg = ceps::toUpper(ws[0])=="NOT";
189  if (m_couplingAttrNeg)
190  {
191  CEPS_ABORT_IF(ws.size()<2,
192  "BilayerParameters: could not read attribute of non-coupled elements"
193  );
194  for(CepsUInt i=1;i<ws.size();i++)
195  m_couplingAttrs.insert(ceps::toInt(ws[i]));
196  }
197  else
198  {
199  for(CepsUInt i=0;i<ws.size();i++)
200  m_couplingAttrs.insert(ceps::toInt(ws[i]));
201  CepsBool ok = m_tissueAttributes.empty() or m_tissueAttributes.contains(-1)
202  or m_couplingAttrs.contains(-1);
203 
204  for (CepsAttribute attr:m_couplingAttrs)
205  ok = ok or m_tissueAttributes.contains(attr);
206 
207  CEPS_ABORT_IF(not ok,
208  "Any of the given coupling attributes can not be found in the tissue attributes"
209  );
210  }
211 
212 }
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsInt CepsAttribute
Used to define regions.
Definition: CepsTypes.hpp:215
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
CepsBool hasAnalyticSolution() const
Tells if there is an analytic or reference solution.
void addUnknown(const CepsString &label, CepsSet< CepsAttribute > attrs={}, CepsLocationFlag flag=CepsLocationFlag::Point, const CepsString &unit="")
Register a new unknown.
Unknown * getUnknown(const CepsString &label) const
Get an unknown by its name.
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...
TensorField< GeomCell > * m_sigmaI2
Intracellular conductivity, defined on cells.
TensorField< GeomCell > * getSigmaE2() const
Link to extracellular conductivity.
BilayerMonodomainProblem(Geometry *g, InputParameters *=nullptr)
Constructor with input strings and geometry.
CepsBool m_couplingAttrNeg
true if given attribute is for UNcoupled elements
CepsVector< Unknown * > getTMVUnknowns() const override
Returns a vector containing all unknowns that are a TMV (especially useful for bilayer)
CepsString m_sigmaEOptions2
Extracellular conductivity parameters string for layer 2.
Unknown * getTMVUnknown1() const
Link to the single unknown of the problem.
CepsReal getCouplingStrength() const
coefficient that forces u1=u2 on coupled elements
void setupWithParameters(InputParameters *p) override
Initializes the problem from text input file.
CepsReal m_couplingStr
adds s*(u1-u2) on coupled elements
CepsString m_fibersOptions2
Text input description.
TensorField< GeomCell > * m_sigmaE2
Extracellulat conductivity, defined on cells.
TensorField< GeomCell > * getSigmaI2() const
Link to intracellular conductivity.
Unknown * getTMVUnknown2() const
Link to the single unknown of the problem.
CepsVector< Unknown * > getCardiacUnknowns() const override
Returns a vector containing all unknowns that are cardiac unknowns (eg. vm, ui or ue)
CepsSet< CepsAttribute > getCouplingAttributes() const
where to apply coupling
void defineUnknowns() override
A single unknown for transmembrane voltage.
CepsSet< CepsAttribute > m_couplingAttrs
where to apply coupling
CepsString m_sigmaIOptions2
Intracellular conductivity parameters string for layer 2.
void run() override
Run the simulation.
void initializeConductivities() override
Sets the myocardium with physical properties for both layers.
CepsBool getCouplingAttrNeg() const
true if given attribute if for UNcoupled elements
Monodomain solver on two atrial layers.
A abstract class that regroups common parameters of cardiac problems.
CepsString m_fibersOptions
Options for fiber orientation.
virtual void initializeConductivities()
Generates the functors that compute conductivity either from inputs or volume fraction.
CepsString m_sigmaIOptions
Options for intracellular conductivity.
TensorField< GeomCell > * m_sigmaI
Intracellular conductivity, defined on cells.
CepsString m_sigmaEOptions
Options for extracellulat conductivity.
CepsSet< CepsAttribute > m_tissueAttributes
Identifier for the tissue region, default {-1}.
TensorField< GeomCell > * m_sigmaE
Extracellulat conductivity, defined on cells.
void initializeEquation() override
Initializes all the elements of the PDE from options.
void solve() override
Performs all iterations of the PDE solver.
Profiler * getProfiler() const
Access to profiler.
Definition: CepsObject.cpp:46
A Field is an object wrapped around a SAFunc functor, defined on at least one domain.
Definition: Field.hpp:80
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
Reads and stores simulation configuration.
CepsBool hasKey(const keyType &key) const
Tells if key exists in input file.
CepsString getString(const keyType &key) const
Reads a CepsString from configuration.
CepsReal getReal(const keyType &key) const
Reads a floating point value from configuration.
void stop(CepsString lbl)
Stops the measure of a labeled chronometer.
void start(CepsString lbl, CepsString dspl="")
Creates or continue a labeled chronometer.
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
Definition: Unknown.hpp:45
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
Definition: CepsString.cpp:38
CepsInt toInt(const CepsString &s)
Cast CepsString to CepsInt.
Definition: CepsString.cpp:270
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
Definition: CepsString.cpp:124
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:257
static constexpr const char * vm1
Transmembrane voltage layer 1.
static constexpr const char * vm2
Transmembrane voltage layer 2.