Boussinesq engines and experimental closures#
The equations of the Boussinesq solver are on Boussinesq theory, and the solvers side by side are on The solvers of the aquifer. This note is for the contributor who works on how the equations are solved. It gives the choice of method and engine, the details that the code does not show at a glance, the two experimental obstacle closures and the diagnostics of a run. The modules of the backend are on Package: solver.
Methods and engines#
Two choices are independent. The method is the physics, with its unknowns, closure, space
scheme and time scheme. The engine is the numerics, with its nonlinear solver, matrix layout,
Jacobian and linear solver. Two runs can share a method and differ by the engine. The keys
are solver.boussinesq.surface_interaction_model for the closure and
solver.boussinesq.backend for the engine.
The closure and the runtime backend resolve to one method (resolve_method_spec in
hydromodpy/solver/boussinesq/catalog.py).
Method |
Unknowns |
Closure |
Runtime backends |
|---|---|---|---|
|
\(h\) |
|
|
|
\(h, q^{\mathrm{ex}}, q^{\mathrm{dry}}\) |
|
|
|
\(h\) |
|
|
|
\(h\) |
|
|
With auto, the closure is complementarity on PETSc and regularized_partition on every
other backend. A closure that the backend does not implement is refused when the solve
starts, with the message The requested Boussinesq surface-interaction model is not implemented. The space scheme is the same for all four methods.
The triangles come from the triangle engine, generated by mesh.engine or read from a file by
mesh.triangle.path.
This pair loads, and the run then refuses it, because the complementarity closure runs only on PETSc.
# not checked: shows a pair that loads and that the run refuses
base_config = "project.toml"
[solver]
backend = "boussinesq"
[[simulation.process]]
id = "flow_main"
kind = "flow"
solvers = ["boussinesq"]
[solver.boussinesq]
backend = "scipy_sparse"
surface_interaction_model = "complementarity"
The runtime backends are numerical engines for one method. They are not separate
hydrological models. The pairs are in resolve_engine_spec of the same catalog.py.
Backend |
Nonlinear solver |
Jacobian |
Linear solver |
|---|---|---|---|
|
damped Newton, dense |
forward finite differences |
NumPy dense solve |
|
SciPy |
semi-analytic, dense |
MINPACK |
|
damped Newton, sparse |
semi-analytic, plus colored finite differences for the release |
SciPy |
|
PETSc SNES |
semi-analytic, sparse |
direct LU |
The PETSc engines need petsc4py and run only on Linux. On another system the run stops with
a message that starts Boussinesq runtime_backend='petsc' is only supported on Linux. They
run in serial, on PETSc.COMM_SELF.
The nonlinear solve#
Every engine looks for a head \(h\) that makes the residual vector zero. The vector it tests is
the solver residual. It is the balance in m³/s on a free cell, and \(h_j - H^D_j\) in meters on
a constrained cell. The tolerance solver.boussinesq.tol_residual_inf applies to the
largest absolute entry. The iteration budget is solver.boussinesq.max_iterations.
When the key is not set, the runtime has its own budget, larger on scipy_sparse than on the
others (build_runtime_options in solver_contract.py). A step that does not converge ends
the run.
The local and SciPy engines#
The local engine is a damped Newton loop written to be read (_newton_loop_template in
runtimes/newton_common.py). It builds a dense Jacobian by forward finite differences, with
a step of \(10^{-7}\max(1, \lvert h \rvert)\) on each head in turn (build_dense_fd_jacobian).
It solves \(J\,\delta = -R\), then halves the step until the largest residual entry falls. If
the entry never falls, the solve stops and is not converged.
The scipy engine keeps the same residual and gives SciPy a semi-analytic dense Jacobian.
scipy.optimize.root with the hybr method drives the solve (runtimes/scipy_dense.py).
SciPy stops on its own criterion on the step, set from
solver.boussinesq.tol_state_update_inf. The run then checks the residual against the
tolerance, so a solve that SciPy calls successful but whose residual is above the tolerance is
reported as not converged.
Both engines assemble a dense Jacobian. An explicit local or scipy therefore refuses a
mesh of more than 400 cells (_assert_runtime_mesh_size_supported in boussinesq.py). The
default auto runs local up to 400 cells and scipy_sparse above, and logs the engine once
(resolve_runtime_backend_name in solver_contract.py).
The SciPy sparse engine#
The scipy_sparse engine runs the same Newton loop with a sparse Jacobian
(runtimes/scipy_sparse.py). The smooth terms are differentiated analytically. These are the
internal fluxes, the storage, the drain and the constraints. The release \(s_i\) is completed by
finite differences, and the columns that share no row are perturbed together (graph coloring).
If the matrix is singular, the step is solved again with a diagonal shift that grows by a
factor of ten at each of up to six tries. For a steady solve, the initial guess moves to the
middle of the cell wherever the head sits exactly on the top or the bottom, because the
partition Jacobian can be singular there (interiorize_regularized_partition_initial_guess).
This is the reference engine for larger meshes on every system.
The PETSc engines#
The PETSc partition engine solves the same head-only residual with PETSc SNES, a Newton
method with a backtracking line search (runtimes/petsc_partition.py). The linear systems
use a direct LU factorization with a small diagonal shift against zero pivots
(_configure_default_snes in runtimes/petsc_common.py). The absolute tolerance of SNES is
the residual tolerance, and its relative and step tolerances are off.
The Jacobian also receives a diagonal shift that decays with the residual. It is a light pseudo-transient regularization for large meshes, and it reads
where \(R_0\) is the residual of the first iterate. The shift vanishes as the solve converges.
The residual does not contain it, so the solution is the one of the unshifted system
(regularized_partition_jacobian_shift in runtimes/partition_utils.py).
The mixed engine solves the system of \(3n\) unknowns of The lower obstacle, with the
rates scaled by \(q_s\) (_solve_mixed_problem in runtimes/petsc_mixed.py). The residual has
three blocks. They are the balance with \(-a_i q^{\mathrm{dry}}_i\), the Fischer-Burmeister
equation of the surface and the one of the bottom. The run converges when SNES reports a
convergence and the largest entry of the full residual is below the tolerance.
The starting point of the mixed solve is a numerical choice. The head is clipped between the
bottom and the top, and a free cell whose balance at the bottom still asks to lose water
starts at the bottom. In a transient run, the first guess of \(q^{\mathrm{ex}}\) is the release
that the regularized partition would give when the recharge is positive or a well flux is
negative, and zero otherwise (_initial_transient_q_ex_guess). That guess uses a depth scale
of 5 % of the head scale \(h_s\) and ignores
solver.boussinesq.partition_release_depth_m, so that it starts off the kink of the
Fischer-Burmeister function. The choice changes the path to the solution and leaves the
equations as they are.
The experimental obstacle closures#
Two more closures are marked experimental on their cards. Both run on PETSc only, and both keep the head as the only unknown.
vi_obstacle solves the balance with the head bounded between the bottom and the land
surface, as a variational inequality (PETSc SNESVI). The release is not in the system, so
\(s_i = 0\) while the solver iterates. After convergence, the balance left on a cell at its
upper bound is the saturation excess, and the balance left on a cell at its lower bound is the
unmet demand (reconstruct_obstacle_reactions in runtimes/petsc_vi/obstacle.py).
The first expression is used at the upper bound and the second at the lower bound. The upper
bound is relaxed when a positive drain conductance is declared, so that the drain carries the
exchange at the surface (runtimes/vi_bounds.py). Each time step can be cut into substeps
with solver.boussinesq.vi_substeps_per_period, and a failed time step can be retried
with more substeps.
ts_vi_obstacle hands the time stepping to PETSc TS with a backward Euler scheme, inside
each time step, and keeps the same bounds. The storage term is \(a_i S_{y,i}\,\dot h_i\),
because the head is bounded. The ts_vi_* keys below set the number of steps and the
adaptivity. The steady solve for the initial state of a ts_vi_obstacle run uses the
regularized partition (steady_initialization_runtime in solver_contract.py).
A file that chooses the first closure and cuts each period into substeps writes this block.
[solver.boussinesq]
backend = "petsc"
surface_interaction_model = "vi_obstacle"
vi_substeps_per_period = 4
vi_substep_on_failure = true
What the run reports#
The run writes _boussinesq_state_history.npz and _boussinesq_summary.json in the solver
folder. The summary carries diagnostics of the surface and of the bottom, computed on the
accepted snapshots (runtime_summary.py).
Key family |
Meaning |
|---|---|
|
Cells where the surface release is active, the number of windows in which it turns on and off, the peak rate and the peak head above the surface. |
|
Accepted heads below the bottom of the aquifer, and the negative storage volume they would imply. |
|
Cells where the dry deficit is active, its peak rate and its integrated volume. |
|
The state history of \(q^{\mathrm{dry}}\), in the npz file. |
Read the dry deficit apart from the discharge terms. It says where the bottom constraint was active and how much demand the storage could not meet.