What's new

Prerequisites

Within this tutorial the Lax-Friedrichs flux will be implemented as an alternative to the Upwind flux (see chapter DifferentialOperator). For both fluxes a convergence study will be performed and the "experimental order of convergence" (EOC) will be computed. For the implementation of the Lax-Friedrichs flux and the Upwind flux it is recommended to work through chapter DifferentialOperator first as the definition of fluxes is explained there in more detail. For the second part of the tutorial, chapter GridInstantiation has already taught the basics of doing a convergence study.

1 Problem statement

As an examplary problem, we consider the scalar transport equation

$$ \frac{\delta c}{\delta t} + \nabla \cdot (\vec{u} c) = 0 $$

in the domain $\Omega = [-1, 1] \times [-1, 1]$, where the concentration $c = c(x,y,t) \in \mathbb{R}$ is unknown and the velocity field is given by $$ \vec{u} = \begin{pmatrix} y\\-x \end{pmatrix} $$ The analytical solution for the problem above is given by $$ c_\text{Exact}(x,y,t) = \cos(\cos(t) x - \sin(t) y) \quad \text{ for } (x,y) \in \Omega, $$ which can be used to describe the initial and boundary conditions.

2 Solution within the BoSSS Framework

First, we define functions for the given velocity field and the exact solution

2 Definition of the numerical fluxes

Before implementing the ScalarTransportFlux as done in Tutorial 4, we define both fluxes as functions in terms of the parameters Uin, Uout, the normal vector n and the velocityVector. Recalling the Upwind flux, the corresponding flux function is defined as

The second flux we are considering now, is the Lax-Friedrichs flux $$ \hat{f}(c_h^-, c_h^+, \vec{u} \cdot \vec{n}) = \overline{\vec{u} \, c_h} \cdot \vec{n} + \frac{C}{2} \lbrack \lbrack {c_h} \rbrack \rbrack. $$ The constant $C \in \mathbb{R}^+$ has to be sufficiently large in order to guarantee the stability of the numerical scheme. We choose $$ C = \max \vert{\vec{u} \cdot \vec{n}}\vert = 1 $$ for the given problem.

For the implementation of the ScalarTransportFlux we want to generate instances by the definition of the numericalFlux.

Therefore a new constructor is implemented and the implementation of InnerEdgeFlux is rewritten in terms of the numericalFlux.

For both numerical fluxes we define a DifferentialOperator that uses the corresponding flux to compute div(...)

3 Convergence study

In the following a convergence study for the discretization error will be performed on grids with $2\times2$, $4\times4$, $8\times8$ and $16\times16$ cells.

The error at $t = \pi /4$ will be investigated for the polynomial degrees $p = 0, \ldots, 3$ of the ansatzfunctions.

The study will be done for both numerical fluxes.

We start by defining a series of nested grids for the convergence study

Then, a SinglePhaseField is defined for each polynomial degree on each grid. The initial value is projected on each field.

Since the error at a fourth revolution is considered, the initial concentration has to be simulated until $\textbf{endTime} = \pi / 4$. For the timestepping we are using the classical fourth order Runge-Kutta scheme.

The timestep size should be chosen small enough in order to reduce the temporal error, so that the spatial error dominates for the convergence study.

A MultidimensionalArray is a special double array that enables shallow resizing and data extraction. For example, sub-arrays can be extracted without needing to copy the entries of the MultidimensionalArray. BoSSS makes extensive use of this class because this is crucial for the performance. Here, we create a three-dimensional array, where the first index corresponds to the flux function, the second to the DG degree and the third to the number of cells.

4 Plotting results

For the convergence plots the error is plotted over the mesh size, where the coarsest grid size is defined as size = 1.

First, we are looking at the convergence plot of the Upwind flux. Therefore, an instance of Gnuplot has to be generated.

The convergence plot is also done for the Lax-Friedrichs flux.

5 Linear regression by ordinary least squares

For the determination of the experimental order of convergence (EOC) the linear regression is used to compute the slope of the line in the log-log plot. In the following, the ordinary least squares method is implemented to estimate the regression coefficient of the slope for given sets of x- and y-values.

Verification that the slope is computed correctly

The experimental orders of convergence (EOC) are computed for both fluxes for each polynomial degree of the ansatzfunctions