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

head_only_regularized_partition

\(h\)

regularized_partition

local, scipy, scipy_sparse, petsc

mixed_complementarity

\(h, q^{\mathrm{ex}}, q^{\mathrm{dry}}\)

complementarity

petsc

head_only_vi_obstacle

\(h\)

vi_obstacle

petsc

head_only_ts_vi_obstacle

\(h\)

ts_vi_obstacle

petsc

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

local

damped Newton, dense

forward finite differences

NumPy dense solve

scipy

SciPy root, method hybr

semi-analytic, dense

MINPACK hybr

scipy_sparse

damped Newton, sparse

semi-analytic, plus colored finite differences for the release

SciPy spsolve

petsc

PETSc SNES newtonls, or SNESVI vinewtonrsls, or TS with SNESVI

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

\[\mathrm{shift} = \max\Bigl(10^{-8},\ 0.2\;\mathrm{median}_{J_{ii} \neq 0}\, \lvert J_{ii}\rvert\ \min\bigl(1,\ \lVert R\rVert_\infty / \lVert R_0\rVert_\infty\bigr)\Bigr)\]

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).

\[q^{\mathrm{ex}}_i = \frac{\max(-R_i,\ 0)}{a_i}, \qquad q^{\mathrm{dry}}_i = \frac{\max(R_i,\ 0)}{a_i}\]

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

surface_threshold_*

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.

bottom_threshold_*

Accepted heads below the bottom of the aquifer, and the negative storage volume they would imply.

bottom_constraint_*

Cells where the dry deficit is active, its peak rate and its integrated volume.

dry_deficit_history_m_s

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.

Parameters of this page#

[solver.boussinesq]
# backend = "auto"Engine the Boussinesq solver uses for its nonlinear solve. experimental
Path
solver.boussinesq.backend
More

'local' and 'scipy' build a dense matrix and run on at most 400 cells; 'scipy_sparse' and 'petsc' (it needs petsc4py) have no such limit. 'auto' runs 'local' up to 400 cells and 'scipy_sparse' above, and logs the choice. The MODFLOW solvers do not read it.

Values
  • "auto"
  • "local"
  • "scipy"
  • "scipy_sparse"
  • "petsc"
Accepted
"auto" | "local" | "scipy" | "scipy_sparse" | "petsc"
Example
"auto", "scipy_sparse"
Was
flow.runtime_backend
# surface_interaction_model = "auto"Optional Boussinesq surface-interaction closure selector. dev experimental if "complementarity" | "vi_obstacle" | "ts_vi_obstacle"
Path
solver.boussinesq.surface_interaction_model
More

'regularized_partition' uses the Marcais-style q_ex = G_r(theta) R(balance) law; 'complementarity' uses the mixed PETSc q_ex-perp-(z_top-h) formulation; 'vi_obstacle' uses the PETSc head-only VI obstacle formulation, and 'ts_vi_obstacle' the same one integrated by PETSc TS; 'auto' keeps the historical backend-dependent default.

Values
  • "auto"
  • "regularized_partition"
  • "complementarity"
  • "vi_obstacle"
  • "ts_vi_obstacle"
Accepted
"auto" | "regularized_partition" | "complementarity" | "vi_obstacle" | "ts_vi_obstacle"
Example
"auto", "regularized_partition"
Was
flow.surface_interaction_model
# max_iterations = ‹integer›Optional override for the nonlinear iteration budget used by the Boussinesq runtime backend. - dev experimental
Path
solver.boussinesq.max_iterations
Accepted
integer
Unit
-
Was
flow.runtime_max_iterations
# tol_residual_inf = ‹number›Optional override for the infinity-norm residual tolerance used by the Boussinesq runtime backend. dev experimental
Path
solver.boussinesq.tol_residual_inf
Accepted
number
Was
flow.runtime_tol_residual_inf
# tol_state_update_inf = ‹number›Optional override for the infinity-norm state-update tolerance used by Boussinesq backends that track it. dev experimental
Path
solver.boussinesq.tol_state_update_inf
Accepted
number
Was
flow.runtime_tol_state_update_inf
# vi_substeps_per_period = 1Fixed number of Backward-Euler substeps per time step for the PETSc VI obstacle runtime. - dev experimental
Path
solver.boussinesq.vi_substeps_per_period
More

A stress period holds simulation.time.substeps_per_period time steps. Rate-based forcing values are kept unchanged on each substep.

Accepted
integer
Unit
-
Was
flow.vi_substeps_per_period
# vi_substep_on_failure = falseWhen true, retry a failed PETSc VI obstacle time step with increasing substep counts. dev experimental
Path
solver.boussinesq.vi_substep_on_failure
Accepted
true | false
Was
flow.vi_substep_on_failure
# vi_max_adaptive_substeps = ‹integer›Maximum number of PETSc VI obstacle substeps allowed for adaptive failure retries. - dev experimental
Path
solver.boussinesq.vi_max_adaptive_substeps
Accepted
integer
Unit
-
Was
flow.vi_max_adaptive_substeps
# ts_vi_steps_per_period = 4Fixed PETSc TS Backward-Euler steps per time step for the TS VI obstacle runtime. - dev experimental
Path
solver.boussinesq.ts_vi_steps_per_period
More

A stress period holds simulation.time.substeps_per_period time steps.

Accepted
integer
Unit
-
Was
flow.ts_vi_steps_per_period
# ts_vi_adapt = falseEnable PETSc TS adaptivity for the TS VI obstacle runtime. dev experimental
Path
solver.boussinesq.ts_vi_adapt
Accepted
true | false
Was
flow.ts_vi_adapt
# ts_vi_dt_min_fraction = 0.015625Minimum TS VI step as a fraction of the time-step length. - dev experimental
Path
solver.boussinesq.ts_vi_dt_min_fraction
Accepted
number
Unit
-
Was
flow.ts_vi_dt_min_fraction
# ts_vi_dt_max_fraction = 0.25Maximum TS VI step as a fraction of the time-step length. - dev experimental
Path
solver.boussinesq.ts_vi_dt_max_fraction
Accepted
number
Unit
-
Was
flow.ts_vi_dt_max_fraction
# ts_vi_type = "beuler"PETSc TS type for the TS VI obstacle runtime. dev experimental
Path
solver.boussinesq.ts_vi_type
Accepted
string
Was
flow.ts_vi_type
# ts_vi_snes_type = "vinewtonrsls"PETSc SNES type for the TS VI obstacle runtime. dev experimental
Path
solver.boussinesq.ts_vi_snes_type
Accepted
string
Was
flow.ts_vi_snes_type

Lines generated from the models, as in the reference. Open one for its card.