3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_PARAMETERS_HH
25#define DUMUX_PARAMETERS_HH
26
27#include <iostream>
28#include <list>
29#include <sstream>
30#include <unordered_map>
31#include <fstream>
32#include <functional>
33
34#include <dune/common/parametertree.hh>
35
38
39namespace Dumux {
40
47
48 using DefaultParams = std::function<void (Dune::ParameterTree&)>;
49 using Usage = std::function<void (const char *, const std::string &)>;
50
51public:
52
54 static void init(int argc, char **argv, const Usage& usage);
55
57 static void init(int argc, char **argv,
58 std::string parameterFileName,
59 const Usage& usage = [](const char *, const std::string &){});
60
62 static void init(int argc, char **argv,
63 const DefaultParams& defaultParams,
64 const Usage& usage);
65
82 static void init(int argc, char **argv,
83 const DefaultParams& defaultParams = [] (Dune::ParameterTree&) {},
84 std::string parameterFileName = "",
85 const Usage& usage = [](const char *, const std::string &){});
86
94 static void init(const DefaultParams& params = [] (Dune::ParameterTree&) {},
95 const DefaultParams& defaultParams = [] (Dune::ParameterTree&) {});
96
108 static void init(const std::string& parameterFileName,
109 const DefaultParams& params = [] (Dune::ParameterTree&) {},
110 bool inputFileOverwritesParams = true,
111 const DefaultParams& defaultParams = [] (Dune::ParameterTree&) {});
112
114 static void print();
115
117 static Dune::ParameterTree parseCommandLine(int argc, char **argv);
118
124 static const LoggingParameterTree& getTree();
125
126private:
128 static Dune::ParameterTree& paramTree_();
129
131 static Dune::ParameterTree& defaultParamTree_();
132
135 static void applyGlobalDefaults_(Dune::ParameterTree& params);
136
138 static void mergeTree_(Dune::ParameterTree& target, const Dune::ParameterTree& source, bool overwrite = true);
139
141 static void mergeTreeImpl_(Dune::ParameterTree& target, const Dune::ParameterTree& source, bool overwrite, const std::string& group);
142};
143
150template<typename T, typename... Args>
151T getParam(Args&&... args)
152{ return Parameters::getTree().template get<T>(std::forward<Args>(args)... ); }
153
160template<typename T, typename... Args>
161T getParamFromGroup(Args&&... args)
162{ return Parameters::getTree().template getFromGroup<T>(std::forward<Args>(args)... ); }
163
169inline bool hasParam(const std::string& param)
170{ return Parameters::getTree().hasKey(param); }
171
177inline bool hasParamInGroup(const std::string& paramGroup, const std::string& param)
178{ return Parameters::getTree().hasKeyInGroup(param, paramGroup); }
179
185inline std::vector<std::string> getParamSubGroups(const std::string& subGroupName, const std::string& paramGroup)
186{ return Parameters::getTree().getSubGroups(subGroupName, paramGroup); }
187
188} // end namespace Dumux
189
190#endif
Function printing a default usage message.
A parameter tree that logs which parameters have been used.
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:185
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition: parameters.hh:161
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:177
bool hasParam(const std::string &param)
Check whether a key exists in the parameter tree.
Definition: parameters.hh:169
T getParam(Args &&... args)
A free function to get a parameter from the parameter tree singleton.
Definition: parameters.hh:151
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
A parameter tree that logs which parameters have been used.
Definition: loggingparametertree.hh:43
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:133
bool hasKeyInGroup(const std::string &key, const std::string &groupPrefix) const
test for key in group
Definition: loggingparametertree.hh:90
bool hasKey(const std::string &key) const
test for key
Definition: loggingparametertree.hh:72
Parameter class managing runtime input parameters.
Definition: parameters.hh:46
static const LoggingParameterTree & getTree()
Get the parameter tree.
Definition: parameters.cc:223
static void print()
prints all used and unused parameters
Definition: parameters.cc:176
static void init(int argc, char **argv, const Usage &usage)
Initialize the parameter tree singletons.
Definition: parameters.cc:45
static Dune::ParameterTree parseCommandLine(int argc, char **argv)
Parse command line arguments into a parameter tree.
Definition: parameters.cc:182