version 3.10-dev
parameters.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_PARAMETERS_HH
13#define DUMUX_PARAMETERS_HH
14
15#include <iostream>
16#include <list>
17#include <sstream>
18#include <unordered_map>
19#include <fstream>
20#include <functional>
21
22#include <dune/common/parametertree.hh>
23
26
27namespace Dumux {
28
35
36 using DefaultParams = std::function<void (Dune::ParameterTree&)>;
37 using Usage = std::function<void (const char *, const std::string &)>;
38
39public:
40
42 static void init(int argc, char **argv, const Usage& usage);
43
45 static void init(int argc, char **argv,
46 std::string parameterFileName,
47 const Usage& usage = [](const char *, const std::string &){});
48
50 static void init(int argc, char **argv,
51 const DefaultParams& defaultParams,
52 const Usage& usage);
53
70 static void init(int argc, char **argv,
71 const DefaultParams& defaultParams = [] (Dune::ParameterTree&) {},
72 std::string parameterFileName = "",
73 const Usage& usage = [](const char *, const std::string &){});
74
82 static void init(const DefaultParams& params = [] (Dune::ParameterTree&) {},
83 const DefaultParams& defaultParams = [] (Dune::ParameterTree&) {});
84
96 static void init(const std::string& parameterFileName,
97 const DefaultParams& params = [] (Dune::ParameterTree&) {},
98 bool inputFileOverwritesParams = true,
99 const DefaultParams& defaultParams = [] (Dune::ParameterTree&) {});
100
102 static void print();
103
105 static Dune::ParameterTree parseCommandLine(int argc, char **argv);
106
112 static const LoggingParameterTree& getTree();
113
114private:
116 static Dune::ParameterTree& paramTree_();
117
119 static Dune::ParameterTree& defaultParamTree_();
120
123 static void applyGlobalDefaults_(Dune::ParameterTree& params);
124
126 static void mergeTree_(Dune::ParameterTree& target, const Dune::ParameterTree& source, bool overwrite = true);
127
129 static void mergeTreeImpl_(Dune::ParameterTree& target, const Dune::ParameterTree& source, bool overwrite, const std::string& group);
130};
131
138template<typename T = std::string, typename... Args>
139T getParam(Args&&... args)
140{ return Parameters::getTree().template get<T>(std::forward<Args>(args)... ); }
141
148template<typename T = std::string, typename... Args>
149T getParamFromGroup(Args&&... args)
150{ return Parameters::getTree().template getFromGroup<T>(std::forward<Args>(args)... ); }
151
157inline bool hasParam(const std::string& param)
158{ return Parameters::getTree().hasKey(param); }
159
165inline bool hasParamInGroup(const std::string& paramGroup, const std::string& param)
166{ return Parameters::getTree().hasKeyInGroup(param, paramGroup); }
167
173inline std::vector<std::string> getParamSubGroups(const std::string& subGroupName, const std::string& paramGroup)
174{ return Parameters::getTree().getSubGroups(subGroupName, paramGroup); }
175
176} // end namespace Dumux
177
178#endif
A parameter tree that logs which parameters have been used.
Definition: loggingparametertree.hh:31
std::vector< std::string > getSubGroups(const std::string &subGroupName, std::string groupPrefix) const
obtain a vector of all full group names for a specified subgroup name
Definition: loggingparametertree.hh:121
bool hasKeyInGroup(const std::string &key, const std::string &groupPrefix) const
test for key in group
Definition: loggingparametertree.hh:78
bool hasKey(const std::string &key) const
test for key
Definition: loggingparametertree.hh:60
Parameter class managing runtime input parameters.
Definition: parameters.hh:34
static const LoggingParameterTree & getTree()
Get the parameter tree.
Definition: parameters.cc:211
static void print()
prints all used and unused parameters
Definition: parameters.cc:164
static void init(int argc, char **argv, const Usage &usage)
Initialize the parameter tree singletons.
Definition: parameters.cc:33
static Dune::ParameterTree parseCommandLine(int argc, char **argv)
Parse command line arguments into a parameter tree.
Definition: parameters.cc:170
Function printing a default usage message.
std::vector< std::string > getParamSubGroups(const std::string &subGroupName, const std::string &paramGroup)
Get a list of sub groups from the parameter tree sorted by relevance.
Definition: parameters.hh:173
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition: parameters.hh:149
bool hasParamInGroup(const std::string &paramGroup, const std::string &param)
Check whether a key exists in the parameter tree with a model group prefix.
Definition: parameters.hh:165
bool hasParam(const std::string &param)
Check whether a key exists in the parameter tree.
Definition: parameters.hh:157
T getParam(Args &&... args)
A free function to get a parameter from the parameter tree singleton.
Definition: parameters.hh:139
A parameter tree that logs which parameters have been used.
Definition: adapt.hh:17