Runtime simulation parameters can be parsed to the program via a parameter file, via the command line, or can be initialized programmatically. We discuss all three approaches. Moreover, most parameters have default values as explained below. Runtime parameters are a configuration mechanism at program runtime (avoiding recompilation).
The parameter tree is initialized by Dumux::Parameters::init. This constructs a parameter tree singleton from which parameters can be retrieved via accessor functions. The parameter tree can stores key-value pairs of type string. Values can also be other parameter trees (subtrees, groups). A simple program only initializing the parameter tree looks like this
We can also specify a parameter file (default: params.input
) to be parsed (the expected INI file format is described below):
Default parameters can explicitly be set upon initialization
The following variant omits reading command-line arguments and only parsing the specified input parameter file params.input
:
Runtime parameters can be read from the parameter tree with the functions Dumux::getParam (converts string to requested type)
where the specified default value is expected to be convertible to the type TYPE
. Some examples are
Not specifying a default parameter causes the function to throws a Dumux::ParameterException
if parameter doesn't exist in the parameter tree.
The function Dumux::getParamFromGroup traverses the parameter tree
for example
first looks for the key FreeFlow.Problem.Gravity
and then looks for the key Problem.Gravity
. This function is useful when configuring multiple simulation components or multi-domain problem via the single parameter tree.
Reading parameters from the tree can be a very slow operation. Therefore, we recommend to read parameters in constructors of high-level classes and in particular never read parameters in functions called for all elements.
The existence of a parameter in the parameter tree can be queried with the function Dumux::hasParam.
There exists also a variant using hierarchical group lookup as described above for Dumux::getParamFromGroup using the function Dumux::hasParamInGroup:
There is a bookkeeping mechanism keeping track of used and unused parameters throughout the lifetime of the program. It is useful to print a parameter report using Dumux::Parameters::print at the end of the main file. This reports unused parameters and is great, for instance, for detecting typos in configuration files.
The parameter files are expected to use the Dune INI syntax (consists of [Group]
and Key = Value
pairs). An example is given below:
All parameter that can be specified via the parameter file can also be overwritten via the command line using the following exemplary form:
The following could be used in combination with the parameter file above:
As first argument a parameter file can be specified:
Parameters are parsed into the parameter tree in the following precedence:
We curate a list of available pre-defined parameters here: parameterlist.txt.
Note that not all listed parameters will be available in all types of simulations. For example, naturally, the Newton solver can only be configured (via parameters in the group [Newton]
) for simulations that actually use a Newton solver. Model-specific parameters are only read and used when the corresponding model is in use.