10#include <dune/common/parametertree.hh>
11#include <dune/functions/functionspacebases/concepts.hh>
20 static void init(std::string
const& in);
30 std::enable_if_t<!std::is_arithmetic_v<T>,
int> = 0>
31 static std::optional<T>
get(std::string
const& key)
33 if (
pt().hasKey(key)) {
35 return getVector<T>(key);
37 return pt().get<T>(key);
44 std::enable_if_t<std::is_arithmetic_v<T>,
int> = 0>
45 static std::optional<T>
get(std::string
const& key) {
46 if (
pt().hasKey(key)) {
48 std::string valStr =
pt().get(key, aux);
49 return parseExpression<T>(valStr,key);
64 static void get(std::string
const& key, T& value) {
65 value = get<T>(key).value_or(value);
69 static void set(std::string
const& key, T
const& value)
83 static void clearData() {}
89 static Dune::ParameterTree&
pt()
95 void read(std::string
const& fn,
bool force =
false);
96 void write(std::string
const& fn);
103 static std::optional<T>
getVector(
const std::string& key) {
104 if constexpr (std::is_arithmetic_v<typename T::value_type>) {
106 std::vector<std::string> aux;
107 auto valStr =
pt().get(key, aux);
108 if constexpr(Dune::models<Dune::Functions::Concept::HasResize, T>())
109 result.resize(valStr.size());
111 assert(result.size() == valStr.size());
112 for (std::size_t i = 0; i < valStr.size(); ++i) {
113 result[i] = parseExpression<typename T::value_type,T>(valStr[i],key,i);
117 return pt().get<T>(key);
123 static bool parse(
const std::string& input, T& result) {
124 std::string inputSwap = input;
125 std::string allowedChars =
"+-*/()0123456789";
128 std::string notAllowed =
",abcdfghijklmnopqrstuvwxyzABCDFGHIJKLMNOPQRSTUVWXYZ";
129 std::size_t found = inputSwap.find_first_of(allowedChars);
130 std::size_t found2 = inputSwap.find_first_of(notAllowed);
133 if (found != std::string::npos && found2 == std::string::npos) {
134 parser.SetExpr(input);
135 result = parser.Eval();
142 static T parseExpression(
const std::string& input,
143 const std::string& key) {
145 if (
parse(input, result))
return result;
147 return pt().get<T>(key);
150 template<
typename T,
typename Container>
151 static T parseExpression(
const std::string& input,
152 const std::string& key,
155 if (
parse(input, result))
return result;
157 auto container =
pt().get<Container>(key);
162 template <
typename Container,
typename =
void>
165 template <
typename Container>
167 std::enable_if_t<std::is_arithmetic<typename Container::value_type>::value &&
168 !std::is_same<Container, std::string>::value>>
181 bool breakOnMissingTag_ =
false;
Definition Initfile.hpp:17
void read(std::string const &fn, bool force=false)
Fill an parametr-tree from a file with filename fn.
Definition Initfile.cpp:32
void getInternalParameters()
read standard values for output and information of parameter-values
Definition Initfile.cpp:38
static void get(std::string const &key, T &value)
Get parameter-values from parameter-tree with default value.
Definition Initfile.hpp:64
static int getMsgInfo()
Returns specified info level.
Definition Initfile.hpp:75
static std::optional< T > getVector(const std::string &key)
get Parameter values for vector types
Definition Initfile.hpp:103
static void printParameters()
print all data in singleton to std::cout
Definition Initfile.cpp:49
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition Initfile.hpp:31
Dune::ParameterTree pt_
ParameterTree to read/store parameter values.
Definition Initfile.hpp:184
static Initfile & singlett()
Return the singleton that contains the data.
Definition Initfile.hpp:173
static Dune::ParameterTree & pt()
Return the parameter-tree.
Definition Initfile.hpp:89
static bool parse(const std::string &input, T &result)
replace expression with the respective result
Definition Initfile.hpp:123
static void init(std::string const &in)
initialize singleton object and global parameters
Definition Initfile.cpp:25
Template for container types with [] operator and existing value_type.
Definition Initfile.hpp:163