Reference documentation for deal.II version 8.5.0

Table of contents  

This example is devoted to the MeshWorker framework and the discontinuous Galerkin method, or in short: DG method. It includes the following topics.
The particular concern of this program are the loops of DG methods. These turn out to be especially complex, primarily because for the face terms, we have to distinguish the cases of boundary, regular interior faces and interior faces with hanging nodes, respectively. The MeshWorker framework implements the standard loop over all cells and faces in MeshWorker::loop() and takes care of distinguishing between all the different faces.
There are two things left to do if you use MeshWorker: first, you need to write the local integrators for your problem. Second, you select classes from the MeshWorker namespace and combine them to achieve your goal.
The model problem solved in this example is the linear advection equation
\[ \nabla\cdot \left({\mathbf \beta} u\right)=0 \qquad\mbox{in }\Omega, \]
subject to the boundary conditions
\[ u=g\quad\mbox{on }\Gamma_, \]
on the inflow part \(\Gamma_\) of the boundary \(\Gamma=\partial\Omega\) of the domain. Here, \({\mathbf \beta}={\mathbf \beta}({\bf x})\) denotes a vector field, \(u\) the (scalar) solution function, \(g\) a boundary value function,
\[ \Gamma_:=\{{\bf x}\in\Gamma, {\mathbf \beta}({\bf x})\cdot{\bf n}({\bf x})<0\} \]
the inflow part of the boundary of the domain and \({\bf n}\) denotes the unit outward normal to the boundary \(\Gamma\). This equation is the conservative version of the advection equation already considered in step9 of this tutorial. In particular, we solve the advection equation on \(\Omega=[0,1]^2\) with \({\mathbf \beta}=\frac{1}{x}(x_2, x_1)\) representing a circular counterclockwise flow field, and \(g=1\) on \({\bf x}\in\Gamma_^1:=[0,0.5]\times\{0\}\) and \(g=0\) on \({\bf x}\in \Gamma_\setminus \Gamma_^1\).
We apply the wellknown upwind discontinuous Galerkin method. To this end, we introduce the mesh dependent bilinear form
\[ \sum_{T\in \mathbb T_h}\bigl(u_h,{\mathbf \beta}\cdot\nabla v_h\bigr)_T +\sum_{F\in\mathbb F_h^i} \bigl<u_h^, \beta\cdot[v_h\mathbf n]\bigr>_{F} + \bigl<u_h, v_h \beta\cdot \mathbf n\bigr>_{\Gamma_+} =\bigl<g, v_h \beta\cdot\mathbf n\bigr>_{\Gamma_}. \]
Here, \(\mathbb T_h\) is the set of all active cells of the triangulation and \(\mathbb F_h^i\) is the set of all active interior faces. \((\cdot, \cdot)_T\) and \(\left<\cdot, \cdot\right>_{F}\) denote the L^{2}inner products on the cell \(T\) and a face \(F\), respectively. The jump is defined as \([v\mathbf n] = v^+\mathbf n^+ + v^\mathbf n^\), where the superscripts refer to the upwind ('+') and downwind ('') values at the face.
In order to implement this bilinear form, we need to compute the cell terms \(\bigl(u_h,{\mathbf \beta}\cdot\nabla v_h\bigr)_T\), the internal fluxes \(\bigl<u_h^, \beta\cdot[v_h\mathbf n]\bigr>_{F}\), and the boundary terms \(\bigl<u_h, v_h \beta\cdot \mathbf n]\bigr>_{\Gamma_+}\) and \(\bigl<g, \beta\cdot\mathbf n v_h\bigr>_{\Gamma_}\). The summation of all those is done by MeshWorker::integration_loop().
The first few files have already been covered in previous examples and will thus not be further commented on:
Here the discontinuous finite elements are defined. They are used in the same way as all other finite elements, though – as you have seen in previous tutorial programs – there isn't much user interaction with finite element classes at all: they are passed to DoFHandler
and FEValues
objects, and that is about it.
We are going to use the simplest possible solver, called Richardson iteration, that represents a simple defect correction. This, in combination with a block SSOR preconditioner (defined in precondition_block.h), that uses the special block matrix structure of system matrices arising from DG discretizations.
We are going to use gradients as refinement indicator.
Here come the new include files for using the MeshWorker framework. The first contains the class MeshWorker::DoFInfo, which provides local integrators with a mapping between local and global degrees of freedom. It stores the results of local integrals as well in its base class Meshworker::LocalResults. In the second of these files, we find an object of type MeshWorker::IntegrationInfo, which is mostly a wrapper around a group of FEValues objects. The file meshworker/simple.h
contains classes assembling locally integrated data into a global system containing only a single matrix. Finally, we will need the file that runs the loop over all mesh cells and faces.
Like in all programs, we finish this section by including the needed C++ headers and declaring we want to use objects in the dealii namespace without prefix.
First, we define a class describing the inhomogeneous boundary data. Since only its values are used, we implement value_list(), but leave all other functions of Function undefined.
Given the flow direction, the inflow boundary of the unit square \([0,1]^2\) are the right and the lower boundaries. We prescribe discontinuous boundary values 1 and 0 on the xaxis and value 0 on the right boundary. The values of this function on the outflow boundaries will not be used within the DG scheme.
After this preparations, we proceed with the main class of this program, called AdvectionProblem. It is basically the main class of step6. We do not have a ConstraintMatrix, because there are no hanging node constraints in DG discretizations.
Major differences will only come up in the implementation of the assemble functions, since here, we not only need to cover the flux integrals over faces, we also use the MeshWorker interface to simplify the loops involved.
Furthermore we want to use DG elements of degree 1 (but this is only specified in the constructor). If you want to use a DG method of a different degree the whole program stays the same, only replace 1 in the constructor by the desired polynomial degree.
The next four members represent the linear system to be solved. system_matrix
and right_hand_side
are generated by assemble_system()
, the solution
is computed in solve()
. The sparsity_pattern
is used to determine the location of nonzero elements in system_matrix
.
Finally, we have to provide functions that assemble the cell, boundary, and inner face terms. Within the MeshWorker framework, the loop over all cells and much of the setup of operations will be done outside this class, so all we have to provide are these three operations. They will then work on intermediate objects for which first, we here define typedefs to the info objects handed to the local integration functions in order to make our life easier below.
The following three functions are then the ones that get called inside the generic loop over all cells and faces. They are the ones doing the actual integration.
In our code below, these functions do not access member variables of the current class, so we can mark them as static
and simply pass pointers to these functions to the MeshWorker framework. If, however, these functions would want to access member variables (or needed additional arguments beyond the ones specified below), we could use the facilities of boost::bind (or std::bind, respectively) to provide the MeshWorker framework with objects that act as if they had the required number and types of arguments, but have in fact other arguments already bound.
We start with the constructor. The 1 in the constructor call of fe
is the polynomial degree.
In the function that sets up the usual finite element data structures, we first need to distribute the DoFs.
We start by generating the sparsity pattern. To this end, we first fill an intermediate object of type DynamicSparsityPattern with the couplings appearing in the system. After building the pattern, this object is copied to sparsity_pattern
and can be discarded.
To build the sparsity pattern for DG discretizations, we can call the function analogue to DoFTools::make_sparsity_pattern, which is called DoFTools::make_flux_sparsity_pattern:
Finally, we set up the structure of all components of the linear system.
Here we see the major difference to assembling by hand. Instead of writing loops over cells and faces, we leave all this to the MeshWorker framework. In order to do so, we just have to define local integration functions and use one of the classes in namespace MeshWorker::Assembler to build the global system.
This is the magic object, which knows everything about the data structures and local integration. This is the object doing the work in the function MeshWorker::loop(), which is implicitly called by MeshWorker::integration_loop() below. After the functions to which we provide pointers did the local integration, the MeshWorker::Assembler::SystemSimple object distributes these into the global sparse matrix and the right hand side vector.
First, we initialize the quadrature formulae and the update flags in the worker base class. For quadrature, we play safe and use a QGauss formula with number of points one higher than the polynomial degree used. Since the quadratures for cells, boundary and interior faces can be selected independently, we have to hand over this value three times.
These are the types of values we need for integrating our system. They are added to the flags used on cells, boundary and interior faces, as well as interior neighbor faces, which is forced by the four true
values.
After preparing all data in info_box
, we initialize the FEValues objects in there.
The object created so far helps us do the local integration on each cell and face. Now, we need an object which receives the integrated (local) data and forwards them to the assembler.
Now, we have to create the assembler object and tell it, where to put the local data. These will be our system matrix and the right hand side.
Finally, the integration loop over all active cells (determined by the first argument, which is an active iterator).
As noted in the discussion when declaring the local integration functions in the class declaration, the arguments expected by the assembling integrator class are not actually function pointers. Rather, they are objects that can be called like functions with a certain number of arguments. Consequently, we could also pass objects with appropriate operator() implementations here, or the result of std::bind if the local integrators were, for example, nonstatic member functions.
These are the functions given to the MeshWorker::integration_loop() called just above. They compute the local contributions to the system matrix and right hand side on cells and faces.
First, let us retrieve some of the objects used here from info
. Note that these objects can handle much more complex structures, thus the access here looks more complicated than might seem necessary.
With these objects, we continue local integration like always. First, we loop over the quadrature points and compute the advection vector in the current point.
We solve a homogeneous equation, thus no right hand side shows up in the cell term. What's left is integrating the matrix entries.
Now the same for the boundary terms. Note that now we use FEValuesBase, the base class for both FEFaceValues and FESubfaceValues, in order to get access to normal vectors.
Finally, the interior face terms. The difference here is that we receive two info objects, one for each cell adjacent to the face and we assemble four matrices, one for each cell and two for coupling back and forth.
For quadrature points, weights, etc., we use the FEValuesBase object of the first argument.
For additional shape functions, we have to ask the neighbors FEValuesBase.
Then we get references to the four local matrices. The letters u and v refer to trial and test functions, respectively. The numbers indicate the cells provided by info1 and info2. By convention, the two matrices in each info object refer to the test functions on the respective cell. The first matrix contains the interior couplings of that cell, while the second contains the couplings between cells.
Here, following the previous functions, we would have the local right hand side vectors. Fortunately, the interface terms only involve the solution and the right hand side does not receive any contributions.
This term we've already seen:
We additionally assemble the term \((\beta\cdot n u,\hat v)_{\partial \kappa_+}\),
This one we've already seen, too:
And this is another new one: \((\beta\cdot n \hat u,\hat v)_{\partial \kappa_}\):
For this simple problem we use the simplest possible solver, called Richardson iteration, that represents a simple defect correction. This, in combination with a block SSOR preconditioner, that uses the special block matrix structure of system matrices arising from DG discretizations. The size of these blocks are the number of DoFs per cell. Here, we use a SSOR preconditioning as we have not renumbered the DoFs according to the flow field. If the DoFs are renumbered in the downstream direction of the flow, then a block GaussSeidel preconditioner (see the PreconditionBlockSOR class with relaxation=1) does a much better job.
Here we create the preconditioner,
then assign the matrix to it and set the right block size:
After these preparations we are ready to start the linear solver.
We refine the grid according to a very simple refinement criterion, namely an approximation to the gradient of the solution. As here we consider the DG(1) method (i.e. we use piecewise bilinear shape functions) we could simply compute the gradients on each cell. But we do not want to base our refinement indicator on the gradients on each cell only, but want to base them also on jumps of the discontinuous solution function over faces between neighboring cells. The simplest way of doing that is to compute approximative gradients by difference quotients including the cell under consideration and its neighbors. This is done by the DerivativeApproximation
class that computes the approximate gradients in a way similar to the GradientEstimation
described in step9 of this tutorial. In fact, the DerivativeApproximation
class was developed following the GradientEstimation
class of step9. Relating to the discussion in step9, here we consider \(h^{1+d/2}\nabla_h u_h\). Furthermore we note that we do not consider approximate second derivatives because solutions to the linear advection equation are in general not in \(H^2\) but in \(H^1\) (to be more precise, in \(H^1_\beta\)) only.
The DerivativeApproximation
class computes the gradients to float precision. This is sufficient as they are approximate and serve as refinement indicators only.
Now the approximate gradients are computed
and they are cellwise scaled by the factor \(h^{1+d/2}\)
Finally they serve as refinement indicator.
The output of this program consists of epsfiles of the adaptively refined grids and the numerical solutions given in gnuplot format. This was covered in previous examples and will not be further commented on.
Write the grid in eps format.
Output of the solution in gnuplot format.
The following run
function is similar to previous examples.
The following main
function is similar to previous examples as well, and need not be commented on.
The output of this program consist of the console output, the eps files including the grids, and the solutions given in gnuplot format.
We show the solutions on the initial mesh, the mesh after two and after five adaptive refinement steps.
Then we show the final grid (after 5 refinement steps) and the solution again, this time with a nicer 3d rendering (obtained using the DataOutBase::write_vtk function and the VTKbased VisIt visualization program) that better shows the sharpness of the jump on the refined mesh and the over and undershoots of the solution along the interface:
And finally we show a plot of a 3d computation.
In this program we have used discontinuous elements. It is a legitimate question to ask why not simply use the normal, continuous ones. Of course, to everyone with a background in numerical methods, the answer is obvious: the continuous Galerkin (cG) method is not stable for the transport equation, unless one specifically adds stabilization terms. The DG method, however, is stable. Illustrating this with the current program is not very difficult; in fact, only the following minor modifications are necessary:
While the 2d solution has been shown above, containing a number of small spikes at the interface that are, however, stable in height under mesh refinement, results look much different when using a continuous element:
0  1  
2  3  
4  5 
In refinement iteration 5, the image can't be plotted in a reasonable way any more as a 3d plot. We thus show a color plot with a range of \([1,2]\) (the solution values of the exact solution lie in \([0,1]\), of course). In any case, it is clear that the continuous Galerkin solution exhibits oscillatory behavior that gets worse and worse as the mesh is refined more and more.
There are a number of strategies to stabilize the cG method, if one wants to use continuous elements for some reason. Discussing these methods is beyond the scope of this tutorial program; an interested reader could, for example, take a look at step31.
Given that the exact solution is known in this case, one interesting avenue for further extensions would be to confirm the order of convergence for this program. In the current case, the solution is nonsmooth, and so we can not expect to get a particularly high order of convergence, even if we used higher order elements. But even if the solution is smooth, the equation is not elliptic and so it is not immediately clear that we should obtain a convergence order that equals that of the optimal interpolation estimates (i.e. for example that we would get \(h^3\) convergence in the \(L^2\) norm by using quadratic elements).
In fact, for hyperbolic equations, theoretical predictions often indicate that the best one can hope for is an order one half below the interpolation estimate. For example, for the streamline diffusion method (an alternative method to the DG method used here to stabilize the solution of the transport equation), one can prove that for elements of degree \(p\), the order of convergence is \(p+\frac 12\) on arbitrary meshes. While the observed order is frequently \(p+1\) on uniformly refined meshes, one can construct socalled Peterson meshes on which the worse theoretical bound is actually attained. This should be relatively simple to verify, for example using the VectorTools::integrate_difference function.
A different direction is to observe that the solution of transport problems often has discontinuities and that therefore a mesh in which we bisect every cell in every coordinate direction may not be optimal. Rather, a better strategy would be to only cut cells in the direction parallel to the discontinuity. This is called anisotropic mesh refinement and is the subject of step30.