![]() |
Vulpes
0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
|
Author: Pedro Peixoto ppeix.nosp@m.oto@.nosp@m.usp.b.nosp@m.r
This note records:
Reference for notation and DG formulation style: L. Cangiani, Z. Dong, E. H. Georgoulis, and P. Houston, hp-Version Discontinuous Galerkin Methods on Polygonal and Polyhedral Meshes, Springer, 2017. DOI: 10.1007/978-3-319-19800-2
Consider the Poisson problem
\[-\Delta u = f \quad \text{in } \Omega, \]
with Dirichlet boundary condition
\[u = g \quad \text{on } \partial\Omega. \]
Let \(\mathcal{T}_h\) be a mesh, \(\mathcal{F}_h\) the set of interior faces, and \(\mathcal{F}_h^{\mathcal{B}}\) the set of boundary faces. For a scalar \(w\) and vector \(\tau\), on an interior face shared by elements \(K^+\) and \(K^-\) (with outward normals \(n^+,n^-\)), define
\[\{\!\{w\}\!\} = \tfrac12(w^+ + w^-), \qquad [\![w]\!] = w^+ n^+ + w^- n^-. \]
A standard symmetric interior penalty DG (SIPG) bilinear form is
\[a_h(u_h,v_h) = \sum_{K\in\mathcal{T}_h} \int_K \nabla u_h\cdot\nabla v_h\,dx - \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \{\!\{\nabla u_h\}\!\}\cdot [\![v_h]\!] \,ds - \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \{\!\{\nabla v_h\}\!\}\cdot [\![u_h]\!] \,ds + \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \gamma [\![u_h]\!]\cdot[\![v_h]\!] \,ds. \]
The linear functional for Dirichlet data is
\[\ell_h(v_h) = \sum_{K\in\mathcal{T}_h}\int_K f v_h\,dx - \sum_{e\in\mathcal{F}_h^{\mathcal{B}}} \int_e g\,\nabla v_h\cdot n\,ds + \sum_{e\in\mathcal{F}_h^{\mathcal{B}}} \int_e \gamma g v_h\,ds. \]
where \(\gamma\) is the discontinuous penalty function.
The DG problem is: find \(u_h\in V_h\) such that
\[a_h(u_h,v_h) = \ell_h(v_h) \qquad \forall v_h\in V_h. \]
Vulpes, and in fact most DG codes, loop over cells and then the edges of the respective cells, not through the whole set of faces directly. Here we will re-write the formulation above to accommodate for that.
We will look into the internal edge term, dropping the \(_h\) for brevity, and noting that \(n^+=-n^-\).
\[ - \{\!\{\nabla u\}\!\}\cdot [\![v]\!] - \{\!\{\nabla v\}\!\}\cdot [\![u]\!] =\\ - \frac{1}{2}(\nabla u^{+} +\nabla u^{-}) \cdot (v^+ n^+ + v^- n^-) - \frac{1}{2}(\nabla v^+ + \nabla v^-)\cdot (u^+n^++u^-n^-) =\\ - \frac{1}{2}(\nabla u^{+}\cdot n^+)v^+ - \frac{1}{2}(\nabla u^{-}\cdot n^-)v^- + \frac{1}{2}(\nabla u^{+}\cdot n^+)v^- + \frac{1}{2}(\nabla u^{-}\cdot n^-)v^+ + \\ - \frac{1}{2}(\nabla v^{+}\cdot n^+)u^+ - \frac{1}{2}(\nabla v^{-}\cdot n^-)u^- + \frac{1}{2}(\nabla v^{+}\cdot n^+)u^- + \frac{1}{2}(\nabla v^{-}\cdot n^-)u^+ . \]
We will split these terms into the cell interior forms (C), that do not have mixed terms with cell and neighbor, and the mixed ones, with connections to neighbors (N), so that
\[- \{\!\{\nabla u\}\!\}\cdot [\![v]\!] - \{\!\{\nabla v\}\!\}\cdot [\![u]\!] = C+N \]
with
\[C = C^++C^- = \\- \frac{1}{2}(\nabla u^{+}\cdot n^+)v^+ - \frac{1}{2}(\nabla u^{-}\cdot n^-)v^- \\ - \frac{1}{2}(\nabla v^{+}\cdot n^+)u^+ - \frac{1}{2}(\nabla v^{-}\cdot n^-)u^- \]
\[N = N^+ + N^- = \\ \frac{1}{2}(\nabla u^{+}\cdot n^+)v^- + \frac{1}{2}(\nabla u^{-}\cdot n^-)v^+ \\ + \frac{1}{2}(\nabla v^{+}\cdot n^+)u^- + \frac{1}{2}(\nabla v^{-}\cdot n^-)u^+, \]
where
\[C^+ = - \frac{1}{2}(\nabla u^{+}\cdot n^+)v^+ - \frac{1}{2}(\nabla v^{+}\cdot n^+)u^+ \]
\[N^+ = \frac{1}{2}(\nabla u^{+}\cdot n^+)v^-+ \frac{1}{2}(\nabla v^{+}\cdot n^+)u^- \]
and similar for \(C^-\) and \(N^-\), just swapping \(+\) for \(-\), and vice versa. Note C only depends on the respective cell (either \(K^+\) or \(K^-\), but not both). Therefore our original form reads as:
\[- \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \{\!\{\nabla u_h\}\!\}\cdot [\![v_h]\!] \,ds - \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \{\!\{\nabla v_h\}\!\}\cdot [\![u_h]\!] \,ds = \\ = \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e C_e^+ + C_e^- + N_e^+ + N_e^- \, ds \]
There are 2 important things happening here:
\[ \sum_{K\in\mathcal{T}_h} \sum_{e\in K } \int_e C^K_e \, ds = \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e C_e^+ + C_e^- \, ds \]
and the same for the \(N\).Now, defining
\[\text{IA}^K = - \sum_{e\in K } \int_e \frac{1}{2}(\nabla u^{K}\cdot n^K)v^K \, ds \]
and
\[\text{IAn}^K_e = \int_e \frac{1}{2}(\nabla u^{K}\cdot n^K)v^{K'} \, ds, \]
where \(K'\) is the neighbour cell of \(K\) with respect to the given edge/face \(e\), and observing that
\[\text{IA}^K + (\text{IA}^K)^t = \sum_{e\in K } \int_e C_e^K, \]
where \(()^t\) here means the transposition of trial and test basis function, we can finally write the original weakform as appears in the Vulpes code:
\[- \sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \{\!\{\nabla u\}\!\}\cdot [\![v]\!] + \{\!\{\nabla v\}\!\}\cdot [\![u]\!] \, ds = \sum_{K\in\mathcal{T}_h} \text{IA}^K + (\text{IA}^K)^t + \sum_{K\in\mathcal{T}_h} \sum_{e\in K } \text{IAn}^K_e + (\text{IAn}^K_e)^t, \]
A similar analysis can be done for other terms in the bilinear form, for instance with the penalty term:
\[\sum_{e\in\mathcal{F}_h\cup\mathcal{F}_h^{\mathcal{B}}} \int_e \gamma [\![u_h]\!]\cdot[\![v_h]\!]. \]
From examples/assembly/laplacian/lap_dg_2d_main.cpp, Vulpes assembles the Laplacian with modal DG basis and the manufactured solution
\[u(x,y)=\sin(2\pi x)\sin(2\pi y), \qquad f(x,y)=8\pi^2\sin(2\pi x)\sin(2\pi y). \]
The file defines the following expressions (symbol names in parentheses):
\[\int_K \nabla u\cdot\nabla v\,dx \]
\[\int_{\partial K} bc\,(\nabla u\cdot n)\,v\,ds \]
with\[bc = \begin{cases} -\tfrac12 & \text{if face has neighbor (interior)},\\ -1 & \text{if boundary face}. \end{cases} \]
In vulpes, every time that there is an edge/facet integration that relies only on the current cell (so restricted to information in \(K\), integrated on \(\partial K\)), the output is always the sum of the integrals over all edges/facets.
\[\int_{\partial K} \gamma\,u\,v\,ds \]
where \(\gamma\) is created as a penalty expression with scaling proportional to polynomial order (configured with factor 10.0 in the example).\[\int_e \tfrac12\,(\nabla u\cdot n)\,v_{\text{neigh}}\,ds \]
\[-\int_e \gamma\,u\,v_{\text{neigh}}\,ds \]
\[\int_K f v\,dx \]
\[\int_{\partial K\cap\partial\Omega} u_{\text{exact}}\,(\gamma v - \nabla v\cdot n)\,ds \]
The matrix and vectors are assembled as:
\[A = K + IA + IA^t + SA + IAn + IAn^t + SAn, \]
with block insertions over local cell dofs and neighbor-cell dofs.In the Vulpes implementation, \(IA^t\) and \(IAn^t\) are assembled explicitly as transpose insertions of the corresponding local face blocks (equivalently, swapping test/trial roles in those terms).
Concretely, two things must happen simultaneously to assemble a transposed contribution correctly:
In summary: assembling the transpose of a local contribution requires both la::RowMajor on the data buffer and swapped row/column index arrays.
\[\mathrm{rhs} = F + F_{\text{Dirichlet}}. \]
The code also builds:
If the mesh is periodic, the discrete Laplacian has a constant null space. The implementation:
This removes the arbitrary additive constant and allows consistent error computation.
The implemented form is an interior-penalty DG Laplacian where:
So the code realizes a standard IPDG/SIPG-style discretization written in a cell-wise block assembly style suitable for polygonal meshes.
The 2D convergence example is in examples/assembly/laplacian/lap_dg_2d_main.cpp. A 3D sequential version is in lap_dg_3d_main.cpp. Single-run 2D and 3D MPI examples are in examples/assembly/laplacian/MPI/.
Each example can read its parameters from a JSON file. Example parameter files are provided in the source directory:
The 2D parameter file looks like:
Copy or edit one of these files to define a run.
A complete JSON file or every positional CLI parameter must be supplied. The programs do not search for a parameter file automatically.
From the build directory, pass the JSON file as the first argument:
Parameters can also be supplied directly on the command line, or used to override values after a JSON path. Positional order is order n_lvls mesh_kind output_path; all four are required without JSON:
To see all options:
For distributed assembly and execution, see MPI Laplacian Assembly.
The supported 2D mesh families are (see the meshes tutorial 01_Meshes_2D.md):
The supported 3D mesh families are:
For a first-order DG convergence run on the periodic Voronoi mesh sequence:
To save the convergence output to a text file:
For each mesh in the selected sequence, the code prints:
At the end of the run a formatted convergence table is printed and saved as a CSV to output/laplacian/convergence_{dim}d_p{order}_{mesh_kind}.csv.
VTK files for mesh and solution visualization are written to output/laplacian/ with the naming convention:
You can view just the mesh file in Paraview. For instance output/laplacian/lap_2d_p1_voronoi_periodic_2_mesh.vtu. This file only contains mesh information, but no solution of the Laplace problem.
Figure: Voronoi periodic mesh used to obtain the solution of the Poisson problem. File: output/laplacian/lap_2d_p1_voronoi_periodic_2_mesh.vtu
To view the solution, or error, use the solution file for the corresponding order and mesh, for instance output/laplacian/lap_2d_p1_voronoi_periodic_2.vtu. It outputs the numerical solution \(u_h\), the projected exact solution, and the error field.
Important remark: scalar fields are exported from Vulpes in a higher dimension grid, with submeshing, to allow appropriate view of the higher order basis space. So, you will notice the DOF number will not match the actual problem DOF, and the grid will not be the same as the original grid, as it has sub-triangulations.
Figure: Numerical solution for the Poisson problem using polyDG with P1 on Voronoi periodic mesh. File: output/laplacian/lap_2d_p1_voronoi_periodic_2.vtu
Note below the submeshing strategy (asking Paraview to show the wireframe), here showing the numerical solution:
The error is computed based on the difference of the values of the modal coefficients, that is:
Only a few lines differ from the serial assembly: wrap the mesh in ParallelMesh, finalize an MPI-aware DoF numbering, and assemble owned cells. The weak form and the SparseMatrix, Vector, and LinearSolver calls remain unchanged; Vulpes uses distributed PETSc objects underneath.
From the build directory:
The MPI-specific positional order is order mesh_kind nel dof_distrib_type [mesh_file] [output_path], also used for overrides after a JSON path. Instead of n_lvls, nel selects the mesh size (cells per direction for Cartesian meshes), mesh-file index, or agglomeration size/depth. load_file requires mesh_file and ignores nel; use --help for supported mesh kinds and selectors.
Open the exported .pvtu in ParaView, keeping its per-rank .vtu pieces alongside it. It contains u_h, u_exact, and u_error. Reported errors are the globally computed, matrix-based \(L^2\) error and \(H^1\) semi-error.
Warning: Keep dof_distrib_type = 2 for export so owned-cell coefficients are locally owned, and set thread counts before launching to control threads per rank.