Skip to content

Feature/netgen periodic meshes#5217

Draft
UZerbinati wants to merge 4 commits into
mainfrom
feature/netgen-periodic-meshes
Draft

Feature/netgen periodic meshes#5217
UZerbinati wants to merge 4 commits into
mainfrom
feature/netgen-periodic-meshes

Conversation

@UZerbinati

@UZerbinati UZerbinati commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

ngsPETSc PR: NGSolve/ngsPETSc#124

Umberto Zerbinati and others added 2 commits June 25, 2026 14:16
When a Netgen mesh carries periodic identifications, ngsPETSc now produces
a vertex-merged (periodic) DMPlex. This finishes the job on the Firedrake
side: the Mesh() netgen branch detects periodicity, builds the intermediate
topology without reordering, and attaches a discontinuous DG1 coordinate
field (MeshGeometry._periodic_coordinates) carrying the un-wrapped geometry
via _postprocess_periodic_mesh, exactly as Firedrake's own periodic meshes.

Each Firedrake cell is matched to its Netgen element by geometry (hashing
the wrapped per-cell coordinates), which is robust to reordering. The DG
coordinate space uses the equispaced variant required by
_set_dg_coordinates. High-order curving of periodic meshes raises
NotImplementedError for now.

Adds regression tests for a periodic square (one and two directions), a
periodic cylinder, and the too-coarse error path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a "Periodic Meshes" section to the Netgen integration demo showing how
to declare OCC periodic identifications and import the resulting mesh into
Firedrake. The worked example is the periodic-cylinder ("screw pinch")
reduced model of a tokamak: a cylinder whose two circular ends are
identified, making the axial (toroidal) direction periodic. It labels the
lateral wall, checks the geometry survives the vertex merge (volume 2*pi^2),
and solves a manufactured Helmholtz problem with Dirichlet data on the wall
and periodicity on the ends, demonstrating seam continuity. Also documents
the too-coarse ValueError and the degree==1 limitation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread firedrake/mesh.py
Comment on lines +3488 to +3489
topology_reorder = False if netgen_periodic else reorder
topology = MeshTopology(plex, name=plex.getName(), reorder=topology_reorder,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
topology_reorder = False if netgen_periodic else reorder
topology = MeshTopology(plex, name=plex.getName(), reorder=topology_reorder,
reorder = False if netgen_periodic else reorder
topology = MeshTopology(plex, name=plex.getName(), reorder=reorder,

Comment thread firedrake/mesh.py
Comment on lines +3058 to +3059
@PETSc.Log.EventDecorator()
def _periodic_coordinates(self, permutation_tol=1e-8):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move this to netgen.py

Comment thread firedrake/mesh.py
# is finished off with a discontinuous coordinate field below. That field
# is built on the un-reordered topology (as for Firedrake's own periodic
# meshes), so suppress reordering here and reapply it in postprocessing.
netgen_periodic = len(netgen_firedrake_mesh.meshMap.ngMesh.GetIdentifications()) > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do as the comment says and supress reordering here. Remove the comment, we don't like AI slop

Comment thread firedrake/mesh.py
# discontinuous coordinate field carrying the un-wrapped geometry.
if degree != 1:
raise NotImplementedError(
"High-order curving of periodic netgen meshes is not supported yet."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Support this, I support you

Comment thread firedrake/mesh.py
Comment on lines +3510 to +3522
from firedrake.utility_meshes import _postprocess_periodic_mesh
permutation_tol = netgen_flags.get("permutation_tol", 1e-8)
coordinates = mesh._periodic_coordinates(permutation_tol=permutation_tol)
temp = _postprocess_periodic_mesh(coordinates,
mesh.comm,
distribution_parameters,
reorder,
name,
kwargs.get("distribution_name"),
kwargs.get("permutation_name"))
temp.netgen_mesh = mesh.netgen_mesh
temp.netgen_flags = mesh.netgen_flags
mesh = temp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

create a helper function in netgen.py doing everything here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants