Exercise Properties (DuMuX course)
## Problem set-up
The problem setup is identical to the previous Exercise Basic.
Preparing the exercise
- Navigate to the directory
exercise-properties
Exercise 2 deals with a two-phase compositional problem (2p2c). Goal is to learn how to use compile and runtime parameters and the DuMux property system.
Task 1: Getting familiar with the code
Locate all the files you will need for this exercise
- The main file:
exercise2.cc
- The problem file:
injection2p2cproblem.hh
- The spatial parameters file:
injection2p2cspatialparams.hh
- The input file:
exercise2.input
- Two header files containing:
- a custom local residual in:
mylocalresidual.hh
- a custom material law in:
mymateriallaw.hh
- a custom local residual in:
### Task 2: Compiling and running the program
- Change to the build-directory
cd ../build-cmake/exercise_properties
- Compile the executable
exercise_properties
make exercise_properties
- Run the problem and inspect the result
./exercise_properties
Note: Because the input file has the same name as the executable, DuMuX will find it automatically.
If gnuplot is installed on your system, you should see a plot of the capillary pressure - saturation relationship.
### Task 3: Implement and use a different material law
DuMuX uses the term material law to describe the law used to compute
- pc-Sw relations
- kr-Sw relations
- their inverse relations
The file mymateriallaw.hh
contains a custom implementation of such a material law.
- Implement the method
Scalar pc(const Params ¶ms, Scalar swe)
by implementing your own capillary pressure relationship, e.g. a simple linear relationshipp_C(S_w) = 1\cdot 10^5 \cdot (1-S_w) + p_e
.
Note: MyMaterialLaw
uses the BrooksCoreyParams
class as parameter input. You can get the entry pressure that is set in the spatial params as follows
const auto pe = params.pe();
The type (i.e. C++ type) of the material law is set in the file injection2p2cspatialparams.hh
by declaring the following alias in the public section of the spatial parameters class:
using MaterialLaw = EffToAbsLaw<RegularizedBrooksCorey<Scalar>>;
- Make DuMuX use your own material law by including the header
mymateriallaw.hh
and changing the aliasMaterialLaw
. This will make sure that your material law is used everywhere else in the code.
Note: Also use the wrapper class EffToAbsLaw
. It takes care of converting absolute to effective saturations considering residual saturations. MyMaterialLaw
as other material laws (like Brooks-Corey, VanGenuchten, ...) in DuMuX only deals with effective saturations.
- Verify your changes by recompiling and running the program. You should see a plot of your new function.
For the next task, disable the plotting feature by changing the settings in the input file exercise2.input
[Problem]
OnlyPlotMaterialLaws = false
### Task 4: Implement a custom local residual
Most types in DuMuX are properties that can be changed just like the material law. In the following task we implement our own 2p2c local residual, i.e. the class that computes the element residual in every Newton iteration. The file mylocalresidual.hh
contains a copy of the similar to the original local residual class used for all compositional models renamed to template<class TypeTag> class MyCompositionalLocalResidual
.
- Make DuMuX use this new local residual by inluding the header
mylocalresidual.hh
and setting the corresponding property in theProperty
namespace in the fileinjection2p2cproblem.hh
// note that every property struct knows about TypeTag
SET_PROP(Injection2p2cTypeTag, LocalResidual)
{
using type = MyCompositionalLocalResidual<TypeTag>;
};
// or using the convenience macro
SET_TYPE_PROP(Injection2p2cTypeTag, LocalResidual,
MyCompositionalLocalResidual<TypeTag>);
You want to make the new local residual special by adding a switch enabling / disabling diffusion. We will achieve this with a DuMuX parameter which is read from the input file and defaults to a property value if the input file doesn't contain the parameter.
- Modify the
computeFlux
method to only call thediffusiveFlux
method if diffusion is enabled. You can get the new parameter by adding the lines
// ... in the computeFlux method of MyCompositionalLocalResidual
auto enableDiffusion = getParam<bool>("Problem.EnableDiffusion", true);
You can now enable and disable diffusion through the input file
[Problem]
EnableDiffusion = true / false
- Verify the difference in the parameter
x_w^{N2}
, i.e. the mole fraction of nitrogen in the water phase, with and without diffusion.
Note that due to diffusion being a slow process you can only see the difference in later times.