Here we will expand on what we've covered in the basics exercise, and the problem set up will remain the same.
Here we will expand on what we've covered in the basics exercise (see `dumux-course/exercises/exercise-basic/README.md`), and the problem set up will remain the same.
## Preparing the exercise
*Navigate to the directory `dumux-course/exercises/exercise-runtimeparams/`
Navigate to the directory `dumux-course/exercises/exercise-runtimeparams/`
<br><br>
### Task 1: Understanding Input Parameters
...
...
@@ -17,36 +17,32 @@ For this task we will edit the following files:
* The shared __problem file__: `problem.hh`
* And the shared __input file__: `params.input`
Parameters can either be directly defined within your program, or specified
via the input file. Within every main file, (`*.cc`), the following function
is called, which will read in the input file parameters
Parameters can either be directly defined within your program, or specified via the input file. Within every main file, (`*.cc`), the following function is called
```c++
// parse command line arguments and input file
Parameters::init(argc,argv);
```
This input file should either be named the same as the executable file, with a
trailing `*.input`, or be named `prarams.input` as is standard in our CMake system.
Alternatively, arbitrarily named input file names can be explicitly written
as the first shell argument after the executable file is called.
This will read in the parameters from the input file.
The input file should either be named the same as the executable file, with a trailing `*.input`, or be named `prarams.input` as this is the standard in our CMake system.
Alternatively, arbitrarily named input files (e.g. `exercise1.input`) can be explicitly written as the first shell argument after the executable file (here `exercise_runtimeparams`) is called.
```bash
./exercise_runtimeparams
(Calls the file params.input as the default input file.)
#(Calls the file params.input as the default input file.)
```
```bash
./exercise_runtimeparams exercise1.input
(Calls the input file provided (exercise1.input) as the input file.)
#(Calls the input file provided (exercise1.input) as the input file.)
```
In the input file `params.input` you can find the following section
```ini
[SpatialParams]
PermeabilityAquitard=1e-15 # m^2
EntryPressureAquitard=4.5e4 # Pa
Aquitard.BrooksCoreyPcEntry=4.5e4 # Pa
PermeabilityAquifer=1e-12 # m^2
EntryPressureAquifer=1e4 # Pa
Aquifer.BrooksCoreyPcEntry=1e4 # Pa
```
When a parameter is defined directly within your program, you'll need to recompile your program every time you change the value. When a parameter is passed via the input file, this is not the case. If we decided to vary the entry pressure in our geologic units a few times via the parameters listed above, there would be no need to recompile between simulation runs.
`<TYPE>`,`<GROUPNAME>`,`<PARAMNAME>` should be appropriately defined for your variable:
*`<TYPE>` is the type of the parameter to read
*`<GROUPNAME>` is the group in the input file
*`<PARAMNAME>` is the name of the parameter in the input file
*`<TYPE>` is the type of the parameter to read (e.g. `Scalar`)
*`<GROUPNAME>` is the group in the input file (e.g. `Problem`)
*`<PARAMNAME>` is the name of the parameter in the input file (e.g. `AquiferDepth`)
An example of this is already performed in the problem constructor. The Injection Duration (`injectionDuration_`) is defined via the input file, and can then be used later in the problem.
An example of this is already performed in the problem constructor. The Injection Duration (`injectionDuration_`) is defined via the input file and can then be used later in the problem header.
Key Problem.TotalAreaSpecificInflow not found in the parameter tree ---> Abort!
```
To avoid this, we can place a default value in the variable definition. Whenever the parameter is specified in the input file, this default value in your class will be overwritten, but in the case that no value is provided in the input file, this default value will be used. In order to do this, follow the following template.
To avoid this, we can place a default value in the variable definition. Whenever the parameter is specified in the input file, this default value in your class will be overwritten. In the case that no value is provided in the input file, this default value will be used. In order to do this, follow the following template.
* > __Task 3__: Set up the totalAreaSpecificInflow_ variable to record a default value of `-1e-4`, and run this with and without a provided value of `-1e-3` in the input file.
* > __Task 3__: Set up the `totalAreaSpecificInflow_` variable to record a default value of `-1e-4` and run this with and without a provided value of `-1e-3` in the input file.
<br><br>
### Task 4: Other Runtime Parameter Functions
<hr>
Setting default values for variables defined with runtime parameters can also lead to problems. If one runtime parameter from the input file is set to multiple different variables, each with a different Default value, changing the variable in one location can lead to unexpected changes elsewhere. On top of this, in DuMu<sup>x</sup>, there are a few base variables that are set with default values for all DuMu<sup>x</sup> simulations. These can be found in the header file `dumux/common/parameters.hh` in the function `globalDefaultParameters`.
Setting default values for variables defined with runtime parameters can also lead to problems. If one runtime parameter from the input file is set to multiple different variables, each with a different default value, changing the variable in one location can lead to unexpected changes elsewhere. On top of this, in DuMu<sup>x</sup>, there are a few base variables that are set with default values for all DuMu<sup>x</sup> simulations. These can be found in the header file `dumux/common/parameters.hh` in the function `globalDefaultParameters`.
One way to check this is to use either the `hasParam()` or the `hasParamInGroup()` function. These functions returning `bool`s will check to see if a parameter is read in via the input file. These functions are also both defined in the `dumux/dumux/common/parameters.hh` class, and follow a similar format to that of `getParam()` and `getParamFromGroup()`
One way to check this is to use either the `hasParam()` or the `hasParamInGroup()` function. These functions returning `bool`s will check to see if a parameter is read in via the input file. These functions are also both defined in the `dumux/dumux/common/parameters.hh` class, and follow a similar format to that of `getParam()` and `getParamFromGroup()`.
An example of this would look like this:
...
...
@@ -171,4 +168,4 @@ else
Using these functions we can better check which parameter values are being included in our program.
* > __Task 4__: Using one of the bool hasParam functions, place output in the problem file to alert the user to where the parameter value comes from.
* > __Task 4__: Using one of the bool `hasParam` functions, place an output in the problem file to alert the user where the parameter value comes from.