Block-structured adaptive-mesh (AMR) reinitialization ("redistancing") of an advected level-set scalar, built on the AMReX framework.
The library restores the signed-distance property
| Capability | Options |
|---|---|
| Redistancing algorithm | LevelSetRedistance (Sussman PDE) and GeometricRedistance (Ausas–Dari–Buscaglia geometric, mass-preserving) |
| PDE spatial discretization | First-order Godunov upwind Hamiltonian, fifth-order HJ-WENO5 |
| PDE pseudo-time integration | TVD-RK2, TVD-RK3 (SSP, Shu–Osher) |
| PDE interface preservation | Russo–Smereka subcell constraint |
| PDE mass/volume control | Sussman–Fatemi volume-conserving correction (multi-level FillPatch) |
| Geometric reconstruction | Bounded-facet (segment/disc) reconstruction with $\mathbf n = \nabla\phi/ |
| Geometric propagation | Parallel Rouy–Tourin (Jacobi) eikonal sweeps |
| Geometric mass control | Band-local per-neighbourhood volume correction (feature-safe) |
| AMR | Multi-level FillPatchTwoLevels, average_down, dynamic regridding |
| Advection (tests) | Godunov / WENO5 upwind, TVD-RK3, Berger–Colella time subcycling, smoothed conservative coarse-band sync |
| Configuration | Runtime ParmParse control of scheme, integrator, and all physical parameters |
| CI | Combined regression driver → JUnit XML; standalone rotation executables; Doxygen docs |
| Tooling | Jupyter harness: run, parse, plot, animate, and mass-conservation comparison |
Reinitialization integrates the Hamilton–Jacobi PDE to steady state in a pseudo-time
with
A four-stage geometric scheme that computes distances directly from a reconstructed interface:
-
Bounded-facet reconstruction — each cut cell yields a segment (2D) / disc (3D) of half-extent
$L$ through the crossing centroid, normal$\mathbf n = \nabla\phi_0/|\nabla\phi_0|$ . Bounding the facet prevents an unbounded plane from chamfering convex corners. -
First-band distances — minimum bounded-facet distance over the
$3^d$ neighbourhood, frozen as Dirichlet data. -
Propagation — parallel Rouy–Tourin (Jacobi) eikonal sweeps solve
$|\nabla d| = 1$ ; the band is then clamped and$\operatorname{sgn}(\phi_0)$ reapplied. - Band-local mass preservation — a per-neighbourhood normal shift $$ \delta_{ij} = \frac{\sum_{\Omega_{ij}}\bigl(H_\epsilon(\phi_0)-H_\epsilon(\phi)\bigr)} {\sum_{\Omega_{ij}} \delta_\epsilon(\phi)}, \qquad \phi \mathrel{-}= \delta_{ij}, $$ restores volume where a corner lost area without translating intact thin features (so it does not close the Zalesak slot).
amrex_levelset_redistance/
├── CMakeLists.txt # root build (adds Source, Test, Docs)
├── README.md LICENSE CITATION.cff
├── CONTRIBUTING.md CODE_OF_CONDUCT.md .clang-format .gitignore
├── .github/workflows/ # ci.yml, docs.yml
├── inputs/
│ ├── inputs.regression # combined regression driver (all namespaces)
│ ├── inputs.zdisk2d # standalone 2D Zalesak disk
│ └── inputs.zsphere3d # standalone 3D Zalesak sphere
├── Source/
│ ├── RedistanceUtil.H # shared host/device helpers (redist_detail)
│ ├── LevelSetRedistance.H / .cpp # Sussman PDE driver (Godunov/WENO5,
│ │ # RK2/RK3, Russo–Smereka, Sussman–Fatemi)
│ ├── GeometricRedistance.H / .cpp # geometric mass-preserving driver (ADB 2011)
│ ├── AdvectionSolver.H / .cpp # subcycling advection integrator + sync
│ └── ZalesakProblem.H / .cpp # Zalesak IC, tagging, metrics, I/O
├── Test/
│ ├── RegressionMain.cpp RegressionTests.H # combined driver + registry
│ ├── JUnitReport.H / .cpp # JUnit XML writer + msg hook
│ ├── UnitTest.cpp ConvergenceTest.cpp
│ ├── VolumeTest.cpp GeometricTest.cpp
│ ├── ZalesakTest.cpp ZalesakSyncTest.cpp
│ ├── GeometricCornerTest.cpp # static slot/corner unit test
│ ├── ZalesakDisk2D.cpp # standalone 2D (own main)
│ └── ZalesakSphere3D.cpp # standalone 3D (own main)
├── Docs/
│ ├── index.html # user guide (tracked) -> site root on Pages
│ ├── main_page.md # Doxygen API landing page (tracked)
│ ├── Doxyfile.in # CMake-configured Doxygen template (tracked)
│ ├── CMakeLists.txt # `docs` target (tracked)
│ └── api/ # generated Doxygen HTML (git-ignored) -> /api/
└── zalesak_harness.py # Jupyter/Jupytext harness (run, plot, animate)
- CMake ≥ 3.20, a C++17 compiler
- Git (AMReX is fetched automatically if not already installed)
- Optional: MPI, and CUDA / HIP / SYCL for GPU builds
The 2D and 3D executables require separate builds (AMREX_SPACEDIM is compile-time):
# 2D, CPU + MPI
cmake -S . -B build -DREDIST_DIM=2 -DREDIST_MPI=ON
cmake --build build -j
# 3D
cmake -S . -B build3d -DREDIST_DIM=3
cmake --build build3d -j
# CUDA GPU (3D)
cmake -S . -B buildcuda -DREDIST_DIM=3 -DREDIST_GPU_BACKEND=CUDA
cmake --build buildcuda -j| CMake option | Default | Meaning |
|---|---|---|
REDIST_DIM |
2 |
Spatial dimension (2 or 3) |
REDIST_MPI |
ON |
Enable MPI |
REDIST_OMP |
OFF |
Enable OpenMP |
REDIST_GPU_BACKEND |
NONE |
NONE, CUDA, HIP, or SYCL |
cmake --build build --target docs # HTML in build/Docs/html/index.htmlcd build/Test
# Full suite → single JUnit report
./regression inputs.regression --output regression_results.xml
# A single test
./regression inputs.regression --only geometric_test
# Via CTest (each case also emits its own XML)
ctest --output-on-failureThe driver exits non-zero if any case fails, so it doubles as a single pass/fail gate. The XML is ingestible by GitHub Actions (mikepenz/action-junit-report), GitLab (artifacts:reports:junit), and Jenkins.
| Test | Verifies | Metric |
|---|---|---|
unit_test |
$ | \nabla\phi |
convergence_test |
Reinitialization convergence rate | value error vs exact signed distance (order ≈ 2) |
volume_test |
Sussman–Fatemi reduces enclosed-volume drift | smoothed-Heaviside volume A/B |
geometric_test |
Geometric driver restores $ | \nabla\phi |
zalesak_test |
Shape/area error after rotating the slotted disk | finest-data masked sym. difference |
zalesak_sync_test |
Conservative coarse-band sync reduces coarse–fine mismatch | smoothed coarse–fine volume A/B |
Metric note. Several metrics use a smoothed Heaviside rather than a sharp cell count, and the convergence test measures the value error against the exact signed distance. These choices measure exactly the quantity each mechanism controls and are robust to sub-cell interface motion and MPI decomposition (verified rank-invariant on 1–8 ranks, 2D and 3D).
These select the redistancing algorithm at runtime via redist.method, support time-series animation, and (2D) log per-step volume to volume.txt for mass-conservation studies.
# 2D disk — level-set vs geometric
cd build/Test
./test_zdisk2d inputs.zdisk2d redist.method=levelset
./test_zdisk2d inputs.zdisk2d redist.method=geometric
# 3D slotted sphere
cd build3d/Test
./test_zsphere3d inputs.zsphere3d redist.method=geometric
# Static slot/corner unit test (2D)
cd build/Test
./test_geom_cornerRedist.* — PDE redistancing driver:
| Key | Default | Meaning |
|---|---|---|
scheme |
godunov1 |
godunov1 | weno5
|
integrator |
rk3 |
rk2 | rk3
|
subcell_fix |
1 |
Russo–Smereka interface constraint |
volume_fix |
0 |
Sussman–Fatemi volume conservation |
cfl |
0.5 |
|
sign_eps |
1.0 |
Sign-smoothing width (cells) |
weno_eps |
1e-6 |
WENO5 regularization |
vc_eps, vc_radius
|
1.5, 1
|
Volume-fix delta width / neighbourhood radius |
n_iter |
5 |
Default pseudo-time iterations |
Geom.* — geometric redistancing driver:
| Key | Default | Meaning |
|---|---|---|
mass_preserving |
1 |
Band-local volume-conserving correction |
band |
5.0 (6.0 for Zalesak) |
Narrow-band half-width (cells) |
prop_iters |
0 |
Eikonal propagation iterations (0 → auto) |
mass_eps |
1.5 |
Smoothed-Heaviside width (cells) for the correction |
vc_radius |
2 |
Local mass-correction neighbourhood radius (cells) |
redist.method — levelset | geometric (standalone executables).
Test namespaces (tst.*, conv.*, vol.*, zalesak.*, sync.*, geom.*, zd2d.*, zs3d.*) are documented in the corresponding inputs/* files.
#include "LevelSetRedistance.H" // PDE driver
#include "GeometricRedistance.H" // geometric driver
amrex::Vector<amrex::MultiFab*> phi = /* per-level level-set pointers */;
// PDE (Sussman) redistancing:
LevelSetRedistance ls(&amrcore, /*nghost=*/3);
ls.setScheme(RedistScheme::WENO5);
ls.setIntegrator(RedistIntegrator::RK3);
ls.setInterfaceConstraint(true); // Russo–Smereka
ls.setVolumeConservation(false); // Sussman–Fatemi (optional)
ls.readParameters(); // "Redist" inputs override
ls.redistance(phi, /*n_iter=*/5);
// Geometric (Ausas–Dari–Buscaglia) redistancing:
GeometricRedistance geo(&amrcore, /*nghost=*/3);
geo.setMassPreserving(true); // band-local correction
geo.readParameters(); // "Geom" inputs override
geo.redistance(phi, /*n_iter=*/0); // 0 => auto propagation iterationszalesak_harness.py (Jupytext-compatible; jupytext --to notebook zalesak_harness.py) provides:
- Build / run / parse helpers for both the combined driver and the standalone executables.
- Static visualisation — 2D contour + symmetric-difference maps; 3D orthogonal slices +
phi = 0marching-cubes isosurface. - Time-series animation — drives the
plot_intframe output and animates the rotating slot (2D contours, 3D slices) with in-notebook playback and GIF/MP4 export. - Method comparison — level-set vs geometric shape-error / drift bar charts and interface overlays.
- Mass-conservation comparison — loads the per-step
volume.txtlogs and plots volume-vs-time, relative-drift-vs-time, and the instantaneous drift rate (exposing per-reinit mass "kicks").
Requirements:
pip install numpy matplotlib yt scikit-image jupytext # + system ffmpeg for MP4The algorithms implemented here draw on the following literature. If you use this code in academic work, please cite the relevant methods below alongside AMReX.
- Osher, S. and Sethian, J. A. (1988). Fronts propagating with curvature-dependent speed: Algorithms based on Hamilton–Jacobi formulations. J. Comput. Phys., 79(1), 12–49. doi:10.1016/0021-9991(88)90002-2
- Sussman, M., Smereka, P. and Osher, S. (1994). A level set approach for computing solutions to incompressible two-phase flow. J. Comput. Phys., 114(1), 146–159. doi:10.1006/jcph.1994.1155
- Rouy, E. and Tourin, A. (1992). A viscosity solutions approach to shape-from-shading. SIAM J. Numer. Anal., 29(3), 867–884. doi:10.1137/0729053
- Bardi, M. and Osher, S. (1991). The nonconvex multidimensional Riemann problem for Hamilton–Jacobi equations. SIAM J. Math. Anal., 22(2), 344–351. doi:10.1137/0522022
- Liu, X.-D., Osher, S. and Chan, T. (1994). Weighted essentially non-oscillatory schemes. J. Comput. Phys., 115(1), 200–212. doi:10.1006/jcph.1994.1187
- Jiang, G.-S. and Shu, C.-W. (1996). Efficient implementation of weighted ENO schemes. J. Comput. Phys., 126(1), 202–228. doi:10.1006/jcph.1996.0130
- Jiang, G.-S. and Peng, D. (2000). Weighted ENO schemes for Hamilton–Jacobi equations. SIAM J. Sci. Comput., 21(6), 2126–2143. doi:10.1137/S106482759732455X
- Shu, C.-W. and Osher, S. (1988). Efficient implementation of essentially non-oscillatory shock-capturing schemes. J. Comput. Phys., 77(2), 439–471. doi:10.1016/0021-9991(88)90177-5
- Gottlieb, S., Shu, C.-W. and Tadmor, E. (2001). Strong stability-preserving high-order time discretization methods. SIAM Review, 43(1), 89–112. doi:10.1137/S003614450036757X
- Russo, G. and Smereka, P. (2000). A remark on computing distance functions. J. Comput. Phys., 163(1), 51–67. doi:10.1006/jcph.2000.6553
- du Chéné, A., Min, C. and Gibou, F. (2008). Second-order accurate computation of curvatures in a level set framework using novel high-order reinitialization schemes. J. Sci. Comput., 35(2–3), 114–131. doi:10.1007/s10915-007-9177-1
- Min, C. (2010). On reinitializing level set functions. J. Comput. Phys., 229(8), 2764–2772. doi:10.1016/j.jcp.2009.12.032
- Sussman, M. and Fatemi, E. (1999). An efficient, interface-preserving level set redistancing algorithm and its application to interfacial incompressible fluid flow. SIAM J. Sci. Comput., 20(4), 1165–1191. doi:10.1137/S1064827596298245
- Ausas, R. F., Dari, E. A. and Buscaglia, G. C. (2011). A geometric mass-preserving redistancing scheme for the level set function. Int. J. Numer. Methods Fluids, 65(8), 989–1010. doi:10.1002/fld.2227 — the geometric driver implemented in
GeometricRedistance.
- Sethian, J. A. (1996). A fast marching level set method for monotonically advancing fronts. Proc. Natl. Acad. Sci. USA, 93(4), 1591–1595. doi:10.1073/pnas.93.4.1591 — the sequential alternative to the parallel Jacobi Rouy–Tourin sweep used here.
- Berger, M. J. and Oliger, J. (1984). Adaptive mesh refinement for hyperbolic partial differential equations. J. Comput. Phys., 53(3), 484–512. doi:10.1016/0021-9991(84)90073-1
- Berger, M. J. and Colella, P. (1989). Local adaptive mesh refinement for shock hydrodynamics. J. Comput. Phys., 82(1), 64–84. doi:10.1016/0021-9991(89)90035-1
- Zalesak, S. T. (1979). Fully multidimensional flux-corrected transport algorithms for fluids. J. Comput. Phys., 31(3), 335–362. doi:10.1016/0021-9991(79)90051-2
- Zhang, W., Almgren, A., Beckner, V., Bell, J., et al. (2019). AMReX: A framework for block-structured adaptive mesh refinement. J. Open Source Softw., 4(37), 1370. doi:10.21105/joss.01370
- AMReX-Codes. AMReX [software]. https://github.com/AMReX-Codes/amrex
@article{OsherSethian1988,
author = {Osher, Stanley and Sethian, James A.},
title = {Fronts propagating with curvature-dependent speed:
Algorithms based on {Hamilton--Jacobi} formulations},
journal = {Journal of Computational Physics},
volume = {79}, number = {1}, pages = {12--49}, year = {1988},
doi = {10.1016/0021-9991(88)90002-2}
}
@article{SussmanSmerekaOsher1994,
author = {Sussman, Mark and Smereka, Peter and Osher, Stanley},
title = {A level set approach for computing solutions to
incompressible two-phase flow},
journal = {Journal of Computational Physics},
volume = {114}, number = {1}, pages = {146--159}, year = {1994},
doi = {10.1006/jcph.1994.1155}
}
@article{RouyTourin1992,
author = {Rouy, Elisabeth and Tourin, Agn\`{e}s},
title = {A viscosity solutions approach to shape-from-shading},
journal = {SIAM Journal on Numerical Analysis},
volume = {29}, number = {3}, pages = {867--884}, year = {1992},
doi = {10.1137/0729053}
}
@article{JiangShu1996,
author = {Jiang, Guang-Shan and Shu, Chi-Wang},
title = {Efficient implementation of weighted {ENO} schemes},
journal = {Journal of Computational Physics},
volume = {126}, number = {1}, pages = {202--228}, year = {1996},
doi = {10.1006/jcph.1996.0130}
}
@article{JiangPeng2000,
author = {Jiang, Guang-Shan and Peng, Danping},
title = {Weighted {ENO} schemes for {Hamilton--Jacobi} equations},
journal = {SIAM Journal on Scientific Computing},
volume = {21}, number = {6}, pages = {2126--2143}, year = {2000},
doi = {10.1137/S106482759732455X}
}
@article{ShuOsher1988,
author = {Shu, Chi-Wang and Osher, Stanley},
title = {Efficient implementation of essentially non-oscillatory
shock-capturing schemes},
journal = {Journal of Computational Physics},
volume = {77}, number = {2}, pages = {439--471}, year = {1988},
doi = {10.1016/0021-9991(88)90177-5}
}
@article{GottliebShuTadmor2001,
author = {Gottlieb, Sigal and Shu, Chi-Wang and Tadmor, Eitan},
title = {Strong stability-preserving high-order time
discretization methods},
journal = {SIAM Review},
volume = {43}, number = {1}, pages = {89--112}, year = {2001},
doi = {10.1137/S003614450036757X}
}
@article{RussoSmereka2000,
author = {Russo, Giovanni and Smereka, Peter},
title = {A remark on computing distance functions},
journal = {Journal of Computational Physics},
volume = {163}, number = {1}, pages = {51--67}, year = {2000},
doi = {10.1006/jcph.2000.6553}
}
@article{duCheneMinGibou2008,
author = {du Ch\'{e}n\'{e}, Arthur and Min, Chohong and Gibou, Fr\'{e}d\'{e}ric},
title = {Second-order accurate computation of curvatures in a level set
framework using novel high-order reinitialization schemes},
journal = {Journal of Scientific Computing},
volume = {35}, number = {2--3}, pages = {114--131}, year = {2008},
doi = {10.1007/s10915-007-9177-1}
}
@article{Min2010,
author = {Min, Chohong},
title = {On reinitializing level set functions},
journal = {Journal of Computational Physics},
volume = {229}, number = {8}, pages = {2764--2772}, year = {2010},
doi = {10.1016/j.jcp.2009.12.032}
}
@article{SussmanFatemi1999,
author = {Sussman, Mark and Fatemi, Emad},
title = {An efficient, interface-preserving level set redistancing
algorithm and its application to interfacial incompressible
fluid flow},
journal = {SIAM Journal on Scientific Computing},
volume = {20}, number = {4}, pages = {1165--1191}, year = {1999},
doi = {10.1137/S1064827596298245}
}
@article{AusasDariBuscaglia2011,
author = {Ausas, Roberto F. and Dari, Enzo A. and Buscaglia, Gustavo C.},
title = {A geometric mass-preserving redistancing scheme for the
level set function},
journal = {International Journal for Numerical Methods in Fluids},
volume = {65}, number = {8}, pages = {989--1010}, year = {2011},
doi = {10.1002/fld.2227}
}
@article{Sethian1996,
author = {Sethian, James A.},
title = {A fast marching level set method for monotonically
advancing fronts},
journal = {Proceedings of the National Academy of Sciences},
volume = {93}, number = {4}, pages = {1591--1595}, year = {1996},
doi = {10.1073/pnas.93.4.1591}
}
@article{BergerColella1989,
author = {Berger, Marsha J. and Colella, Phillip},
title = {Local adaptive mesh refinement for shock hydrodynamics},
journal = {Journal of Computational Physics},
volume = {82}, number = {1}, pages = {64--84}, year = {1989},
doi = {10.1016/0021-9991(89)90035-1}
}
@article{BergerOliger1984,
author = {Berger, Marsha J. and Oliger, Joseph},
title = {Adaptive mesh refinement for hyperbolic partial
differential equations},
journal = {Journal of Computational Physics},
volume = {53}, number = {3}, pages = {484--512}, year = {1984},
doi = {10.1016/0021-9991(84)90073-1}
}
@article{Zalesak1979,
author = {Zalesak, Steven T.},
title = {Fully multidimensional flux-corrected transport
algorithms for fluids},
journal = {Journal of Computational Physics},
volume = {31}, number = {3}, pages = {335--362}, year = {1979},
doi = {10.1016/0021-9991(79)90051-2}
}
@article{AMReX_JOSS,
author = {Zhang, Weiqun and Almgren, Ann and Beckner, Vince and
Bell, John and others},
title = {{AMReX}: A framework for block-structured adaptive mesh
refinement},
journal = {Journal of Open Source Software},
volume = {4}, number = {37}, pages = {1370}, year = {2019},
doi = {10.21105/joss.01370}
}| Source component | Primary reference(s) |
|---|---|
LevelSetRedistance (PDE) |
Sussman, Smereka & Osher (1994); Osher & Sethian (1988) |
| Godunov Hamiltonian | Rouy & Tourin (1992); Bardi & Osher (1991) |
RedistScheme::WENO5 |
Jiang & Peng (2000); Jiang & Shu (1996); Liu, Osher & Chan (1994) |
RedistIntegrator::RK2/RK3 |
Shu & Osher (1988); Gottlieb, Shu & Tadmor (2001) |
setInterfaceConstraint (subcell) |
Russo & Smereka (2000); du Chéné, Min & Gibou (2008); Min (2010) |
setVolumeConservation |
Sussman & Fatemi (1999) |
GeometricRedistance (bounded facet + local mass) |
Ausas, Dari & Buscaglia (2011) |
| Geometric eikonal propagation | Rouy & Tourin (1992); Sethian (1996) |
AdvectionSolver subcycling / sync |
Berger & Colella (1989); Berger & Oliger (1984) |
ZalesakProblem benchmark |
Zalesak (1979) |
AMR data structures / FillPatch |
Zhang et al. (2019) |
Both redistancing drivers pass the full suite in 2D and 3D. On the Zalesak benchmark (one revolution, 2 AMR levels):
| Method | Shape error (sym.diff / A₀) | Area drift |
|---|---|---|
LevelSetRedistance (WENO5 + RK3 + Russo–Smereka + Sussman–Fatemi) |
~2.0×10⁻³ | ~2.0×10⁻⁴ |
GeometricRedistance (bounded facet + band-local mass) |
~2.2×10⁻² | ~−9.2×10⁻³ |
The PDE driver is the stronger choice for corner-heavy, thin-feature geometries like the Zalesak disk — it pins the contour cell-locally each reinit, whereas the geometric driver re-derives the interface. The geometric driver is a legitimate, feature-preserving option (its bounded-facet reconstruction keeps corners and the band-local correction keeps the slot open) and is the natural choice where a reconstruction-based distance is preferred over a PDE relaxation.
- 2D and 3D suites pass on physically meaningful metrics (value-error convergence ≈ 2; smoothed-volume conservation; smoothed coarse–fine sync).
- MPI-invariant across 1–8 ranks (2D and 3D).
- Both redistancing methods exercised via the standalone rotation executables and the
geometric_testregression case.
Distributed under the BSD 3-Clause License — see LICENSE.
Copyright (c) 2026, The University of Edinburgh.
AMReX itself is distributed under the BSD-3-Clause license; retain its copyright and license notices when redistributing.
- David Ingram, The University of Edinburgh — ORCID 0000-0002-8669-8942.
- Developed with assistance from ELM, the University of Edinburgh's secure generative-AI gateway.
Built on AMReX, developed at Lawrence Berkeley National Laboratory with U.S. Department of Energy support. The numerical methods are due to the authors cited above.
Note on citations: DOIs and volume/page details have been provided to the best of accuracy; please verify each reference against the publisher of record before inclusion in a formal manuscript.