This section presents a set of examples which are not covered in detail in the previous sections. The examples can be found in the tutorial folder in Kaskade 7.
Unlike the preceding tutorials, these pages give an overview rather than a complete
listing. The full sources are in the respective tutorial/... directories. From the
Kaskade 7 root directory, the maintained examples are built and run with the
following targets:
| Example | Build | Run |
|---|---|---|
| Stationary heat transfer | make build-stationaryHeatTransfer-tutorial |
make run-stationaryHeatTransfer-tutorial |
| Instationary Navier–Stokes | make build-instationaryNavierStokes-tutorial |
make run-instationaryNavierStokes-tutorial |
| Embedded error estimation | make build-embeddedErrorEstimation-tutorial |
make run-embeddedErrorEstimation-tutorial |
| Hierarchical error estimation | make build-HBerrorEstimation-tutorial |
make run-HBerrorEstimation-tutorial |
| Monodomain (Aliev–Panfilov) | make build-cardio-tutorial |
make run-cardio-tutorial |
| Stokes | make build-stokes-tutorial |
make run-stokes-tutorial |
| SST pollution | currently does not build with 7.8 (see note below) | – |
The default runs are sized for producing the figures, not for a quick smoke test:
the Navier–Stokes example integrates up to tEnd=1, and the cardiac example performs
40 LIMEX steps on a three-dimensional mesh. Pass smaller values such as
--tEnd 0.05 or --maxSteps 2 while experimenting.
Several examples write into a graph/ subdirectory. The run-... targets create
it; if you start a binary directly, create the directory first with mkdir -p graph,
otherwise the VTK writer reports a FileIOException.
This tutorial can be found at tutorial/stationary_heattransfer. It covers
The PDE is given by
\[ \begin{aligned} -\nabla \cdot (\kappa \nabla u) + qu &= f &&\quad x \in \Omega \\ u &= 0 &&\quad \text{on } \Gamma_D \\ \kappa \frac{\partial u}{\partial n} &= 0 &&\quad \text{on } \Gamma_N \end{aligned} \]
with \( \partial \Omega = \Gamma_D \cup \Gamma_N \), where \( \Gamma_D = \{x_1=0,x_1=1\} \) and \( \Gamma_N \) is the remaining part of the boundary. The domain is the unit square or unit cube. These equations are implemented in ht.hh. For calculations, we set \( \kappa=1 \), \( q=1 \), homogeneous Dirichlet data, and the source \( f \) in a way such that \( u = x_1(x_1-1) e^{-(x_1-0.5)^2}\) is solution of the above PDE for \( x=(x_1,x_2) \in \Omega \) for dimension 2 or \( x=(x_1,x_2,x_3) \in \Omega \) for dimension 3:
template <class Evaluators>
void evaluateAt(LocalPosition<Grid> const& x, Evaluators const& evaluators)
{
u = data.template value<0>(evaluators);
du = data.template derivative<0>(evaluators)[0];
xglob = cell.geometry().global(x);
double v, w, vX, vXX, wX, wXX, uXX;
v = xglob[0]*(xglob[0] - 1);
w = exp(-(xglob[0] - 0.5)*(xglob[0] - 0.5));
vX = 2*xglob[0] - 1;
vXX = 2;
wX = -2*(xglob[0] - 0.5)*w;
wXX = -2*w - 2*(xglob[0] - 0.5)*wX;
uXX = vXX*w + 2*vX*wX + v*wXX;
f = -F.kappa*uXX + F.q*v*w;
}
template<int row, int col, int dim>
Dune::FieldMatrix<Scalar, TestVars::template Components<row>::m, AnsatzVars::template Components<col>::m>
d2 (VariationalArg<Scalar,dim> const &arg1, VariationalArg<Scalar,dim> const &arg2) const
{
if ( (xglob[0]<=1e-12) || (xglob[0]>=(1-1e-12)) )
return penalty*arg1.value*arg2.value;
else return 0.0;
}
Direct or iterative solver timing functions for assembly, solution, etc.
Output as .vtk for visualization (3D):

This tutorial can be found at tutorial/instationary_NavierStokes It deals with the
The PDE is given by
\[ \begin{aligned} \frac{\partial u}{\partial t}-\mu \Delta u + (u\cdot \nabla)u+\frac{1}{\rho} \nabla p &= 0 &&\quad (x,y) \in \Omega \\ \nabla \cdot u &= 0 &&\quad (x,y) \in \Omega \\ u(x,y,t) &= -1 &&\quad \text{on } \partial \Omega|_{y=1} \\ u(x,y,t) &= 0 &&\quad \text{elsewhere on } \partial \Omega \\ u(x,y,0) &= 0 &&\quad (x,y) \in \Omega \end{aligned} \]
with velocity \( u=\bigl( u_1(x,y,t), u_2(x,y,t) \bigr)^T \), pressure \( p=p(x,y,t) \), density of the fluid \( \rho \), kinematic viscosity \( \mu \). The domain is the unit square \( \Omega = [0,1] \times [0,1] \). For incompressible flows, no explicit boundary conditions for the pressure must be given.
using VariableDescriptions = boost::fusion::vector<Variable<SpaceIndex<1>,Components<2>>,
Variable<SpaceIndex<0>,Components<1>>>;
[...]
H1Space pressureSpace(gridManager,gridManager.grid().leafGridView(),porder); // Taylor-Hood: porder = order-1
H1Space velocitySpace(gridManager,gridManager.grid().leafGridView(),order);
For the example in tutorial/Embedded_errorEstimation, we consider
This equation \[ \begin{aligned} -\nabla \cdot (\nabla u) &= f(x) &&\quad x\in \Omega \\ u &= u_b(x) &&\quad \text{on } \partial \Omega \end{aligned} \] for \( x=(x_1,x_2) \) or \( x=(x_1,x_2,x_3) \) is treated in the same way as the stationary heat transfer problem (for implementation details see as well: Laplace equation). The right-hand side is determined in a way such that \[ u=x_1x_2(x_1-1)(x_2-1)e^{-100((x_1-0.5)^2+(x_2-0.5)^2)} \] is the solution of the equation in 2D. In 3D, the equation reads analogously. We set \( u_b(x) = 0 \) for homogeneous boundary conditions. We now control the discretization error by an error estimation, where the estimator provides information about the global and local error (read more in section Adaptivity). The local estimation is used to refine the mesh where the estimated error exceeds a certain prescribed threshold. If the global error indicates sufficient accuracy, the mesh adaption procedure stops.
// perform local mesh adaption while local error tolerance not "accurate", i.e. not met
do{
[... solve equation ...]
x.data = solution.data;
// embedded error estimation:
VariableSet::VariableSet e = x;
projectHierarchically(e);
e -= x; // representation of the error
accurate = embeddedErrorEstimator(variableSet,e,x,IdentityScaling(),tol,gridManager,verbosity); // returns true if the error is below the tolerance and the mesh hat not been refined, otherwise false
nnz = assembler.nnz(0,1,0,1,onlyLowerTriangle);
size_t size = variableSet.degreesOfFreedom(0,1); // get current number of dof if the mesh has been refined
} while (!accurate)
tutorial/HB_errorEstimation solves the Poisson equation on the unit square with a
localized Gaussian peak as manufactured solution. The peak is smooth but very
concentrated, so a uniform mesh resolves it poorly. The example uses P1 elements
and a hierarchic basis (HB) error estimator, which is applicable to linear finite
elements, unlike the embedded estimator above.
The estimator extends the P1 space by a hierarchic space of order order+1:
using H1ExSpaces = boost::fusion::vector<H1Space<Grid> const*,
H1HierarchicExtensionSpace<Grid> const*>;
H1HierarchicExtensionSpace<Grid> extensionSpace(gridManager,
gridManager.grid().leafGridView(), order+1);
H1ExSpaces exSpaces(&temperatureSpace, &extensionSpace);
It assembles the defect equation on the extension space. One Jacobi step is enough for an error indicator; the coefficients are then summed per cell:
estAssembler.assemble(ErrorEstimator(LinearizationAt<Functional>(F, x), dx));
ExCoefficientVectors estRhs(estAssembler.rhs());
ExCoefficientVectors estSol = exVariableSetDesc.zeroCoefficientVector();
EstOperator estOperator(estAssembler);
JacobiPreconditioner<EstOperator> jacobi(estOperator, 1.0);
jacobi.apply(estSol, estRhs);
Cells whose indicator exceeds half the largest indicator are marked for refinement, the mesh is adapted, and the solve/estimate/refine cycle is repeated until the estimated error is below the tolerance. The program is part of the regular tutorial build:
make build-HBerrorEstimation-tutorial
make run-HBerrorEstimation-tutorial
It writes graph/peak-*.vtu for ParaView. The detailed theory is in the
Adaptivity section.
Kaskade prints a one-time notice that second derivatives of hierarchic shape functions are not implemented. The Poisson estimator only uses first derivatives, so the returned zero Hessian does not affect the result.
The propagation of electrical excitation through cardiac tissue is described by the monodomain equations, a reaction-diffusion system for the transmembrane potential \( u \) and a set of state variables \( v \) characterizing the cell membrane. The reaction term is supplied by a membrane model: a system of ODEs that describes the nonlinear dynamics of the ionic currents through the cell membranes. Several dozen such models of varying complexity exist; one of the simplest is the Aliev-Panfilov model (see AlievPanfilov1996), which enters the monodomain equations as one building block.
In general form, the monodomain system reads \[ \begin{aligned} \chi \left( C_m \frac{\partial u}{\partial t} + I_{\textrm{ion}}(u,v) \right) &= \nabla \cdot (\sigma \nabla u) + I_{\textrm{app}}, \\ \frac{\partial v}{\partial t} &= g(u,v), \end{aligned} \] where \( \chi \) is the surface-to-volume ratio, \( C_m \) the membrane capacitance, \( \sigma \) the conductivity tensor, \( I_{\textrm{ion}} \) the ionic current, and \( I_{\textrm{app}} \) an applied stimulus.
In the tutorial at tutorial/cardio, the factors \( \chi C_m \) are absorbed into the time scale and the conductivity tensor is replaced by a scalar conductivity \( \kappa \). Writing \( f(u,v) = -I_{\textrm{ion}}(u,v) \), the system becomes
\[
\begin{aligned}
\frac{\partial u}{\partial t} - \nabla \cdot (\kappa \nabla u) &= f(u,v) + I_{\textrm{app}}, \\
\frac{\partial v}{\partial t} &= g(u,v)
\end{aligned}
\]
on a 3D domain. Here, \( u \) is the transmembrane potential and \( v \) is the recovery variable that initiates repolarization.
For the Aliev-Panfilov membrane model, the reaction terms are \[ \begin{aligned} f(u,v) &= -g_a u (u-a)(u-1) - uv, \\ g(u,v) &= \frac{1}{4} \epsilon(u,v) \left( -v - g_s u (u-a-1) \right), \end{aligned} \] with \( \epsilon(u,v)=\epsilon_0 + \frac{\mu_1 v}{u+\mu_2} \). Cardiac activities such as the initiation and upstroke of the action potential are controlled by \( f \). The parameters \( g_a, g_s \) are excitation rate constants and \( a \) is the threshold parameter related to the excitation threshold potential. The restitution properties of the action potential are determined by \( \epsilon(u,v) \) with restitution parameters \( \mu_1, \mu_2 \) and \( \epsilon_0 \). The tutorial uses
The parameters used in this tutorial are
kappa = 0.001;
a = 0.1;
gs = 8.0;
ga = 8.0;
mu1 = 0.07;
mu2 = 0.3;
eps1 = 0.01; // epsilon_0
The geometry is created by using the createCuboid method:
double dh = 0.1;
Dune::FieldVector<double,dim> c0(0.0), dc(0.0);
c0[0]=1.0; c0[1]=1.0; c0[2]=1.0;
dc[0]=1.0; dc[1]=1.0; dc[2]=0.1;
GridManager<Grid> gridManager( createCuboid<Grid>(c0,dc,dh,true) );
Assembly of the system of two variables is done within the d1 and d2 caches. Here, the right-hand sides (d1), stiffness (d2) and mass (b2) matrices get assembled in blocks via row and col indices, e.g. for d1 cache:
template<int row, int dim>
Dune::FieldVector<Scalar, TestVars::template Components<row>::m>
d1 (VariationalArg<Scalar,dim> const& arg) const
{
if (row==uIdx) return -F.kappa*(du*arg.derivative[0]) + f(u,v)*arg.value + ex*arg.value;
else if (row==vIdx) return g(u,v)*arg.value;
assert("wrong index\n"==0);
return 0;
}
with \( f(u,v) = -g_a u (u-a)(u-1) - uv \) and \( g(u,v) = \frac{1}{4}(\epsilon_0 +\frac{\mu_1 v}{u+\mu_2})(-v-g_s u(u-a-1)) \). The initial excitation ex is modeled as
Scalar excitation(Position const& x) const
{
Scalar Iapp = 0.0;
// slab
if(t<0.015)
if ( (x[0]>=1.4) && (x[0]<=1.6) && (x[1]>=1.4) && (x[1]<=1.6) && (x[2]>=1.05) && (x[2]<=1.1) )
{
Iapp=10000.0*t;
if (Iapp > 100.0) Iapp = 100.0;
}
return Iapp;
}
We consider for the tutorial at tutorial/stokes the
\[ \begin{aligned} -\Delta u + \nabla p &= 0 && \quad (x,y) \in \Omega \\ \nabla \cdot u &= 0 && \quad (x,y) \in \Omega \\ u(x,y) &= -1 &&\quad \text{on } \partial \Omega|_{y=1} \\ u(x,y) &= 0 &&\quad \text{elsewhere on } \partial \Omega \end{aligned} \] with velocity \( u=u(x,y) \) and pressure \( p=p(x,y) \). We have to construct a velocity and a pressure space of different orders
H1Space pressureSpace(gridManager,gridManager.grid().leafGridView(),porder); // Taylor-Hood: porder = order-1
H1Space velocitySpace(gridManager,gridManager.grid().leafGridView(),order);
This example is a model for the pollution of the stratosphere by supersonic transport aircraft (SST). It describes the interaction of chemical species O, O3, NO and NO2 along with a simple diffusion process. It can be found at tutorial/sst_pollution and deals with
default.json.tutorial/sst_pollution is not part of the default make tutorial target. None of
its variants currently compile with Kaskade 7.8: sst.cpp still uses the now
private VariableSetDescription::CoefficientVectorRepresentation and the removed
writeVTKFile helper, while the historical sst_giant.cpp and sst_nleqErr.cpp
variants additionally include the removed algorithm/ directory. The model and
parameters below remain a useful reference, but the sources need to be ported to
the current coefficient-vector and writeVTK APIs before they can be run.
System of four equations
\[
\begin{aligned}
0 &= D\Delta u_1 + k_{1,1} - k_{1,2}u_1 +k_{1,3}u_2 + k_{1,4}u_4 - k_{1,5}u_1 u_2 - k_{1,6} u_1 u_4 \\
0 &= D\Delta u_2 + k_{2,1}u_1 - k_{2,2}u_2 + k_{2,3}u_1 u_2 - k_{2,4} u_2 u_3 \\
0 &= D\Delta u_3 - k_{3,1}u_3 + k_{3,2}u_4 + k_{3,3}u_1 u_4 - k_{3,4} u_2 u_3 + 800.0 + \text{SST} \\
0 &= D\Delta u_4 - k_{4,1}u_4 + k_{4,2}u_2 u_3 - k_{4,3}u_1 u_4 + 800.0
\end{aligned}
\]
where
\[
\begin{aligned}
D &= 0.5 \cdot 10^{-9} \\
SST &=
\begin{cases}
3250, & \text{if}\ (x,y) \in [0.5,0.6]^2 \\
360, & \text{otherwise.}
\end{cases}
\end{aligned}
\]
and the boundary conditions
\[
\frac{\partial u_i}{\partial n} = 0 \quad \text{for } i=1,\ldots,4 \text{ on } \partial \Omega
\]
with \( \Omega = [0,1] \times [0,1] \).
\( u = (u_1,u_2,u_3,u_4) \) describes the density/concentration of a substance at position \( x \in \Omega \), then the term \( D \Delta u \) describes the diffusion with a diffusion coefficient \( D \). The rest of the equation describes the process that changes the present \( u \) by chemical reaction or any other mechanism, not limited to diffusion in space. The parameters \( k \) are called the reaction rates.
Two sets of start values for the Newton iteration are provided. The first one produces a mildly nonlinear problem, which can be solved by applying an ordinary Newton iteration. The second one produces a highly nonlinear problem for which a damped Newton method is necessary in order to solve it. For \( (x,y) \in \Omega \), we have \[ \begin{aligned} &\text{first set:} &\qquad \qquad & \text{second set:} \\ &u_1^0(x,y) = 1.306028 \cdot 10^6 && u_1^0(x,y) = 10^9 \\ &u_2^0(x,y) = 1.076508 \cdot 10^{12} & & u_2^0(x,y) = 10^9 \\ &u_3^0 (x,y) = 6.457715 \cdot 10^{10} && u_3^0(x,y) = 10^{13} \\ &u_4^0(x,y) = 3.542285 \cdot 10^{10} & & u_4^0(x,y) = 10^7 \end{aligned} \]
The GIANT (Global Inexact Affine Invariant Newton Techniques) and GBIT (Good Broyden - Error based iterative linear solver) references are:
GIANT - A Software Package for the Numerical Solution of Very Large Systems of Highly Nonlinear Equations, U. Nowak, L. Weimann, 1990 https://opus4.kobv.de/opus4-zib/frontdoor/index/index/docId/474