A hierarchical basis#
Author: Jørgen S. Dokken
SPDX-License-Identifier: MIT
We solve the same Laplace eigenvalue problem as in the submesh demo, with the same SIPG discretisation [ABCM02] and error indicator [Lar00]. Here, the space with a cell-wise degree is represented as a subset of the degrees of freedom of a single discontinuous space of the maximal degree \(p_{max}\), which only works with a hierarchical basis.
A hierarchical basis#
Basix provides orthonormal polynomial sets: the Dubiner polynomials
[Dub91] on simplices, and tensor products of Legendre polynomials on
quadrilaterals and hexahedra. dolfinx_padapt.approaches.hierarchical_element() builds a
discontinuous element from these polynomials, sorted by degree (the total degree on simplices,
and the largest degree in each direction on quadrilaterals and hexahedra). Its degrees of freedom
are the moments against the basis functions. The first dims[k] basis functions then span the
space of degree \(k\), \(P_k\) on simplices and \(Q_k\) on quadrilaterals and hexahedra.
We verify this against the Legendre variant of the discontinuous Lagrange element of Basix: as
both bases are orthonormal, the projection onto the first dims[k] basis functions reproduces
every basis function of degree \(k\).
from mpi4py import MPI
from petsc4py import PETSc
import basix
import numpy as np
from dolfinx_padapt import EigenvalueProblem, create_pacman
from dolfinx_padapt.adaptivity import solve_adaptive
from dolfinx_padapt.approaches import HierarchicalApproach, hierarchical_element
from dolfinx_padapt.forms import Parameters
from dolfinx_padapt.plotting import Animation
pmax = 3
for cell in (basix.CellType.triangle, basix.CellType.quadrilateral, basix.CellType.hexahedron):
element, dims = hierarchical_element(cell, pmax)
points, weights = basix.make_quadrature(cell, 2 * pmax)
phi = element.tabulate(0, points)[0]
spans = []
for k in range(pmax + 1):
reference = basix.create_element(
basix.ElementFamily.P, cell, k, basix.LagrangeVariant.legendre, discontinuous=True
)
psi = reference.tabulate(0, points)[0, :, :, 0]
coefficients = phi[:, : dims[k]].T @ (weights[:, None] * psi)
spans.append(bool(np.allclose(phi[:, : dims[k]] @ coefficients, psi)))
PETSc.Sys.Print(f"{cell.name}: dims = {dims.tolist()}, first dims[k] span degree k: {spans}")
triangle: dims = [1, 3, 6, 10], first dims[k] span degree k: [True, True, True, True]
quadrilateral: dims = [1, 4, 9, 16], first dims[k] span degree k: [True, True, True, True]
hexahedron: dims = [1, 8, 27, 64], first dims[k] span degree k: [True, True, True, True]
Restriction to the cell-wise degree#
A cell \(K\) of degree \(p_K\) keeps the degrees of freedom dofmap.list[K, :dims[p_K]].
The parallel layout of the kept degrees of freedom is computed with
dolfinx.common.create_sub_index_map(), and the matrices of the cell-wise degree are
extracted from the matrices of degree \(p_{max}\) with
petsc4py.PETSc.Mat.createSubMatrix().
The penalty parameter of SIPG depends on the degree on each facet. With
penalty="global", the penalty \(\sigma=\alpha p_{max}^2\) is used on every facet, which is
stable for every distribution of degrees. Then the matrices of degree \(p_{max}\) are only
assembled once, and every iteration only extracts sub-matrices.
mesh = create_pacman(MPI.COMM_WORLD, h=0.3, h_corner=0.01)
params = Parameters(pmin=1, pmax=6, penalty="global")
approach = HierarchicalApproach(EigenvalueProblem(mesh), params)
with Animation(mesh.comm, "hierarchical.gif") as animation:
history = solve_adaptive(approach, max_iterations=15, callback=animation)
it dofs error eta update solve estim. values, degrees
0 543 3.625e-02 3.637e+00 0.001 0.033 0.001 lambda=11.80784512, {1: 181}
1 618 1.912e-02 1.945e+00 0.000 0.004 0.001 lambda=11.61256199, {1: 156, 2: 25}
2 734 1.016e-02 1.082e+00 0.000 0.005 0.001 lambda=11.51055856, {1: 128, 2: 45, 3: 8}
3 882 4.140e-03 6.377e-01 0.000 0.006 0.001 lambda=11.44192527, {1: 88, 2: 78, 3: 15}
4 1060 1.380e-03 3.684e-01 0.000 0.007 0.001 lambda=11.41046903, {1: 56, 2: 92, 3: 31, 4: 2}
5 1300 3.197e-04 1.909e-01 0.000 0.009 0.001 lambda=11.39839066, {1: 21, 2: 97, 3: 58, 4: 5}
6 1398 1.736e-04 1.506e-01 0.000 0.010 0.001 lambda=11.39672554, {1: 10, 2: 97, 3: 66, 4: 7, 5: 1}
7 1470 9.978e-05 1.255e-01 0.000 0.011 0.001 lambda=11.39588427, {1: 3, 2: 97, 3: 71, 4: 8, 5: 1, 6: 1}
8 1542 5.669e-05 1.069e-01 0.000 0.011 0.001 lambda=11.39539324, {2: 89, 3: 82, 4: 6, 5: 2, 6: 2}
9 1576 5.337e-05 1.057e-01 0.000 0.011 0.001 lambda=11.39535543, {2: 84, 3: 87, 4: 6, 6: 4}
10 1810 2.396e-05 7.033e-02 0.000 0.014 0.001 lambda=11.39502034, {2: 38, 3: 123, 4: 16, 6: 4}
11 2003 1.983e-05 6.246e-02 0.000 0.015 0.001 lambda=11.39497323, {2: 10, 3: 136, 4: 30, 5: 1, 6: 4}
12 2376 1.832e-05 5.896e-02 0.000 0.020 0.001 lambda=11.39495605, {3: 94, 4: 71, 5: 11, 6: 5}
13 2609 1.804e-05 5.824e-02 0.000 0.023 0.001 lambda=11.39495285, {3: 55, 4: 106, 5: 13, 6: 7}
14 2755 1.799e-05 5.809e-02 0.000 0.024 0.001 lambda=11.39495227, {3: 32, 4: 125, 5: 16, 6: 8}
Note that the assembly time of the first iteration includes the assembly of the full matrices. The fine matrices hold the degrees of freedom of degree \(p_{max}\) on every cell:
num_full = approach.function_space.dofmap.index_map.size_global
PETSc.Sys.Print(f"Full space: {num_full} dofs, active: {approach.num_dofs} dofs")
Full space: 5068 dofs, active: 2755 dofs
Limitations
The approach is limited to discontinuous spaces: Basix has no hierarchical continuous Lagrange basis, and selecting rows and columns of a continuous space cannot break the continuity at the interface between two degrees.
The matrices of degree \(p_{max}\) are assembled and stored, and each cell is integrated with the quadrature of degree \(p_{max}\).
With a degree dependent penalty (
penalty="local"), the fine matrices are assembled at every iteration.
Douglas N. Arnold, Franco Brezzi, Bernardo Cockburn, and L. Donatella Marini. Unified analysis of discontinuous Galerkin methods for elliptic problems. SIAM Journal on Numerical Analysis, 39(5):1749–1779, 2002. doi:10.1137/S0036142901384162.
Moshe Dubiner. Spectral methods on triangles and other domains. Journal of Scientific Computing, 6(4):345–390, 1991. doi:10.1007/BF01060030.
Mats G. Larson. A posteriori and a priori error analysis for finite element approximations of self-adjoint elliptic eigenvalue problems. SIAM Journal on Numerical Analysis, 38(2):608–625, 2000. doi:10.1137/S0036142997320164.