In this example we will show how to implement a system of coupled PDEs. We define
\begin{eqnarray*} -\Delta u_1 &=& f &\text{ in } \Omega \\ u_0 - u_1 &=& 0 &\text{ in } \Omega \\ u_1 &=& g &\text{ on } \Gamma \end{eqnarray*}
whereby \( \Omega \subset \mathbb{R}^d, \quad 1 \le d \le 3 \) denotes the domain and \( \Gamma = \partial \Omega \) its boundary.
We set the right hand side functions to
\begin{eqnarray*} f &=& -1.0 \\ g &=& 0. \end{eqnarray*}
The system can be written in matrix-vector form as
\[ \begin{pmatrix} I & -I \\ 0 & -\Delta \end{pmatrix} \begin{pmatrix} u_0\\ u_1 \end{pmatrix} = \begin{pmatrix} 0\\ f \end{pmatrix}. \]
We will now look at the source code of the example in detail. You can also find the complete source code for all files below.
First we include the required AMDiS headers. AMDiS.hpp
is a collection of headers that are commonly used. In this example we also use the ProblemStat
class, which we explicitly include. We will also use the predefined operators in LocalOperators.hpp
.
Most AMDiS classes and functions are found in the AMDiS namespace. To make life easier for us we therefore tell the compiler to look for our classes in this namespace.
Our example begins with a call to the main
function. Any command line argument we pass can be used with the argc
and argv
arguments. As every AMDiS program requires us to set up an Environment
at the start we do that here.
We define the grid manager used in this example - a structured axis-aligned cube grid. Note that GRIDDIM
is a constant passed by the buildsystem. By default we build the example for \( GRIDDIM = 2 \). Then we proceed to call the MeshCreator
to build our grid.
Now we create and initialize the problem. We use the Dune::Functions::BasisFactory
functions power
and lagrange
to define nodal (lagrange) basis functions of order 2 for both \( u_0 \text{ and } u_1 \). We also set up an AdaptInfo
object that controls the adaptation procedure later on.
Next we add the operators that define our problem. Since we are using a basis with more than one basis node we need to specify the indices of the basis node an operator belongs to. This corresponds to the indices within the matrix-vector form above as follows
\begin{eqnarray*} (0,0) &\rightarrow& I \\ (0,1) &\rightarrow& -I \\ (1,0) &\rightarrow& 0 \\ (1,1) &\rightarrow& -\Delta. \end{eqnarray*}
Lastly we set the constraints: We have dirichlet boundary conditions on the left and lower part of the boundary, as indicated by the predicate function and prescribe a value of zero. Since we only want to apply the constraint to the first component \( u_1 \) we pass the index 1 as argument to the function.
Now we can assemble the system, solve it and write the results to a file.
With that the example ends. We return 0 to indicate a successful run.
We describe the options used by the example's parameter file vecellipt.dat.2d
. For a full description of all options see the reference page.
Parameters for the grid "elliptMesh":
ellipt->mesh
specifies the name of the grid used by the problem named "ellipt".
This parameter specifies the symmetry structure of the assembled matrix.
Parameters for the solver employed by the problem "ellipt":
Parameters for the output generated by the problem "ellipt". Note that the index in brackets relates to the index of the basis node, so [0]
refers to the component \( u_0 \) while [1]
refers to the component \( u_1 \).
Using a console we navigate to the examples directory where the vecellipt.2d
files resides and run the file while also passing the necessary arguments.
Running vecellipt.2d
in bash could look like this:
In this section we show some sample output of vecellipt.2d
using the default arguments.
162 local DOFs fill-in of assembled matrix: 4356 assemble needed 0.000800004 seconds === GeneralizedPCGSolver === rate=0.489578, T=0.000923321, TIT=2.71565e-05, IT=35 solution of discrete system needed 0.0066155 seconds writeFiles needed 0.000301686 seconds
Using ParaView we can inspect the output file and obtain a visualization that looks like this.
The complete source code for the example and the parameter files can be found here: