Skip to content

Add a label for each named Netgen region to the DMPlex - #134

Open
pbrubeck wants to merge 4 commits into
mainfrom
pbrubeck/feature/region-labels
Open

pbrubeck wants to merge 4 commits into
mainfrom
pbrubeck/feature/region-labels

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

createPETScDMPlex now also marks each entity in a label named after its Netgen region, with the region number as the label value. This is the same layout that the PETSc Gmsh reader creates with -dm_plex_gmsh_use_regions -dm_plex_gmsh_use_generic.

 for codim in range(tdim):
+    names = ngMesh.GetRegionNames(dim=tdim - codim)
-    if codim == 0 and all cells are in region 1:
+    if codim == 0 and all cells are in region 1 and no region has a name:
         continue
     for each entity e of codimension codim:
         plex.setLabelValue("Face Sets", point, e.index)      # or Cell Sets / Edge Sets
+        if names[e.index - 1]:
+            plex.setLabelValue(names[e.index - 1], point, e.index)

Code that reads only the DMPlex can then find the region names without the Netgen mesh. For example, Firedrake can treat Netgen meshes in the same way as Gmsh meshes (firedrakeproject/firedrake#5199). The labels are distributed and checkpointed with the DMPlex.

A mesh whose cells all belong to one named region now gets a Cell Sets label. Before, it had no cell label, so the cells of that region could not be found from the DMPlex. In Firedrake, dx(1) on such a mesh integrated over nothing.

Evidence

  • Before: test_netgen_plex_has_region_name_labels fails, because the DMPlex has no left or right label.
    After: it passes. For each named edge of a rectangle, the label holds only that region number, and its points are the Face Sets points with that number. The test runs with geometric dimension 2 and 3, so it also covers surface meshes.
  • Before: test_netgen_plex_labels_cells_of_one_named_region fails, because the DMPlex has no Cell Sets label.
    After: it passes. Cell Sets and the fluid label both hold every cell with value 1.

tests/test_plex.py passes at 1 and 2 ranks, and make lint lint_test scores 10/10.

Merge Danger

Door: two-way

Blast Radius: small

The change adds labels and changes no existing label value. Each named label holds the same points as the matching Face Sets, Cell Sets or Edge Sets stratum, so it adds the cost of distributing that data a second time. OCC meshes in 2D name their cells default when no name is given, so these meshes now also get Cell Sets and default labels on every cell. A region name that is the same as an existing label name, for example celltype, would add values to that label.

AI tool used: Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

@pbrubeck pbrubeck added the enhancement New feature or request label Nov 27, 2026
Mark each entity in a label named after its Netgen region, with the
region number as value, in the same way as the PETSc Gmsh reader with
-dm_plex_gmsh_use_regions. Codes that read the DMPlex can then find the
region names without the Netgen mesh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pbrubeck
pbrubeck force-pushed the pbrubeck/feature/region-labels branch from 6c65291 to 4826742 Compare November 27, 2026 17:09
pbrubeck added a commit to firedrakeproject/firedrake that referenced this pull request Nov 27, 2026
Drop this commit once NGSolve/ngsPETSc#134 merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cells had no Cell Sets label when they all belonged to region 1, so
codes that read the DMPlex could not find the cells of a named region.
Skip the cell labels only if that region has no name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Netgen can leave boundary region names empty. Restore the default name on the input mesh so callers can still select those regions after conversion.

Reproduces and resolves the multicomponent demo failure in firedrakeproject/firedrake#5740.

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant