Linear Solvers#
OpenImpala provides two compiled C++ multigrid solver families—matrix-free AMReX MLMG and HYPRE structured Krylov/multigrid solvers—plus a pure-Python SciPy / CuPy Jacobi-preconditioned Conjugate Gradient fallback for platforms without compiled C++ wheels.
AMReX MLMG (solver="auto" or "mlmg")#
By default, oi.tortuosity(..., solver="auto") selects AMReX’s matrix-free geometric multigrid solver (MLABecLaplacian + V-cycle multigrid):
Matrix-free: evaluates the 7-point harmonic-face stencil on the fly without assembling an explicit 7-band sparse matrix or storing Krylov subspace basis vectors.
3.2×–4.4× lower memory footprint than FlexGMRES+PFMG/SMG: requires roughly ~304–319 bytes per voxel across the full multigrid hierarchy (including 3-axis face conductances, ghost halos, and V-cycle levels), compared to ~1,016 bytes per voxel for HYPRE
FlexGMRES + PFMGand ~1,390 bytes per voxel forFlexGMRES + SMG.CPU + CUDA native: executes identical AMReX
ParallelForkernels across OpenMP threads and NVIDIA GPUs with grid-independent V-cycle counts (\(11\)–\(18\) iterations from \(32^3\) to \(256^3\)).
import openimpala as oi
vol = oi.datasets.two_phase_cubic()
res = oi.tortuosity(vol, phase=1, direction="z", solver="mlmg", mlmg_eps=1e-9)
Measured Memory & Runtime Comparison#
Measured on 3D Gaussian random porous media (\(\phi = 0.50\), two x86_64 OpenMP threads; all solvers agree to \(|\Delta\tau| < 4\times 10^{-8}\)):
Solver Backend |
\(64^3\) Peak RAM |
\(128^3\) Time |
\(128^3\) Peak RAM |
Footprint |
\(256^3\) (\(16.8\text{M}\) vox) |
|---|---|---|---|---|---|
AMReX |
75 MB |
4.06 s |
638 MB |
~304–319 B/vox |
33.1 s / 4,856 MB |
HYPRE |
95 MB |
21.91 s |
710 MB |
~355–380 B/vox |
— |
HYPRE |
268 MB |
33.34 s |
2,031 MB |
~1,016–1,073 B/vox |
— |
HYPRE |
347 MB |
66.87 s |
2,779 MB |
~1,388–1,414 B/vox |
— |
Pure-Python ( |
82 MB |
34.89 s |
699 MB |
~328–350 B/vox |
— |
HYPRE Structured Solvers#
For extreme diffusivity contrasts (\(\kappa \ll 10^{-2}\) in multi-phase media) or periodic homogenisation cell problems (oi.effective_diffusivity()), OpenImpala dispatches to HYPRE’s structured-grid Krylov solvers preconditioned by Semicoarsening Multigrid (SMG) or Pointwise Semicoarsening Multigrid (PFMG):
Python |
Algorithm |
Preconditioner |
Recommended Use Case |
|---|---|---|---|
|
AMReX geometric multigrid |
Native V-cycle |
Default fast path for |
|
Conjugate Gradient |
|
SPD flow-through diffusion on large MPI decompositions |
|
Flexible GMRES |
|
Default for |
|
BiCGSTAB |
|
Alternative Krylov solver when GMRES memory grows |
|
GMRES |
|
General structured linear systems |
|
Standalone PFMG |
— |
Fast pointwise multigrid on large regular grids |
|
Standalone SMG |
— |
Highly anisotropic voxel aspect ratios (\(h_z \gg h_x\)) |
Select the HYPRE preconditioner in oi.tortuosity() via preconditioner="pfmg" (lower memory, faster setup on GPUs) or preconditioner="smg" (stronger plane-smoothing on high-aspect-ratio grids):
res = oi.tortuosity(
vol,
phase=1,
direction="z",
solver="pcg",
preconditioner="pfmg",
)
Periodic Cell-Problem Solver (oi.effective_diffusivity)#
oi.effective_diffusivity() solves three periodic cell problems using HYPRE (solver="flexgmres" by default with PFMG preconditioning on the periodic structured grid):
deff = oi.effective_diffusivity(vol, phase=1, solver="flexgmres")
Convergence Tolerances in C++ Input Files#
When running the standalone C++ Diffusion executable or tuning HYPRE via ParmParse:
hypre.eps = 1.0e-9 # Relative residual convergence tolerance
hypre.maxiter = 500 # Maximum Krylov iterations