Skip to content
Snippets Groups Projects
Commit e06756fa authored by Timo Koch's avatar Timo Koch
Browse files

More fixups exercise runtime.

parent ea2002fd
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ For this task we will edit the following files:
* And the shared __input file__: `exercise_runtimeparams.input`
Parameters can either be directly defined within your program, or specified
via the input file. Within every main file, (*.cc), the following function
via the input file. Within every main file, (`*.cc`), the following function
is called, which will read in the imput file parameters
```c++
......@@ -26,7 +26,7 @@ Parameters::init(argc, argv);
```
This input file should either be named the same as the executable file, with a
trailing ".input", as is standard in our CMake system, or be explicitly written
trailing `*.input`, as is standard in our CMake system, or be explicitly written
as the first shell argument after the executable file is called.
```bash
......@@ -54,7 +54,7 @@ When a parameter is defined directly within your program, you'll need to recompi
### Task 2: Setting a variable to collect a runtime parameter
<hr>
Let's free one of the variables in this exercise. Within the class `injection2p2cproblem.hh`, in the first line of the neumann boundary condition definition function neumannAtPos(-), the injection rate is defined as $`1e-4 kg/(s m^2)`$.
Let's free one of the variables in this exercise. Within the class `injection2p2cproblem.hh`, in the first line of the neumann boundary condition definition function `neumannAtPos(...)`, the injection rate is defined as $`1e-4 kg/(s m^2)`$.
```c++
// inject nitrogen. negative values mean injection
......@@ -82,7 +82,7 @@ variable_ = getParamFromGroup<TYPE>("GROUPNAME", "PARAMNAME");
* `<GROUPNAME>` is the group in the input file
* `<PARAMNAME>` is the name of the parameter in the input file
An example of this is already performed in the problem constructor. The Injection Duration (injectionDuration_) is defined via the imput 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 imput file, and can then be used later in the problem.
```c++
// depth of the aquifer, units: m
......@@ -91,7 +91,7 @@ aquiferDepth_ = getParam<Scalar>("Problem.AquiferDepth");
injectionDuration_ = getParamFromGroup<Scalar>("Problem","InjectionDuration");
```
The injection duration parameter is located in the "Problem" group, is named "InjectionDuration", and has the type "Scalar".
The injection duration parameter is located in the `[Problem]` group, is named `InjectionDuration`, and has the type `Scalar`.
This variable should then be defined as Scalar at the bottom of this problem class in the private section.
......@@ -99,7 +99,7 @@ This variable should then be defined as Scalar at the bottom of this problem cla
Scalar injectionDuration_;
```
In the input file, within the group [Problem], a value is set to the Parameter name called in the class.
In the input file, within the group `[Problem]`, a value is set to the Parameter name called in the class.
```ini
[Problem]
......@@ -111,7 +111,7 @@ InjectionDuration = 2.628e6 # in seconds, i.e. one month
```c++
values[Indices::conti0EqIdx + FluidSystem::N2Idx]= -1e-4/FluidSystem::molarMass(FluidSystem::N2Idx);
```
with a runtime variable. (2a) Develop a new variable called totalAreaSpecificInflow_, (2b) record a value to this variable from a path in the input file, and (2c) incorporate this variable into the injection boundary condition.
with a runtime variable. (2a) Develop a new variable called `totalAreaSpecificInflow_`, (2b) record a value to this variable from a path in the input file, and (2c) incorporate this variable into the injection boundary condition.
When your problem file and the input file are edited, compile and run the exercise.
......@@ -122,7 +122,7 @@ make exercise_runtimeparams && ./exercise_runtimeparams exercise_runtimeparams.i
### Task 3: Default Values for Runtime Parameters
<hr>
In the case that no path to a required runtime parameter is provided in the input file, the program will no longer run. You can try this if you like by removing the TotalAreaSpecificInflow from the input file. The resulting error message should look like this:
In the case that no path to a required runtime parameter is provided in the input file, the program will no longer run. You can try this if you like by removing the `TotalAreaSpecificInflow` from the input file. The resulting error message should look like this:
```bash
loggingparametertree.hh:316:
......@@ -144,9 +144,9 @@ variable_ = getParamFromGroup<TYPE>("GROUPNAME","PARAMNAME", DEFAULTVALUE);
### 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 DUMUX, there are a few base variables that are set with default values for all dumux 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 bool functions 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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment