Restricted dofmaps#
Author: Jørgen S. Dokken
SPDX-License-Identifier: MIT
We solve the same Laplace eigenvalue problem as in the submesh demo, but instead of creating a submesh for each degree, we create one function space \(V_i\) per degree \(i\) on the whole mesh, and restrict its dofmap to the cells of degree \(i\). The discretisation (SIPG [ABCM02] with weakly imposed boundary conditions [Nit71]) and the error indicator [Lar00] are the same.
from mpi4py import MPI
from petsc4py import PETSc
import dolfinx
import numpy as np
from dolfinx_padapt import DegreeField, EigenvalueProblem, create_pacman
from dolfinx_padapt.adaptivity import solve_adaptive
from dolfinx_padapt.approaches import RestrictedApproach, restrict_function_space
from dolfinx_padapt.forms import Parameters
from dolfinx_padapt.plotting import Animation
mesh = create_pacman(MPI.COMM_WORLD, h=0.3, h_corner=0.01)
params = Parameters(pmin=1, pmax=6)
Restricting a dofmap#
Given the cells of degree \(i\) (including ghost cells), we keep the degrees of freedom of the
parent space \(V_i\) in the closure of these cells. The parallel layout of the kept degrees of
freedom is computed with dolfinx.common.create_sub_index_map(), and a new
dolfinx.cpp.fem.DofMap is created on the same mesh.
As an illustration, we give the cells in the left half of the domain degree 2, and restrict a second order space to them.
degrees = DegreeField(mesh, 1, 2)
V2 = dolfinx.fem.functionspace(mesh, ("DG", 2))
midpoints = dolfinx.mesh.compute_midpoints(
mesh, mesh.topology.dim, np.arange(degrees.num_owned_cells, dtype=np.int32)
)
degrees.set_degrees(np.where(midpoints[:, 0] < 0, 2, 1).astype(np.int32))
cells = degrees.cells(2, include_ghosts=True)
V2_restricted, sub_to_parent = restrict_function_space(V2, cells)
PETSc.Sys.Print(
f"Parent space: {V2.dofmap.index_map.size_global} dofs,"
f" restricted space: {V2_restricted.dofmap.index_map.size_global} dofs"
)
Parent space: 1086 dofs, restricted space: 696 dofs
Interface integrals see both cells
A kernel of an interior facet integral is always tabulated for both cells of the facet,
even if the form only uses one restriction of \(V_i\). The assembler only treats a side as
missing from a space if its cell is mapped to -1 by an entity map. With a submesh, a cell
outside the submesh is mapped to -1, and the assembler skips its dofmap. A restricted space
lives on the parent mesh, so there is no entity map, and the assembler reads the dofmap of
both cells (DOLFINx assumes a dofmap has valid entries on every cell of its mesh).
On the interface between a cell of degree \(i\) and a cell of degree \(j\), the dofmap of the cell
outside \(\Omega_i\) therefore points to the degrees of freedom of a neighbour in \(\Omega_i\)
(valid local indices of \(V_i\)). The contributions to these are identically zero, as the
restriction of \(V_i\) to the outside cell never appears in the form. An outside cell with
several neighbours in \(\Omega_i\) points to one of them, which can add (zero) entries to the
sparsity pattern, coupling the neighbours. All other cells have the dofmap entries -1,
which the assembler never reads.
On each process, the owned cells of degree 1 next to a cell of degree 2 point to the degrees of freedom of their neighbour, the other cells of degree 1 have no degrees of freedom:
outside = np.flatnonzero(degrees.cell_degrees[: degrees.num_owned_cells] != 2)
rows = V2_restricted.dofmap.list[outside]
num_outside = mesh.comm.allreduce(len(outside), op=MPI.SUM)
num_neighbours = mesh.comm.allreduce(int(np.sum(rows[:, 0] >= 0)), op=MPI.SUM)
PETSc.Sys.Print(f"Cells of degree 1: {num_outside}, next to a cell of degree 2: {num_neighbours}")
Cells of degree 1: 65, next to a cell of degree 2: 9
The adaptive loop#
The forms of every block \((i, j)\) are compiled once. Every iteration restricts the parent spaces to the current degrees, and creates the forms with these spaces.
with Animation(mesh.comm, "restricted.gif") as animation:
history = solve_adaptive(approach, max_iterations=15, callback=animation)
it dofs error eta update solve estim. values, degrees
0 543 2.724e-02 3.591e+00 0.013 0.007 0.001 lambda=11.70518532, {1: 181}
1 618 1.301e-02 1.848e+00 0.014 0.007 0.001 lambda=11.54301805, {1: 156, 2: 25}
2 712 6.576e-03 1.079e+00 0.013 0.008 0.001 lambda=11.4696747, {1: 130, 2: 47, 3: 4}
3 894 2.044e-03 5.722e-01 0.014 0.010 0.001 lambda=11.41803881, {1: 80, 2: 89, 3: 12}
4 1051 8.217e-04 3.691e-01 0.013 0.011 0.001 lambda=11.40411079, {1: 55, 2: 96, 3: 28, 4: 2}
5 1170 5.039e-04 2.696e-01 0.013 0.012 0.001 lambda=11.40048878, {1: 40, 2: 95, 3: 42, 4: 4}
6 1280 2.549e-04 2.032e-01 0.013 0.013 0.001 lambda=11.3976522, {1: 24, 2: 101, 3: 50, 4: 4, 5: 2}
7 1420 1.108e-04 1.474e-01 0.013 0.015 0.001 lambda=11.39600952, {1: 8, 2: 103, 3: 62, 4: 4, 5: 2, 6: 2}
8 1460 9.590e-05 1.329e-01 0.013 0.016 0.001 lambda=11.39584005, {1: 6, 2: 100, 3: 67, 4: 4, 6: 4}
9 1747 2.551e-05 7.497e-02 0.013 0.019 0.001 lambda=11.39503798, {2: 40, 3: 132, 4: 5, 6: 4}
10 1912 2.039e-05 6.442e-02 0.014 0.022 0.001 lambda=11.39497967, {2: 19, 3: 138, 4: 19, 5: 1, 6: 4}
11 2214 1.854e-05 5.976e-02 0.014 0.027 0.001 lambda=11.3949585, {2: 1, 3: 116, 4: 54, 5: 6, 6: 4}
12 2509 1.809e-05 5.842e-02 0.014 0.031 0.001 lambda=11.39495339, {3: 70, 4: 94, 5: 11, 6: 6}
13 2777 1.799e-05 5.810e-02 0.013 0.037 0.001 lambda=11.39495223, {3: 30, 4: 125, 5: 18, 6: 8}
14 3141 1.796e-05 5.799e-02 0.013 0.047 0.001 lambda=11.3949519, {3: 10, 4: 108, 5: 49, 6: 14}
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.
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.
Joachim Nitsche. Über ein Variationsprinzip zur Lösung von Dirichlet-Problemen bei Verwendung von Teilräumen, die keinen Randbedingungen unterworfen sind. Abhandlungen aus dem Mathematischen Seminar der Universität Hamburg, 36(1):9–15, 1971. doi:10.1007/BF02995904.