deal.II version GIT relicensing-2287-g6548a49e0a 2024-12-20 18:30:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
The step-82 tutorial program

This tutorial depends on step-47.

Table of contents
  1. Introduction
  2. The commented program
  1. Results
  2. The plain program

This program was contributed by Andrea Bonito (Texas A&M University) and Diane Guignard (University of Ottawa).

This material is based upon work supported by the National Science Foundation under Grant No. DMS-1817691. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Note
If you use this program as a basis for your own work, please consider citing it in your list of references. The initial version of this work was contributed to the deal.II project by the authors listed in the following citation: 10.5281/zenodo.5598180

Introduction

Problem Statement

In this example, we consider the local discontinuous Galerkin (LDG) method for approximating the solution to the bi-Laplacian problem,

\begin{align*} \Delta^2 u & = f \quad \mbox{in } \Omega, \\ \nabla u & = \mathbf{0} \quad \mbox{on } \partial\Omega, \\ u & = 0 \quad \mbox{on } \partial\Omega, \end{align*}

where \(\Omega\subset\mathbb{R}^d\) \((d=2,3)\) is an open bounded Lipschitz domain and \(f\in L^2(\Omega)\). This is the same problem we have already considered in step-47, but we will take here a different approach towards solving it: Rather than using continuous finite elements and the interior penalty method, we consider discontinuous finite elements and the local discontinuous Galerkin method defined using lifting operators.

The weak formulation of this problem reads as follows: find \(u\in H_0^2(\Omega)\) such that

\[ \int_{\Omega}D^2u:D^2v = \int_{\Omega}fv \qquad \forall \, v\in H_0^2(\Omega), \]

where \(D^2v\) denotes the Hessian of \(v\) and \(H_0^2(\Omega)\dealcoloneq\{v\in H^2(\Omega): \,\, v=0 \mbox{ and } \nabla v=\mathbf{0} \,\, \mbox{ on } \partial\Omega\}\). Using so-called lifting operators as well as the Nitsche approach to impose the homogeneous Dirichlet boundary conditions, the LDG approximation of this problem consists of replacing the Hessians by discrete Hessians (see below) and adding penalty terms involving properly scaled jump terms. In particular, the versatility of the method described below is of particular interest for nonlinear problems or problems with intricate weak formulations for which the design of discrete algorithms is challenging.

Discretization

Finite element spaces

For \(h>0\), let \(\mathcal{T}_h\) be a partition of \(\Omega\) into quadrilateral (hexahedral if \(d=3\)) elements \(K\) of diameter \(h_{K}\leq h\) and let \(\mathcal{E}_h=\mathcal{E}_h^0\cup\mathcal{E}_h^b\) denote the set of (interior and boundary) faces. We restrict the discussion to conforming subdivisions to avoid technicalities already addressed in previous tutorials. The diameter of \(e \in \mathcal{E}_h\) is denoted \(h_e\). For any integer \(k\ge 2\), we introduce the (discontinuous) finite element space

\[ \mathbb{V}_h\dealcoloneq\left\{v_h\in L^2(\Omega): \,\, v_h|_K\circ F_{K}\in\mathbb{Q}_k \quad \forall \, K \in\mathcal{T}_h \right\}, \]

where \(F_{K}\) is the map from the reference element \(\hat{K}\) (unit square/cube) to the physical element \(K\). For \(v_h\in\mathbb{V}_h\), the piecewise differential operators are denoted with a subscript \(h\), for instance \(\nabla_h v_h|_K=\nabla(v_h|_K)\) and \(D_h^2 v_h=\nabla_h\nabla_h v_h\). For \(e\in\mathcal{E}_h\), we assign a normal \(\mathbf{n}_e\). The choice of normal is irrelevant except that when \(e\) is a boundary face, \(\mathbf{n}_e\) is the normal pointing outward \(\Omega\).

Jumps, averages, and discrete reconstruction of differential operators

The piecewise differential operators do not have enough information to be accurate approximations of their continuous counterparts. They are missing inter-element information.

This leads to the introductions of jump and average operators:

\[ \jump{v_h}|_e \dealcoloneq \left\{\begin{array}{ll} v_h|_{K_1}-v_h|_{K_2} & e\in\mathcal{E}_h^0 \\ v_h|_{K_1} & e\in\mathcal{E}_h^b \end{array}\right. \quad \mbox{and} \quad \average{v_h}|_e \dealcoloneq \left\{\begin{array}{ll} \frac{1}{2}(v_h|_{K_1}+v_h|_{K_2}) & e\in\mathcal{E}_h^0 \\ v_h|_{K_1} & e\in\mathcal{E}_h^b, \end{array}\right. \]

respectively, where \(K_1\) and \(K_2\) are the two elements adjacent to \(e\) so that \(\mathbf{n}_e\) points from \(K_1\) to \(K_2\) (with obvious modification when \(e\) is a boundary edge). These are the same operators that we have previously used not only in step-47, but also in other tutorials related to discontinuous Galerkin methods (e.g., step-12).

With these notations, we are now in position to define the discrete/reconstructed Hessian \(H_h(v_h)\in\left[L^2(\Omega)\right]^{d\times d}\) of \(v_h\in\mathbb{V}_h\); that is, something that will take the role of \(D^2 v\) in the definition of the weak formulation above when moving from the continuous to the discrete formulation. We first consider two local lifting operators \(r_e:[L^2(e)]^d\rightarrow[\mathbb{V}_h]^{d\times d}\) and \(b_e:L^2(e)\rightarrow[\mathbb{V}_h]^{d\times d}\) defined for \(e\in\mathcal{E}_h\) by, respectively,

\[ r_e\left(\boldsymbol{\phi}\right) \in [\mathbb{V}_h]^{d\times d}: \, \int_{\Omega} \tau_h : r_e\left(\boldsymbol{\phi}\right) = \int_e\average{\tau_h}\mathbf{n}_e\cdot\boldsymbol{\phi} \qquad \forall \, \tau_h\in [\mathbb{V}_h]^{d\times d} \]

and

\[ b_e(\phi) \in [\mathbb{V}_h]^{d\times d}: \, \int_{\Omega} \tau_h : b_e(\phi) = \int_e\average{{\rm div}\, \tau_h}\cdot\mathbf{n}_e\phi \qquad \forall \, \tau_h\in [\mathbb{V}_h]^{d\times d}. \]

We have \({\rm supp}\,(r_e\left(\boldsymbol{\phi}\right))={\rm supp}\,(b_e(\phi))=\omega_e\), where \(\omega_e\) denotes the patch of (one or two) elements having \(e\) as part of their boundaries.

The discrete Hessian operator \(H_h:\mathbb{V}_h\rightarrow\left[L^2(\Omega)\right]^{2\times 2}\) is then given by

\[ H_h(v_h) \dealcoloneq D_h^2 v_h -R_h(\jump{\nabla_h v_h})+B_h(\jump{v_h}) \dealcoloneq D_h^2 v_h - \sum_{e\in\mathcal{E}_h}r_e\left(\jump{\nabla_h v_h}\right)+\sum_{e\in\mathcal{E}_h}b_e\left(\jump{v_h}\right). \]

Note
In general, the polynomial degree of the finite element space for the two lifting terms do not need to be the same as the one used for the approximate solution. A different polynomial degree for each lifting term can also be considered.

Note that other differential operators (e.g., gradient or divergence) can be reconstructed in a similar fashion, see for instance [179].

Motivation for the lifting operators

The discrete Hessian \(H_h\) is designed such that it weakly converges to the continuous Hessian \(D^2\), see the note in the next section for a precise statement. As already mentioned above, the broken Hessian is not a suitable candidate as it contains no information about inter-element jumps. We provide here an informal discussion motivating the definition of the two lifting operators and we refer to [182] and [37] for more details (although the definitions are slightly different unless the mesh is affine). The goal is then to construct a discrete operator \(H_h\) such that for all \(\tau\in [C_0^{\infty}(\Omega)]^{d\times d}\) we have

\[ \int_{\Omega}H_h(v_h):\tau\longrightarrow \int_{\Omega}D^2v:\tau \qquad \mbox{as } \,\, h\rightarrow 0 \]

for any sequence \(\{v_h\}_{h>0}\) in \(\mathbb{V}_h\) such that \(v_h\rightarrow v\) in \(L^2(\Omega)\) as \(h\rightarrow 0\) for some \(v\in H^2(\Omega)\). Let \(\tau\in [C_0^{\infty}(\Omega)]^{d\times d}\). Integrating by parts twice we get

\[ \int_{\Omega}D^2v:\tau = -\int_{\Omega}\nabla v\cdot \mbox{div}(\tau) = \int_{\Omega}v \mbox{ div}(\mbox{div}(\tau)) \]

while

\[ \int_{\Omega}v_h \mbox{ div}(\mbox{div}(\tau)) \longrightarrow \int_{\Omega}v \mbox{ div}(\mbox{div}(\tau)) \qquad \mbox{as } \,\, h\rightarrow 0. \]

Now, we integrate two times by parts the left term, taking into account that \(v_h\) is not necessarily continuous across interior faces. For any \(K\in\mathcal{T}_h\) we have

\[ \int_K v_h \mbox{ div}(\mbox{div}(\tau)) = -\int_K \nabla v_h\cdot \mbox{div}(\tau) + \int_{\partial K} v_h \mbox{ div}(\tau)\cdot \mathbf{n}_K =\int_K D^2v_h:\tau - \int_{\partial K}\nabla v_h\cdot (\tau\mathbf{n}_K) + \int_{\partial K} v_h \mbox{ div}(\tau)\cdot \mathbf{n}_K, \]

where \(\mathbf{n}_K\) denotes the outward unit normal to \(K\). Then, summing over the elements \(K\in\mathcal{T}_h\) and using that \(\tau\) is smooth, we obtain

\[ \int_{\Omega} v_h \mbox{ div}(\mbox{div}(\tau)) = \int_{\Omega} D_h^2v_h:\tau - \sum_{e\in\mathcal{E}_h}\int_e\jump{\nabla_h v_h}\cdot \average{\tau}\mathbf{n}_e + \sum_{e\in\mathcal{E}_h}\int_e v_h \average{\mbox{div}(\tau)}\cdot \mathbf{n}_e \]

which reveals the motivation for the definition of the two lifting operators: if \(\tau\) was an admissible test function, then the right-hand side would be equal to \(\int_{\Omega}H_h(v_h):\tau\) and we would have shown the desired (weak) convergence. Actually, if we add and subtract \(\tau_h\), the Lagrange interpolant of \(\tau\) in \([\mathbb{V}_h\cap H_0^1(\Omega)]^{d\times d}\), we can show that the right-hand side is indeed equal to \(\int_{\Omega}H_h(v_h):\tau\) up to terms that tends to zero as \(h\rightarrow 0\) under appropriate assumptions on \(v_h\).

It is worth mentioning that defining \(H_h\) without the lifting operators \(r_e\) and \(b_e\) for \(e\in\mathcal{E}_h^b\) would not affect the weak convergence property (the integrals over boundary faces are zero since \(\tau\) is compactly supported in \(\Omega\)). However, they are included in \(H_h\) to ensure that the solution of the discrete problem introduced in the next section satisfies the homogeneous Dirichlet boundary conditions in the limit \(h\rightarrow 0\).

LDG approximations

The proposed LDG approximation of the bi-Laplacian problem reads: find \(u_h\in\mathbb{V}_h\) such that

\[ A_h(u_h,v_h)\dealcoloneq a_h(u_h,v_h)+j_h(u_h,v_h) = F_h(v_h) \qquad \forall \, v_h\in\mathbb{V}_h, \]

where

\begin{align*} a_h(u_h,v_h) & \dealcoloneq \int_{\Omega}H_h(u_h):H_h(v_h), \\ j_h(u_h,v_h) & \dealcoloneq \gamma_1\sum_{e\in\mathcal{E}_h}h_e^{-1}\int_e\jump{\nabla_h u_h}\cdot\jump{\nabla_h v_h}+\gamma_0\sum_{e\in\mathcal{E}_h}h_e^{-3}\int_e\jump{u_h}\jump{v_h}, \\ F_h(v_h) & \dealcoloneq \int_{\Omega}fv_h. \end{align*}

Here, \(\gamma_0,\gamma_1>0\) are penalty parameters.

Let \(\{\varphi_i\}_{i=1}^{N_h}\) be the standard basis functions that generate \(\mathbb{V}_h\). We can then express the solution as \(u_h=\sum_{j=1}^{N_h}U_j\varphi_j\) and the problem reads: find \(\boldsymbol{U}=(U_j)_{j=1}^{N_h}\in\mathbb{R}^{N_h}\) such that

\[ A\boldsymbol{U} = \boldsymbol{F}, \]

where \(A=(A_{ij})_{i,j=1}^{N_h}\in\mathbb{R}^{N_h\times N_h}\) and \(\boldsymbol{F}=(F_i)_{i=1}^{N_h}\in\mathbb{R}^{N_h}\) are defined by

\[ A_{ij}\dealcoloneq A_h(\varphi_j,\varphi_i) \quad \text{and} \quad F_i\dealcoloneq F_h(\varphi_i), \qquad 1\leq i,j \leq N_h. \]

Note
The sparsity pattern associated with the above LDG method is slightly larger than that of, e.g., the symmetric interior penalty discontinuous Galerkin (SIPG) method. This is because the lifting operators in \(H_h\) extend shape functions defined on one cell to the neighboring cell where it may overlap with the lifted shape functions from a neighbor of the neighbor. However, we have the following interesting properties:
  1. The bilinear form \(A_h(\cdot,\cdot)\) is coercive with respect to the DG \(H^2\) norm

    \[ \|v_h\|_{H_h^2(\Omega)}^2\dealcoloneq\|D_h^2v_h\|_{L^2(\Omega)}^2+\sum_{e\in\mathcal{E}_h}h_e^{-1}\|\jump{\nabla_h v_h}\|_{L^2(e)}^2+\sum_{e\in\mathcal{E}_h}h_e^{-3}\|\jump{v_h}\|_{L^2(e)}^2 \]

    for any choice of penalty parameters \(\gamma_0,\gamma_1>0\). In other words, the stability of the method is ensured for any positive parameters. This is in contrast with interior penalty methods for which they need to be large enough. (See also the discussions about penalty parameters in the step-39, step-47, and step-74 programs.)
  2. If \(\{v_h\}_{h>0}\subset \mathbb{V}_h\) is a sequence uniformly bounded in the \(\|\cdot\|_{H_h^2(\Omega)}\) norm such that \(v_h\rightarrow v\) in \(L^2(\Omega)\) as \(h\rightarrow 0\) for some \(v\in H^2(\Omega)\), then the discrete Hessian \(H_h(v_h)\) weakly converges to \(D^2v\) in \([L^2(\Omega)]^{2\times 2}\) as \(h\rightarrow 0\). Note that the uniform boundedness assumption implies that the limit \(v\) belongs to \(H_0^2(\Omega)\).
  3. The use of a reconstructed operator simplifies the design of the numerical algorithm. In particular, no integration by parts is needed to derive the discrete problem. This strategy of replacing differential operators by appropriate discrete counter-parts can be applied to nonlinear and more general problems, for instance variational problems without a readily accessible strong formulation. It has been used for instance in [38] and [39] in the context of large bending deformation of plates.

As in step-47, we could consider \(C^0\) finite element approximations by replacing FE_DGQ<dim> by FE_Q<dim> (and include the appropriate header file deal.II/fe/fe_q.h) in the program below. In this case, the jump of the basis functions across any interior face is zero, and thus \(b_e\left(\jump{\varphi_i}\right)=\mathbf{0}\) for all \(e\in\mathcal{E}_h^0\), and could be dropped to save computational time. While an overkill for the bi-Laplacian problem, the flexibility of fully discontinuous methods combined with reconstructed differential operators is advantageous for nonlinear problems.

Implementation

As customary, we assemble the matrix \(A\) and the right-hand side \(\boldsymbol{F}\) by looping over the elements \(K\in\mathcal{T}_h\). Since we are using discontinuous finite elements, the support of each \(\varphi_i\) is only one element \(K\in\mathcal{T}_h\). However, due to the lifting operators, the support of \(H_h(\varphi_i)\) is \(K\) plus all the neighbors of \(K\) (recall that for \(e\in \mathcal{E}_h\), the support of the lifting operators \(r_e\) and \(b_e\) is \(\omega_e\)). Therefore, when integrating over a cell \(K_c\), we need to consider the following interactions (case \(d=2\))

 
dofs \(K_c\) \(\leftrightarrow\) dofs \(K_c\)   (stored in stiffness_matrix_cc)
dofs \(K_c\) \(\leftrightarrow\) dofs \(K_{n_k}\)   (stored in stiffness_matrix_cn and stiffness_matrix_nc)
dofs \(K_{n_k}\) \(\leftrightarrow\) dofs \(K_{n_k}\)   (stored in stiffness_matrix_nn)
dofs \(K_{n_k}\) \(\leftrightarrow\) dofs \(K_{n_l}\), \(k\ne l\)   (stored in stiffness_matrix_n1n2 and stiffness_matrix_n2n1)

The last of these accounts that the lifted shape functions from one of the neighbor cells may overlap on \(K_c\) with the lifted shape functions of another neighbor cell, as mentioned above. In other words, we need to compute the discrete Hessian of all the basis functions with support on \(K_c\) as well as all the basis functions with support on the neighboring cells of \(K_c\). This is done in the function compute_discrete_hessians. A cell \(K_c\) can have fewer than four neighbors (six when \(d=3\)) when at least one face \(e\subset\partial K_c\) is part of the boundary of the domain. It can also have more neighbors when hanging nodes are present. To simplify the presentation we do not discuss the latter.

Due to the local support of the basis functions, many of the terms of the discrete Hessian are zero. For any basis function \(\varphi^c\) with support on \(K_c\) we have \(r_e\left(\jump{\nabla_h\varphi^c}\right)\not\equiv 0\) only if \(e\subset\partial K_c\), and similarly for \(b_e\left(\jump{\varphi^c}\right)\). Therefore, the discrete Hessian of \(\varphi^c\) reduces to

\[ H_h(\varphi^c)=D_h^2\varphi^c-\sum_{e\subset\partial K}r_e\left(\jump{\nabla_h \varphi^c}\right)+\sum_{e\subset\partial K}b_e\left(\jump{\varphi^c}\right). \]

Furthermore, since we integrate on \(K_c\), we only need to evaluate the discrete Hessian at quadrature points \(x_q\) that belong to \(K_c\), namely \(H_h(\varphi^c)(x_q)\). We store this information in

\[ {\rm compute\_discrete\_hessians[i][q]}, \qquad 0\leq {\rm i} < {\rm n\_dofs}, \,\, 0\leq {\rm q} < {\rm n\_q\_points}, \]

where n_dofs = fe_values.dofs_per_cell is the number of degrees of freedom per cell and n_q_points = quad.size() is the number of quadrature points on \(K_c\). For any basis function \(\varphi^n\) with support on a neighboring cell, the discrete Hessian \(H_h(\varphi^n)\) evaluated on \(K_c\) contains only the two lifting terms, but not the term involving \(D^2_h\varphi^n\), since \(\varphi^n|_{K}\equiv 0\). Moreover, only the lifting over the common face \(e\) is nonzero on \(K_c\), namely for all \(x_q\in K_c\)

\[ H_h(\varphi^n)(x_q)=-r_e\left(\jump{\nabla_h\varphi^n}\right)(x_q)+b_e\left(\jump{\varphi^n}\right)(x_q). \]

This information is stored in

\[ {\rm compute\_discrete\_hessians\_neigh[face\_no][i][q]}, \qquad 0\leq {\rm face\_no} < {\rm n\_faces}, \,\, 0\leq {\rm i} < {\rm n\_dofs}, \,\, 0\leq {\rm q} < {\rm n\_q\_points}, \]

where n_dofs and n_q_points are as above, and n_faces = GeometryInfo<dim>::faces_per_cell is the number of faces of \(K_c\). As we shall see in the next section, we will only need to solve half of the local problems for the lifting terms.

Note
The variable discrete_hessians_neigh is of size n_faces x n_dofs x n_q_points. However, we only need to consider the interior faces, namely we do not need to fill discrete_hessians_neigh[face_no][i][q] whenever face_no corresponds to a boundary face. We could then save a little bit of storage by considering \(0\leq {\rm face\_no} < {\rm n\_faces}\) with n_faces the actual number of neighboring cells, i.e., not counting the boundary faces. By doing so, we could also avoid testing if a face lies on the boundary in the assembly of the matrix.

Computation of the lifting terms

We now describe the computation of the lifting operators \(r_e\) and \(b_e\) on each cell \(K_c\). This turns out to be a bit cumbersome, but it follows similar schemes as other reconstruction operators – see, for example, the "weak Galerkin" approach on step-61 or the "hybridizable discontinuous Galerkin" method in step-51. We focus on \(b_e\) for an interior face \(e\in\mathcal{E}_h^0\), but the other cases are treated similarly.

We have \(e=\partial K_c\cap \partial K_n\) for some neighbor \(K_n\) of \(K_c\). For a basis function \(\varphi\in\mathbb{V}_h\) with support on \(K_c\) or \(K_n\) (for the other basis functions we have \(b_e\left(\jump{\varphi}\right)\equiv 0\)), we write \(b_e\left(\jump{\varphi}\right)\in[\mathbb{V}_h]^{d\times d}\) as

\[ b_e\left(\jump{\varphi}\right)=\sum_{n=1}^{N_c+N_n}B_n\psi_n, \]

where \(\{\psi_n\}_{n=1}^{N_c}\) and \(\{\psi_n\}_{n=N_c+1}^{N_c+N_n}\) are the basis functions of \([\mathbb{V}_h]^{d\times d}\) which have support on \(K_c\) and \(K_n\), respectively. The coefficients \(\boldsymbol{B}=(B_n)_{n=1}^{N_c+N_n}\in\mathbb{R}^{N_c+N_c}\) of the lifting operator \(b_e\) are obtain upon solving the linear system

\[ M\boldsymbol{B}=\boldsymbol{G}, \]

where the components of the (local) mass matrix and the right-hand side are given respectively by

\[ M_{mn}\dealcoloneq\int_{\Omega}\psi_n:\psi_m \quad \mbox{and} \quad G_m\dealcoloneq\int_e\average{{\rm div}\, \psi_m}\cdot \mathbf{n}_e\jump{\varphi}, \qquad 1\leq m,n \leq N_c+N_n. \]

Note that this system has the decoupled form

\[ \left[\begin{array}{cc} M_c & \mathbf{0} \\ \mathbf{0} & M_n \end{array}\right]\left[\begin{array}{c} \boldsymbol{B}_c \\ \boldsymbol{B}_n \end{array}\right]=\left[\begin{array}{c} \boldsymbol{G}_c \\ \boldsymbol{G}_n \end{array}\right] \]

with \(M_c\in\mathbb{R}^{N_c\times N_c}\), \(M_n\in\mathbb{R}^{N_n\times N_n}\), \(\boldsymbol{B}_c,\boldsymbol{G}_c\in\mathbb{R}^{N_c}\), and \(\boldsymbol{B}_n,\boldsymbol{G}_n\in\mathbb{R}^{N_n}\).

In fact, since we evaluate the discrete Hessians at quadrature points \(x_q\in K_c\) and \(\psi_n|_{K_c}\equiv 0\) for \(n=N_c+1,\ldots,N_c+N_n\), we have

\[ b_e\left(\jump{\varphi}\right)(x_q)=\sum_{n=1}^{N_c+N_n}B_n\psi_n(x_q)=\sum_{n=1}^{N_c}B_n\psi_n(x_q). \]

As a consequence, only the coefficients \(B_n\), \(n=1,\ldots,N_c\), are needed.

To compute the components \(G_m\), \(m=1,\ldots,N_c\), we take advantage of the relation

\[ \mathbf{n}_e\jump{\varphi}=\mathbf{n}_{K_c}\varphi|_{K_c}+\mathbf{n}_{K_n}\varphi|_{K_n}, \]

where \(\mathbf{n}_{K_c}\) (resp. \(\mathbf{n}_{K_n}\)) denotes the outward unit normal to \(K_c\) (resp. \(K_n\)). Therefore, if \(\varphi=\varphi^c\), namely \(\varphi\) has support on the current cell \(K_c\), then

\[ G_m=\int_e\average{{\rm div}\, \psi_m}\cdot\mathbf{n}_e\jump{\varphi^c}=\frac{1}{2}\int_e{\rm div}\, \psi_m\cdot\mathbf{n}_{K_c}\varphi^c, \]

while if \(\varphi=\varphi^n\), namely \(\varphi\) has support on the neighboring cell \(K_n\), then

\[ G_m=\int_e\average{{\rm div}\, \psi_m}\cdot\mathbf{n}_e\jump{\varphi^n}=\frac{1}{2}\int_e{\rm div}\, \psi_m\cdot\mathbf{n}_{K_n}\varphi^n. \]

The factor \(\frac{1}{2}\) comes from the average operator as \(e\) is assumed to be an interior face.

Test case

The performance of the numerical algorithm will be assessed using a manufactured solution \(u:(0,1)^d\rightarrow\mathbb{R}\) given by

\[ u(x,y)=x^2(1-x)^2y^2(1-y)^2 \]

if \(d=2\), while if \(d=3\) we take

\[ u(x,y,z)=x^2(1-x)^2y^2(1-y)^2z^2(1-z)^2. \]

For different values of \(h\), we will report the error \(u-u_h\) measured in the discrete \(H^2\) metric (defined above but extended to piecewise \(H^2\) functions), the discrete \(H^1\) metric

\[ \|v\|_{H_h^1(\Omega)}^2 \dealcoloneq \|\nabla_h v\|_{L^2(\Omega)}^2+\sum_{e\in\mathcal{E}_h}h_e^{-1}\|\jump{v}\|_{L^2(e)}^2, \quad v\in \prod_{K\in\mathcal{T}_h}H^1(K), \]

as well as the \(L^2\) metric.

The commented program

Include files

All the include files have already been discussed in previous tutorials.

  #include <deal.II/grid/tria.h>
  #include <deal.II/grid/grid_generator.h>
  #include <deal.II/grid/tria_accessor.h>
  #include <deal.II/grid/tria_iterator.h>
 
  #include <deal.II/dofs/dof_handler.h>
  #include <deal.II/dofs/dof_accessor.h>
  #include <deal.II/dofs/dof_tools.h>
 
  #include <deal.II/fe/fe_dgq.h>
  #include <deal.II/fe/fe_values.h>
  #include <deal.II/fe/fe_system.h>
 
  #include <deal.II/base/quadrature_lib.h>
  #include <deal.II/base/function.h>
 
  #include <deal.II/numerics/data_out.h>
 
  #include <deal.II/lac/vector.h>
  #include <deal.II/lac/full_matrix.h>
  #include <deal.II/lac/sparse_matrix.h>
  #include <deal.II/lac/dynamic_sparsity_pattern.h>

The following three header files are for the solvers. The linear system is solved using a direct method while the conjugate gradient method is used to solve the local problems for the lifting terms.

  #include <deal.II/lac/sparse_direct.h>
  #include <deal.II/lac/solver_cg.h>
  #include <deal.II/lac/precondition.h>
 
  #include <fstream>
  #include <iostream>
 
 
  namespace Step82
  {
  using namespace dealii;
 

The BiLaplacianLDGLift class template

The main class of this program is similar to that of step-3 or step-20, as well as many other tutorial programs. The key function here is compute_discrete_hessians() which, as its name suggests, computes the discrete Hessians needed for the assembly of the matrix \(A\).

  template <int dim>
  class BiLaplacianLDGLift
  {
  public:
  BiLaplacianLDGLift(const unsigned int n_refinements,
  const unsigned int fe_degree,
  const double penalty_jump_grad,
  const double penalty_jump_val);
 
  void run();
 
  private:
  void make_grid();
  void setup_system();
  void assemble_system();
  void assemble_matrix();
  void assemble_rhs();
 
  void solve();
 
  void compute_errors();
  void output_results() const;
 

As indicated by its name, the function assemble_local_matrix() is used for the assembly of the (local) mass matrix used to compute the two lifting terms (see the matrix \(\boldsymbol{M}_c\) introduced in the introduction when describing the computation of \(b_e\)). The function compute_discrete_hessians() computes the required discrete Hessians: the discrete Hessians of the basis functions with support on the current cell (stored in the output variable discrete_hessians) and the basis functions with support on a neighbor of the current cell (stored in the output variable discrete_hessians_neigh). More precisely, discrete_hessians[i][q_point] stores \(H_h(\varphi_i)(x_q)\), where \(\varphi_i\) is a basis function with support on cell, while discrete_hessians_neigh[face_no][i][q_point] stores \(H_h(\varphi_i)(x_q)\), where \(\varphi_i\) is a basis function of the neighboring cell adjacent to the face face=cell->face(face_no).

  void assemble_local_matrix(const FEValues<dim> &fe_values_lift,
  const unsigned int n_q_points,
  FullMatrix<double> &local_matrix);
 
  void compute_discrete_hessians(
  const typename DoFHandler<dim>::active_cell_iterator &cell,
  std::vector<std::vector<Tensor<2, dim>>> &discrete_hessians,
  std::vector<std::vector<std::vector<Tensor<2, dim>>>>
  &discrete_hessians_neigh);
 
 
  const unsigned int n_refinements;
 
  const FE_DGQ<dim> fe;
  DoFHandler<dim> dof_handler;
 
typename ActiveSelector::active_cell_iterator active_cell_iterator
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation

We also need a variable that describes the finite element space \([\mathbb{V}_h]^{d\times d}\) used for the two lifting operators. The other member variables below are as in most of the other tutorial programs.

  const FESystem<dim> fe_lift;
 
  SparsityPattern sparsity_pattern;
  Vector<double> solution;
 

Finally, the last two variables correspond to the penalty coefficients \(\gamma_1\) and \(\gamma_0\) for the jump of \(\nabla_hu_h\) and \(u_h\), respectively.

  const double penalty_jump_grad;
  const double penalty_jump_val;
  };
 
 
 

Equation data

This class implement the right-hand side \(f=\Delta^2 u\) corresponding to the manufactured solution \(u\) defined in the introduction.

  template <int dim>
  class RightHandSide : public Function<dim>
  {
  public:
  RightHandSide()
  : Function<dim>()
  {}
 
  virtual double value(const Point<dim> &p,
  const unsigned int component = 0) const override;
  };
 
 
 
  template <int dim>
  double RightHandSide<dim>::value(const Point<dim> &p,
  const unsigned int /*component*/) const
  {
  double return_value = 0.0;
 
  if (dim == 2)
  {
  return_value = 24.0 * Utilities::fixed_power<2>(p[1] * (1.0 - p[1])) +
  +24.0 * Utilities::fixed_power<2>(p[0] * (1.0 - p[0])) +
  2.0 * (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
  (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]);
  }
  else if (dim == 3)
  {
  return_value = 24.0 * Utilities::fixed_power<2>(p[1] * (1.0 - p[1]) *
  p[2] * (1.0 - p[2])) +
  24.0 * Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) *
  p[2] * (1.0 - p[2])) +
  24.0 * Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) *
  p[1] * (1.0 - p[1])) +
  2.0 * (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
  (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
  Utilities::fixed_power<2>(p[2] * (1.0 - p[2])) +
  2.0 * (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
  (2.0 - 12.0 * p[2] + 12.0 * p[2] * p[2]) *
  Utilities::fixed_power<2>(p[1] * (1.0 - p[1])) +
  2.0 * (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
  (2.0 - 12.0 * p[2] + 12.0 * p[2] * p[2]) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
  }
  else
 
  return return_value;
  }
 
 
 
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Definition point.h:111
#define DEAL_II_NOT_IMPLEMENTED()

This class implement the manufactured (exact) solution \(u\). To compute the errors, we need the value of \(u\) as well as its gradient and its Hessian.

  template <int dim>
  class ExactSolution : public Function<dim>
  {
  public:
  ExactSolution()
  : Function<dim>()
  {}
 
  virtual double value(const Point<dim> &p,
  const unsigned int component = 0) const override;
 
  virtual Tensor<1, dim>
  gradient(const Point<dim> &p,
  const unsigned int component = 0) const override;
 
  hessian(const Point<dim> &p,
  const unsigned int component = 0) const override;
  };
 
 
 
  template <int dim>
  double ExactSolution<dim>::value(const Point<dim> &p,
  const unsigned int /*component*/) const
  {
  double return_value = 0.0;
 
  if (dim == 2)
  {
  return_value =
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]));
  }
  else if (dim == 3)
  {
  return_value = Utilities::fixed_power<2>(
  p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]) * p[2] * (1.0 - p[2]));
  }
  else
 
  return return_value;
  }
 
 
 
  template <int dim>
  ExactSolution<dim>::gradient(const Point<dim> &p,
  const unsigned int /*component*/) const
  {
  Tensor<1, dim> return_gradient;
 
  if (dim == 2)
  {
  return_gradient[0] =
  (2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
  4.0 * Utilities::fixed_power<3>(p[0])) *
  Utilities::fixed_power<2>(p[1] * (1.0 - p[1]));
  return_gradient[1] =
  (2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
  4.0 * Utilities::fixed_power<3>(p[1])) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
  }
  else if (dim == 3)
  {
  return_gradient[0] =
  (2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
  4.0 * Utilities::fixed_power<3>(p[0])) *
  Utilities::fixed_power<2>(p[1] * (1.0 - p[1]) * p[2] * (1.0 - p[2]));
  return_gradient[1] =
  (2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
  4.0 * Utilities::fixed_power<3>(p[1])) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[2] * (1.0 - p[2]));
  return_gradient[2] =
  (2.0 * p[2] - 6.0 * Utilities::fixed_power<2>(p[2]) +
  4.0 * Utilities::fixed_power<3>(p[2])) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]));
  }
  else
 
  return return_gradient;
  }
 
 
 
  template <int dim>
  ExactSolution<dim>::hessian(const Point<dim> &p,
  const unsigned int /*component*/) const
  {
  SymmetricTensor<2, dim> return_hessian;
 
  if (dim == 2)
  {
  return_hessian[0][0] = (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
  Utilities::fixed_power<2>(p[1] * (1.0 - p[1]));
  return_hessian[0][1] =
  (2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
  4.0 * Utilities::fixed_power<3>(p[0])) *
  (2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
  4.0 * Utilities::fixed_power<3>(p[1]));
  return_hessian[1][1] = (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
  }
  else if (dim == 3)
  {
  return_hessian[0][0] =
  (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
  Utilities::fixed_power<2>(p[1] * (1.0 - p[1]) * p[2] * (1.0 - p[2]));
  return_hessian[0][1] =
  (2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
  4.0 * Utilities::fixed_power<3>(p[0])) *
  (2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
  4.0 * Utilities::fixed_power<3>(p[1])) *
  Utilities::fixed_power<2>(p[2] * (1.0 - p[2]));
  return_hessian[0][2] =
  (2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
  4.0 * Utilities::fixed_power<3>(p[0])) *
  (2.0 * p[2] - 6.0 * Utilities::fixed_power<2>(p[2]) +
  4.0 * Utilities::fixed_power<3>(p[2])) *
  Utilities::fixed_power<2>(p[1] * (1.0 - p[1]));
  return_hessian[1][1] =
  (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[2] * (1.0 - p[2]));
  return_hessian[1][2] =
  (2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
  4.0 * Utilities::fixed_power<3>(p[1])) *
  (2.0 * p[2] - 6.0 * Utilities::fixed_power<2>(p[2]) +
  4.0 * Utilities::fixed_power<3>(p[2])) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
  return_hessian[2][2] =
  (2.0 - 12.0 * p[2] + 12.0 * p[2] * p[2]) *
  Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]));
  }
  else
 
  return return_hessian;
  }
 
 
 
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const

Implementation of the BiLaplacianLDGLift class

BiLaplacianLDGLift::BiLaplacianLDGLift

In the constructor, we set the polynomial degree of the two finite element spaces, we associate the corresponding DoF handlers to the triangulation, and we set the two penalty coefficients.

  template <int dim>
  BiLaplacianLDGLift<dim>::BiLaplacianLDGLift(const unsigned int n_refinements,
  const unsigned int fe_degree,
  const double penalty_jump_grad,
  const double penalty_jump_val)
  : n_refinements(n_refinements)
  , fe(fe_degree)
  , dof_handler(triangulation)
  , fe_lift(FE_DGQ<dim>(fe_degree), dim * dim)
  , penalty_jump_grad(penalty_jump_grad)
  , penalty_jump_val(penalty_jump_val)
  {}
 
 
 

BiLaplacianLDGLift::make_grid

To build a mesh for \(\Omega=(0,1)^d\), we simply call the function GridGenerator::hyper_cube and then refine it using refine_global. The number of refinements is hard-coded here.

  template <int dim>
  void BiLaplacianLDGLift<dim>::make_grid()
  {
  std::cout << "Building the mesh............." << std::endl;
 
 
  triangulation.refine_global(n_refinements);
 
  std::cout << "Number of active cells: " << triangulation.n_active_cells()
  << std::endl;
  }
 
 
 
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)

BiLaplacianLDGLift::setup_system

In the following function, we set up the degrees of freedom, the sparsity pattern, the size of the matrix \(A\), and the size of the solution and right-hand side vectors \(\boldsymbol{U}\) and \(\boldsymbol{F}\). For the sparsity pattern, we cannot directly use the function DoFTools::make_flux_sparsity_pattern (as we would do for instance for the SIPG method) because we need to take into account the interactions of a neighboring cell with another neighboring cell as described in the introduction. The extended sparsity pattern is built by iterating over all the active cells. For the current cell, we collect all its degrees of freedom as well as the degrees of freedom of all its neighboring cells, and then couple everything with everything.

  template <int dim>
  void BiLaplacianLDGLift<dim>::setup_system()
  {
  dof_handler.distribute_dofs(fe);
 
  std::cout << "Number of degrees of freedom: " << dof_handler.n_dofs()
  << std::endl;
 
  DynamicSparsityPattern dsp(dof_handler.n_dofs(), dof_handler.n_dofs());
 
  const auto dofs_per_cell = fe.dofs_per_cell;
 
  for (const auto &cell : dof_handler.active_cell_iterators())
  {
  std::vector<types::global_dof_index> dofs(dofs_per_cell);
  cell->get_dof_indices(dofs);
 
  for (unsigned int f = 0; f < cell->n_faces(); ++f)
  if (!cell->face(f)->at_boundary())
  {
  const auto neighbor_cell = cell->neighbor(f);
 
  std::vector<types::global_dof_index> tmp(dofs_per_cell);
  neighbor_cell->get_dof_indices(tmp);
 
  dofs.insert(std::end(dofs), std::begin(tmp), std::end(tmp));
  }
 
  for (const auto i : dofs)
  for (const auto j : dofs)
  {
  dsp.add(i, j);
  dsp.add(j, i);
  }
  }
 
  sparsity_pattern.copy_from(dsp);
 
 
  matrix.reinit(sparsity_pattern);
  rhs.reinit(dof_handler.n_dofs());
 
  solution.reinit(dof_handler.n_dofs());
 
@ matrix
Contents is actually a matrix.
STL namespace.
Definition types.h:32

At the end of the function, we output this sparsity pattern as a scalable vector graphic. You can visualize it by loading this file in most web browsers:

  std::ofstream out("sparsity-pattern.svg");
  sparsity_pattern.print_svg(out);
  }
 
 
 

BiLaplacianLDGLift::assemble_system

This function simply calls the two functions responsible for the assembly of the matrix and the right-hand side.

  template <int dim>
  void BiLaplacianLDGLift<dim>::assemble_system()
  {
  std::cout << "Assembling the system............." << std::endl;
 
  assemble_matrix();
  assemble_rhs();
 
  std::cout << "Done. " << std::endl;
  }
 
 
 

BiLaplacianLDGLift::assemble_matrix

This function assembles the matrix \(A\) whose entries are defined by \(A_{ij}=A_h(\varphi_j,\varphi_i)\) which involves the product of discrete Hessians and the penalty terms.

  template <int dim>
  void BiLaplacianLDGLift<dim>::assemble_matrix()
  {
  matrix = 0;
 
  const QGauss<dim> quad(fe.degree + 1);
  const QGauss<dim - 1> quad_face(fe.degree + 1);
 
  const unsigned int n_q_points = quad.size();
  const unsigned int n_q_points_face = quad_face.size();
 
 
  FEFaceValues<dim> fe_face(
 
  FEFaceValues<dim> fe_face_neighbor(
 
  const unsigned int n_dofs = fe_values.dofs_per_cell;
 
  std::vector<types::global_dof_index> local_dof_indices(n_dofs);
  std::vector<types::global_dof_index> local_dof_indices_neighbor(n_dofs);
  std::vector<types::global_dof_index> local_dof_indices_neighbor_2(n_dofs);
 
@ update_hessians
Second derivatives of shape functions.
@ update_values
Shape function values.
@ update_normal_vectors
Normal vectors.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.

As indicated in the introduction, the following matrices are used for the contributions of the products of the discrete Hessians.

  FullMatrix<double> stiffness_matrix_cc(n_dofs,
  n_dofs); // interactions cell / cell
  FullMatrix<double> stiffness_matrix_cn(
  n_dofs, n_dofs); // interactions cell / neighbor
  FullMatrix<double> stiffness_matrix_nc(
  n_dofs, n_dofs); // interactions neighbor / cell
  FullMatrix<double> stiffness_matrix_nn(
  n_dofs, n_dofs); // interactions neighbor / neighbor
  FullMatrix<double> stiffness_matrix_n1n2(
  n_dofs, n_dofs); // interactions neighbor1 / neighbor2
  FullMatrix<double> stiffness_matrix_n2n1(
  n_dofs, n_dofs); // interactions neighbor2 / neighbor1
 

The following matrices are used for the contributions of the two penalty terms:

  FullMatrix<double> ip_matrix_cc(n_dofs, n_dofs); // interactions cell / cell
  FullMatrix<double> ip_matrix_cn(n_dofs,
  n_dofs); // interactions cell / neighbor
  FullMatrix<double> ip_matrix_nc(n_dofs,
  n_dofs); // interactions neighbor / cell
  FullMatrix<double> ip_matrix_nn(n_dofs,
  n_dofs); // interactions neighbor / neighbor
 
  std::vector<std::vector<Tensor<2, dim>>> discrete_hessians(
  n_dofs, std::vector<Tensor<2, dim>>(n_q_points));
  std::vector<std::vector<std::vector<Tensor<2, dim>>>>
  discrete_hessians_neigh(GeometryInfo<dim>::faces_per_cell,
  discrete_hessians);
 
  for (const auto &cell : dof_handler.active_cell_iterators())
  {
  fe_values.reinit(cell);
  cell->get_dof_indices(local_dof_indices);
 

We now compute all the discrete Hessians that are not vanishing on the current cell, i.e., the discrete Hessian of all the basis functions with support on the current cell or on one of its neighbors.

  compute_discrete_hessians(cell,
  discrete_hessians,
  discrete_hessians_neigh);
 

First, we compute and add the interactions of the degrees of freedom of the current cell.

  stiffness_matrix_cc = 0;
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  const double dx = fe_values.JxW(q);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  const Tensor<2, dim> &H_i = discrete_hessians[i][q];
  const Tensor<2, dim> &H_j = discrete_hessians[j][q];
 
  stiffness_matrix_cc(i, j) += scalar_product(H_j, H_i) * dx;
  }
  }
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  matrix(local_dof_indices[i], local_dof_indices[j]) +=
  stiffness_matrix_cc(i, j);
  }
 

Next, we compute and add the interactions of the degrees of freedom of the current cell with those of its neighbors. Note that the interactions of the degrees of freedom of a neighbor with those of the same neighbor are included here.

  for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
  {
  const typename DoFHandler<dim>::face_iterator face =
  cell->face(face_no);
 
  const bool at_boundary = face->at_boundary();
  if (!at_boundary)
  {
typename ActiveSelector::face_iterator face_iterator

There is nothing to be done if boundary face (the liftings of the Dirichlet BCs are accounted for in the assembly of the RHS; in fact, nothing to be done in this program since we prescribe homogeneous BCs).

  neighbor_cell = cell->neighbor(face_no);
  neighbor_cell->get_dof_indices(local_dof_indices_neighbor);
 
  stiffness_matrix_cn = 0;
  stiffness_matrix_nc = 0;
  stiffness_matrix_nn = 0;
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  const double dx = fe_values.JxW(q);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  const Tensor<2, dim> &H_i = discrete_hessians[i][q];
  const Tensor<2, dim> &H_j = discrete_hessians[j][q];
 
  const Tensor<2, dim> &H_i_neigh =
  discrete_hessians_neigh[face_no][i][q];
  const Tensor<2, dim> &H_j_neigh =
  discrete_hessians_neigh[face_no][j][q];
 
  stiffness_matrix_cn(i, j) +=
  scalar_product(H_j_neigh, H_i) * dx;
  stiffness_matrix_nc(i, j) +=
  scalar_product(H_j, H_i_neigh) * dx;
  stiffness_matrix_nn(i, j) +=
  scalar_product(H_j_neigh, H_i_neigh) * dx;
  }
  }
  }
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  matrix(local_dof_indices[i],
  local_dof_indices_neighbor[j]) +=
  stiffness_matrix_cn(i, j);
  matrix(local_dof_indices_neighbor[i],
  local_dof_indices[j]) +=
  stiffness_matrix_nc(i, j);
  matrix(local_dof_indices_neighbor[i],
  local_dof_indices_neighbor[j]) +=
  stiffness_matrix_nn(i, j);
  }
  }
 
  } // boundary check
  } // for face
 

We now compute and add the interactions of the degrees of freedom of a neighboring cells with those of another neighboring cell (this is where we need the extended sparsity pattern).

  for (unsigned int face_no = 0; face_no < cell->n_faces() - 1; ++face_no)
  {
  const typename DoFHandler<dim>::face_iterator face =
  cell->face(face_no);
 
  const bool at_boundary = face->at_boundary();
  if (!at_boundary)
  { // nothing to be done if boundary face (the liftings of the

Dirichlet BCs are accounted for in the assembly of the RHS; in fact, nothing to be done in this program since we prescribe homogeneous BCs)

  for (unsigned int face_no_2 = face_no + 1;
  face_no_2 < cell->n_faces();
  ++face_no_2)
  {
  const typename DoFHandler<dim>::face_iterator face_2 =
  cell->face(face_no_2);
 
  const bool at_boundary_2 = face_2->at_boundary();
  if (!at_boundary_2)
  {
  neighbor_cell = cell->neighbor(face_no);
  neighbor_cell->get_dof_indices(
  local_dof_indices_neighbor);
  neighbor_cell_2 = cell->neighbor(face_no_2);
  neighbor_cell_2->get_dof_indices(
  local_dof_indices_neighbor_2);
 
  stiffness_matrix_n1n2 = 0;
  stiffness_matrix_n2n1 = 0;
 
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  const double dx = fe_values.JxW(q);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  const Tensor<2, dim> &H_i_neigh =
  discrete_hessians_neigh[face_no][i][q];
  const Tensor<2, dim> &H_j_neigh =
  discrete_hessians_neigh[face_no][j][q];
 
  const Tensor<2, dim> &H_i_neigh2 =
  discrete_hessians_neigh[face_no_2][i][q];
  const Tensor<2, dim> &H_j_neigh2 =
  discrete_hessians_neigh[face_no_2][j][q];
 
  stiffness_matrix_n1n2(i, j) +=
  scalar_product(H_j_neigh2, H_i_neigh) * dx;
  stiffness_matrix_n2n1(i, j) +=
  scalar_product(H_j_neigh, H_i_neigh2) * dx;
  }
  }
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  matrix(local_dof_indices_neighbor[i],
  local_dof_indices_neighbor_2[j]) +=
  stiffness_matrix_n1n2(i, j);
  matrix(local_dof_indices_neighbor_2[i],
  local_dof_indices_neighbor[j]) +=
  stiffness_matrix_n2n1(i, j);
  }
  } // boundary check face_2
  } // for face_2
  } // boundary check face_1
  } // for face_1
 
 

Finally, we compute and add the two penalty terms.

  for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
  {
  const typename DoFHandler<dim>::face_iterator face =
  cell->face(face_no);
 
  const double mesh_inv = 1.0 / face->diameter(); // h_e^{-1}
  const double mesh3_inv =
  1.0 / Utilities::fixed_power<3>(face->diameter()); // h_e^{-3}
 
  fe_face.reinit(cell, face_no);
 
  ip_matrix_cc = 0; // filled in any case (boundary or interior face)
 
  const bool at_boundary = face->at_boundary();
  if (at_boundary)
  {
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face.JxW(q);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  ip_matrix_cc(i, j) += penalty_jump_grad * mesh_inv *
  fe_face.shape_grad(j, q) *
  fe_face.shape_grad(i, q) * dx;
  ip_matrix_cc(i, j) += penalty_jump_val * mesh3_inv *
  fe_face.shape_value(j, q) *
  fe_face.shape_value(i, q) * dx;
  }
  }
  }
  else
  { // interior face
 
  neighbor_cell = cell->neighbor(face_no);
  const unsigned int face_no_neighbor =
  cell->neighbor_of_neighbor(face_no);
 

In the next step, we need to have a global way to compare the cells in order to not calculate the same jump term twice:

  if (neighbor_cell->id() < cell->id())
  continue; // skip this face (already considered)
  else
  {
  fe_face_neighbor.reinit(neighbor_cell, face_no_neighbor);
  neighbor_cell->get_dof_indices(local_dof_indices_neighbor);
 
  ip_matrix_cn = 0;
  ip_matrix_nc = 0;
  ip_matrix_nn = 0;
 
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face.JxW(q);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  ip_matrix_cc(i, j) +=
  penalty_jump_grad * mesh_inv *
  fe_face.shape_grad(j, q) *
  fe_face.shape_grad(i, q) * dx;
  ip_matrix_cc(i, j) +=
  penalty_jump_val * mesh3_inv *
  fe_face.shape_value(j, q) *
  fe_face.shape_value(i, q) * dx;
 
  ip_matrix_cn(i, j) -=
  penalty_jump_grad * mesh_inv *
  fe_face_neighbor.shape_grad(j, q) *
  fe_face.shape_grad(i, q) * dx;
  ip_matrix_cn(i, j) -=
  penalty_jump_val * mesh3_inv *
  fe_face_neighbor.shape_value(j, q) *
  fe_face.shape_value(i, q) * dx;
 
  ip_matrix_nc(i, j) -=
  penalty_jump_grad * mesh_inv *
  fe_face.shape_grad(j, q) *
  fe_face_neighbor.shape_grad(i, q) * dx;
  ip_matrix_nc(i, j) -=
  penalty_jump_val * mesh3_inv *
  fe_face.shape_value(j, q) *
  fe_face_neighbor.shape_value(i, q) * dx;
 
  ip_matrix_nn(i, j) +=
  penalty_jump_grad * mesh_inv *
  fe_face_neighbor.shape_grad(j, q) *
  fe_face_neighbor.shape_grad(i, q) * dx;
  ip_matrix_nn(i, j) +=
  penalty_jump_val * mesh3_inv *
  fe_face_neighbor.shape_value(j, q) *
  fe_face_neighbor.shape_value(i, q) * dx;
  }
  }
  }
  } // face not visited yet
 
  } // boundary check
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  matrix(local_dof_indices[i], local_dof_indices[j]) +=
  ip_matrix_cc(i, j);
  }
  }
 
  if (!at_boundary)
  {
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  for (unsigned int j = 0; j < n_dofs; ++j)
  {
  matrix(local_dof_indices[i],
  local_dof_indices_neighbor[j]) +=
  ip_matrix_cn(i, j);
  matrix(local_dof_indices_neighbor[i],
  local_dof_indices[j]) += ip_matrix_nc(i, j);
  matrix(local_dof_indices_neighbor[i],
  local_dof_indices_neighbor[j]) +=
  ip_matrix_nn(i, j);
  }
  }
  }
 
  } // for face
  } // for cell
  }
 
 
 

BiLaplacianLDGLift::assemble_rhs

This function assemble the right-hand side of the system. Since we consider homogeneous Dirichlet boundary conditions, imposed weakly in the bilinear form using the Nitsche approach, it only involves the contribution of the forcing term \(\int_{\Omega}fv_h\).

  template <int dim>
  void BiLaplacianLDGLift<dim>::assemble_rhs()
  {
  rhs = 0;
 
  const QGauss<dim> quad(fe.degree + 1);
  FEValues<dim> fe_values(
 
  const unsigned int n_dofs = fe_values.dofs_per_cell;
  const unsigned int n_quad_pts = quad.size();
 
  const RightHandSide<dim> right_hand_side;
 
  Vector<double> local_rhs(n_dofs);
  std::vector<types::global_dof_index> local_dof_indices(n_dofs);
 
  for (const auto &cell : dof_handler.active_cell_iterators())
  {
  fe_values.reinit(cell);
  cell->get_dof_indices(local_dof_indices);
 
  local_rhs = 0;
  for (unsigned int q = 0; q < n_quad_pts; ++q)
  {
  const double dx = fe_values.JxW(q);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  local_rhs(i) +=
  right_hand_side.value(fe_values.quadrature_point(q)) *
  fe_values.shape_value(i, q) * dx;
  }
  }
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  rhs(local_dof_indices[i]) += local_rhs(i);
  }
  }
 
 
 
@ update_quadrature_points
Transformed quadrature points.

BiLaplacianLDGLift::solve

To solve the linear system \(A\boldsymbol{U}=\boldsymbol{F}\), we proceed as in step-74 and use a direct method. We could as well use an iterative method, for instance the conjugate gradient method as in step-3.

  template <int dim>
  void BiLaplacianLDGLift<dim>::solve()
  {
  SparseDirectUMFPACK A_direct;
  A_direct.initialize(matrix);
  A_direct.vmult(solution, rhs);
  }
 
 
 
void initialize(const SparsityPattern &sparsity_pattern)

BiLaplacianLDGLift::compute_errors

This function computes the discrete \(H^2\), \(H^1\) and \(L^2\) norms of the error \(u-u_h\), where \(u\) is the exact solution and \(u_h\) is the approximate solution. See the introduction for the definition of the norms.

  template <int dim>
  void BiLaplacianLDGLift<dim>::compute_errors()
  {
  double error_H2 = 0;
  double error_H1 = 0;
  double error_L2 = 0;
 
  const QGauss<dim> quad(fe.degree + 1);
  const QGauss<dim - 1> quad_face(fe.degree + 1);
 
  FEValues<dim> fe_values(fe,
  quad,
 
  FEFaceValues<dim> fe_face(fe,
  quad_face,
 
  FEFaceValues<dim> fe_face_neighbor(fe,
  quad_face,
 
  const unsigned int n_q_points = quad.size();
  const unsigned int n_q_points_face = quad_face.size();
 

We introduce some variables for the exact solution...

  const ExactSolution<dim> u_exact;
 

...and for the approximate solution:

  std::vector<double> solution_values_cell(n_q_points);
  std::vector<Tensor<1, dim>> solution_gradients_cell(n_q_points);
  std::vector<Tensor<2, dim>> solution_hessians_cell(n_q_points);
 
  std::vector<double> solution_values(n_q_points_face);
  std::vector<double> solution_values_neigh(n_q_points_face);
  std::vector<Tensor<1, dim>> solution_gradients(n_q_points_face);
  std::vector<Tensor<1, dim>> solution_gradients_neigh(n_q_points_face);
 
  for (const auto &cell : dof_handler.active_cell_iterators())
  {
  fe_values.reinit(cell);
 
  fe_values.get_function_values(solution, solution_values_cell);
  fe_values.get_function_gradients(solution, solution_gradients_cell);
  fe_values.get_function_hessians(solution, solution_hessians_cell);
 

We first add the bulk terms.

  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  const double dx = fe_values.JxW(q);
 
  error_H2 += (u_exact.hessian(fe_values.quadrature_point(q)) -
  solution_hessians_cell[q])
  .norm_square() *
  dx;
  error_H1 += (u_exact.gradient(fe_values.quadrature_point(q)) -
  solution_gradients_cell[q])
  .norm_square() *
  dx;
  error_L2 += Utilities::fixed_power<2>(
  u_exact.value(fe_values.quadrature_point(q)) -
  solution_values_cell[q]) *
  dx;
  } // for quadrature points
 

We then add the face contributions.

  for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
  {
  const typename DoFHandler<dim>::face_iterator face =
  cell->face(face_no);
 
  const double mesh_inv = 1.0 / face->diameter(); // h^{-1}
  const double mesh3_inv =
  1.0 / Utilities::fixed_power<3>(face->diameter()); // h^{-3}
 
  fe_face.reinit(cell, face_no);
 
  fe_face.get_function_values(solution, solution_values);
  fe_face.get_function_gradients(solution, solution_gradients);
 
  const bool at_boundary = face->at_boundary();
  if (at_boundary)
  {
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face.JxW(q);
  const double u_exact_q =
  u_exact.value(fe_face.quadrature_point(q));
  const Tensor<1, dim> u_exact_grad_q =
  u_exact.gradient(fe_face.quadrature_point(q));
 
  error_H2 +=
  mesh_inv *
  (u_exact_grad_q - solution_gradients[q]).norm_square() *
  dx;
  error_H2 += mesh3_inv *
  Utilities::fixed_power<2>(u_exact_q -
  solution_values[q]) *
  dx;
  error_H1 += mesh_inv *
  Utilities::fixed_power<2>(u_exact_q -
  solution_values[q]) *
  dx;
  }
  }
  else
  { // interior face
 
  neighbor_cell = cell->neighbor(face_no);
  const unsigned int face_no_neighbor =
  cell->neighbor_of_neighbor(face_no);
 
constexpr numbers::NumberTraits< Number >::real_type norm_square() const

In the next step, we need to have a global way to compare the cells in order to not calculate the same jump term twice:

  if (neighbor_cell->id() < cell->id())
  continue; // skip this face (already considered)
  else
  {
  fe_face_neighbor.reinit(neighbor_cell, face_no_neighbor);
 
  fe_face.get_function_values(solution, solution_values);
  fe_face_neighbor.get_function_values(solution,
  solution_values_neigh);
  fe_face.get_function_gradients(solution,
  solution_gradients);
  fe_face_neighbor.get_function_gradients(
  solution, solution_gradients_neigh);
 
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face.JxW(q);
 

To compute the jump term, we use the fact that \(\jump{u}=0\) and \(\jump{\nabla u}=\mathbf{0}\) since \(u\in H^2(\Omega)\).

  error_H2 +=
  mesh_inv *
  (solution_gradients_neigh[q] - solution_gradients[q])
  .norm_square() *
  dx;
  error_H2 +=
  mesh3_inv *
  Utilities::fixed_power<2>(solution_values_neigh[q] -
  solution_values[q]) *
  dx;
  error_H1 +=
  mesh_inv *
  Utilities::fixed_power<2>(solution_values_neigh[q] -
  solution_values[q]) *
  dx;
  }
  } // face not visited yet
 
  } // boundary check
 
  } // for face
 
  } // for cell
 
  error_H2 = std::sqrt(error_H2);
  error_H1 = std::sqrt(error_H1);
  error_L2 = std::sqrt(error_L2);
 
  std::cout << "DG H2 norm of the error: " << error_H2 << std::endl;
  std::cout << "DG H1 norm of the error: " << error_H1 << std::endl;
  std::cout << " L2 norm of the error: " << error_L2 << std::endl;
  }
 
 
 
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)

BiLaplacianLDGLift::output_results

This function, which writes the solution to a vtk file, is copied from step-3.

  template <int dim>
  void BiLaplacianLDGLift<dim>::output_results() const
  {
  DataOut<dim> data_out;
  data_out.attach_dof_handler(dof_handler);
  data_out.add_data_vector(solution, "solution");
  data_out.build_patches();
 
  std::ofstream output("solution.vtk");
  data_out.write_vtk(output);
  }
 
 
 
void attach_dof_handler(const DoFHandler< dim, spacedim > &)

BiLaplacianLDGLift::assemble_local_matrix

As already mentioned above, this function is used to assemble the (local) mass matrices needed for the computations of the lifting terms. We reiterate that only the basis functions with support on the current cell are considered.

  template <int dim>
  void BiLaplacianLDGLift<dim>::assemble_local_matrix(
  const FEValues<dim> &fe_values_lift,
  const unsigned int n_q_points,
  FullMatrix<double> &local_matrix)
  {
  const FEValuesExtractors::Tensor<2> tau_ext(0);
 
  const unsigned int n_dofs = fe_values_lift.dofs_per_cell;
 
  local_matrix = 0;
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  const double dx = fe_values_lift.JxW(q);
 
  for (unsigned int m = 0; m < n_dofs; ++m)
  for (unsigned int n = 0; n < n_dofs; ++n)
  {
  local_matrix(m, n) +=
  scalar_product(fe_values_lift[tau_ext].value(n, q),
  fe_values_lift[tau_ext].value(m, q)) *
  dx;
  }
  }
  }
 
 
 

BiLaplacianLDGLift::compute_discrete_hessians

This function is the main novelty of this program. It computes the discrete Hessian \(H_h(\varphi)\) for all the basis functions \(\varphi\) of \(\mathbb{V}_h\) supported on the current cell and those supported on a neighboring cell. The first argument indicates the current cell (referring to the global DoFHandler object), while the other two arguments are output variables that are filled by this function.

In the following, we need to evaluate finite element shape functions for the fe_lift finite element on the current cell. Like for example in step-61, this "lift" space is defined on every cell individually; as a consequence, there is no global DoFHandler associated with this because we simply have no need for such a DoFHandler. That leaves the question of what we should initialize the FEValues and FEFaceValues objects with when we ask them to evaluate shape functions of fe_lift on a concrete cell. If we simply provide the first argument to this function, cell, to FEValues::reinit(), we will receive an error message that the given cell belongs to a DoFHandler that has a different finite element associated with it than the fe_lift object we want to evaluate. Fortunately, there is a relatively easy solution: We can call FEValues::reinit() with a cell that points into a triangulation – the same cell, but not associated with a DoFHandler, and consequently no finite element space. In that case, FEValues::reinit() will skip the check that would otherwise lead to an error message. All we have to do is to convert the DoFHandler cell iterator into a Triangulation cell iterator; see the first couple of lines of the function below to see how this can be done.

  template <int dim>
  void BiLaplacianLDGLift<dim>::compute_discrete_hessians(
  const typename DoFHandler<dim>::active_cell_iterator &cell,
  std::vector<std::vector<Tensor<2, dim>>> &discrete_hessians,
  std::vector<std::vector<std::vector<Tensor<2, dim>>>>
  &discrete_hessians_neigh)
  {
  const typename Triangulation<dim>::cell_iterator cell_lift =
  static_cast<typename Triangulation<dim>::cell_iterator>(cell);
 
  const QGauss<dim> quad(fe.degree + 1);
  const QGauss<dim - 1> quad_face(fe.degree + 1);
 
  const unsigned int n_q_points = quad.size();
  const unsigned int n_q_points_face = quad_face.size();
 

The information we need from the basis functions of \(\mathbb{V}_h\): fe_values is needed to add the broken Hessian part of the discrete Hessian, while fe_face and fe_face_neighbor are used to compute the right-hand sides for the local problems.

 
  FEFaceValues<dim> fe_face(
 
  FEFaceValues<dim> fe_face_neighbor(
 
  const unsigned int n_dofs = fe_values.dofs_per_cell;
 

The information needed from the basis functions of the finite element space for the lifting terms: fe_values_lift is used for the (local) mass matrix (see \(\boldsymbol{M}_c\) in the introduction), while fe_face_lift is used to compute the right-hand sides (see \(\boldsymbol{G}_c\) for \(b_e\)).

  FEValues<dim> fe_values_lift(fe_lift,
  quad,
 
  FEFaceValues<dim> fe_face_lift(
  fe_lift, quad_face, update_values | update_gradients | update_JxW_values);
 
  const FEValuesExtractors::Tensor<2> tau_ext(0);
 
  const unsigned int n_dofs_lift = fe_values_lift.dofs_per_cell;
  FullMatrix<double> local_matrix_lift(n_dofs_lift, n_dofs_lift);
 
  Vector<double> local_rhs_re(n_dofs_lift), local_rhs_be(n_dofs_lift),
  coeffs_re(n_dofs_lift), coeffs_be(n_dofs_lift), coeffs_tmp(n_dofs_lift);
 
  SolverControl solver_control(1000, 1e-12);
  SolverCG<Vector<double>> solver(solver_control);
 
  double factor_avg; // 0.5 for interior faces, 1.0 for boundary faces
 
  fe_values.reinit(cell);
  fe_values_lift.reinit(cell_lift);
 

We start by assembling the (local) mass matrix used for the computation of the lifting terms \(r_e\) and \(b_e\).

  assemble_local_matrix(fe_values_lift, n_q_points, local_matrix_lift);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  discrete_hessians[i][q] = 0;
 
  for (unsigned int face_no = 0;
  face_no < discrete_hessians_neigh.size();
  ++face_no)
  {
  discrete_hessians_neigh[face_no][i][q] = 0;
  }
  }
 

In this loop, we compute the discrete Hessian at each quadrature point \(x_q\) of cell for each basis function supported on cell, namely we fill-in the variable discrete_hessians[i][q]. For the lifting terms, we need to add the contribution of all the faces of cell.

  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  coeffs_re = 0;
  coeffs_be = 0;
 
  for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
  {
  const typename DoFHandler<dim>::face_iterator face =
  cell->face(face_no);
 
  const bool at_boundary = face->at_boundary();
 

Recall that by convention, the average of a function across a boundary face \(e\) reduces to the trace of the function on the only element adjacent to \(e\), namely there is no factor \(\frac{1}{2}\). We distinguish between the two cases (the current face lies in the interior or on the boundary of the domain) using the variable factor_avg.

  factor_avg = 0.5;
  if (at_boundary)
  {
  factor_avg = 1.0;
  }
 
  fe_face.reinit(cell, face_no);
  fe_face_lift.reinit(cell_lift, face_no);
 
  local_rhs_re = 0;
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face_lift.JxW(q);
  const Tensor<1, dim> normal = fe_face.normal_vector(
  q); // same as fe_face_lift.normal_vector(q)
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  local_rhs_re(m) +=
  factor_avg *
  (fe_face_lift[tau_ext].value(m, q) * normal) *
  fe_face.shape_grad(i, q) * dx;
  }
  }
 

Here, local_rhs_be(m) corresponds to \(G_m\) introduced in the comments about the implementation of the lifting \(b_e\) in the case \(\varphi=\varphi^c\).

  local_rhs_be = 0;
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face_lift.JxW(q);
  const Tensor<1, dim> normal = fe_face.normal_vector(
  q); // same as fe_face_lift.normal_vector(q)
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  local_rhs_be(m) += factor_avg *
  fe_face_lift[tau_ext].divergence(m, q) *
  normal * fe_face.shape_value(i, q) * dx;
  }
  }
 
  coeffs_tmp = 0;
  solver.solve(local_matrix_lift,
  coeffs_tmp,
  local_rhs_re,
  coeffs_re += coeffs_tmp;
 
  coeffs_tmp = 0;
  solver.solve(local_matrix_lift,
  coeffs_tmp,
  local_rhs_be,
  coeffs_be += coeffs_tmp;
 
  } // for face
 
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  discrete_hessians[i][q] += fe_values.shape_hessian(i, q);
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  discrete_hessians[i][q] -=
  coeffs_re[m] * fe_values_lift[tau_ext].value(m, q);
  }
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  discrete_hessians[i][q] +=
  coeffs_be[m] * fe_values_lift[tau_ext].value(m, q);
  }
  }
  } // for dof i
 
 
 

In this loop, we compute the discrete Hessian at each quadrature point \(x_q\) of cell for each basis function supported on a neighboring neighbor_cell of cell, namely we fill-in the variable discrete_hessians_neigh[face_no][i][q]. For the lifting terms, we only need to add the contribution of the face adjacent to cell and neighbor_cell.

  for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
  {
  const typename DoFHandler<dim>::face_iterator face =
  cell->face(face_no);
 
  const bool at_boundary = face->at_boundary();
 
  if (!at_boundary)
  {

For non-homogeneous Dirichlet BCs, we would need to compute the lifting of the prescribed BC (see the "Possible Extensions" section for more details).

  neighbor_cell = cell->neighbor(face_no);
  const unsigned int face_no_neighbor =
  cell->neighbor_of_neighbor(face_no);
  fe_face_neighbor.reinit(neighbor_cell, face_no_neighbor);
 
  for (unsigned int i = 0; i < n_dofs; ++i)
  {
  coeffs_re = 0;
  coeffs_be = 0;
 
  fe_face_lift.reinit(cell_lift, face_no);
 
  local_rhs_re = 0;
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face_lift.JxW(q);
  const Tensor<1, dim> normal =
  fe_face_neighbor.normal_vector(q);
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  local_rhs_re(m) +=
  0.5 * (fe_face_lift[tau_ext].value(m, q) * normal) *
  fe_face_neighbor.shape_grad(i, q) * dx;
  }
  }
 

Here, local_rhs_be(m) corresponds to \(G_m\) introduced in the comments about the implementation of the lifting \(b_e\) in the case \(\varphi=\varphi^n\).

  local_rhs_be = 0;
  for (unsigned int q = 0; q < n_q_points_face; ++q)
  {
  const double dx = fe_face_lift.JxW(q);
  const Tensor<1, dim> normal =
  fe_face_neighbor.normal_vector(q);
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  local_rhs_be(m) +=
  0.5 * fe_face_lift[tau_ext].divergence(m, q) *
  normal * fe_face_neighbor.shape_value(i, q) * dx;
  }
  }
 
  solver.solve(local_matrix_lift,
  coeffs_re,
  local_rhs_re,
  solver.solve(local_matrix_lift,
  coeffs_be,
  local_rhs_be,
 
  for (unsigned int q = 0; q < n_q_points; ++q)
  {
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  discrete_hessians_neigh[face_no][i][q] -=
  coeffs_re[m] * fe_values_lift[tau_ext].value(m, q);
  }
 
  for (unsigned int m = 0; m < n_dofs_lift; ++m)
  {
  discrete_hessians_neigh[face_no][i][q] +=
  coeffs_be[m] * fe_values_lift[tau_ext].value(m, q);
  }
  }
 
  } // for dof i
  } // boundary check
  } // for face
  }
 
 
 

BiLaplacianLDGLift::run

  template <int dim>
  void BiLaplacianLDGLift<dim>::run()
  {
  make_grid();
 
  setup_system();
  assemble_system();
 
  solve();
 
  compute_errors();
  output_results();
  }
 
  } // namespace Step82
 
 
 

The main function

This is the main function. We define here the number of mesh refinements, the polynomial degree for the two finite element spaces (for the solution and the two liftings) and the two penalty coefficients. We can also change the dimension to run the code in 3d.

  int main()
  {
  try
  {
  const unsigned int n_ref = 3; // number of mesh refinements
 
  const unsigned int degree =
  2; // FE degree for u_h and the two lifting terms
 
  const double penalty_grad =
  1.0; // penalty coefficient for the jump of the gradients
  const double penalty_val =
  1.0; // penalty coefficient for the jump of the values
 
  Step82::BiLaplacianLDGLift<2> problem(n_ref,
  degree,
  penalty_grad,
  penalty_val);
 
  problem.run();
  }
  catch (std::exception &exc)
  {
  std::cerr << std::endl
  << std::endl
  << "----------------------------------------------------"
  << std::endl;
  std::cerr << "Exception on processing: " << std::endl
  << exc.what() << std::endl
  << "Aborting!" << std::endl
  << "----------------------------------------------------"
  << std::endl;
  return 1;
  }
  catch (...)
  {
  std::cerr << std::endl
  << std::endl
  << "----------------------------------------------------"
  << std::endl;
  std::cerr << "Unknown exception!" << std::endl
  << "Aborting!" << std::endl
  << "----------------------------------------------------"
  << std::endl;
  return 1;
  }
 
  return 0;
  }

Results

When running the program, the sparsity pattern is written to an svg file, the solution is written to a vtk file, and some results are printed to the console. With the current setup, the output should read

Number of active cells: 64
Number of degrees of freedom: 576
Assembling the system.............
Done.
DG H2 norm of the error: 0.0151063
DG H1 norm of the error: 0.000399747
L2 norm of the error: 5.33856e-05

This corresponds to the bi-Laplacian problem with the manufactured solution mentioned above for \(d=2\), 3 refinements of the mesh, degree \(k=2\), and \(\gamma_0=\gamma_1=1\) for the penalty coefficients. By changing the number of refinements, we get the following results:

n_ref n_cells n_dofs error H2 rate error H1 rate error L2 rate
1 4 36 5.651e-02 3.366e-03 3.473e-04
2 16 144 3.095e-02 0.87 1.284e-03 1.39 1.369e-04 1.34
3 64 576 1.511e-02 1.03 3.997e-04 1.68 5.339e-05 1.36
4 256 2304 7.353e-03 1.04 1.129e-04 1.82 1.691e-05 1.66
5 1024 9216 3.609e-03 1.03 3.024e-05 1.90 4.789e-06 1.82
6 4096 36864 1.785e-03 1.02 7.850e-06 1.95 1.277e-06 1.91

This matches the expected optimal convergence rates for the \(H^2\) and \(H^1\) norms, but is sub-optimal for the \(L_2\) norm. Incidentally, this also matches the results seen in step-47 when using polynomial degree \(k=2\).

Indeed, just like in step-47, we can regain the optimal convergence order if we set the polynomial degree of the finite elements to \(k=3\) or higher. Here are the numbers for \(k=3\):

n_ref n_cells n_dofs error H2 rate error H1 rate error L2 rate
1 4 36 1.451e-02 5.494e-04 3.035e-05
2 16 144 3.565e-03 2.02 6.870e-05 3.00 2.091e-06 3.86
3 64 576 8.891e-04 2.00 8.584e-06 3.00 1.352e-07 3.95
4 256 2304 2.223e-04 2.00 1.073e-06 3.00 8.594e-09 3.98
5 1024 9216 5.560e-05 2.00 1.341e-07 3.00 5.418e-10 3.99
6 4096 36864 1.390e-05 2.00 1.676e-08 3.00 3.245e-11 4.06

Possible extensions

The code can be easily adapted to deal with the following cases:

  1. Non-homogeneous Dirichlet boundary conditions on (part of) the boundary \(\partial \Omega\) of \(\Omega\).
  2. Hanging-nodes (proceed as in step-14 to not visit a sub-face twice when computing the lifting terms in compute_discrete_hessians and the penalty terms in assemble_matrix).
  3. LDG method for the Poisson problem (use the discrete gradient consisting of the broken gradient and the lifting of the jump of \(u_h\)).

We give below additional details for the first of these points.

Non-homogeneous Dirichlet boundary conditions

If we prescribe non-homogeneous Dirichlet conditions, say

\[ \nabla u=\mathbf{g} \quad \mbox{and} \quad u=g \qquad \mbox{on } \partial \Omega, \]

then the right-hand side \(\boldsymbol{F}\) of the linear system needs to be modified as follows

\[ F_i:=\int_{\Omega}f\varphi_i-\sum_{e\in\mathcal{E}_h^b}\int_{\Omega}r_e(\mathbf{g}):H_h(\varphi_i)+\sum_{e\in\mathcal{E}_h^b}\int_{\Omega}b_e(g):H_h(\varphi_i)+\gamma_1\sum_{e\in\mathcal{E}_h^b}h_e^{-1}\int_e\mathbf{g}\cdot\nabla\varphi_i+\gamma_0\sum_{e\in\mathcal{E}_h^b}h_e^{-3}\int_e g\varphi_i, \qquad 1\leq i \leq N_h. \]

Note that for any given index \(i\), many of the terms are zero. Indeed, for \(e\in \mathcal{E}_h^b\) we have \({\rm supp}\,(r_e(\mathbf{g}))={\rm supp}\,(b_e(g))=K\), where \(K\) is the element for which \(e\subset\partial K\). Therefore, the liftings \(r_e(\mathbf{g})\) and \(b_e(g)\) contribute to \(F_i\) only if \(\varphi_i\) has support on \(K\) or a neighbor of \(K\). In other words, when integrating on a cell \(K\), we need to add

\[ \int_{K}f\varphi_i+\sum_{e\in\mathcal{E}_h^b, e\subset\partial K}\left[-\int_{K}r_e(\mathbf{g}):H_h(\varphi_i)+\int_{K}b_e(g):H_h(\varphi_i)+\gamma_1h_e^{-1}\int_e\mathbf{g}\cdot\nabla\varphi_i+\gamma_0h_e^{-3}\int_e g\varphi_i\right] \]

to \(F_i\) for the indices \(i\) such that \(\varphi_i\) has support on \(K\) and

\[ \sum_{e\in\mathcal{E}_h^b, e\subset\partial K}\left[-\int_{K}r_e(\mathbf{g}):H_h(\varphi_i)+\int_{K}b_e(g):H_h(\varphi_i)\right] \]

to \(F_i\) for the indices \(i\) such that \(\varphi_i\) has support on a neighbor of \(K\).

Note
Note that we can easily consider the case where Dirichlet boundary conditions are imposed only on a subset \(\emptyset\neq\Gamma_D\subset\partial \Omega\). In this case, we simply need to replace \(\mathcal{E}_h^b\) by \(\mathcal{E}_h^D\subset\mathcal{E}_h^b\) consisting of the faces belonging to \(\Gamma_D\). This also affects the matrix \(A\) (simply replace \(\mathcal{E}_h=\mathcal{E}_h^0\cup\mathcal{E}_h^b\) by \(\mathcal{E}_h=\mathcal{E}_h^0\cup\mathcal{E}_h^D\)).

The plain program

/* ------------------------------------------------------------------------
*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright (C) 2021 - 2024 by the deal.II authors
*
* This file is part of the deal.II library.
*
* Part of the source code is dual licensed under Apache-2.0 WITH
* LLVM-exception OR LGPL-2.1-or-later. Detailed license information
* governing the source code and code contributions can be found in
* LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
*
* ------------------------------------------------------------------------
*
* Authors: Andrea Bonito and Diane Guignard, 2021.
*/
#include <fstream>
#include <iostream>
namespace Step82
{
using namespace dealii;
template <int dim>
class BiLaplacianLDGLift
{
public:
BiLaplacianLDGLift(const unsigned int n_refinements,
const unsigned int fe_degree,
const double penalty_jump_grad,
const double penalty_jump_val);
void run();
private:
void make_grid();
void setup_system();
void assemble_system();
void assemble_matrix();
void assemble_rhs();
void solve();
void compute_errors();
void output_results() const;
void assemble_local_matrix(const FEValues<dim> &fe_values_lift,
const unsigned int n_q_points,
FullMatrix<double> &local_matrix);
void compute_discrete_hessians(
std::vector<std::vector<Tensor<2, dim>>> &discrete_hessians,
std::vector<std::vector<std::vector<Tensor<2, dim>>>>
&discrete_hessians_neigh);
const unsigned int n_refinements;
const FE_DGQ<dim> fe;
DoFHandler<dim> dof_handler;
const FESystem<dim> fe_lift;
SparsityPattern sparsity_pattern;
Vector<double> solution;
const double penalty_jump_grad;
const double penalty_jump_val;
};
template <int dim>
class RightHandSide : public Function<dim>
{
public:
RightHandSide()
: Function<dim>()
{}
virtual double value(const Point<dim> &p,
const unsigned int component = 0) const override;
};
template <int dim>
double RightHandSide<dim>::value(const Point<dim> &p,
const unsigned int /*component*/) const
{
double return_value = 0.0;
if (dim == 2)
{
return_value = 24.0 * Utilities::fixed_power<2>(p[1] * (1.0 - p[1])) +
+24.0 * Utilities::fixed_power<2>(p[0] * (1.0 - p[0])) +
2.0 * (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
(2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]);
}
else if (dim == 3)
{
return_value = 24.0 * Utilities::fixed_power<2>(p[1] * (1.0 - p[1]) *
p[2] * (1.0 - p[2])) +
24.0 * Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) *
p[2] * (1.0 - p[2])) +
24.0 * Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) *
p[1] * (1.0 - p[1])) +
2.0 * (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
(2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
Utilities::fixed_power<2>(p[2] * (1.0 - p[2])) +
2.0 * (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
(2.0 - 12.0 * p[2] + 12.0 * p[2] * p[2]) *
Utilities::fixed_power<2>(p[1] * (1.0 - p[1])) +
2.0 * (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
(2.0 - 12.0 * p[2] + 12.0 * p[2] * p[2]) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
}
else
return return_value;
}
template <int dim>
class ExactSolution : public Function<dim>
{
public:
ExactSolution()
: Function<dim>()
{}
virtual double value(const Point<dim> &p,
const unsigned int component = 0) const override;
gradient(const Point<dim> &p,
const unsigned int component = 0) const override;
hessian(const Point<dim> &p,
const unsigned int component = 0) const override;
};
template <int dim>
double ExactSolution<dim>::value(const Point<dim> &p,
const unsigned int /*component*/) const
{
double return_value = 0.0;
if (dim == 2)
{
return_value =
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]));
}
else if (dim == 3)
{
return_value = Utilities::fixed_power<2>(
p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]) * p[2] * (1.0 - p[2]));
}
else
return return_value;
}
template <int dim>
ExactSolution<dim>::gradient(const Point<dim> &p,
const unsigned int /*component*/) const
{
Tensor<1, dim> return_gradient;
if (dim == 2)
{
return_gradient[0] =
(2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
4.0 * Utilities::fixed_power<3>(p[0])) *
Utilities::fixed_power<2>(p[1] * (1.0 - p[1]));
return_gradient[1] =
(2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
4.0 * Utilities::fixed_power<3>(p[1])) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
}
else if (dim == 3)
{
return_gradient[0] =
(2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
4.0 * Utilities::fixed_power<3>(p[0])) *
Utilities::fixed_power<2>(p[1] * (1.0 - p[1]) * p[2] * (1.0 - p[2]));
return_gradient[1] =
(2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
4.0 * Utilities::fixed_power<3>(p[1])) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[2] * (1.0 - p[2]));
return_gradient[2] =
(2.0 * p[2] - 6.0 * Utilities::fixed_power<2>(p[2]) +
4.0 * Utilities::fixed_power<3>(p[2])) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]));
}
else
return return_gradient;
}
template <int dim>
ExactSolution<dim>::hessian(const Point<dim> &p,
const unsigned int /*component*/) const
{
SymmetricTensor<2, dim> return_hessian;
if (dim == 2)
{
return_hessian[0][0] = (2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
Utilities::fixed_power<2>(p[1] * (1.0 - p[1]));
return_hessian[0][1] =
(2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
4.0 * Utilities::fixed_power<3>(p[0])) *
(2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
4.0 * Utilities::fixed_power<3>(p[1]));
return_hessian[1][1] = (2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
}
else if (dim == 3)
{
return_hessian[0][0] =
(2.0 - 12.0 * p[0] + 12.0 * p[0] * p[0]) *
Utilities::fixed_power<2>(p[1] * (1.0 - p[1]) * p[2] * (1.0 - p[2]));
return_hessian[0][1] =
(2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
4.0 * Utilities::fixed_power<3>(p[0])) *
(2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
4.0 * Utilities::fixed_power<3>(p[1])) *
Utilities::fixed_power<2>(p[2] * (1.0 - p[2]));
return_hessian[0][2] =
(2.0 * p[0] - 6.0 * Utilities::fixed_power<2>(p[0]) +
4.0 * Utilities::fixed_power<3>(p[0])) *
(2.0 * p[2] - 6.0 * Utilities::fixed_power<2>(p[2]) +
4.0 * Utilities::fixed_power<3>(p[2])) *
Utilities::fixed_power<2>(p[1] * (1.0 - p[1]));
return_hessian[1][1] =
(2.0 - 12.0 * p[1] + 12.0 * p[1] * p[1]) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[2] * (1.0 - p[2]));
return_hessian[1][2] =
(2.0 * p[1] - 6.0 * Utilities::fixed_power<2>(p[1]) +
4.0 * Utilities::fixed_power<3>(p[1])) *
(2.0 * p[2] - 6.0 * Utilities::fixed_power<2>(p[2]) +
4.0 * Utilities::fixed_power<3>(p[2])) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]));
return_hessian[2][2] =
(2.0 - 12.0 * p[2] + 12.0 * p[2] * p[2]) *
Utilities::fixed_power<2>(p[0] * (1.0 - p[0]) * p[1] * (1.0 - p[1]));
}
else
return return_hessian;
}
template <int dim>
BiLaplacianLDGLift<dim>::BiLaplacianLDGLift(const unsigned int n_refinements,
const unsigned int fe_degree,
const double penalty_jump_grad,
const double penalty_jump_val)
: n_refinements(n_refinements)
, fe(fe_degree)
, dof_handler(triangulation)
, fe_lift(FE_DGQ<dim>(fe_degree), dim * dim)
, penalty_jump_grad(penalty_jump_grad)
, penalty_jump_val(penalty_jump_val)
{}
template <int dim>
void BiLaplacianLDGLift<dim>::make_grid()
{
std::cout << "Building the mesh............." << std::endl;
triangulation.refine_global(n_refinements);
std::cout << "Number of active cells: " << triangulation.n_active_cells()
<< std::endl;
}
template <int dim>
void BiLaplacianLDGLift<dim>::setup_system()
{
dof_handler.distribute_dofs(fe);
std::cout << "Number of degrees of freedom: " << dof_handler.n_dofs()
<< std::endl;
DynamicSparsityPattern dsp(dof_handler.n_dofs(), dof_handler.n_dofs());
const auto dofs_per_cell = fe.dofs_per_cell;
for (const auto &cell : dof_handler.active_cell_iterators())
{
std::vector<types::global_dof_index> dofs(dofs_per_cell);
cell->get_dof_indices(dofs);
for (unsigned int f = 0; f < cell->n_faces(); ++f)
if (!cell->face(f)->at_boundary())
{
const auto neighbor_cell = cell->neighbor(f);
std::vector<types::global_dof_index> tmp(dofs_per_cell);
neighbor_cell->get_dof_indices(tmp);
dofs.insert(std::end(dofs), std::begin(tmp), std::end(tmp));
}
for (const auto i : dofs)
for (const auto j : dofs)
{
dsp.add(i, j);
dsp.add(j, i);
}
}
sparsity_pattern.copy_from(dsp);
matrix.reinit(sparsity_pattern);
rhs.reinit(dof_handler.n_dofs());
solution.reinit(dof_handler.n_dofs());
std::ofstream out("sparsity-pattern.svg");
sparsity_pattern.print_svg(out);
}
template <int dim>
void BiLaplacianLDGLift<dim>::assemble_system()
{
std::cout << "Assembling the system............." << std::endl;
assemble_matrix();
assemble_rhs();
std::cout << "Done. " << std::endl;
}
template <int dim>
void BiLaplacianLDGLift<dim>::assemble_matrix()
{
matrix = 0;
const QGauss<dim> quad(fe.degree + 1);
const QGauss<dim - 1> quad_face(fe.degree + 1);
const unsigned int n_q_points = quad.size();
const unsigned int n_q_points_face = quad_face.size();
FEFaceValues<dim> fe_face_neighbor(
const unsigned int n_dofs = fe_values.dofs_per_cell;
std::vector<types::global_dof_index> local_dof_indices(n_dofs);
std::vector<types::global_dof_index> local_dof_indices_neighbor(n_dofs);
std::vector<types::global_dof_index> local_dof_indices_neighbor_2(n_dofs);
FullMatrix<double> stiffness_matrix_cc(n_dofs,
n_dofs); // interactions cell / cell
FullMatrix<double> stiffness_matrix_cn(
n_dofs, n_dofs); // interactions cell / neighbor
FullMatrix<double> stiffness_matrix_nc(
n_dofs, n_dofs); // interactions neighbor / cell
FullMatrix<double> stiffness_matrix_nn(
n_dofs, n_dofs); // interactions neighbor / neighbor
FullMatrix<double> stiffness_matrix_n1n2(
n_dofs, n_dofs); // interactions neighbor1 / neighbor2
FullMatrix<double> stiffness_matrix_n2n1(
n_dofs, n_dofs); // interactions neighbor2 / neighbor1
FullMatrix<double> ip_matrix_cc(n_dofs, n_dofs); // interactions cell / cell
FullMatrix<double> ip_matrix_cn(n_dofs,
n_dofs); // interactions cell / neighbor
FullMatrix<double> ip_matrix_nc(n_dofs,
n_dofs); // interactions neighbor / cell
FullMatrix<double> ip_matrix_nn(n_dofs,
n_dofs); // interactions neighbor / neighbor
std::vector<std::vector<Tensor<2, dim>>> discrete_hessians(
n_dofs, std::vector<Tensor<2, dim>>(n_q_points));
std::vector<std::vector<std::vector<Tensor<2, dim>>>>
discrete_hessians_neigh(GeometryInfo<dim>::faces_per_cell,
discrete_hessians);
for (const auto &cell : dof_handler.active_cell_iterators())
{
fe_values.reinit(cell);
cell->get_dof_indices(local_dof_indices);
compute_discrete_hessians(cell,
discrete_hessians,
discrete_hessians_neigh);
stiffness_matrix_cc = 0;
for (unsigned int q = 0; q < n_q_points; ++q)
{
const double dx = fe_values.JxW(q);
for (unsigned int i = 0; i < n_dofs; ++i)
for (unsigned int j = 0; j < n_dofs; ++j)
{
const Tensor<2, dim> &H_i = discrete_hessians[i][q];
const Tensor<2, dim> &H_j = discrete_hessians[j][q];
stiffness_matrix_cc(i, j) += scalar_product(H_j, H_i) * dx;
}
}
for (unsigned int i = 0; i < n_dofs; ++i)
for (unsigned int j = 0; j < n_dofs; ++j)
{
matrix(local_dof_indices[i], local_dof_indices[j]) +=
stiffness_matrix_cc(i, j);
}
for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
{
const typename DoFHandler<dim>::face_iterator face =
cell->face(face_no);
const bool at_boundary = face->at_boundary();
if (!at_boundary)
{
neighbor_cell = cell->neighbor(face_no);
neighbor_cell->get_dof_indices(local_dof_indices_neighbor);
stiffness_matrix_cn = 0;
stiffness_matrix_nc = 0;
stiffness_matrix_nn = 0;
for (unsigned int q = 0; q < n_q_points; ++q)
{
const double dx = fe_values.JxW(q);
for (unsigned int i = 0; i < n_dofs; ++i)
{
for (unsigned int j = 0; j < n_dofs; ++j)
{
const Tensor<2, dim> &H_i = discrete_hessians[i][q];
const Tensor<2, dim> &H_j = discrete_hessians[j][q];
const Tensor<2, dim> &H_i_neigh =
discrete_hessians_neigh[face_no][i][q];
const Tensor<2, dim> &H_j_neigh =
discrete_hessians_neigh[face_no][j][q];
stiffness_matrix_cn(i, j) +=
scalar_product(H_j_neigh, H_i) * dx;
stiffness_matrix_nc(i, j) +=
scalar_product(H_j, H_i_neigh) * dx;
stiffness_matrix_nn(i, j) +=
scalar_product(H_j_neigh, H_i_neigh) * dx;
}
}
}
for (unsigned int i = 0; i < n_dofs; ++i)
{
for (unsigned int j = 0; j < n_dofs; ++j)
{
matrix(local_dof_indices[i],
local_dof_indices_neighbor[j]) +=
stiffness_matrix_cn(i, j);
matrix(local_dof_indices_neighbor[i],
local_dof_indices[j]) +=
stiffness_matrix_nc(i, j);
matrix(local_dof_indices_neighbor[i],
local_dof_indices_neighbor[j]) +=
stiffness_matrix_nn(i, j);
}
}
} // boundary check
} // for face
for (unsigned int face_no = 0; face_no < cell->n_faces() - 1; ++face_no)
{
const typename DoFHandler<dim>::face_iterator face =
cell->face(face_no);
const bool at_boundary = face->at_boundary();
if (!at_boundary)
{ // nothing to be done if boundary face (the liftings of the
for (unsigned int face_no_2 = face_no + 1;
face_no_2 < cell->n_faces();
++face_no_2)
{
const typename DoFHandler<dim>::face_iterator face_2 =
cell->face(face_no_2);
const bool at_boundary_2 = face_2->at_boundary();
if (!at_boundary_2)
{
neighbor_cell = cell->neighbor(face_no);
neighbor_cell->get_dof_indices(
local_dof_indices_neighbor);
neighbor_cell_2 = cell->neighbor(face_no_2);
neighbor_cell_2->get_dof_indices(
local_dof_indices_neighbor_2);
stiffness_matrix_n1n2 = 0;
stiffness_matrix_n2n1 = 0;
for (unsigned int q = 0; q < n_q_points; ++q)
{
const double dx = fe_values.JxW(q);
for (unsigned int i = 0; i < n_dofs; ++i)
for (unsigned int j = 0; j < n_dofs; ++j)
{
const Tensor<2, dim> &H_i_neigh =
discrete_hessians_neigh[face_no][i][q];
const Tensor<2, dim> &H_j_neigh =
discrete_hessians_neigh[face_no][j][q];
const Tensor<2, dim> &H_i_neigh2 =
discrete_hessians_neigh[face_no_2][i][q];
const Tensor<2, dim> &H_j_neigh2 =
discrete_hessians_neigh[face_no_2][j][q];
stiffness_matrix_n1n2(i, j) +=
scalar_product(H_j_neigh2, H_i_neigh) * dx;
stiffness_matrix_n2n1(i, j) +=
scalar_product(H_j_neigh, H_i_neigh2) * dx;
}
}
for (unsigned int i = 0; i < n_dofs; ++i)
for (unsigned int j = 0; j < n_dofs; ++j)
{
matrix(local_dof_indices_neighbor[i],
local_dof_indices_neighbor_2[j]) +=
stiffness_matrix_n1n2(i, j);
matrix(local_dof_indices_neighbor_2[i],
local_dof_indices_neighbor[j]) +=
stiffness_matrix_n2n1(i, j);
}
} // boundary check face_2
} // for face_2
} // boundary check face_1
} // for face_1
for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
{
const typename DoFHandler<dim>::face_iterator face =
cell->face(face_no);
const double mesh_inv = 1.0 / face->diameter(); // h_e^{-1}
const double mesh3_inv =
1.0 / Utilities::fixed_power<3>(face->diameter()); // h_e^{-3}
fe_face.reinit(cell, face_no);
ip_matrix_cc = 0; // filled in any case (boundary or interior face)
const bool at_boundary = face->at_boundary();
if (at_boundary)
{
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face.JxW(q);
for (unsigned int i = 0; i < n_dofs; ++i)
for (unsigned int j = 0; j < n_dofs; ++j)
{
ip_matrix_cc(i, j) += penalty_jump_grad * mesh_inv *
fe_face.shape_grad(j, q) *
fe_face.shape_grad(i, q) * dx;
ip_matrix_cc(i, j) += penalty_jump_val * mesh3_inv *
fe_face.shape_value(j, q) *
fe_face.shape_value(i, q) * dx;
}
}
}
else
{ // interior face
neighbor_cell = cell->neighbor(face_no);
const unsigned int face_no_neighbor =
cell->neighbor_of_neighbor(face_no);
if (neighbor_cell->id() < cell->id())
continue; // skip this face (already considered)
else
{
fe_face_neighbor.reinit(neighbor_cell, face_no_neighbor);
neighbor_cell->get_dof_indices(local_dof_indices_neighbor);
ip_matrix_cn = 0;
ip_matrix_nc = 0;
ip_matrix_nn = 0;
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face.JxW(q);
for (unsigned int i = 0; i < n_dofs; ++i)
{
for (unsigned int j = 0; j < n_dofs; ++j)
{
ip_matrix_cc(i, j) +=
penalty_jump_grad * mesh_inv *
fe_face.shape_grad(j, q) *
fe_face.shape_grad(i, q) * dx;
ip_matrix_cc(i, j) +=
penalty_jump_val * mesh3_inv *
fe_face.shape_value(j, q) *
fe_face.shape_value(i, q) * dx;
ip_matrix_cn(i, j) -=
penalty_jump_grad * mesh_inv *
fe_face_neighbor.shape_grad(j, q) *
fe_face.shape_grad(i, q) * dx;
ip_matrix_cn(i, j) -=
penalty_jump_val * mesh3_inv *
fe_face_neighbor.shape_value(j, q) *
fe_face.shape_value(i, q) * dx;
ip_matrix_nc(i, j) -=
penalty_jump_grad * mesh_inv *
fe_face.shape_grad(j, q) *
fe_face_neighbor.shape_grad(i, q) * dx;
ip_matrix_nc(i, j) -=
penalty_jump_val * mesh3_inv *
fe_face.shape_value(j, q) *
fe_face_neighbor.shape_value(i, q) * dx;
ip_matrix_nn(i, j) +=
penalty_jump_grad * mesh_inv *
fe_face_neighbor.shape_grad(j, q) *
fe_face_neighbor.shape_grad(i, q) * dx;
ip_matrix_nn(i, j) +=
penalty_jump_val * mesh3_inv *
fe_face_neighbor.shape_value(j, q) *
fe_face_neighbor.shape_value(i, q) * dx;
}
}
}
} // face not visited yet
} // boundary check
for (unsigned int i = 0; i < n_dofs; ++i)
{
for (unsigned int j = 0; j < n_dofs; ++j)
{
matrix(local_dof_indices[i], local_dof_indices[j]) +=
ip_matrix_cc(i, j);
}
}
if (!at_boundary)
{
for (unsigned int i = 0; i < n_dofs; ++i)
{
for (unsigned int j = 0; j < n_dofs; ++j)
{
matrix(local_dof_indices[i],
local_dof_indices_neighbor[j]) +=
ip_matrix_cn(i, j);
matrix(local_dof_indices_neighbor[i],
local_dof_indices[j]) += ip_matrix_nc(i, j);
matrix(local_dof_indices_neighbor[i],
local_dof_indices_neighbor[j]) +=
ip_matrix_nn(i, j);
}
}
}
} // for face
} // for cell
}
template <int dim>
void BiLaplacianLDGLift<dim>::assemble_rhs()
{
rhs = 0;
const QGauss<dim> quad(fe.degree + 1);
FEValues<dim> fe_values(
const unsigned int n_dofs = fe_values.dofs_per_cell;
const unsigned int n_quad_pts = quad.size();
const RightHandSide<dim> right_hand_side;
Vector<double> local_rhs(n_dofs);
std::vector<types::global_dof_index> local_dof_indices(n_dofs);
for (const auto &cell : dof_handler.active_cell_iterators())
{
fe_values.reinit(cell);
cell->get_dof_indices(local_dof_indices);
local_rhs = 0;
for (unsigned int q = 0; q < n_quad_pts; ++q)
{
const double dx = fe_values.JxW(q);
for (unsigned int i = 0; i < n_dofs; ++i)
{
local_rhs(i) +=
right_hand_side.value(fe_values.quadrature_point(q)) *
fe_values.shape_value(i, q) * dx;
}
}
for (unsigned int i = 0; i < n_dofs; ++i)
rhs(local_dof_indices[i]) += local_rhs(i);
}
}
template <int dim>
void BiLaplacianLDGLift<dim>::solve()
{
A_direct.initialize(matrix);
A_direct.vmult(solution, rhs);
}
template <int dim>
void BiLaplacianLDGLift<dim>::compute_errors()
{
double error_H2 = 0;
double error_H1 = 0;
double error_L2 = 0;
const QGauss<dim> quad(fe.degree + 1);
const QGauss<dim - 1> quad_face(fe.degree + 1);
FEValues<dim> fe_values(fe,
quad,
FEFaceValues<dim> fe_face(fe,
quad_face,
FEFaceValues<dim> fe_face_neighbor(fe,
quad_face,
const unsigned int n_q_points = quad.size();
const unsigned int n_q_points_face = quad_face.size();
const ExactSolution<dim> u_exact;
std::vector<double> solution_values_cell(n_q_points);
std::vector<Tensor<1, dim>> solution_gradients_cell(n_q_points);
std::vector<Tensor<2, dim>> solution_hessians_cell(n_q_points);
std::vector<double> solution_values(n_q_points_face);
std::vector<double> solution_values_neigh(n_q_points_face);
std::vector<Tensor<1, dim>> solution_gradients(n_q_points_face);
std::vector<Tensor<1, dim>> solution_gradients_neigh(n_q_points_face);
for (const auto &cell : dof_handler.active_cell_iterators())
{
fe_values.reinit(cell);
fe_values.get_function_values(solution, solution_values_cell);
fe_values.get_function_gradients(solution, solution_gradients_cell);
fe_values.get_function_hessians(solution, solution_hessians_cell);
for (unsigned int q = 0; q < n_q_points; ++q)
{
const double dx = fe_values.JxW(q);
error_H2 += (u_exact.hessian(fe_values.quadrature_point(q)) -
solution_hessians_cell[q])
.norm_square() *
dx;
error_H1 += (u_exact.gradient(fe_values.quadrature_point(q)) -
solution_gradients_cell[q])
.norm_square() *
dx;
error_L2 += Utilities::fixed_power<2>(
u_exact.value(fe_values.quadrature_point(q)) -
solution_values_cell[q]) *
dx;
} // for quadrature points
for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
{
const typename DoFHandler<dim>::face_iterator face =
cell->face(face_no);
const double mesh_inv = 1.0 / face->diameter(); // h^{-1}
const double mesh3_inv =
1.0 / Utilities::fixed_power<3>(face->diameter()); // h^{-3}
fe_face.reinit(cell, face_no);
fe_face.get_function_values(solution, solution_values);
fe_face.get_function_gradients(solution, solution_gradients);
const bool at_boundary = face->at_boundary();
if (at_boundary)
{
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face.JxW(q);
const double u_exact_q =
u_exact.value(fe_face.quadrature_point(q));
const Tensor<1, dim> u_exact_grad_q =
u_exact.gradient(fe_face.quadrature_point(q));
error_H2 +=
mesh_inv *
(u_exact_grad_q - solution_gradients[q]).norm_square() *
dx;
error_H2 += mesh3_inv *
Utilities::fixed_power<2>(u_exact_q -
solution_values[q]) *
dx;
error_H1 += mesh_inv *
Utilities::fixed_power<2>(u_exact_q -
solution_values[q]) *
dx;
}
}
else
{ // interior face
neighbor_cell = cell->neighbor(face_no);
const unsigned int face_no_neighbor =
cell->neighbor_of_neighbor(face_no);
if (neighbor_cell->id() < cell->id())
continue; // skip this face (already considered)
else
{
fe_face_neighbor.reinit(neighbor_cell, face_no_neighbor);
fe_face.get_function_values(solution, solution_values);
fe_face_neighbor.get_function_values(solution,
solution_values_neigh);
fe_face.get_function_gradients(solution,
solution_gradients);
fe_face_neighbor.get_function_gradients(
solution, solution_gradients_neigh);
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face.JxW(q);
error_H2 +=
mesh_inv *
(solution_gradients_neigh[q] - solution_gradients[q])
.norm_square() *
dx;
error_H2 +=
mesh3_inv *
Utilities::fixed_power<2>(solution_values_neigh[q] -
solution_values[q]) *
dx;
error_H1 +=
mesh_inv *
Utilities::fixed_power<2>(solution_values_neigh[q] -
solution_values[q]) *
dx;
}
} // face not visited yet
} // boundary check
} // for face
} // for cell
error_H2 = std::sqrt(error_H2);
error_H1 = std::sqrt(error_H1);
error_L2 = std::sqrt(error_L2);
std::cout << "DG H2 norm of the error: " << error_H2 << std::endl;
std::cout << "DG H1 norm of the error: " << error_H1 << std::endl;
std::cout << " L2 norm of the error: " << error_L2 << std::endl;
}
template <int dim>
void BiLaplacianLDGLift<dim>::output_results() const
{
DataOut<dim> data_out;
data_out.attach_dof_handler(dof_handler);
data_out.add_data_vector(solution, "solution");
data_out.build_patches();
std::ofstream output("solution.vtk");
data_out.write_vtk(output);
}
template <int dim>
void BiLaplacianLDGLift<dim>::assemble_local_matrix(
const FEValues<dim> &fe_values_lift,
const unsigned int n_q_points,
FullMatrix<double> &local_matrix)
{
const unsigned int n_dofs = fe_values_lift.dofs_per_cell;
local_matrix = 0;
for (unsigned int q = 0; q < n_q_points; ++q)
{
const double dx = fe_values_lift.JxW(q);
for (unsigned int m = 0; m < n_dofs; ++m)
for (unsigned int n = 0; n < n_dofs; ++n)
{
local_matrix(m, n) +=
scalar_product(fe_values_lift[tau_ext].value(n, q),
fe_values_lift[tau_ext].value(m, q)) *
dx;
}
}
}
template <int dim>
void BiLaplacianLDGLift<dim>::compute_discrete_hessians(
std::vector<std::vector<Tensor<2, dim>>> &discrete_hessians,
std::vector<std::vector<std::vector<Tensor<2, dim>>>>
&discrete_hessians_neigh)
{
const typename Triangulation<dim>::cell_iterator cell_lift =
static_cast<typename Triangulation<dim>::cell_iterator>(cell);
const QGauss<dim> quad(fe.degree + 1);
const QGauss<dim - 1> quad_face(fe.degree + 1);
const unsigned int n_q_points = quad.size();
const unsigned int n_q_points_face = quad_face.size();
FEFaceValues<dim> fe_face_neighbor(
const unsigned int n_dofs = fe_values.dofs_per_cell;
FEValues<dim> fe_values_lift(fe_lift,
quad,
FEFaceValues<dim> fe_face_lift(
const unsigned int n_dofs_lift = fe_values_lift.dofs_per_cell;
FullMatrix<double> local_matrix_lift(n_dofs_lift, n_dofs_lift);
Vector<double> local_rhs_re(n_dofs_lift), local_rhs_be(n_dofs_lift),
coeffs_re(n_dofs_lift), coeffs_be(n_dofs_lift), coeffs_tmp(n_dofs_lift);
SolverControl solver_control(1000, 1e-12);
SolverCG<Vector<double>> solver(solver_control);
double factor_avg; // 0.5 for interior faces, 1.0 for boundary faces
fe_values.reinit(cell);
fe_values_lift.reinit(cell_lift);
assemble_local_matrix(fe_values_lift, n_q_points, local_matrix_lift);
for (unsigned int i = 0; i < n_dofs; ++i)
for (unsigned int q = 0; q < n_q_points; ++q)
{
discrete_hessians[i][q] = 0;
for (unsigned int face_no = 0;
face_no < discrete_hessians_neigh.size();
++face_no)
{
discrete_hessians_neigh[face_no][i][q] = 0;
}
}
for (unsigned int i = 0; i < n_dofs; ++i)
{
coeffs_re = 0;
coeffs_be = 0;
for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
{
const typename DoFHandler<dim>::face_iterator face =
cell->face(face_no);
const bool at_boundary = face->at_boundary();
factor_avg = 0.5;
if (at_boundary)
{
factor_avg = 1.0;
}
fe_face.reinit(cell, face_no);
fe_face_lift.reinit(cell_lift, face_no);
local_rhs_re = 0;
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face_lift.JxW(q);
const Tensor<1, dim> normal = fe_face.normal_vector(
q); // same as fe_face_lift.normal_vector(q)
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
local_rhs_re(m) +=
factor_avg *
(fe_face_lift[tau_ext].value(m, q) * normal) *
fe_face.shape_grad(i, q) * dx;
}
}
local_rhs_be = 0;
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face_lift.JxW(q);
const Tensor<1, dim> normal = fe_face.normal_vector(
q); // same as fe_face_lift.normal_vector(q)
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
local_rhs_be(m) += factor_avg *
fe_face_lift[tau_ext].divergence(m, q) *
normal * fe_face.shape_value(i, q) * dx;
}
}
coeffs_tmp = 0;
solver.solve(local_matrix_lift,
coeffs_tmp,
local_rhs_re,
coeffs_re += coeffs_tmp;
coeffs_tmp = 0;
solver.solve(local_matrix_lift,
coeffs_tmp,
local_rhs_be,
coeffs_be += coeffs_tmp;
} // for face
for (unsigned int q = 0; q < n_q_points; ++q)
{
discrete_hessians[i][q] += fe_values.shape_hessian(i, q);
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
discrete_hessians[i][q] -=
coeffs_re[m] * fe_values_lift[tau_ext].value(m, q);
}
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
discrete_hessians[i][q] +=
coeffs_be[m] * fe_values_lift[tau_ext].value(m, q);
}
}
} // for dof i
for (unsigned int face_no = 0; face_no < cell->n_faces(); ++face_no)
{
const typename DoFHandler<dim>::face_iterator face =
cell->face(face_no);
const bool at_boundary = face->at_boundary();
if (!at_boundary)
{
neighbor_cell = cell->neighbor(face_no);
const unsigned int face_no_neighbor =
cell->neighbor_of_neighbor(face_no);
fe_face_neighbor.reinit(neighbor_cell, face_no_neighbor);
for (unsigned int i = 0; i < n_dofs; ++i)
{
coeffs_re = 0;
coeffs_be = 0;
fe_face_lift.reinit(cell_lift, face_no);
local_rhs_re = 0;
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face_lift.JxW(q);
const Tensor<1, dim> normal =
fe_face_neighbor.normal_vector(q);
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
local_rhs_re(m) +=
0.5 * (fe_face_lift[tau_ext].value(m, q) * normal) *
fe_face_neighbor.shape_grad(i, q) * dx;
}
}
local_rhs_be = 0;
for (unsigned int q = 0; q < n_q_points_face; ++q)
{
const double dx = fe_face_lift.JxW(q);
const Tensor<1, dim> normal =
fe_face_neighbor.normal_vector(q);
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
local_rhs_be(m) +=
0.5 * fe_face_lift[tau_ext].divergence(m, q) *
normal * fe_face_neighbor.shape_value(i, q) * dx;
}
}
solver.solve(local_matrix_lift,
coeffs_re,
local_rhs_re,
solver.solve(local_matrix_lift,
coeffs_be,
local_rhs_be,
for (unsigned int q = 0; q < n_q_points; ++q)
{
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
discrete_hessians_neigh[face_no][i][q] -=
coeffs_re[m] * fe_values_lift[tau_ext].value(m, q);
}
for (unsigned int m = 0; m < n_dofs_lift; ++m)
{
discrete_hessians_neigh[face_no][i][q] +=
coeffs_be[m] * fe_values_lift[tau_ext].value(m, q);
}
}
} // for dof i
} // boundary check
} // for face
}
template <int dim>
void BiLaplacianLDGLift<dim>::run()
{
make_grid();
setup_system();
assemble_system();
solve();
compute_errors();
output_results();
}
} // namespace Step82
int main()
{
try
{
const unsigned int n_ref = 3; // number of mesh refinements
const unsigned int degree =
2; // FE degree for u_h and the two lifting terms
const double penalty_grad =
1.0; // penalty coefficient for the jump of the gradients
const double penalty_val =
1.0; // penalty coefficient for the jump of the values
Step82::BiLaplacianLDGLift<2> problem(n_ref,
degree,
penalty_grad,
penalty_val);
problem.run();
}
catch (std::exception &exc)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Exception on processing: " << std::endl
<< exc.what() << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}
catch (...)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Unknown exception!" << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}
return 0;
}
void write_vtk(std::ostream &out) const
void add_data_vector(const VectorType &data, const std::vector< std::string > &names, const DataVectorType type=type_automatic, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation={})
virtual void build_patches(const unsigned int n_subdivisions=0)
Definition data_out.cc:1062
void reinit(const Triangulation< dim, spacedim > &tria)
const unsigned int dofs_per_cell
double JxW(const unsigned int q_point) const
void reinit(const TriaIterator< DoFCellAccessor< dim, spacedim, level_dof_access > > &cell)
void vmult(Vector< double > &dst, const Vector< double > &src) const