Commit 25345e40 authored by Timo Koch's avatar Timo Koch
Browse files

[examples] Update README.mds with new script

* Adds whitespaces before and after code blocks
* Removes some superfluous white space in code blocks
* Some small changes regarding header guards and formatting
parent 83a2a880
This diff is collapsed.
This diff is collapsed.
......@@ -24,12 +24,12 @@ In the following, we take a close look at the files containing the set-up: At fi
## The file `problem.hh`
### The problem class
We enter the problem class where all necessary initial and boundary conditions are set for our simulation.
As this is a Stokes problem, we inherit from the basic <code>NavierStokesProblem</code>.
<details><summary>Toggle to expand code:</summary>
```cpp
#include <dumux/freeflow/navierstokes/problem.hh>
......@@ -40,12 +40,14 @@ template <class TypeTag>
class ChannelExampleProblem : public NavierStokesProblem<TypeTag>
{
```
</details>
We use convenient declarations that we derive from the property system.
<details>
<summary>Toggle to expand code (convenient declarations)</summary>
```cpp
using ParentType = NavierStokesProblem<TypeTag>;
using BoundaryTypes = GetPropType<TypeTag, Properties::BoundaryTypes>;
......@@ -62,6 +64,7 @@ We use convenient declarations that we derive from the property system.
public:
```
</details>
There follows the constructor of our problem class:
......@@ -70,6 +73,7 @@ As no run-time value is specified, we set the outlet pressure to 1.1e5 Pa.
<details>
<summary>Toggle to expand code (constructor)</summary>
```cpp
ChannelExampleProblem(std::shared_ptr<const GridGeometry> gridGeometry)
: ParentType(gridGeometry)
......@@ -78,6 +82,7 @@ As no run-time value is specified, we set the outlet pressure to 1.1e5 Pa.
outletPressure_ = getParam<Scalar>("Problem.OutletPressure", 1.1e5);
}
```
</details>
Now, we define the type of initial and boundary conditions depending on location.
......@@ -94,6 +99,7 @@ of our domain else.
<details>
<summary>Toggle to expand code (<code>boundaryTypesAtPos</code>)</summary>
```cpp
BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
{
......@@ -117,6 +123,7 @@ of our domain else.
return values;
}
```
</details>
Second, we specify the values for the Dirichlet boundaries. We need to fix the values of our primary variables.
......@@ -125,6 +132,7 @@ in x-direction is set to zero if not at the inlet.
<details>
<summary>Toggle to expand code (<code>dirichletAtPos</code>)</summary>
```cpp
PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
{
......@@ -138,6 +146,7 @@ in x-direction is set to zero if not at the inlet.
return values;
}
```
</details>
We specify the values for the initial conditions.
......@@ -145,6 +154,7 @@ We assign constant values for pressure and velocity components.
<details>
<summary>Toggle to expand code (<code>initialAtPos</code>)</summary>
```cpp
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
{
......@@ -157,6 +167,7 @@ We assign constant values for pressure and velocity components.
return values;
}
```
</details>
We need to specify a constant temperature for our isothermal problem.
......@@ -164,53 +175,61 @@ We set it to 10°C.
<details>
<summary>Toggle to expand code (<code>temperature</code>)</summary>
```cpp
Scalar temperature() const
{ return 273.15 + 10; }
private:
```
</details>
The inlet is at the left side of the physical domain.
<details>
<summary>Toggle to expand code (<code>isInlet_</code>)</summary>
```cpp
bool isInlet_(const GlobalPosition& globalPos) const
{
return globalPos[0] < eps_;
}
```
</details>
The outlet is at the right side of the physical domain.
<details>
<summary>Toggle to expand code (<code>isOutlet_</code>)</summary>
```cpp
bool isOutlet_(const GlobalPosition& globalPos) const
{
return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_;
}
```
</details>
Finally, private variables are declared:
<details>
<summary>Toggle to expand code (private variables)</summary>
```cpp
static constexpr Scalar eps_=1e-6;
Scalar inletVelocity_;
Scalar outletPressure_;
};
}
#endif
```
</details>
## The file `main.cc`
......@@ -226,12 +245,14 @@ and another standard header for in- and output.
<details>
<summary>Toggle to expand code (includes of problem file and of standard headers)</summary>
```cpp
#include <config.h>
#include <ctime>
#include <iostream>
```
</details>
Dumux is based on DUNE, the Distributed and Unified Numerics Environment, which provides several grid managers and
......@@ -239,6 +260,7 @@ linear solvers. So we need some includes from that.
<details>
<summary>Toggle to expand code (dune includes)</summary>
```cpp
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/timer.hh>
......@@ -246,6 +268,7 @@ linear solvers. So we need some includes from that.
#include <dune/grid/io/file/vtk.hh>
#include <dune/istl/io.hh>
```
</details>
In Dumux, a property system is used to specify the model. For this, different properties are defined containing
......@@ -267,6 +290,7 @@ The following class contains functionality for additional flux output to the con
<details>
<summary>Toggle to expand code (dumux includes)</summary>
```cpp
#include <dumux/common/properties.hh>
#include <dumux/common/parameters.hh>
......@@ -290,6 +314,7 @@ The following class contains functionality for additional flux output to the con
#include "problem.hh"
```
</details>
</details>
......@@ -302,6 +327,7 @@ We setup the DuMux properties for our simulation (click [here](https://git.iws.u
4. The problem class `ChannelExampleProblem`, which is forward declared before we enter `namespace Dumux` and defined later in this file, is defined to be the problem used in this test problem (charaterized by the TypeTag `ChannelExample`). The fluid system, which contains information about the properties such as density, viscosity or diffusion coefficient of the fluid we're simulating, is set to a constant one phase liquid.
5. We enable caching for the following classes (which stores values that were already calculated for later usage and thus results in higher memory usage but improved CPU speed): the grid volume variables, the grid flux variables, the finite volume grid geometry.
```cpp
namespace Dumux::Properties {
......@@ -334,11 +360,13 @@ struct EnableGridGeometryCache<TypeTag, TTag::ChannelExample> { static constexpr
```
### Beginning of the main function
We begin the main function by making the type tag `ChannelExample`, that we defined in `problem.hh` for this test problem available here.
Then we initializing the message passing interface (MPI), even if we do not plan to run the application in parallel. Finalizing of the MPI is done automatically on exit.
We continue by printing the dumux start message and parsing the command line arguments and runtimeparameters from the input file in the init function.
```cpp
int main(int argc, char** argv) try
{
......@@ -354,6 +382,7 @@ int main(int argc, char** argv) try
Parameters::init(argc, argv);
```
### Set-up and solving of the problem
A gridmanager tries to create the grid either from a grid file or the input file. You can learn more about grids in
......@@ -370,6 +399,7 @@ primary variables (velocities, pressures) as well as secondary variables (densit
We then initialize the vtkoutput. Each model has a predefined model-specific output with relevant parameters
for that model. Here, it is pressure, velocity, density and process rank (relevant in the case of parallelisation).
```cpp
GridManager<GetPropType<TypeTag, Properties::Grid>> gridManager;
gridManager.init();
......@@ -399,6 +429,7 @@ for that model. Here, it is pressure, velocity, density and process rank (releva
vtkWriter.write(0.0);
```
We set up two surfaces over which fluxes are calculated.
We determine the extensions [xMin,xMax]x[yMin,yMax] of the physical domain.
The first surface (added by the first call of addSurface) shall be placed at the middle of the channel.
......@@ -408,6 +439,7 @@ In this case, we add half a cell-width to the x-position in order to make sure t
the cell faces lie on the surface. This assumes a regular cartesian grid.
The second surface (second call of addSurface) is placed at the outlet of the channel.
```cpp
FluxOverSurface<GridVariables,
SolutionVector,
......@@ -442,6 +474,7 @@ The second surface (second call of addSurface) is placed at the outlet of the ch
flux.addSurface("outlet", p0outlet, p1outlet);
```
The incompressible Stokes equation depends only linearly on the velocity, so we could use a linear solver to solve the problem.
Here, we use the show the more general case which would also work for incompressible fluids or the
Navier-Stokes equation. We use non-linear Newton solver for the solution.
......@@ -451,6 +484,7 @@ As a postprocessing, we calculate mass and volume fluxes over the planes specifi
<details>
<summary>Toggle to expand code (assembly, solution process, postprocessing)</summary>
```cpp
using Assembler = StaggeredFVAssembler<TypeTag, DiffMethod::numeric>;
auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables);
......@@ -466,6 +500,7 @@ As a postprocessing, we calculate mass and volume fluxes over the planes specifi
flux.calculateMassOrMoleFluxes();
flux.calculateVolumeFluxes();
```
</details>
### Final Output
......@@ -475,6 +510,7 @@ possibly catched error messages are printed.
<details>
<summary>Toggle to expand code (final output)</summary>
```cpp
vtkWriter.write(1.0);
......@@ -525,6 +561,7 @@ catch (...)
return 4;
}
```
</details>
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment