CEPS  24.01
Cardiac ElectroPhysiology Simulator
ceps.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 #include <unistd.h>
33 
35 
38 void
40 {
41  CEPS_SAYS("Single run detected");
42 
43  AbstractPdeProblem* pb = nullptr;
44 
45  CepsString s = ceps::toKey(p->getString("problem type"));
46  if (s == ceps::toKey("laplacian"))
47  pb = ceps::getNew<LaplacianProblem>(g,p);
48  else if (s == ceps::toKey("dirichlet anode cathode"))
49  pb = ceps::getNew<DirichletAnodeCathodeProblem>(g,p);
50  else if (s == ceps::toKey("flux anode cathode"))
51  pb = ceps::getNew<FluxAnodeCathodeProblem>(g,p);
52  else if (s == ceps::toKey("heat"))
53  pb = ceps::getNew<HeatProblem>(g,p);
54  else if (s == ceps::toKey("monodomain"))
55  pb = ceps::getNew<MonodomainProblem>(g,p);
56  else if (s == ceps::toKey("cl monodomain"))
57  pb = ceps::getNew<CLMonodomainProblem>(g,p);
58  else if (s == ceps::toKey("bidomain"))
59  pb = ceps::getNew<BidomainProblem>(g,p);
60  else if (s == ceps::toKey("extended bidomain"))
61  pb = ceps::getNew<ExtendedBidomainProblem>(g,p);
62  else if (s == ceps::toKey("bilayer monodomain"))
63  pb = ceps::getNew<BilayerMonodomainProblem>(g,p);
64  else if (s == ceps::toKey("pacemaker bidomain"))
65  pb = ceps::getNew<PacemakerBidomainProblem>(g,p);
66  else if (s == ceps::toKey("pacemaker poisson"))
67  pb = ceps::getNew<PacemakerPoissonProblem>(g,p);
68  else
69  CEPS_ABORT(
70  "Unknown type of problem " << s << "\n" <<
71  " Valid types are:\n" << validProblems
72  );
73 
74  pb->run();
76 
77  return;
78 
79 }
80 
81 int
82 main(int argc,CepsChar *argv[])
83 {
84 
85  ceps::initialize(argc,argv);
86  {
87  if (argc == optind)
88  {
89  flags->printHelp(argv);
90  return 0;
91  }
92  InputParameters p(argv[optind]);
93 
94  // Copy parameters file into output directory
95  CepsString outDir = ceps::getDir(p("output file name"));
96  CepsString inDir = ceps::getDir(argv[optind]);
97  CepsString oldFile = inDir + "/" + ceps::getFilename(argv[optind]);
98  CepsString newFile = outDir + "/" + ceps::getFilename(argv[optind]);
99  if (ceps::isMaster() and oldFile != newFile)
100  {
101  CepsString cpCommand = CepsString("mkdir -p ") + outDir + " 2>/dev/null && "
102  + "rm " + newFile + " 2>/dev/null && "
103  + "cp -f " + argv[optind] + " " + newFile;
104  system(cpCommand.c_str());
105  }
106 
108 
109  if (p.hasKey("convergence 3d meshes")
110  or p.hasKey("convergence 2d meshes")
111  or p.hasKey("convergence 1d meshes"))
112  doConvergence(&p);
113  else
114  {
115  Geometry g(&p);
116  doSingleRun(&p,&g);
117  }
118  }
119 
120  return 0;
121 }
122 
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.
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_SEPARATOR
Writes a separator in the debug log and in the terminal.
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
char CepsChar
Char.
Definition: CepsTypes.hpp:125
Flags * flags
Global variable, used in every application.
Definition: ceps.cpp:34
void doSingleRun(InputParameters *p, Geometry *g)
Runs a single simulation Problem type deduced from input string in InputParameters.
Definition: ceps.cpp:39
int main(int argc, CepsChar *argv[])
Definition: ceps.cpp:82
Base class for creating PDEs to solve.
virtual void run()
Computes the solution to the problem. Default does nothing, override it !
Management of run options.
Definition: CepsFlags.hpp:54
void printHelp(CepsChar **argv)
Display info on how to type in command line.
Definition: CepsFlags.cpp:207
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.
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 getFilename(const CepsString &str)
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone...
Definition: CepsString.cpp:556
CepsString toKey(const CepsString &s)
Transform to key type a std::string, upper case and no spaces.
Definition: CepsString.cpp:157
CepsUInt initialize(int argc, char *argv[])
Initializes parallel environment.
CepsBool isMaster()
Is calling process the master ?
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116
void doConvergence(InputParameters *p)
Runs a convergence analysis Problem type deduced from input string in InputParameters.