Fix Darcy Cartesian example script run#273
Merged
lmoresi merged 2 commits intoJun 24, 2026
Merged
Conversation
The example called mesh._deform_mesh(new_coords=...), which the coord-mutation capability gate (underworldcode#246) now rejects once the mesh carries variables (the internal primitive moves nodes without transferring fields). Switched to the public mesh.deform(new_coords) API, which performs the sanctioned field-carrying deform. Verified the example runs end-to-end. Underworld development team with AI support from Claude Code
lmoresi
approved these changes
Jun 24, 2026
lmoresi
left a comment
Member
There was a problem hiding this comment.
Verified — but it was still failing as submitted: it called the internal mesh._deform_mesh(), which the coord-mutation gate (#246) rejects once variables exist. I pushed a one-line fix to use the public mesh.deform(new_coords) API (the sanctioned field-carrying deform); now runs end-to-end (exit 0). Thanks @ss2098 — merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This updates docs/examples/porous_flow/intermediate/Ex_Darcy_Cartesian.py so that the migrated Darcy Cartesian example runs cleanly as a plain Python script.
While running the example with:
pixi run python docs/examples/porous_flow/intermediate/Ex_Darcy_Cartesian.py
the script first failed during mesh deformation because uw.function.evaluate(...) returned an array with extra singleton dimensions:
ValueError: could not broadcast input array from shape (1981,1,1) into shape (1981,)
This update flattens the evaluated coordinate array with np.asarray(...).reshape(-1) before assigning it into new_coords[:, 1].
The example also called PyVista/trame visualization from a terminal run, which produced notebook-backend warnings and eventually caused a segmentation fault. The visualization blocks are now guarded so they only execute inside a real Jupyter notebook. This keeps the script-safe solve and metrics path independent of optional visualization backends.
Finally, the previous max-pressure extraction relied on p_soln.stats() tuple-style unpacking/indexing, but the current return object is not stable for that use. The example now computes the maximum pressure directly from p_soln.data under mesh access, with an MPI allreduce for parallel safety.
The Darcy setup, mesh deformation expression, permeability law, boundary conditions, solve, and reported metric are otherwise unchanged.
Tested with:
pixi run python docs/examples/porous_flow/intermediate/Ex_Darcy_Cartesian.py
Result:
Max pressure: 1.168890