Skip to content

Fix essential BCs on wrapped imported DMPlex meshes#86

Merged
lmoresi merged 1 commit into
underworldcode:developmentfrom
gthyagi:codex/fix_stokes_essential_bc_imported_dmplex
Mar 20, 2026
Merged

Fix essential BCs on wrapped imported DMPlex meshes#86
lmoresi merged 1 commit into
underworldcode:developmentfrom
gthyagi:codex/fix_stokes_essential_bc_imported_dmplex

Conversation

@gthyagi

@gthyagi gthyagi commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix essential BC handling for wrapped imported PETSc.DMPlex meshes by rebuilding named boundary labels from generic imported Gmsh boundary sets.

This bug does not affect the usual:

mesh = uw.discretisation.Mesh(mesh_file, ...)

path, because _from_gmsh(...) already reconstructs named labels such as Bottom, Top, Left, and Right.

It does affect the lower-level path:

plex = PETSc.DMPlex().createFromFile(mesh_file, interpolate=True, comm=...)
mesh = uw.discretisation.Mesh(plex, ...)

where the wrapped mesh may only expose generic labels such as Face Sets / Cell Sets.

Problem

The Stokes essential BC path expects named boundary labels like Bottom to exist on the working DM. For wrapped imported DMPlex meshes, that assumption is false on clean development.

On exact upstream development, the reproducer prints:

raw labels: ['celltype', 'depth', 'Cell Sets', 'Face Sets']
has Bottom label? False
has UW_Boundaries? True
about to solve

and then dies in stokes.solve().

So the issue is specifically:

  • imported raw DMPlex retains generic Gmsh labels
  • named labels are not rebuilt during Mesh(plex, ...)
  • essential BCs added by boundary name cannot attach correctly

Fix

When uw.discretisation.Mesh(...) is constructed from an already-created PETSc.DMPlex, and named boundary labels are missing, unstack the imported generic boundary-set labels into named UW labels before UW_Boundaries is stacked.

In practice this means rebuilding labels such as:

  • Bottom
  • Top
  • Left
  • Right

from imported labels such as:

  • Face Sets
  • Edge Sets
  • Vertex Sets

This keeps the wrapped-DMPlex path consistent with the standard file-import path instead of changing solver-side boundary semantics.

Reproducer

Added:

  • examples/stokes_imported_box_essential_bc.py

It is self-contained:

  • builds a simple Gmsh box mesh with named physical groups
  • imports it through raw PETSc.DMPlex().createFromFile(...)
  • wraps that DMPlex with uw.discretisation.Mesh(plex, ...)
  • applies a nonzero Couette essential BC u = (y, 0) on all four sides
  • solves a trivial Stokes problem and reports the relative velocity L2 error

Results

Before this fix

Run the reproducer against clean development:

PYTHONPATH=/path/to/underworld3_essential_bc_baseline/src \
python -u examples/stokes_imported_box_essential_bc.py

Observed output:

raw labels: ['celltype', 'depth', 'Cell Sets', 'Face Sets']
has Bottom label? False
has UW_Boundaries? True
about to solve

The process then crashes in stokes.solve().

After this fix

Run the same script against this branch:

PYTHONPATH=/path/to/underworld3/src \
python -u examples/stokes_imported_box_essential_bc.py

Observed output:

raw labels: ['celltype', 'depth', 'Cell Sets', 'Face Sets']
has Bottom label? True
has UW_Boundaries? True
about to solve
relative velocity L2 error 4.538571271364606e-16

So the direct imported-DMPlex path now behaves correctly and matches the expected machine-precision solution for this simple imposed-velocity Stokes case.

Scope

This PR only changes the wrapped imported-DMPlex mesh path and adds the reproducer.

@gthyagi gthyagi requested a review from lmoresi as a code owner March 19, 2026 13:51
@lmoresi lmoresi merged commit bb26e2e into underworldcode:development Mar 20, 2026
1 check passed
lmoresi added a commit that referenced this pull request Mar 20, 2026
Convert PR #86 reproducer script into a proper pytest
(test_1012_stokesImportedDMPlex.py) and delete the root examples/
directory which contained only ad-hoc diagnostic scripts.

Underworld development team with AI support from Claude Code
@gthyagi gthyagi deleted the codex/fix_stokes_essential_bc_imported_dmplex branch April 8, 2026 01:47
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