CEPS  24.01
Cardiac ElectroPhysiology Simulator
AllIonicModels.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 
35  CepsString ionOpts,
36  InputParameters* params,
37  AbstractPdeProblem* pb,
39  const CepsSet<CepsAttribute>& tissueAttrs
40 )
41 {
42 
43  AbstractIonicModel* res = nullptr;
44 
45  std::stringstream ss(ionOpts);
46 
47  CepsString errorMessage =
48  CepsString(" Each ionic model input must have the following structure:\n") +
49  " - an integer for the unknown concerned by the model\n" +
50  " - a model name,\n" +
51  " - optionally, one or several integers for the attribute(s) of the region(s)\n" +
52  " in which to use this model,\n" +
53  " Given ionic model is: " + ionOpts;
54 
55  // Unknown
56  CepsUnknownIndex uId = ceps::readInt(ss,"Unable to read unknown identifier.\n" + errorMessage);
57  Unknown* u = pb->getUnknown(uId);
58 
60  CepsString type;
61  ss >> type ;
62  type = ceps::toUpper(type);
63 
64  while (not ss.eof())
65  {
66  CepsAttribute attr;
67  ss >> attr;
68  CEPS_ABORT_IF(prevAttrs[uId].contains(attr),
69  "Cannot assign ionic model " << type << " to region with attribute " << attr <<
70  " for unknown " << uId << " as another ionic model was assigned there"
71  );
72  prevAttrs[uId].insert(attr);
73  attrs.insert(attr);
74  }
75 
76  if (attrs.empty())
77  attrs = tissueAttrs;
78 
79  if (type == "TENTUSSCHER2006_ENDO" or type == "TTP06_ENDO")
80  res = ceps::getNew<TTP06>(TTP06::Type::Endo,u,attrs,params);
81 
82  else if (type == "TENTUSSCHER2006_MIDMYO" or type == "TTP06_MIDMYO")
83  res = ceps::getNew<TTP06>(TTP06::Type::MidMyo,u,attrs,params);
84 
85  else if (type == "TENTUSSCHER2006_EPI" or type == "TTP06_EPI")
86  res = ceps::getNew<TTP06>(TTP06::Type::Epi,u,attrs,params);
87 
88  else if (type == "MS" or type == "MS03")
89  res = ceps::getNew<MS03>(u,attrs,params);
90 
91  else if (type == "MS_MODIFIED" or type == "MS03_MODIFIED")
92  res = ceps::getNew<MS03Modified>(u,attrs,params);
93 
94  else if (type == "AP" or type == "AP95")
95  res = ceps::getNew<AP95>(u,attrs,params);
96 
97  else if (type == "CRN" or type == "CRN98")
98  res = ceps::getNew<CRN98>(u,attrs,params);
99 
100  else if (type == "BEELERREUTER" or type == "BR77")
101  res = ceps::getNew<BR77>(u,pb,attrs,params);
102 
103  else if (type == "BR_MODIFIED" or type == "BR77_MODIFIED")
104  res = ceps::getNew<BR77Modified>(u,pb,attrs,params);
105 
106  else if (type == "ORDMD16_ENDO")
107  res = ceps::getNew<ORdmD16>(ORdmD16::Type::Endo,u,attrs,params);
108 
109  else if (type == "ORDMD16_EPI")
110  res = ceps::getNew<ORdmD16>(ORdmD16::Type::Epi,u,attrs,params);
111 
112  else if (type == "ORDMD16_MIDMYO")
113  res = ceps::getNew<ORdmD16>(ORdmD16::Type::MidMyo,u,attrs,params);
114 
115  else
116  CEPS_ABORT ("Unknown ionic model type \"" << type << "\"\n" <<
117  " Valid types are\n" <<
118  " - TenTusscher2006_Endo (or TTP06_Endo)\n" <<
119  " - TenTusscher2006_MidMyo (or TTP06_MidMyo)\n" <<
120  " - TenTusscher2006_Epi (or TTP06_Epi)\n" <<
121  " - ORdmD16_Endo\n" <<
122  " - ORdmD16_MidMyo\n" <<
123  " - ORdmD16_Epi\n" <<
124  " - MS (or MS03)\n" <<
125  " - MS_Modified (or MS03_Modified)\n" <<
126  " - AP (or AP95)\n" <<
127  " - CRN (or CRN98)\n" <<
128  " - BeelerReuter (or BR77)\n" <<
129  " - BR_Modified (or BR77_Modified)"
130  );
131 
132  if (not tissueAttrs.empty())
133  CEPS_SAYS("Added ionic model " << type << " to region with attributes " << attrs);
134 
135  return res;
136 }
AbstractIonicModel * getIonicModelFromString(CepsString ionOpts, InputParameters *params, AbstractPdeProblem *pb, CepsMap< CepsUnknownIndex, CepsSet< CepsAttribute >> &prevAttrs, const CepsSet< CepsAttribute > &tissueAttrs)
Obtain a new instance of ionic model from input string.
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#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::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
CepsIndex CepsUnknownIndex
For unknowns.
Definition: CepsTypes.hpp:217
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
CepsInt CepsAttribute
Used to define regions.
Definition: CepsTypes.hpp:215
Represents a ionic model for a group of cells, i.e. multiple systems of ODEs.
Base class for creating PDEs to solve.
Unknown * getUnknown(const CepsString &label) const
Get an unknown by its name.
Reads and stores simulation configuration.
@ Epi
Model variant selector.
@ MidMyo
Model variant selector.
@ Endo
Model variant selector.
@ Epi
Model variant selector.
@ MidMyo
Model variant selector.
@ Endo
Model variant selector.
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 contains(const CepsVector< _Type, _Alloc > &vec, const _Type &item)
Tells if vectors contains a given item.
Definition: CepsVector.hpp:56
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
Definition: CepsString.cpp:677
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
Definition: CepsString.cpp:124