Skip to content

High-order coordinates via interpolated DMPlex (netgen-only) - #5277

Open
pbrubeck wants to merge 2 commits into
mainfrom
pbrubeck/netgen-plex
Open

High-order coordinates via interpolated DMPlex (netgen-only)#5277
pbrubeck wants to merge 2 commits into
mainfrom
pbrubeck/netgen-plex

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Description

AI-assisted (Claude Code)

This PR replaces the Python-level Netgen cell-numbering nightmare (find_permutation, netgen_distribute, sfBC_orig, and the dynamic netgen_mesh/netgen_flags mesh attributes) with the PETSc-native approach outlined below.

What changed

  • PETSc now owns the high-order coordinate PetscFE, Section, and Vec for Netgen meshes;
    coordinates are read/written through oriented DMPlex closures in compiled Cython
    (dmcommon.set_cell_coordinates, dmcommon.reordered_coords_high_order), replacing the old
    point-matching/permutation search (find_permutation, netgen_distribute).
  • firedrake/netgen.py is rewritten around a single NetgenGeometry class (replacing
    FiredrakeMesh) that owns the Netgen mesh, the DMPlex it produced, and the operations that
    need the geometry: curve_field, snap (project a refined DMPlex's vertices back onto the
    geometry), and recurve (re-evaluate coordinates at a new degree on a refined mesh).
  • MeshGeometry gains a single _geometry_source attribute (declared in __init__) replacing
    the ad hoc netgen_mesh/netgen_flags/sfBC_orig attributes that were bolted on after
    construction; curve_field and the adaptive-refinement/MeshHierarchy code paths go through
    this attribute uniformly instead of hasattr checks.
  • firedrake/mg/netgen.py (NetgenHierarchy and friends) is deleted; MeshHierarchy builds
    Netgen hierarchies itself via _geometry_source, so there is one hierarchy-construction code
    path instead of two.
  • Netgen mesh construction can run rank-0-only; the geometry is replicated to other ranks lazily
    (NetgenGeometry._local_mesh), only when a distributed refinement needs to snap/recurve
    locally.
  • Adaptive refinement (firedrake/adapt.py) and geometric multigrid (firedrake/mg/mesh.py)
    both preserve high-order Netgen geometry, in serial and under MPI.

Depends on NGSolve/ngsPETSc#125 (the .github/actions/install/action.yml
pin to a branch is marked DROP BEFORE MERGE and will be reverted once that PR merges).

The extension to more generic high-order coordinates support via PetscFE is outlined in
#5278.

Comment thread firedrake/mg/mesh.py Outdated
Comment thread tests/firedrake/regression/test_netgen.py Outdated
Comment thread tests/firedrake/multigrid/test_adaptive_multigrid.py Outdated
Comment thread firedrake/netgen.py
Comment on lines +185 to +189
import finat.ufl
from firedrake.function import CoordinatelessFunction
from firedrake.functionspace import FunctionSpace
from firedrake.cython import dmcommon
from firedrake.mesh import make_mesh_from_coordinates

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to the top

Base automatically changed from pbrubeck/mg-redist to main July 31, 2026 10:37
pbrubeck added 2 commits July 31, 2026 14:24
Cython routines to set cellwise coordinate closures and to read back
high-order DMPlex coordinates in Firedrake node ordering, used to
build curved Netgen meshes without going through curve_field's
FIAT-based permutation search.
Rework Netgen mesh construction (NetgenGeometry) and curved coordinate
handling to go through the standard high-order coordinate DM path
instead of a bespoke curve_field/redistribution scheme, so Netgen
meshes compose with MeshHierarchy/AdaptiveMeshHierarchy like any other
mesh. Drops the now-unused firedrake/mg/netgen.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base:main Run this PR using a main (dev) build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant