Skip to content
Snippets Groups Projects
Commit 4b82289c authored by Martin Schneider's avatar Martin Schneider
Browse files

Merge branch 'doc/ex-model-updates' into 'master'

Doc/ex model updates

See merge request !162
parents 94b31ccf a367b5ca
No related branches found
No related tags found
1 merge request!162Doc/ex model updates
Pipeline #30381 passed
slides/img/box_scv_scvf.png

51.7 KiB

...@@ -4,5 +4,6 @@ title: DuMuX Course Slides ...@@ -4,5 +4,6 @@ title: DuMuX Course Slides
- [Introduction to DuMu^x^](./intro.html) - [Introduction to DuMu^x^](./intro.html)
- [Property System](./properties.html) - [Property System](./properties.html)
- [Model](./model.html)
- [Introduction to Multidomain](./multidomain.html) - [Introduction to Multidomain](./multidomain.html)
- [Discrete Fracture Modeling](./fractures.html) - [Discrete Fracture Modeling](./fractures.html)
--- ---
title: Models in DuMux title: Models in DuMuX
--- ---
# Implementing a new DuMu<sup>X</sup> model # Implementing a new DuMu<sup>X</sup> model
## What is a DuMu<sup>X</sup> model ## What is a DuMu<sup>X</sup> model
A DuMu<sup>X</sup> model is an implementation of a **mathematical model**, generally given by partial differential equations, by using **discretization** schemes. A DuMu<sup>X</sup> model is an implementation of a discretized **mathematical model**, generally given by partial differential equations.
## What is a DuMu<sup>X</sup> model ## What is a DuMu<sup>X</sup> model
Mathematical model (PDE): Mathematical model (PDE):
...@@ -29,8 +29,8 @@ $\begin{equation*} ...@@ -29,8 +29,8 @@ $\begin{equation*}
|B| \frac{S_h(\mathbf{u}^{n+1}_h) - S_h(\mathbf{u}^{n}_h)}{\Delta t} + \sum_{\sigma \in \Sigma_B} F_{B,\sigma}(\mathbf{u}^{n+1}_h) = \int_{B} q \, dx, \quad \forall t_{n+1}\leq T, \; \forall B |B| \frac{S_h(\mathbf{u}^{n+1}_h) - S_h(\mathbf{u}^{n}_h)}{\Delta t} + \sum_{\sigma \in \Sigma_B} F_{B,\sigma}(\mathbf{u}^{n+1}_h) = \int_{B} q \, dx, \quad \forall t_{n+1}\leq T, \; \forall B
\end{equation*}$ \end{equation*}$
* $S_h$: storage calculation * $S_h$: storage term
* $F_{B,\sigma}$: flux over sub control volume face * $F_{B,\sigma}$: flux term over sub control volume face (scvf)
* $q$ source term * $q$ source term
How to implement these terms in DuMu<sup>X</sup>? How to implement these terms in DuMu<sup>X</sup>?
...@@ -75,31 +75,31 @@ with ...@@ -75,31 +75,31 @@ with
$\begin{aligned} $\begin{aligned}
c_B^n: &\:\text{concentration at time $t_n$ and control volume $B$} \\ c_B^n: &\:\text{concentration at time $t_n$ and control volume $B$} \\
c_h: &\:\text{global discrete solution, interpolation using \textbf{basis functions}} \\ c^n_h: &\:\text{global discrete solution at time $t_n$, interpolated using \textbf{basis functions}} \\
\mathbf{n}: &\:\text{unit outer normal vector} \\ \mathbf{n}: &\:\text{unit outer normal vector} \\
\sigma: &\:\text{sub control volume face} \\ \sigma: &\:\text{sub control volume face (scvf)} \\
\end{aligned}$ \end{aligned}$
## Example: Diffusion equation
Discrete model using the Box discretization:
## Local residual $\begin{equation}
The local residual of the diffusion model: \vert B \vert \frac{c_B^{n+1}-c_B^{n}}{\Delta t} - \sum_{\sigma \in \Sigma_{B}} \left[ D \nabla c_h^{n+1} \cdot \boldsymbol{n}_{B,\sigma} \vert \sigma \vert \right] = 0,
```cpp \end{equation}$
namespace Dumux {
template<class TypeTag> <img src=img/box_scv_scvf.png width="90%">
class DiffusionModelLocalResidual
: public GetPropType<TypeTag, Properties::BaseLocalResidual>
{
```
## Local residual ## Local residual
The local residual of the diffusion model:
```cpp ```cpp
namespace Dumux {
template<class TypeTag> template<class TypeTag>
class DiffusionModelLocalResidual class DiffusionModelLocalResidual
: public GetPropType<TypeTag, Properties::BaseLocalResidual> : public GetPropType<TypeTag, Properties::BaseLocalResidual>
{ {
...
}
``` ```
Our class inherits from the class `BaseLocalResidual`, which has to be chosen depending on the discretization scheme, here *Box scheme*. Inherits from the `BaseLocalResidual`, which is chosen depending on the discretization scheme, here *Box scheme*.
## Storage term ## Storage term
```cpp ```cpp
...@@ -107,10 +107,10 @@ NumEqVector computeStorage(const Problem& problem, ...@@ -107,10 +107,10 @@ NumEqVector computeStorage(const Problem& problem,
const SubControlVolume& scv, const SubControlVolume& scv,
const VolumeVariables& volVars) const const VolumeVariables& volVars) const
{ {
NumEqVector storage; NumEqVector storage;
storage[Indices::massBalanceEqIdx] storage[Indices::massBalanceEqIdx]
= volVars.priVar(Indices::concentrationIdx); = volVars.priVar(Indices::concentrationIdx);
return storage; return storage;
} }
``` ```
...@@ -123,29 +123,29 @@ F_{B,\sigma} = -D \nabla c_h^{n+1} \cdot \boldsymbol{n}_{B,\sigma} \vert \sigma ...@@ -123,29 +123,29 @@ F_{B,\sigma} = -D \nabla c_h^{n+1} \cdot \boldsymbol{n}_{B,\sigma} \vert \sigma
with with
$\begin{aligned} $\begin{aligned}
c_h: &\:\text{discrete solution, interpolated using basis functions} \\ c^n_h: &\:\text{global discrete solution at time $t_n$, interpolated using \textbf{basis functions}} \\
\sigma: &\:\text{sub control volume face} \\ \mathbf{n}: &\:\text{unit outer normal vector} \\
\sigma: &\:\text{sub control volume face (scvf)} \\
\end{aligned}$ \end{aligned}$
## Flux term ## Flux term
Implementation takes place in the dedicated function `computeFlux`:
```cpp ```cpp
NumEqVector computeFlux(const Problem& problem, NumEqVector computeFlux(const Problem& problem,
const Element& element, const Element& element,
const FVElementGeometry& fvGeometry, const FVElementGeometry& fvGeometry,
const ElementVolumeVariables& elemVolVars, const ElementVolumeVariables& elemVolVars,
const SubControlVolumeFace& scvf, const SubControlVolumeFace& scvf,
const ElementFluxVariablesCache& elemFluxVarsCache) const const ElementFluxVariablesCache& elemFluxVarsCache) const
{ {
... ...
}
``` ```
## Flux term ## Flux term
Implementation takes place in the dedicated function `computeFlux`:
```cpp ```cpp
NumEqVector computeFlux(...) const NumEqVector computeFlux(...) const
{ {
// Compute ∇c // Compute ∇c
const auto& fluxVarCache = elemFluxVarsCache[scvf]; const auto& fluxVarCache = elemFluxVarsCache[scvf];
Dune::FieldVector<Scalar, dimWorld> gradConcentration(0.0); Dune::FieldVector<Scalar, dimWorld> gradConcentration(0.0);
for (const auto& scv : scvs(fvGeometry)) for (const auto& scv : scvs(fvGeometry))
...@@ -157,14 +157,13 @@ Implementation takes place in the dedicated function `computeFlux`: ...@@ -157,14 +157,13 @@ Implementation takes place in the dedicated function `computeFlux`:
); );
} }
... ...
} }
``` ```
## Flux term ## Flux term
Implementation takes place in the dedicated function `computeFlux`:
```cpp ```cpp
NumEqVector computeFlux(...) const NumEqVector computeFlux(...) const
{ {
... ...
NumEqVector flux; NumEqVector flux;
...@@ -174,13 +173,12 @@ Implementation takes place in the dedicated function `computeFlux`: ...@@ -174,13 +173,12 @@ Implementation takes place in the dedicated function `computeFlux`:
)*scvf.area(); )*scvf.area();
return flux; return flux;
}
}
``` ```
## Local Residual ## Local Residual
A *local residual* implements the discretized mathematical model. A **local residual** implements the discretized mathematical model.
For its implementation different model-specific properties have to be set For its implementation different model-specific properties have to be set
...@@ -197,12 +195,12 @@ struct DiffusionModel {}; ...@@ -197,12 +195,12 @@ struct DiffusionModel {};
} // end namespace Dumux::Properties::TTag } // end namespace Dumux::Properties::TTag
``` ```
## Model properties ## Model properties
By specializing properties for the type tag `DiffusionModel`, every other class that knows about the type tag (this will be for example the assembler or the problem), can extract the type information that we specify here. We can set nodel properties for the `DiffusionModel` type tag
All properties are defined within the namespace `Dumux::Properties` All properties are defined within the namespace `Dumux::Properties`
```cpp ```cpp
namespace Dumux::Properties { namespace Dumux::Properties {
//define all properties //define all properties
} // end namespace Dumux::Properties } // end namespace Dumux::Properties
``` ```
......
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