hemocell
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1/*
2This file is part of the HemoCell library
3
4HemoCell is developed and maintained by the Computational Science Lab
5in the University of Amsterdam. Any questions or remarks regarding this library
6can be sent to: info@hemocell.eu
7
8When using the HemoCell library in scientific work please cite the
9corresponding paper: https://doi.org/10.3389/fphys.2017.00563
10
11The HemoCell library is free software: you can redistribute it and/or
12modify it under the terms of the GNU Affero General Public License as
13published by the Free Software Foundation, either version 3 of the
14License, or (at your option) any later version.
15
16The library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Affero General Public License for more details.
20
21You should have received a copy of the GNU Affero General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24#ifndef HEMOCELL_CONFIG_H
25#define HEMOCELL_CONFIG_H
26
27#include "profiler.h"
28
29#include "external/tinyxml2/tinyxml2.h"
30#include "constant_defaults.h"
31#include "error.h"
32#include <string>
33#include <iostream>
34#include <sstream>
35#include <stdexcept>
36
37namespace hemo {
38
40 tinyxml2::XMLElement * orig;
41
42public:
43 XMLElement(tinyxml2::XMLElement * orig_) : orig(orig_) {}
47 XMLElement operator[](std::string name) const;
48
61 template <typename T>
62 T read() {
63 const char * text = orig->GetText();
64 if (!text) { throw std::invalid_argument(where() + " is empty."); }
65 T ret = T();
66 if (!parseValue(text, ret)) { throw std::invalid_argument(where() + ": cannot convert \"" + text + "\"."); }
67 return ret;
68 }
69
70 tinyxml2::XMLElement * getOrig() { return orig; }
71
73 std::string path() const;
74
75private:
77 std::string where() const;
78
79 template <typename V>
80 static bool parseValue(const std::string & text, V & value) {
81 std::istringstream stream(text);
82 if (!(stream >> value)) { return false; }
83 stream >> std::ws;
84 return stream.eof(); // nothing but whitespace may follow the value
85 }
86 static bool parseValue(const std::string & text, bool & value);
87 static bool parseValue(const std::string & text, std::string & value);
88};
89
90
91class Config {
92 tinyxml2::XMLDocument * orig;
95 std::string fileName;
96
97public:
99 bool checkpointed = false;
100
101 Config(std::string paramXmlFilename);
102 ~Config();
103
104 void reload(std::string paramXmlFilename);
105
106 hemo::XMLElement operator[](std::string name) const;
107
108 tinyxml2::XMLNode * ShallowClone(tinyxml2::XMLDocument * document) const;
109 bool ShallowEqual(const tinyxml2::XMLNode * compare) const;
110 bool Accept(tinyxml2::XMLVisitor * visitor) const;
111
112private:
113 void load(std::string paramXmlFilename);
114};
115
116void loadDirectories(hemo::Config * cfg, bool edit_out_dir = true);
117
125 bool cellsDeletedInfo = false;
126
127 bool enableCEPACfield = false;
128
130
132
133 std::string checkpointDirectory = "./checkpoint/";
134
136};
137
138extern ConfigValues global;
139
144}
145#endif
Definition config.h:91
bool Accept(tinyxml2::XMLVisitor *visitor) const
void load(std::string paramXmlFilename)
Definition config.cpp:47
tinyxml2::XMLDocument * orig
Definition config.h:92
bool ShallowEqual(const tinyxml2::XMLNode *compare) const
void reload(std::string paramXmlFilename)
Definition config.cpp:42
bool checkpointed
True if the root element is Checkpoint (a checkpoint.xml written by HemoCell).
Definition config.h:99
~Config()
Definition config.cpp:72
tinyxml2::XMLNode * ShallowClone(tinyxml2::XMLDocument *document) const
std::string fileName
Definition config.h:95
hemo::XMLElement operator[](std::string name) const
Definition config.cpp:81
Definition profiler.h:47
Definition config.h:39
std::string path() const
Path of this element from the root, e.g. hemocell/sim/tmax.
Definition config.cpp:123
T read()
Read the text of this element as a value of type T.
Definition config.h:62
XMLElement(tinyxml2::XMLElement *orig_)
Definition config.h:43
static bool parseValue(const std::string &text, V &value)
Definition config.h:80
std::string where() const
"<file>, line <n>: <path>" of this element, for error messages.
Definition config.cpp:131
tinyxml2::XMLElement * orig
Definition config.h:40
tinyxml2::XMLElement * getOrig()
Definition config.h:70
XMLElement operator[](std::string name) const
Definition config.cpp:113
double T
Definition constant_defaults.h:137
Definition config.cpp:37
ConfigValues global
Definition config.cpp:204
void loadDirectories(hemo::Config *cfg, bool edit_out_dir)
Definition config.cpp:136
void resetGlobalConfigValues()
Definition config.cpp:206
void loadGlobalConfigValues(hemo::Config *cfg)
Definition config.cpp:216
Definition config.h:121
bool cellsDeletedInfo
Definition config.h:125
bool enableSolidifyMechanics
Definition config.h:129
std::string checkpointDirectory
Definition config.h:133
Profiler statistics
Definition config.h:135
bool hemoCellInitialized
Definition config.h:124
bool enableInteriorViscosity
Definition config.h:131
bool enableCEPACfield
Definition config.h:127