Skip to content

Demos for goal-oriented adaptivity - #5445

Open
pbrubeck wants to merge 7 commits into
mainfrom
pbrubeck/goal-adaptive-callback-demos
Open

pbrubeck wants to merge 7 commits into
mainfrom
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
goal is the integral of the normal derivative through the top boundary.

  • Configure the adaptive loop through solver parameters
    (snes_grid_sequence, goal_atol/goal_rtol, goal_marking_fraction,
    goal_monitor).
  • Pass a GoalOrientedMarker to NonlinearVariationalSolver and supply an exact
    solution so that the monitor reports effectivity indices.
  • Read the estimate from marker.estimates and the solution on the final mesh
    from solver.solve().

The text explains how the marker estimates the discretisation and algebraic
errors separately and reports when the algebraic error dominates.

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

🤖 Generated with Claude Code. Branch cleanup
assisted by OpenAI Codex.

@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
pefarrell
pefarrell previously approved these changes Oct 5, 2026
@pbrubeck
pbrubeck removed this pull request from stack #5444 October 9, 2026 09:55
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback branch from aadab0b to f29280f Compare November 24, 2026 13:48
@pbrubeck
pbrubeck added this pull request to stack #5707 November 24, 2026 14:10
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback branch 3 times, most recently from b8a266d to 48e0dcc Compare November 25, 2026 10:33
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback-demos branch 3 times, most recently from 9d4ba17 to 36b47dd Compare November 25, 2026 18:38
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback branch 3 times, most recently from 7b7f5bc to bb9fab0 Compare November 25, 2026 22:35
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback-demos branch from b909ae9 to 62d5f65 Compare November 26, 2026 10:24
pbrubeck and others added 2 commits November 26, 2026 10:25
Add a GoalOrientedMarker that marks cells from a dual-weighted residual
estimate, and drive adaptive refinement with SNES grid sequencing. A
marking callback that returns None stops grid sequencing. solve() accepts
a marking_callback, and the adjoint solves drop it.

Add _SNESContext.solve_jacobian, which solves the dual problems with the
current Jacobian and its KSP. Replace check_snes_convergence with
check_convergence, which also checks a KSP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: OpenAI Codex
Use SNES grid sequencing and GoalOrientedMarker to refine the mesh for a boundary flux goal.
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback-demos branch from 62d5f65 to 8d759ba Compare November 26, 2026 10:25
@pbrubeck
pbrubeck removed this pull request from stack #5707 November 26, 2026 13:56
Base automatically changed from pbrubeck/goal-adaptive-callback to main November 26, 2026 13:56
pbrubeck and others added 3 commits November 27, 2026 17:33
Replace the initial guess interpolated from the exact solution with the
solution of a Poisson problem. Scale it by the minimiser of the energy along
it, then run the adaptive solve with the trust-region Newton method and the
energy as its objective. Derive the residual from the energy.

Use the net outward flux through the top boundary as the goal, plot the DWR
estimate against the true error, and plot the solution under the adapted mesh
right after the solve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The marker weighted the primal residual by the dual error alone. For a goal
at which the problem is stationary, such as the energy of a minimisation
problem, the dual solution is zero, so the estimate was zero and the
adaptation stopped on the first mesh.

Add the adjoint residual weighted by the primal error, and take the mean of
the two weighted residuals. The enriched primal solution gives the primal
error, so the estimate needs no further global solves. The remainder of the
estimate is cubic in the errors. The cell indicators localise both residuals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Put the adaptive solve and the plots in a helper that starts each goal from
the same initial mesh and initial guess. Plot the solution with the adapted
mesh next to the convergence of the estimate for each goal. Explain the
symmetrised estimate, and how it reduces for the energy goal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pbrubeck
pbrubeck force-pushed the pbrubeck/goal-adaptive-callback-demos branch from dea250a to 40bd921 Compare November 27, 2026 18:09
Assisted-by: OpenAI Codex

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 documentation 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