SpECTRE
v2024.12.16
|
Algorithms to solve linear systems of equations. More...
Namespaces | |
namespace | LinearSolver |
Functionality for solving linear systems of equations. | |
namespace | LinearSolver::Tags |
The DataBox tags associated with the linear solver. | |
namespace | LinearSolver::InnerProductImpls |
Implementations of LinearSolver::inner_product. | |
Classes | |
struct | LinearSolver::cg::ConjugateGradient< Metavariables, FieldsTag, OptionsGroup, SourceTag > |
A conjugate gradient solver for linear systems of equations \(Ax=b\) where the operator \(A\) is symmetric. More... | |
struct | LinearSolver::gmres::Gmres< Metavariables, FieldsTag, OptionsGroup, Preconditioned, SourceTag, ArraySectionIdTag > |
A GMRES solver for nonsymmetric linear systems of equations \(Ax=b\). More... | |
struct | LinearSolver::Richardson::Richardson< FieldsTag, OptionsGroup, SourceTag, ArraySectionIdTag > |
A simple Richardson scheme for solving a system of linear equations \(Ax=b\). More... | |
struct | LinearSolver::Schwarz::Schwarz< FieldsTag, OptionsGroup, SubdomainOperator, SubdomainPreconditioners, SourceTag, ArraySectionIdTag > |
An additive Schwarz subdomain solver for linear systems of equations \(Ax=b\). More... | |
Functions | |
template<typename Lhs , typename Rhs > | |
auto | LinearSolver::inner_product (const Lhs &lhs, const Rhs &rhs) |
The local part of the Euclidean inner product on the vector space w.r.t. which the addition and scalar multiplication of both Lhs and Rhs is defined. More... | |
template<typename T > | |
double | LinearSolver::magnitude_square (const T &vector) |
The local part of the Euclidean inner product of a vector with itself. More... | |
int | lapack::general_matrix_linear_solve (gsl::not_null< DataVector * > rhs_in_solution_out, gsl::not_null< Matrix * > matrix_operator, int number_of_rhs=0) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition. More... | |
int | lapack::general_matrix_linear_solve (gsl::not_null< DataVector * > rhs_in_solution_out, gsl::not_null< std::vector< int > * > pivots, gsl::not_null< Matrix * > matrix_operator, int number_of_rhs=0) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition. More... | |
int | lapack::general_matrix_linear_solve (gsl::not_null< DataVector * > solution, gsl::not_null< Matrix * > matrix_operator, const DataVector &rhs, int number_of_rhs=0) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition. More... | |
int | lapack::general_matrix_linear_solve (gsl::not_null< DataVector * > solution, gsl::not_null< std::vector< int > * > pivots, gsl::not_null< Matrix * > matrix_operator, const DataVector &rhs, int number_of_rhs=0) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition. More... | |
int | lapack::general_matrix_linear_solve (gsl::not_null< DataVector * > rhs_in_solution_out, const Matrix &matrix_operator, int number_of_rhs=0) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition. More... | |
int | lapack::general_matrix_linear_solve (gsl::not_null< DataVector * > solution, const Matrix &matrix_operator, const DataVector &rhs, int number_of_rhs=0) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition. More... | |
Algorithms to solve linear systems of equations.
In a way, the linear solver is for elliptic systems what time stepping is for the evolution code. This is because the DG scheme for an elliptic system reduces to a linear system of equations of the type \(Ax=b\), where \(A\) is a global matrix representing the DG discretization of the problem. Since this is one equation for each node in the computational domain it becomes unfeasible to numerically invert the global matrix \(A\). Instead, we solve the problem iteratively so that we never need to construct \(A\) globally but only need \(Ax\) that can be evaluated locally by virtue of the DG formulation. This action of the operator is what we have to supply in each step of the iterative algorithms implemented here. It is where most of the computational cost goes and usually involves computing a volume contribution for each element and communicating fluxes with neighboring elements. Since the iterative algorithms typically scale badly with increasing grid size, a preconditioner \(P\) is needed in order to make \(P^{-1}A\) easier to invert.
In the iterative algorithms we usually don't work with the physical field \(x\) directly. Instead we need to apply the operator to an internal variable defined by the respective algorithm. This variable is exposed as the LinearSolver::Tags::Operand
prefix, and the algorithm expects that the computed operator action is written into db::add_tag_prefix<LinearSolver::Tags::OperatorAppliedTo, LinearSolver::Tags::Operand<...>>
in each step.
int lapack::general_matrix_linear_solve | ( | gsl::not_null< DataVector * > | rhs_in_solution_out, |
const Matrix & | matrix_operator, | ||
int | number_of_rhs = 0 |
||
) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition.
Several interfaces are provided with combinations of input parameters due to the versatility of the LAPACK utility.
rhs_in_solution_out
or solution
: If the rhs
DataVector
is not separately supplied, this single pass-by-pointer DataVector
acts as the input \( b\), and is overwritten with the solution \(x\); in this case rhs_in_solution_out
must be sufficiently large to contain the solution. If rhs
is separately supplied, solution
will contain \(x\) at the end of the algorithm, and must be sufficiently large to contain the solution.rhs
(optional) : An input DataVector
representing \(b\) that is not overwritten.matrix_operator
: The Matrix
\(A\). If passed by pointer, this matrix will be 'destroyed' and overwritten with LU decomposition information. Optionally, a pivots
vector may be passed by pointer so that the full LUP decomposition information can be recovered from the LAPACK output. If passed by const reference, the wrapper will make a copy so that LAPACK does not overwrite the supplied matrix.pivots
(optional) : a std::vector<int>
, passed by pointer, which will contain the permutation information necessary to reassemble the full matrix information if LAPACK is permitted to modify the input matrix in-place.number_of_rhs
: The number of columns of \(x\) and \(b\). This is thought of as the 'number of right-hand-sides' to be solved for. In most cases, that additional dimension can be inferred from the dimensionality of the matrix and the input vector(s), which occurs if number_of_rhs
is set to 0 (default). If the provided DataVector
is an inappropriate size for that inference (i.e. is not a multiple of the largest dimension of the matrix), or if you only want to solve for the first number_of_rhs
columns, the parameter number_of_rhs
must be supplied.The function return int
is the value provided by the INFO
field of the LAPACK call. It is 0 for a successful linear solve, and nonzero values code for types of failures of the algorithm. See LAPACK documentation for further details about dgesv
: http://www.netlib.org/lapack/
int lapack::general_matrix_linear_solve | ( | gsl::not_null< DataVector * > | rhs_in_solution_out, |
gsl::not_null< Matrix * > | matrix_operator, | ||
int | number_of_rhs = 0 |
||
) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition.
Several interfaces are provided with combinations of input parameters due to the versatility of the LAPACK utility.
rhs_in_solution_out
or solution
: If the rhs
DataVector
is not separately supplied, this single pass-by-pointer DataVector
acts as the input \( b\), and is overwritten with the solution \(x\); in this case rhs_in_solution_out
must be sufficiently large to contain the solution. If rhs
is separately supplied, solution
will contain \(x\) at the end of the algorithm, and must be sufficiently large to contain the solution.rhs
(optional) : An input DataVector
representing \(b\) that is not overwritten.matrix_operator
: The Matrix
\(A\). If passed by pointer, this matrix will be 'destroyed' and overwritten with LU decomposition information. Optionally, a pivots
vector may be passed by pointer so that the full LUP decomposition information can be recovered from the LAPACK output. If passed by const reference, the wrapper will make a copy so that LAPACK does not overwrite the supplied matrix.pivots
(optional) : a std::vector<int>
, passed by pointer, which will contain the permutation information necessary to reassemble the full matrix information if LAPACK is permitted to modify the input matrix in-place.number_of_rhs
: The number of columns of \(x\) and \(b\). This is thought of as the 'number of right-hand-sides' to be solved for. In most cases, that additional dimension can be inferred from the dimensionality of the matrix and the input vector(s), which occurs if number_of_rhs
is set to 0 (default). If the provided DataVector
is an inappropriate size for that inference (i.e. is not a multiple of the largest dimension of the matrix), or if you only want to solve for the first number_of_rhs
columns, the parameter number_of_rhs
must be supplied.The function return int
is the value provided by the INFO
field of the LAPACK call. It is 0 for a successful linear solve, and nonzero values code for types of failures of the algorithm. See LAPACK documentation for further details about dgesv
: http://www.netlib.org/lapack/
int lapack::general_matrix_linear_solve | ( | gsl::not_null< DataVector * > | rhs_in_solution_out, |
gsl::not_null< std::vector< int > * > | pivots, | ||
gsl::not_null< Matrix * > | matrix_operator, | ||
int | number_of_rhs = 0 |
||
) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition.
Several interfaces are provided with combinations of input parameters due to the versatility of the LAPACK utility.
rhs_in_solution_out
or solution
: If the rhs
DataVector
is not separately supplied, this single pass-by-pointer DataVector
acts as the input \( b\), and is overwritten with the solution \(x\); in this case rhs_in_solution_out
must be sufficiently large to contain the solution. If rhs
is separately supplied, solution
will contain \(x\) at the end of the algorithm, and must be sufficiently large to contain the solution.rhs
(optional) : An input DataVector
representing \(b\) that is not overwritten.matrix_operator
: The Matrix
\(A\). If passed by pointer, this matrix will be 'destroyed' and overwritten with LU decomposition information. Optionally, a pivots
vector may be passed by pointer so that the full LUP decomposition information can be recovered from the LAPACK output. If passed by const reference, the wrapper will make a copy so that LAPACK does not overwrite the supplied matrix.pivots
(optional) : a std::vector<int>
, passed by pointer, which will contain the permutation information necessary to reassemble the full matrix information if LAPACK is permitted to modify the input matrix in-place.number_of_rhs
: The number of columns of \(x\) and \(b\). This is thought of as the 'number of right-hand-sides' to be solved for. In most cases, that additional dimension can be inferred from the dimensionality of the matrix and the input vector(s), which occurs if number_of_rhs
is set to 0 (default). If the provided DataVector
is an inappropriate size for that inference (i.e. is not a multiple of the largest dimension of the matrix), or if you only want to solve for the first number_of_rhs
columns, the parameter number_of_rhs
must be supplied.The function return int
is the value provided by the INFO
field of the LAPACK call. It is 0 for a successful linear solve, and nonzero values code for types of failures of the algorithm. See LAPACK documentation for further details about dgesv
: http://www.netlib.org/lapack/
int lapack::general_matrix_linear_solve | ( | gsl::not_null< DataVector * > | solution, |
const Matrix & | matrix_operator, | ||
const DataVector & | rhs, | ||
int | number_of_rhs = 0 |
||
) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition.
Several interfaces are provided with combinations of input parameters due to the versatility of the LAPACK utility.
rhs_in_solution_out
or solution
: If the rhs
DataVector
is not separately supplied, this single pass-by-pointer DataVector
acts as the input \( b\), and is overwritten with the solution \(x\); in this case rhs_in_solution_out
must be sufficiently large to contain the solution. If rhs
is separately supplied, solution
will contain \(x\) at the end of the algorithm, and must be sufficiently large to contain the solution.rhs
(optional) : An input DataVector
representing \(b\) that is not overwritten.matrix_operator
: The Matrix
\(A\). If passed by pointer, this matrix will be 'destroyed' and overwritten with LU decomposition information. Optionally, a pivots
vector may be passed by pointer so that the full LUP decomposition information can be recovered from the LAPACK output. If passed by const reference, the wrapper will make a copy so that LAPACK does not overwrite the supplied matrix.pivots
(optional) : a std::vector<int>
, passed by pointer, which will contain the permutation information necessary to reassemble the full matrix information if LAPACK is permitted to modify the input matrix in-place.number_of_rhs
: The number of columns of \(x\) and \(b\). This is thought of as the 'number of right-hand-sides' to be solved for. In most cases, that additional dimension can be inferred from the dimensionality of the matrix and the input vector(s), which occurs if number_of_rhs
is set to 0 (default). If the provided DataVector
is an inappropriate size for that inference (i.e. is not a multiple of the largest dimension of the matrix), or if you only want to solve for the first number_of_rhs
columns, the parameter number_of_rhs
must be supplied.The function return int
is the value provided by the INFO
field of the LAPACK call. It is 0 for a successful linear solve, and nonzero values code for types of failures of the algorithm. See LAPACK documentation for further details about dgesv
: http://www.netlib.org/lapack/
int lapack::general_matrix_linear_solve | ( | gsl::not_null< DataVector * > | solution, |
gsl::not_null< Matrix * > | matrix_operator, | ||
const DataVector & | rhs, | ||
int | number_of_rhs = 0 |
||
) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition.
Several interfaces are provided with combinations of input parameters due to the versatility of the LAPACK utility.
rhs_in_solution_out
or solution
: If the rhs
DataVector
is not separately supplied, this single pass-by-pointer DataVector
acts as the input \( b\), and is overwritten with the solution \(x\); in this case rhs_in_solution_out
must be sufficiently large to contain the solution. If rhs
is separately supplied, solution
will contain \(x\) at the end of the algorithm, and must be sufficiently large to contain the solution.rhs
(optional) : An input DataVector
representing \(b\) that is not overwritten.matrix_operator
: The Matrix
\(A\). If passed by pointer, this matrix will be 'destroyed' and overwritten with LU decomposition information. Optionally, a pivots
vector may be passed by pointer so that the full LUP decomposition information can be recovered from the LAPACK output. If passed by const reference, the wrapper will make a copy so that LAPACK does not overwrite the supplied matrix.pivots
(optional) : a std::vector<int>
, passed by pointer, which will contain the permutation information necessary to reassemble the full matrix information if LAPACK is permitted to modify the input matrix in-place.number_of_rhs
: The number of columns of \(x\) and \(b\). This is thought of as the 'number of right-hand-sides' to be solved for. In most cases, that additional dimension can be inferred from the dimensionality of the matrix and the input vector(s), which occurs if number_of_rhs
is set to 0 (default). If the provided DataVector
is an inappropriate size for that inference (i.e. is not a multiple of the largest dimension of the matrix), or if you only want to solve for the first number_of_rhs
columns, the parameter number_of_rhs
must be supplied.The function return int
is the value provided by the INFO
field of the LAPACK call. It is 0 for a successful linear solve, and nonzero values code for types of failures of the algorithm. See LAPACK documentation for further details about dgesv
: http://www.netlib.org/lapack/
int lapack::general_matrix_linear_solve | ( | gsl::not_null< DataVector * > | solution, |
gsl::not_null< std::vector< int > * > | pivots, | ||
gsl::not_null< Matrix * > | matrix_operator, | ||
const DataVector & | rhs, | ||
int | number_of_rhs = 0 |
||
) |
Wrapper for LAPACK dgesv, which solves the general linear equation \(A x = b\) by LUP (Lower-triangular, upper-triangular, and permutation) decomposition.
Several interfaces are provided with combinations of input parameters due to the versatility of the LAPACK utility.
rhs_in_solution_out
or solution
: If the rhs
DataVector
is not separately supplied, this single pass-by-pointer DataVector
acts as the input \( b\), and is overwritten with the solution \(x\); in this case rhs_in_solution_out
must be sufficiently large to contain the solution. If rhs
is separately supplied, solution
will contain \(x\) at the end of the algorithm, and must be sufficiently large to contain the solution.rhs
(optional) : An input DataVector
representing \(b\) that is not overwritten.matrix_operator
: The Matrix
\(A\). If passed by pointer, this matrix will be 'destroyed' and overwritten with LU decomposition information. Optionally, a pivots
vector may be passed by pointer so that the full LUP decomposition information can be recovered from the LAPACK output. If passed by const reference, the wrapper will make a copy so that LAPACK does not overwrite the supplied matrix.pivots
(optional) : a std::vector<int>
, passed by pointer, which will contain the permutation information necessary to reassemble the full matrix information if LAPACK is permitted to modify the input matrix in-place.number_of_rhs
: The number of columns of \(x\) and \(b\). This is thought of as the 'number of right-hand-sides' to be solved for. In most cases, that additional dimension can be inferred from the dimensionality of the matrix and the input vector(s), which occurs if number_of_rhs
is set to 0 (default). If the provided DataVector
is an inappropriate size for that inference (i.e. is not a multiple of the largest dimension of the matrix), or if you only want to solve for the first number_of_rhs
columns, the parameter number_of_rhs
must be supplied.The function return int
is the value provided by the INFO
field of the LAPACK call. It is 0 for a successful linear solve, and nonzero values code for types of failures of the algorithm. See LAPACK documentation for further details about dgesv
: http://www.netlib.org/lapack/
auto LinearSolver::inner_product | ( | const Lhs & | lhs, |
const Rhs & | rhs | ||
) |
The local part of the Euclidean inner product on the vector space w.r.t. which the addition and scalar multiplication of both Lhs
and Rhs
is defined.
The linear solver works under the following assumptions:
lhs
and rhs
can each be interpreted as the local chunk of a vector of the same vector space \(V\). Local means there are vectors \(q, p\in V\) such that lhs
and rhs
represent the components of these vectors w.r.t. a subset \(B_i\) of a basis \(B\subset V\).*
and +
operators of Lhs
and Rhs
implement the scalar multiplication and addition in the vector space locally, i.e. restricted to \(B_i\) in the above sense.In practice this means that the full vectors \(p\) and \(q\) can be distributed on many elements, where each only holds local chunks lhs
and rhs
of the components. Scalar multiplication and addition can be performed locally as expected, but computing the full inner product requires a global reduction over all elements that sums their local inner_product
s.
double LinearSolver::magnitude_square | ( | const T & | vector | ) |
The local part of the Euclidean inner product of a vector with itself.