BOUT++ preconditioning#
- Author:
B.Dudson, University of York
Introduction#
This manual describes some of the ways BOUT++ could (and in some cases does) support preconditioning, Jacobian calculations and other methods to speed up simulations. This manual assumes that you’re familiar with how BOUT++ works internally.
Some notation: The ODE being solved is of the form
Here the state vector \(f = \left(f_0, f_1, f_2, \ldots\right)^T\) is a vector containing the evolving (3D) variables \(f_i\left(x,y,z\right)\).
The Jacobian of this system is then
The order of the elements in the vector \({\mathbf{f}}\) is determined in the solver code and SUNDIALS, so here just assume that there exists a map \(\mathbb{I}\) between a global index \(k\) and (variable, position) i.e. \(\left(i,x,y,z\right)\)
and its inverse
Some problem-specific operations which can be used to speed up the timestepping
Jacobian-vector multiply: Given a vector, multiply it by \({\mathbb{J}}\)
Preconditioner multiply: Given a vector, multiply by an approximate inverse of \(\mathbb{M} = \mathbb{I} - \gamma\mathbb{J}\)
Calculate the stencils i.e. non-zero elements in \({\mathbb{J}}\)
Calculate the non-zero elements of \({\mathbb{J}}\)
Physics problems#
Some interesting physics problems of increasing difficulty
Resistive drift-interchange instability#
A “simple” test problem of 2 fields, which results in non-trivial turbulent results. Supports resistive drift wave and interchange instabilities.
Reduced 3-field MHD#
This is a 3-field system of pressure \(P\), magnetic flux \(\psi\) and vorticity \(U\):
The coupled set of equations to be solved are therefore
The Jacobian of this system is therefore:
Where the blue terms are only included in nonlinear simulations.
This Jacobian has large dense blocks because of the Laplacian inversion terms (involving \(\nabla_\perp^{-2}\) which couples together all points in an X-Z plane. The way to make \({\mathbb{J}}\) sparse is to solve \(\phi\) as a constraint (using e.g. the IDA solver) which moves the Laplacian inversion to the preconditioner.
Solving \(\phi\) as a constraint#
The evolving state vector becomes
UEDGE equations#
The UEDGE benchmark is a 4-field model with the following equations:
This set of equations is good in that there is no inversion needed, and so the Jacobian is sparse everywhere. The state vector is
The Jacobian is:
If instead the state vector is
then the Jacobian is
2-fluid turbulence#
Jacobian-vector multiply#
This is currently implemented into the CVODE (SUNDIALS) solver.
Preconditioner-vector multiply#
Reduced 3-field MHD#
The matrix \(\mathbb{M}\) to be inverted can therefore be written
where
For small flow velocities, the inverse of \(\mathbb{D}\) can be approximated using the Binomial theorem:
Following [chacon-2008], [chacon-2002], \(\mathbb{M}\) can be re-written as
The Schur factorization of \(\mathbb{M}\) yields ([chacon-2008])
Where \(\mathbb{P}_{Schur} = \mathbb{D} - \mathbb{L}\mathbb{E}^{-1}\mathbb{U}\) is the Schur complement. Note that this inversion is exact so far. Since \(\mathbb{E}\) is block-diagonal, and \(\mathbb{D}\) can be easily approximated using equation (192), this simplifies the problem to inverting \(\mathbb{P}_{Schur}\), which is much smaller than \(\mathbb{M}\).
A possible approximation to \(\mathbb{P}_{Schur}\) is to neglect:
All drive terms
the curvature term \(\mathbb{L}_P\)
the \(J_{||0}\) term in \(\mathbb{L}_\psi\)
All nonlinear terms (blue terms in equation (191)), including perpendicular terms (so \(\mathbb{D} = \mathbb{I}\))
This gives
Where the commutation of parallel and perpendicular derivatives is also an approximation. This remaining term is just the shear Alfvén wave propagating along field-lines, the fastest wave supported by these equations.
Stencils#
Jacobian calculation#
The (sparse) Jacobian matrix elements can be calculated automatically from the physics code by keeping track of the (linearised) operations going through the RHS function.
For each point, keep the value (as usual), plus the non-zero elements in that row of \({\mathbb{J}}\) and the constant: result = Ax + b Keep track of elements using product rule.
class Field3D {
data[ngx][ngy][ngz]; // The data as now
int JacIndex; // Variable index in Jacobian
SparseMatrix *jac; // Set of rows for indices (JacIndex,*,*,*)
};
JacIndex is set by the solver, so for the system
P.JacIndex = 0
, psi.JacIndex = 1
and U.JacIndex = 2
. All
other fields are given JacIndex = -1
.
SparseMatrix stores the non-zero Jacobian components for the set of rows
corresponding to this variable. Evolving variables do not have an
associated SparseMatrix
object, but any fields which result from
operations on evolving fields will have one.
Chacón, An optimal, parallel, fully implicit Newton-Krylov solver for three-dimensional viscoresistive magnetohydrodynamics, POP, 2008, 15, 056103
Chacón, D.A. Knoll, and J.M. Finn, An Implicit, Nonlinear Reduced Resistive MHD Solver, JCP, 2002, 178, 15-36