Skip to content

Demos for goal-oriented adaptivity - #5445

Open
pbrubeck wants to merge 10 commits into
pbrubeck/goal-adaptive-callbackfrom
pbrubeck/goal-adaptive-callback-demos
Open

pbrubeck wants to merge 10 commits into
pbrubeck/goal-adaptive-callbackfrom
pbrubeck/goal-adaptive-callback-demos

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a demo of goal-oriented mesh adaptivity with the dual-weighted residual
(DWR) method, using the marking callback and the adaptive
solve-estimate-mark-refine cycle from #5273. This PR is stacked on #5273 and
targets pbrubeck/goal-adaptive-callback.

demos/goal_oriented_nonlinear_p_laplacian

The demo solves a strongly nonlinear p-Laplacian (p = 5) on the unit square,
with a manufactured solution, and adapts the mesh for a goal functional: the
normal flux through the top boundary. The demo shows how to:

  • configure the adaptive loop entirely through solver parameters
    (snes_adapt_sequence, dwr_atol/dwr_rtol, dwr_marking_fraction,
    dwr_monitor), with no user-written loop;
  • pass a DWRMarkingCallback to NonlinearVariationalSolver, and an exact
    solution so that the monitor reports effectivity indices;
  • read the estimate from solver.get_marking_callback() and the solution on
    the final mesh from solver.solve().

The text explains that the estimate separates discretisation error from
algebraic error, which permits a coarse nonlinear solver tolerance. It also
explains the warning that is printed when the algebraic error dominates.

The demo is listed in the advanced tutorials and in
tests/firedrake/demos/test_demos_run.py. The references it cites are added to
demos/demo_references.bib.

Mixed-space test

test_dwr_marking_callback_mixed_space in
tests/firedrake/multigrid/test_snes_adapt.py runs the DWR callback on a
mixed RT1 x DG0 Poisson problem in serial and on two ranks. Before this PR,
every DWR test used a scalar space.

🤖 Generated with Claude Code

@pbrubeck pbrubeck added LLM used An LLM was used in the production of this PR base:main Run this PR using a main (dev) build labels Sep 10, 2026
@pbrubeck
pbrubeck added this pull request to stack #5444 September 10, 2026 19:21
pbrubeck and others added 4 commits October 2, 2026 16:35
Since #5414 the demo tests extract only ``.. code-block:: python``
blocks, so these demos ran no code. The goal functional and the error
estimate now come from the callback that get_marking_callback returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

We solve it on the unit square with a known analytical solution, so that we can
compute effectivity indices for our error estimates. Adaptive refinement needs
no special mesh: any Firedrake mesh can be refined in place:

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.

Weird to have two colons in one sentence

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reworded

"dwr_monitor": None,
})

There is no loop to write here, unlike in the ad hoc implementations such a

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.

This feels like a comment put there to contrast with how the code looked before, but of course that code is not visible to the reader. Maybe say 'The adaptive loop is handled inside the solver.'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

method usually needs. The solver runs the configured
SOLVE--ESTIMATE--MARK--REFINE cycle, and the marking callback supplies the
cells to refine. We also pass the exact solution, which lets the monitor
report the true error and an effectivity index. That is a diagnostic, and is

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.

Maybe 'Of course, this is not needed in general.'

Comment thread demos/goal_oriented_linear_elasticity/goal_oriented_linear_elasticity.py.rst Outdated
pbrubeck and others added 3 commits October 5, 2026 15:38
The elasticity demo exercised the same machinery as the p-Laplacian demo.
A mixed RT x DG Poisson test in test_snes_adapt.py keeps the mixed-space
coverage. Also clarify the p-Laplacian demo prose: what solve() returns,
and that the adaptive loop runs inside the solver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pefarrell
pefarrell previously approved these changes Oct 5, 2026
pbrubeck and others added 2 commits October 6, 2026 17:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

base:main Run this PR using a main (dev) build LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants