Skip to content

Support -snes_adapt#5213

Draft
pbrubeck wants to merge 3 commits into
mainfrom
pbrubeck/snes-adapt
Draft

Support -snes_adapt#5213
pbrubeck wants to merge 3 commits into
mainfrom
pbrubeck/snes-adapt

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

Codex-assisted.

Implements UFL-level refinement of a variational problem and PETSc-level refinement of the SNES solver. In this way, users will not require to write the adaptivity loop themselves.

Depends on https://gitlab.com/petsc/petsc/-/merge_requests/9407

Comment thread firedrake/variational_solver.py Outdated
Comment thread firedrake/variational_solver.py Outdated
Comment thread firedrake/variational_solver.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment on lines +584 to +585
if getattr(ctx, "_adapt_marking_callback", None) is not None:
return _adaptively_refine(dm, comm)

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.

This is an antipattern

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.

Add a flag or initialize this to None. Might be better to stash the reult in ctx._fine

Comment thread tests/firedrake/multigrid/test_snes_adapt.py Outdated
Comment thread firedrake/variational_solver.py
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
Comment thread firedrake/dmhooks.py Outdated
@pbrubeck pbrubeck force-pushed the pbrubeck/snes-adapt branch 2 times, most recently from b27150b to 4932ac2 Compare July 2, 2026 15:50
Comment thread firedrake/dmhooks.py
if level == len(hierarchy) - 1:
markers = callback(solver, current_solution)
_validate_refinement_markers(markers, mesh)
hierarchy.add_mesh(mesh.refine_marked_elements(markers))

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.

We should add support for non-netgen meshes. This needs to go through the DMPlex / DMLabel codepath

@pbrubeck pbrubeck force-pushed the pbrubeck/snes-adapt branch 2 times, most recently from 9bab35e to 8e73057 Compare July 2, 2026 17:27
@pbrubeck pbrubeck force-pushed the pbrubeck/snes-adapt branch 3 times, most recently from 230017a to f817644 Compare July 3, 2026 11:15
@pbrubeck pbrubeck force-pushed the pbrubeck/snes-adapt branch 2 times, most recently from 1c7406a to 5ff2783 Compare July 3, 2026 14:21
Comment thread tests/firedrake/multigrid/test_snes_adapt.py Outdated
Comment thread firedrake/variational_solver.py Outdated
Comment thread firedrake/variational_solver.py
Comment thread firedrake/variational_solver.py
self._ctx = ctx
self._work = problem.u_restrict.dof_dset.layout_vec.duplicate()
self.snes.setDM(problem.dm)
self._marking_callback = None

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.

Suggested change
self._marking_callback = None

self._marking_callback = None
if marking_callback is not None:
self.set_marking_callback(marking_callback)
ctx._adapt_marking_callback = self._marking_callback

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.

Suggested change
ctx._adapt_marking_callback = self._marking_callback

"""
if not callable(callback):
raise TypeError(f"marking callback must be callable, not a {type(callback).__name__}")
self.parameters.setdefault("adaptor_criterion", "refine")

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.

This default should live somewhere else

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.

1 participant