hp-adaptivity#

Author: Jørgen S. Dokken

SPDX-License-Identifier: MIT

The previous demos only change the polynomial degree, on a mesh that is graded towards the re-entrant corner of the PacMan domain. Near a singularity, increasing the degree is not efficient: the error converges algebraically in the number of degrees of freedom, also for high degrees. Splitting the cells (h-refinement) is better at a singularity, and increasing the degree (p-refinement) where the solution is smooth. Combining the two, hp-adaptivity converges exponentially [HSuli05].

We solve the Laplace eigenvalue problem of the submesh demo on a quasi-uniform mesh, without grading towards the corner, and with third order geometry, with

  • p-refinement: the degree of the marked cells is increased;

  • h-refinement: the marked cells are split, and keep their degree;

  • hp-refinement: the degree of a marked cell is increased if the solution is smooth on the cell, and the cell is split otherwise.

Refinement of a curved mesh#

The cells are split with the algorithm of [PC00] (dolfinx.mesh.refine()), which also gives the parent cell of each new cell. It only supports straight cells, while our mesh has second order geometry. The mesh is therefore refined in four steps (dolfinx_padapt.refinement.refine_curved()):

  1. The straight mesh with the same topology is created with dolfinx.fem.interpolate_geometry().

  2. The straight mesh is refined.

  3. The refined mesh gets second order geometry with straight cells, again with dolfinx.fem.interpolate_geometry().

  4. The coordinates of the original mesh are a vector valued function in its coordinate space (quadratic Lagrange), which is defined on the straight mesh as well (the meshes have the same topology and dofmap). It is interpolated into the coordinate space of the refined mesh, and its values are the new node coordinates.

The interpolation in the last step evaluates the function at points in the cells of another mesh. Usually, the cell containing each point, and the process owning it, are found by a search with bounding box trees. Here, every point is in the parent cell of the cell it belongs to, on the same process, so we create the dolfinx.geometry.PointOwnershipData directly from the parent cells (dolfinx_padapt.refinement.interpolate_from_parent()). This is exact for discontinuous functions as well, as a point on a facet of a parent cell is evaluated in the parent of its own cell. The refined cells are nested in the curved cells of the original mesh.

The refined cells are nested in the curved cells of the original mesh, so the boundary of the refined mesh is the boundary of the original mesh, which is an approximation of the unit circle. For high degrees, the error of this approximation would dominate, so the new nodes on the boundary are moved to the unit circle (dolfinx_padapt.mesh.pacman_boundary_projection()). The cells that are only enriched keep the geometry of the original mesh, so we use third order geometry.

The new cells get the degree of their parent cell. The forms are compiled once, for the original mesh, and are created on each refined mesh.

Smoothness indicator#

On a cell \(K\) of degree \(p_K\), the solution is expanded in the orthonormal (Legendre) polynomials \(P_j\) of the reference cell, \(u_h\vert_K = \sum_j a_j P_j\). The energy of the modes of degree \(k\),

\[ E_k = \Bigl(\sum_{\deg P_j = k}\vert a_j\vert^2\Bigr)^{1/2}, \]

decays exponentially, \(E_k\approx C e^{-\sigma_K k}\), if the solution is smooth, and slowly near a singularity [HSuli05, Mav94]. The decay rate \(\sigma_K\) is the least squares fit of \(\log E_k\) for \(k=1,\dots,p_K\) (dolfinx_padapt.smoothness.decay_factor()). A marked cell is enriched if \(e^{-\sigma_K}\) is below a threshold (0.2 by default), and split otherwise, or if it is at the maximal degree. A cell of degree one has a single mode, and is always enriched first.

The adaptive loops#

We start every run from the same quasi-uniform mesh. For h-refinement, the degree is fixed to two.

histories = {}
for refinement in (Refinement.p, Refinement.h, Refinement.hp):
    PETSc.Sys.Print(f"{refinement.value}-refinement")
    mesh = create_pacman(MPI.COMM_WORLD, h=0.3, order=3)
    run_params = Parameters(pmin=2, pmax=2) if refinement == Refinement.h else params
    approach = SubmeshApproach(EigenvalueProblem(mesh), run_params)
    kwargs = dict(
        max_iterations=16,
        refinement=refinement,
        boundary_projection=pacman_boundary_projection,
    )
    if refinement == Refinement.hp:
        with Animation(mesh.comm, "hp.gif") as animation:
            history = solve_adaptive(approach, callback=animation, **kwargs)
    else:
        history = solve_adaptive(approach, **kwargs)
    histories[f"{refinement.value}-refinement"] = history
p-refinement
h-refinement
hp-refinement
 it     dofs      error        eta  update   solve  estim.  values, degrees
  0      261  3.341e-02  4.006e+00   0.015   0.005   0.001  lambda=11.77547015, {1: 87}
  1      330  1.656e-02  2.301e+00   0.016   0.005   0.001  lambda=11.58348591, {1: 64, 2: 23}
  2      385  1.121e-02  1.676e+00   0.016   0.006   0.001  lambda=11.52248892, {1: 51, 2: 32, 3: 4}
  3      559  7.912e-03  1.351e+00   0.016   0.007   0.001  lambda=11.4849036, {1: 44, 2: 47, 3: 4, 4: 7}
  4      940  2.171e-03  6.833e-01   0.016   0.011   0.001  lambda=11.41948984, {1: 15, 2: 80, 3: 10, 4: 21}
  5     1193  7.544e-04  4.607e-01   0.016   0.013   0.001  lambda=11.40334353, {1: 2, 2: 92, 3: 11, 4: 35}
  6     1944  2.951e-04  3.098e-01   0.017   0.021   0.001  lambda=11.39811037, {2: 104, 3: 30, 4: 68}
  7     2566  1.557e-04  2.215e-01   0.016   0.028   0.001  lambda=11.39652128, {2: 86, 3: 46, 4: 106}
  8     3633  3.135e-05  1.002e-01   0.016   0.038   0.002  lambda=11.39510447, {2: 93, 3: 99, 4: 139}
  9     4356  8.778e-06  6.105e-02   0.017   0.047   0.002  lambda=11.3948473, {2: 96, 3: 117, 4: 174}
 10     4904  5.512e-06  4.872e-02   0.017   0.053   0.002  lambda=11.39481009, {2: 99, 3: 122, 4: 206}
 11     5909  2.259e-06  3.478e-02   0.017   0.068   0.002  lambda=11.39477302, {2: 84, 3: 140, 4: 267}
 12     6678  4.920e-07  2.556e-02   0.018   0.075   0.002  lambda=11.39475289, {2: 82, 3: 162, 4: 303, 5: 1}
 13     7783  8.608e-07  1.644e-02   0.018   0.090   0.003  lambda=11.39473747, {2: 101, 3: 190, 4: 349, 5: 2}
 14     8528  1.371e-06  1.101e-02   0.017   0.096   0.003  lambda=11.39473166, {2: 91, 3: 178, 4: 406, 5: 4, 6: 1}
 15     9464  1.640e-06  6.716e-03   0.018   0.114   0.003  lambda=11.39472859, {2: 96, 3: 157, 4: 465, 5: 15, 6: 1}
gif

The cells at the corner are split, and the degree is increased away from it.

Convergence#

if MPI.COMM_WORLD.rank == 0:
    plot_convergence(
        histories,
        "hp_convergence.png",
        ylabel=r"$\vert\lambda_h - \lambda\vert/\lambda$",
    )
../_images/c74b338f50d13fbbf852e86185c53a0a8cbe6c98dd9c854bf0457aafdfa348d7.png

convergence

With p-refinement, the error stagnates once the cells at the corner have the maximal degree. h-refinement converges algebraically. hp-refinement is slower at first: the corner cells are enriched up to degree three or four before the decay of their Legendre coefficients shows that the solution is not smooth there. Once they are split, the error decreases much faster than with h-refinement, and hp-refinement reaches an error below \(10^{-6}\) with a fraction of the degrees of freedom. The error then increases slightly. The discrete eigenvalue is not a one-sided bound with SIPG, and the cells that are never split keep the third order geometry of the initial mesh, whose error is of this size.

[HSuli05] (1,2)

Paul Houston and Endre Süli. A note on the design of hp-adaptive finite element methods for elliptic partial differential equations. Computer Methods in Applied Mechanics and Engineering, 194(2–5):229–243, 2005. doi:10.1016/j.cma.2004.04.009.

[Mav94]

Catherine Mavriplis. Adaptive mesh strategies for the spectral element method. Computer Methods in Applied Mechanics and Engineering, 116(1–4):77–86, 1994. doi:10.1016/S0045-7825(94)80010-3.

[PC00]

A. Plaza and G. F. Carey. Local refinement of simplicial grids based on the skeleton. Applied Numerical Mathematics, 32(2):195–218, 2000. doi:10.1016/S0168-9274(99)00022-7.