-
Melanie Lipp authoredMelanie Lipp authored
#2 (DuMuX course)
Exercise## Problem set-up
The problem setup is identical to the previous exercise 1.
Preparing the exercise
- Navigate to the directory
dumux/tutorial/ex2
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/tutorial/ex2
- Compile the executable
exercise2
make exercise2
- Run the problem and inspect the result
./exercise2
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 relationship.
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 using the DuMuX property system
SET_PROP(InjectionSpatialParams, MaterialLaw)
{
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
using type = EffToAbsLaw<RegularizedBrooksCorey<Scalar>>;
};
- Make DuMuX use your own material law by including the header
mymateriallaw.hh
and changing the aliastype
. 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: Enable/Disable Gravity -> DuMuX parameters
DuMuX has many parameters that have default values. For example, all simulations consider gravity effects by default. You can disable gravity for a study, simply by setting the parameter in the input file
[Problem]
EnableGravity = false
Run the simulation with and without gravity. Change the Problem.Name
parameter to create output files with different
names. Compare the results using paraview. You should immediately see the difference.
A list of parameters that can be set through the input file is given here.
### Task 5: Implement your own 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 , 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.