Skip to content

docs: SNESFAS / Vanka / grid-sequencing investigation (notes + working prototypes)#245

Open
lmoresi wants to merge 1 commit into
developmentfrom
docs/snesfas-investigation
Open

docs: SNESFAS / Vanka / grid-sequencing investigation (notes + working prototypes)#245
lmoresi wants to merge 1 commit into
developmentfrom
docs/snesfas-investigation

Conversation

@lmoresi

@lmoresi lmoresi commented Jun 16, 2026

Copy link
Copy Markdown
Member

Preserves the parked multilevel-nonlinear-Stokes solver investigation as documentation, so the substantial trial-and-error analysis and — importantly — the working implementations are not lost. Docs and example scripts only; no src/ or tests/ changes. Everything runs through petsc_options + petsc4py on stock UW3.

Design notes (docs/developer/design/)

  • snesfas-feasibility.md — SNESFAS works in UW3 via options alone; mesh-independent on scalar nonlinear problems; adaptation benign.
  • snesfas-vanka-feasibility-study.md — the Vanka deep-dive: custom-IS pressure-support patches work on simplex P2–P1 where stock PCPATCH fails; mesh-independent Vanka multigrid (5/5/6 outer iterations across 16× DOFs); FAS-Vanka gives 2 nonlinear iterations vs 10 on viscoplastic but fails at extreme contrast; three-way FMG/GAMG/FAS-Vanka comparison.
  • multilevel-nonlinear-stokes-strategy.md — capstone + the decision to park (small win in the current 2-D regime, high engineering load, codebase cleanup first), with the conditions to return (3-D / large-parallel / a real FMG-failing benchmark) and the cheapest re-entry point (a Tier-1 grid_sequence helper).

Working prototypes (docs/examples/snesfas_investigation/)

Precedent: docs/examples/submesh_investigation/. Curated, self-contained, byte-compile clean, with a README documenting each script, the key recipes, and known limits.

  • vanka_asm.py — the core custom-IS Vanka recipe (pressure-support patches).
  • vanka_mg.py — mesh-independent Vanka geometric multigrid.
  • fas_vanka.pyworking SNESFAS-Vanka for nonlinear Stokes at modest contrast (the 2-vs-10 plasticity case).
  • benchmark_3way.py — FMG vs GAMG vs FAS-Vanka.
  • notched_beam_cascade.py — grid-sequencing / nested-iteration prototype.

These are research prototypes — not tested, not tier-classified. Reported wall-clock numbers are soft (JIT / machine noise); the iteration counts are the reliable comparator.

Underworld development team with AI support from Claude Code

…on (design notes + working prototypes)

Lands the parked multilevel-nonlinear-Stokes investigation as documentation so the
significant trial-and-error and the WORKING implementations are not lost. No src/ or
test changes — everything runs through petsc_options + petsc4py on stock UW3.

Design notes (docs/developer/design/):
 - snesfas-feasibility.md: SNESFAS via options; mesh-independent on scalar nonlinear;
   adaptation benign.
 - snesfas-vanka-feasibility-study.md: the Vanka deep-dive; custom-IS pressure-support
   patches work where stock PCPATCH fails; mesh-independent Vanka-MG (5/5/6); FAS-Vanka
   2-vs-10 on plasticity but fails at extreme contrast; 3-way FMG/GAMG/FAS-Vanka.
 - multilevel-nonlinear-stokes-strategy.md: capstone + decision to park (small 2D win,
   high engineering load, cleanup first) with return-conditions (3D/parallel/real
   FMG-failing benchmark) and the cheapest re-entry (Tier-1 grid_sequence helper).

Working prototypes (docs/examples/snesfas_investigation/, precedent: submesh_investigation/):
 vanka_asm.py (core custom-IS Vanka recipe), vanka_mg.py (mesh-independent Vanka MG),
 fas_vanka.py (working SNESFAS-Vanka for nonlinear, modest contrast — the 2-vs-10 case),
 benchmark_3way.py (FMG/GAMG/FAS-Vanka), notched_beam_cascade.py (grid sequencing).
 Cross-imports made self-contained; all byte-compile. README documents each + the
 recipes + known limits.

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings June 16, 2026 04:12

Copilot AI left a comment

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.

Pull request overview

Adds a preserved set of research notes and runnable example prototypes documenting an investigation into SNESFAS, custom-IS Vanka smoothers, and grid sequencing for multilevel nonlinear Stokes in Underworld3—explicitly as docs/examples only (no src/ or tests/ changes).

Changes:

  • Adds multiple petsc4py-based prototype scripts demonstrating custom-IS PCASM Vanka (standalone, MG, and FAS injection) plus a grid-sequencing cascade example.
  • Adds a README that indexes the scripts and captures the key “recipes” and known limits.
  • Adds developer design notes summarizing feasibility, results, and a decision to park further engineering work for now.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
docs/examples/snesfas_investigation/vanka_mg.py Prototype of full-saddle geometric MG using custom-IS Vanka as a level smoother; compares vs FMG.
docs/examples/snesfas_investigation/vanka_asm.py Minimal standalone custom-IS PCASM Vanka construction and convergence measurement on the assembled saddle Jacobian.
docs/examples/snesfas_investigation/fas_vanka.py Prototype injecting custom-IS Vanka into SNESFAS level smoothers (nonlinear multigrid).
docs/examples/snesfas_investigation/benchmark_3way.py Benchmark driver comparing FMG vs GAMG vs FAS-Vanka on linear contrast + nonlinear yield cases.
docs/examples/snesfas_investigation/notched_beam_cascade.py Prototype nested-iteration/grid-sequencing cascade to warm-start nonlinear solves across resolutions.
docs/examples/snesfas_investigation/README.md Index + usage guidance + key recipes/limits for the preserved prototypes.
docs/developer/design/snesfas-feasibility.md Design note establishing SNESFAS feasibility (scalar + Stokes) via options-only setup and documenting results.
docs/developer/design/snesfas-vanka-feasibility-study.md Design note deep-diving Vanka feasibility and documenting the working custom-IS approach and results.
docs/developer/design/multilevel-nonlinear-stokes-strategy.md Strategy/decision note: landscape summary, findings, and rationale for parking further work.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +23
"""
import os
FAS-Vanka: nonlinear multigrid (SNESFAS) with the custom-IS PCASM Vanka smoother.

Turnkey-via-options is not available (PCPATCH won't build pressure-support patches
in this build), so we inject the custom index sets into each FAS level smoother:
1. solve once with an LU smoother (assembles every level operator),
2. for each level smoother SNES: build pressure-support patches from its operator,
install PCASM(RESTRICT)+sub-LU wrapped in a GMRES Krylov smoother,
3. re-solve, driving the SNES directly.

The patch *structure* depends only on sparsity, so it stays valid as the operator
values change across nonlinear iterations.
"""
import time
import importlib.util
import numpy as np
import sympy
import underworld3 as uw
from petsc4py import PETSc

_spec = importlib.util.spec_from_file_location("va", os.path.join(os.path.dirname(os.path.abspath(__file__)), "vanka_mg.py"))
va = importlib.util.module_from_spec(_spec); _spec.loader.exec_module(va)
Comment on lines +1 to +26
"""
import os
Three good choices: FMG vs GAMG vs FAS-Vanka on hard Stokes benchmarks.

FMG : Newton + fieldsplit-Schur + velocity-block geometric MG (preconditioner="fmg")
GAMG : Newton + fieldsplit-Schur + velocity-block algebraic MG (preconditioner="gamg")
FAS-Vanka : nonlinear multigrid on the full saddle, custom-IS PCASM Vanka smoother

(1) SolCx viscosity step, eta_B = 1 .. 1e6 (linear, discontinuous viscosity)
(2) Viscoplastic yield, tau_y = 10 .. 0.25 (strong nonlinearity)

Open top (no pressure nullspace). refinement=2 => 3-level hierarchy. The point is
robustness with stock settings — no per-problem tuning.

Run: pixi run -e amr-dev python benchmark_3way.py
"""
import time
import importlib.util
import numpy as np
import sympy
import underworld3 as uw
from underworld3.function import analytic as A

fv = importlib.util.module_from_spec(
importlib.util.spec_from_file_location("fv", os.path.join(os.path.dirname(os.path.abspath(__file__)), "fas_vanka.py")))
importlib.util.spec_from_file_location("fv", os.path.join(os.path.dirname(os.path.abspath(__file__)), "fas_vanka.py")).loader.exec_module(fv)
return mesh, st, v, p


def solve_level(st, v, p, warm=None, max_it=40):
print("COLD (zero initial guess at each resolution):")
for cs in CELLSIZES:
mesh, st, v, p = build(cs)
ndof = st.snes.getJacobian()[0].getSize()[0] if False else None
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