Skip to content

Fix Darcy Cartesian example script run#273

Merged
lmoresi merged 2 commits into
underworldcode:developmentfrom
ss2098:ss2098/fix-darcy-cartesian-script-run
Jun 24, 2026
Merged

Fix Darcy Cartesian example script run#273
lmoresi merged 2 commits into
underworldcode:developmentfrom
ss2098:ss2098/fix-darcy-cartesian-script-run

Conversation

@ss2098

@ss2098 ss2098 commented Jun 22, 2026

Copy link
Copy Markdown

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

@ss2098 ss2098 requested a review from lmoresi as a code owner June 22, 2026 21:39
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 lmoresi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@lmoresi lmoresi merged commit a15d6bc into underworldcode:development Jun 24, 2026
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