CEPS  24.01
Cardiac ElectroPhysiology Simulator
runConvergence.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 
33 template<typename PbType>
34 void
36 {
37  InputParameters* p = cs->getParameters();
38  CepsString base = ceps::getBaseName(p->getString("output file name"));
39  CepsString dir = ceps::getDir (p->getString("output file name"));
40  if (p->hasKey("activation time data"))
41  {
42  CepsString dir2 = dir + "/snapshots/";
43  CepsString amap = dir2 + base + "_APD-0";
44  CepsString ext = (ceps::fileExists(amap+".pvtu")) ? ".pvtu" : ".vtk";
45  CepsString command = "cp " + amap + ext + " " + dir + "/" + base + "_APD_"
46  + ceps::toString(dt) + "_" + ceps::toString(hmax) + ext;
47  ceps::execute(command);
48  }
49  if (p->hasKey("probe points"))
50  {
51  CepsString command = "cp " + dir + "/" + base + "_probes.dat "
52  + dir + "/" + base + "_probes_" + ceps::toString(dt) + "_" + ceps::toString(hmax) + ".dat";
53  ceps::execute(command);
54  }
55  return;
56 }
57 
58 template<typename PbType>
59 void
61 {
62  ConvergenceStudy<PbType>* cs = ceps::getNew<ConvergenceStudy<PbType>>(p,refSol);
63 
64  // Set callback if required
65  if (copyMap and ceps::isMaster()) {
66  // // Callback method for cardiac convergence tests that copies the activation map in the top directory
67  // // When this function is called, the output directory is already set to dir/cvNum/
68  std::function<void(ConvergenceStudy<PbType>*,CepsReal,CepsReal)> copyFunc = copyActivationMap<PbType>;
69  cs->setCallBackMethod(copyFunc);
70  }
71 
72  // Run the convergence analysis
73 
74  cs->run();
75 
77 }
78 
79 void
81 {
82  CepsString s = ceps::toKey(p->getString("problem type"));
83  if (s == ceps::toKey("dirichlet anode cathode"))
84  runConvergenceT<DirichletAnodeCathodeProblem>(p);
85  else if (s == ceps::toKey("flux anode cathode"))
86  runConvergenceT<FluxAnodeCathodeProblem>(p);
87  else if (s == ceps::toKey("monodomain"))
88  runConvergenceT<MonodomainProblem>(p,true,true);
89  else if (s == ceps::toKey("cl monodomain"))
90  runConvergenceT<CLMonodomainProblem>(p,true,true);
91  else if (s == ceps::toKey("bidomain"))
92  runConvergenceT<BidomainProblem>(p,true,true);
93  else if (s == ceps::toKey("extended bidomain"))
94  runConvergenceT<ExtendedBidomainProblem>(p, true, true);
95  else if (s == ceps::toKey("bilayer monodomain"))
96  runConvergenceT<BilayerMonodomainProblem>(p,true,true);
97  else if (s == ceps::toKey("pacemaker bidomain"))
98  runConvergenceT<PacemakerBidomainProblem>(p, true, true);
99  else if (s == ceps::toKey("pacemaker poisson"))
100  runConvergenceT<PacemakerPoissonProblem>(p, true, true);
101  else
102  CEPS_ABORT(
103  "Unknown type of problem " << s << "\n" <<
104  " Valid types are:\n" << validProblems
105  );
106 
107  return;
108 }
constexpr const char * validProblems
Definition: AllProblems.hpp:43
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
Generic class that regroups common elements of convergence studies.
void setCallBackMethod(std::function< void(ConvergenceStudy< PdeProblem_t > *, CepsReal, CepsReal)>)
Determines the method that is called after computation of each numerical solution.
void run()
Runs the study.
InputParameters * getParameters() const
Link to parameters.
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.
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
Definition: CepsString.cpp:521
CepsString execute(CepsString command, CepsBool withErr=false, CepsBool abortOnErr=false)
Not really a parallel thing. Calls system() and deals with return code.
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
Definition: CepsString.hpp:409
CepsString toKey(const CepsString &s)
Transform to key type a std::string, upper case and no spaces.
Definition: CepsString.cpp:157
CepsBool isMaster()
Is calling process the master ?
CepsString getBaseName(const CepsString &str)
Extracts the base of a file name, without path, nor extension. Ex: getBaseName("/path/to/myfile....
Definition: CepsString.cpp:563
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
Definition: CepsString.cpp:595
void doConvergence(InputParameters *p)
Runs a convergence analysis Problem type deduced from input string in InputParameters.
void runConvergenceT(InputParameters *p, CepsBool refSol, CepsBool copyMap)
Runs a convergence analysis; templated on problem type.
void copyActivationMap(ConvergenceStudy< PbType > *cs, CepsReal dt, CepsReal hmax)
Callback functions that saves activation maps from cvNum directory to avoid overwriting.