Repository navigation
Fix AMR code by applying error estimator from Larson 2001 - #349
Merged
Merged
Conversation
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.
Fix the error indicator and parallel marking in the adaptive refinement demo
The adaptive mesh refinement demo (
$-\Delta u = 1$ , and the indicator was summed incorrectly in parallel. This PR fixes the residual,
chapter2/amr.py) solves the Laplaceeigenvalue problem, but
mark_cellsused the error indicator for the Poisson problemweights the facet term as in Larson (2000), and fixes the parallel marking, the formula in the text
and the termination check.
What was wrong
f + div(grad(uh_r))withf = 1;lamunusedlam_h * uh_r + div(grad(uh_r))dsbut noscatter_reverse(InsertMode.add)after assembly(lam - exact) / abs(exact) < 1e-5, which passes as soon aslam < exactabs(lam - exact) / abs(exact)uh_rin the GIFnp.sign(min), so round-off on the boundary could flip the frameThe residual bug comes from the upstream
ngsPETSc demo this
tutorial was ported from. There, the Poisson estimator from the ngsPETSc paper was kept when the
loop was changed to solve an eigenvalue problem. Refinement still concentrated at the re-entrant
corner, because the facet jumps dominate there, so the GIF looked right. Away from the corner, a
different set of cells was marked.
Changes
mark_cellsConstant, so theform isn't recompiled at every iteration.
h("±") / 2 * flux_jump**2againstw("±"), with a singleterm,
inner((flux_jump / 2) ** 2, 2 * avg(h * w)) * dS. Each cell now getssquared jump over each of its interior facets, as in Larson (2000), Equation 5.2.
assemble_vector, callseta_squared.x.scatter_reverse(dolfinx.la.InsertMode.add). WithGhostMode.shared_facet, each facet on a process boundary is integrated on one process only, sowithout this, owned cells next to the boundary lost the facet contributions from their
neighbours.
eta_maxis computed with anallreducethat also works on a processwith no cells.
W.dofmap.list, instead of assuming that dofibelongsto cell
i.ufl.conditionalthrough anExpression. This also removes the version check forinterpolation_points.Text
is half the jump of the normal derivative, integrated over
weighted by
inner((flux_jump / 2) ** 2, 2 * avg(h * w)) * dSinUFL. Each interior facet contributes to both of its cells, and
The note also says that Larson bounds the error by
reverse scatter.
references.bib, with a per-page{bibliography}block usingkeyprefix: amr-,following
chapter4/mixed_poisson.py.Loop and plotting
domain,
write_frametakes the sign of the eigenfunction from the value with the largest magnitude. Ituses
min(initial=...)andmax(initial=...)so that a process with no dofs doesn't raise.chapter2/amr.ipynbwas regenerated withjupytext --sync.Testing
NetGen is not available in the environment where this was developed, so the full demo was not run.
Instead, the final
mark_cellswas copied verbatim from the tutorial and tested on a P3 function onthe unit square, using a 12×12 mesh with
GhostMode.shared_facetfor the parallel tests.Parallel:
Facet term against Larson's definition, on a graded 9×7 mesh where neighbouring cells have$J = [\nabla u_h\cdot\mathbf n]$ is the jump of the normal derivative.
different diameters.
inner((flux_jump / 2) ** 2, 2 * avg(h * w)) * dSruff checkandruff format --checkpass.Not yet checked:
{bibliography}block. The Jupyter Book build in CIexecutes the demo in serial and renders the page.
amr.pywithmpirun, so the parallel fixes are onlycovered by the test above. A suggested check is
mpirun -n 2 python3 amr.py.amr.gifis generated by the book build. A different set of cells is now marked, so therefinement pattern in the GIF will change.
🤖 Generated with Claude Code