DG Basics: Projection and Approximation Properties

What's new

Prerequisites

No BoSSS specific prerequisites are needed to complete this tutorial.

Problem statement

First, we define two functions: $g_1$ is continuous, $g_2$ has a discontinuity at $x = \pi$ in the first derivative

$$ g_1(x) := \sin(x), $$$$g_2(x) := \vert \sin(x) \vert ,$$

The function argument is a vector $x \in R^n$, consisting only of one entry since we are working in a one dimensional space.

BoSSS however supports 1D, 2D and 3D, so the spatial coordinate is a general vector.

Solution within the BoSSS framework

Note:

  1. This tutorial can be found in the source code repository as asd ue2Basics.ipynb. One can directly load this into Jupyter to interactively work with the following code examples.
  2. In the following line, the reference to BoSSSpad.dll is required. You must either set #r "BoSSSpad.dll" to something which is appropirate for your computer (e.g. C:\Program Files (x86)\FDY\BoSSS\bin\Release\net5.0\BoSSSpad.dll if you installed the binary distribution), or, if you are working with the source code, you must compile BoSSSpad and put it side-by-side to this worksheet file (from the original location in the repository, you can use the scripts getbossspad.sh, resp. getbossspad.bat).

Plotting the functions

First, we plot the functions that are defined above over the interval $(0 ,2 \pi)$ with 1000 sampling points using a Gnuplot-object.

We define equidistant sampling points...

...and compute the function values. In the loop, we have to convert the scalar x[i] into an array with one element, since $g_1$ has to be feed with arrays.

For now, we are using the simple plotting interface, which supports Matlab-Style format specifiers and color names.

(More advanced plots can be produced with Plot2Ddata and/or Gnuplot classes)

Note

In order to obtain an output for the plot or any other command, there must not be a semicolon ; at the end of the line!

Next, we create a grid which has a cell boundary exactly at the position of the discontinuity of $g_2$.

We can get the total number of cells by using the following command:

The recently created grid-object is not directly usable because it contains only the nodes of the grid.

We have to create a GridData-object which provides all necessary transformation metrics, etc. .

Projection onto the DG space

At this point, we are able to create the so-called DG fields to approximate $g_1$ on grid1.

Therefore, we project $g_1$ onto grid1 using polynomial orders of $p=2$ and $p=8$.

Now, let us plot the projected solution for $p=2$.

By using the upsampling parameter, we can determine the amount of sampling points per cell.

Computing the $L^2$-error

Next, we learn how to compute the $L^2$-error for both approximations of $g_1$ with different polynomial degrees:

Plotting the point-wise error

Now, we plot the point-wise error for the approximation of $g_1$ on grid1 with a polynomial degree of 8.

Decay behavior of the DG modes for smooth and non-smooth functions

We investigate the decay behavior of the DG modes for smooth and non-smooth functions.

For this purpose, we create a second grid which has the discontinuity of $g_2$ within a cell and project $g_2$ onto this grid like mentioned above.

The cell coordinates can be extracted by using the Coordinates parameter.

Only the absolute value shall be plotted. We use a for-loop to replace the data in cell0, cell1 and cell2 by their absolute values.

Note

Using a shortcut for the for-loop above, the absolute values in cell0 can also be stored using the following command:

Now, we would like to plot the logarithm (use Math.Log10(...)) of the absolute values of the DG coordinates.

Convergence study

In this section, we learn how to perform a convergence study for $g_2$ for two different sequences of grid resolutions and different polynomial orders.

Therefore, we define two different sequences of grid resolutions:

Grid resolutions so that the kink in g2 is located at a cell boundary:

Grid resolutions so that the kink in g2 is located within a cell:

We save our errors into a multidimensional array by looping over

We plot the error for the grids which have the kink at the cell boundary, there we reach spectral convergence:

Now we plot the error for the grids which have the kink within a cell; due to the low regularity, the convergence of the DG method degenerates:

Where to go from here? (Further Reading)

This tutorial addressed the very basics of setting up a BoSSS~application, namely grid instantiation, the $L^2$-projection of functions onto the DG space and performing a spatial convergence study. Where do you go from here? We recommend that you continue with other relevant basics as provided in the tutorials dealing with the creation of a spatial operator, explicit time integration and the implementation of numerical fluxes.