A function to create objects of all InverseLinearOperator subclasses.
These are, as of June 06, 2023:
ConjugateGradient, PConjugateGradient, BiConjugateGradient,
BiConjugateGradientStabilized, MinimumResidual, LSMR, GMRES.
The kwargs given must be compatible with the chosen solver subclass.
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (e.g. a matrix-vector product A*p).
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on the
Conjugate gradient algorithm for solving linear system Ax=b.
Implementation from [1], page 137.
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for L2-norm of residual r = A*x - b.
maxiter (int) – Maximum number of iterations.
verbose (bool) – If True, L2-norm of residual r is printed at each iteration.
recycle (bool) – Stores a copy of the output in x0 to speed up consecutive calculations of slightly altered linear systems
References
[1] A. Maister, Numerik linearer Gleichungssysteme, Springer ed. 2015.
Conjugate gradient algorithm for solving linear system Ax=b.
Only working if A is an hermitian and positive-definite linear operator.
Implementation from [1], page 137.
Info can be accessed using get_info(), see :func:~`basic.InverseLinearOperator.get_info`.
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system Ax = b. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x – Numerical solution of the linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
Return type:
psydac.linalg.basic.Vector
References
[1] A. Maister, Numerik linearer Gleichungssysteme, Springer ed. 2015.
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on a preconditioned conjugate gradient method.
The Preconditioned Conjugate Gradient (PCG) algorithm solves the linear
system A x = b where A is a symmetric and positive-definite matrix, i.e.
A = A^T and y A y > 0 for any vector y. The preconditioner P is a matrix
which approximates the inverse of A. The algorithm assumes that P is also
symmetric and positive definite.
Since this is a matrix-free iterative method, both A and P are provided as
LinearOperator objects which must implement the dot method.
pc (psydac.linalg.basic.LinearOperator) – Preconditioner which should approximate the inverse of A (optional).
Like A, the preconditioner should be symmetric and positive definite.
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for L2-norm of residual r = A x - b. (Default: 1e-6)
maxiter (int) – Maximum number of iterations. (Default: 1000)
verbose (bool) – If True, the L2-norm of the residual r is printed at each iteration.
(Default: False)
recycle (bool) – If True, a copy of the output is stored in x0 to speed up consecutive
calculations of slightly altered linear systems. (Default: False)
Preconditioned Conjugate Gradient (PCG) solves the symetric positive definte
system Ax = b. It assumes that pc.dot(r) returns the solution to Ps = r,
where P is positive definite.
Info can be accessed using get_info(), see :func:~`basic.InverseLinearOperator.get_info`.
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on the
Biconjugate gradient (BCG) algorithm for solving linear system Ax=b.
Implementation from [1], page 175.
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for 2-norm of residual r = A*x - b.
maxiter (int) – Maximum number of iterations.
verbose (bool) – If True, 2-norm of residual r is printed at each iteration.
recycle (bool) – Stores a copy of the output in x0 to speed up consecutive calculations of slightly altered linear systems
References
[1] A. Maister, Numerik linearer Gleichungssysteme, Springer ed. 2015.
Biconjugate gradient (BCG) algorithm for solving linear system Ax=b.
Implementation from [1], page 175.
Info can be accessed using get_info(), see :func:~`basic.InverseLinearOperator.get_info`.
ToDo: Add optional preconditioner
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x – Numerical solution of linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
Return type:
psydac.linalg.basic.Vector
References
[1] A. Maister, Numerik linearer Gleichungssysteme, Springer ed. 2015.
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on the
Biconjugate gradient Stabilized (BCGSTAB) algorithm for solving linear system Ax=b.
Implementation from [1], page 175.
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for 2-norm of residual r = A*x - b.
maxiter (int) – Maximum number of iterations.
verbose (bool) – If True, 2-norm of residual r is printed at each iteration.
recycle (bool) – Stores a copy of the output in x0 to speed up consecutive calculations of slightly altered linear systems
References
[1] A. Maister, Numerik linearer Gleichungssysteme, Springer ed. 2015.
Biconjugate gradient stabilized method (BCGSTAB) algorithm for solving linear system Ax=b.
Implementation from [1], page 175.
ToDo: Add optional preconditioner
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x (psydac.linalg.basic.Vector) – Numerical solution of linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
info (dict) –
Dictionary containing convergence information:
’niter’ = (int) number of iterations
’success’ = (boolean) whether convergence criteria have been met
’res_norm’ = (float) 2-norm of residual vector r = A*x - b.
References
[1] H. A. van der Vorst. Bi-CGSTAB: A fast and smoothly converging variant of Bi-CG for the
solution of nonsymmetric linear systems. SIAM J. Sci. Stat. Comp., 13(2):631–644, 1992.
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on the
preconditioned Biconjugate gradient Stabilized (PBCGSTAB) algorithm for solving linear system Ax=b.
Implementation from [1], page 251.
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
Preconditioned biconjugate gradient stabilized method (PBCGSTAB) algorithm for solving linear system Ax=b.
Implementation from [1], page 251.
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x (psydac.linalg.basic.Vector) – Numerical solution of linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
info (dict) –
Dictionary containing convergence information:
’niter’ = (int) number of iterations
’success’ = (boolean) whether convergence criteria have been met
’res_norm’ = (float) 2-norm of residual vector r = A*x - b.
References
[1] A. Maister, Numerik linearer Gleichungssysteme, Springer ed. 2015.
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function
Use MINimum RESidual iteration to solve Ax=b
MINRES minimizes norm(A*x - b) for a real symmetric matrix A. Unlike
the Conjugate Gradient method, A can be indefinite or singular.
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for 2-norm of residual r = A*x - b.
maxiter (int) – Maximum number of iterations.
verbose (bool) – If True, 2-norm of residual r is printed at each iteration.
recycle (bool) – Stores a copy of the output in x0 to speed up consecutive calculations of slightly altered linear systems
Notes
This is an adaptation of the MINRES Solver in Scipy, where the method is modified to accept Psydac data structures,
scipy/scipy
Use MINimum RESidual iteration to solve Ax=b
MINRES minimizes norm(A*x - b) for a real symmetric matrix A. Unlike
the Conjugate Gradient method, A can be indefinite or singular.
Info can be accessed using get_info(), see :func:~`basic.InverseLinearOperator.get_info`.
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x (psydac.linalg.basic.Vector) – Numerical solution of linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
info (dict) – Dictionary containing convergence information:
- ‘niter’ = (int) number of iterations
- ‘success’ = (boolean) whether convergence criteria have been met
- ‘res_norm’ = (float) 2-norm of residual vector r = A*x - b.
Notes
This is an adaptation of the MINRES Solver in Scipy, where the method is modified to accept Psydac data structures,
scipy/scipy
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on the
Iterative solver for least-squares problems.
lsmr solves the system of linear equations Ax=b. If the system
is inconsistent, it solves the least-squares problem min||b-Ax||_2.
A is a rectangular matrix of dimension m-by-n, where all cases are
allowed: m = n, m > n, or m < n. b is a vector of length m.
The matrix A may be dense or sparse (usually sparse).
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for 2-norm of residual r = A*x - b.
atol (float) – Absolute tolerance for 2-norm of residual r = A*x - b.
btol (float) – Relative tolerance for 2-norm of residual r = A*x - b.
maxiter (int) – Maximum number of iterations.
conlim (float) – lsmr terminates if an estimate of cond(A) exceeds
conlim.
verbose (bool) – If True, 2-norm of residual r is printed at each iteration.
recycle (bool) – Stores a copy of the output in x0 to speed up consecutive calculations of slightly altered linear systems
Notes
This is an adaptation of the LSMR Solver in Scipy, where the method is modified to accept Psydac data structures,
scipy/scipy
Iterative solver for least-squares problems.
lsmr solves the system of linear equations Ax=b. If the system
is inconsistent, it solves the least-squares problem min||b-Ax||_2.
A is a rectangular matrix of dimension m-by-n, where all cases are
allowed: m = n, m > n, or m < n. b is a vector of length m.
The matrix A may be dense or sparse (usually sparse).
Info can be accessed using get_info(), see :func:~`basic.InverseLinearOperator.get_info`.
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x – Numerical solution of linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
Return type:
psydac.linalg.basic.Vector
Notes
This is an adaptation of the LSMR Solver in Scipy, where the method is modified to accept Psydac data structures,
scipy/scipy
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
A LinearOperator subclass. Objects of this class are meant to be created using :func:~`solvers.inverse`.
The .dot (and also the .solve) function are based on the
generalized minimal residual algorithm for solving linear system Ax=b.
Implementation from Wikipedia
Parameters:
A (psydac.linalg.basic.LinearOperator) – Left-hand-side matrix A of linear system; individual entries A[i,j]
can’t be accessed, but A has ‘shape’ attribute and provides ‘dot(p)’
function (i.e. matrix-vector product A*p).
x0 (psydac.linalg.basic.Vector) – First guess of solution for iterative solver (optional).
tol (float) – Absolute tolerance for L2-norm of residual r = A*x - b.
maxiter (int) – Maximum number of iterations.
verbose (bool) – If True, L2-norm of residual r is printed at each iteration.
recycle (bool) – Stores a copy of the output in x0 to speed up consecutive calculations of slightly altered linear systems
References
[1] Y. Saad and M.H. Schultz, “GMRES: A generalized minimal residual algorithm for solving nonsymmetric linear systems”, SIAM J. Sci. Stat. Comput., 7:856–869, 1986.
Generalized minimal residual algorithm for solving linear system Ax=b.
Implementation from Wikipedia.
Info can be accessed using get_info(), see :func:~`basic.InverseLinearOperator.get_info`.
Parameters:
b (psydac.linalg.basic.Vector) – Right-hand-side vector of linear system Ax = b. Individual entries b[i] need
not be accessed, but b has ‘shape’ attribute and provides ‘copy()’ and
‘inner(p)’ functions (b.inner(p) is the vector inner product b*p); moreover,
scalar multiplication and sum operations are available.
out (psydac.linalg.basic.Vector | NoneType) – The output vector, or None (optional).
Returns:
x – Numerical solution of the linear system. To check the convergence of the solver,
use the method InverseLinearOperator.get_info().
Return type:
psydac.linalg.basic.Vector
References
[1] Y. Saad and M.H. Schultz, “GMRES: A generalized minimal residual algorithm for solving nonsymmetric linear systems”, SIAM J. Sci. Stat. Comput., 7:856–869, 1986.
The result is written to the Vector out, if provided.
Parameters:
v (Vector) – The vector to which the linear operator (self) is applied. It must
belong to the domain of self.
out (Vector) – The vector in which the result of the operation is stored. It must
belong to the codomain of self. If out is None, a new vector is
created and returned.
Returns:
The result of the operation. If out is None, a new vector is
returned. Otherwise, the result is stored in out and out is
returned.
\[\begin{split}\left( \matrix{
A & \Delta t B \cr
\Delta t C & \\text{Id}
} \\right)
\left( \matrix{
x^{n+1} \cr y^{n+1}
} \\right)
=
\left( \matrix{
A & - \Delta t B \cr
- \Delta t C & \\text{Id}
} \\right)
\left( \matrix{
x^n \cr y^n
} \\right)\end{split}\]
using the Schur complement \(S = A - \Delta t^2 BC\), where Id is the identity matrix
and \((x^n, y^n)\) is given. The solution is given by
\[\begin{split}x^{n+1} = S^{-1} \left[ (A + \Delta t^2 BC) \, x^n - 2 \Delta t B \, y^n \\right] \,.\end{split}\]
Parameters:
A (LinearOperator) – Upper left block from [[A B], [C Id]].
\[\left( \matrix{
A & B^{\top} \cr
B & 0
} \right)
\left( \matrix{
x \cr y
} \right)
=
\left( \matrix{
f \cr 0
} \right)\]
using either the Uzawa iteration \(BA^{-1}B^{\top} y = BA^{-1} f\) or using on of the solvers given in psydac.linalg.solvers. The prefered solver is GMRES.
The decission which variant to use is given by the type of A. If A is of type list of xp.ndarrays or sc.sparse.csr_matrices, then this class uses the Uzawa algorithm.
If A is of type LinearOperator or BlockLinearOperator, a solver is used for the inverse.
Using the Uzawa algorithm, solution is given by:
\[y = \left[ B A^{-1} B^{\top}\right]^{-1} B A^{-1} f \,, \qquad
x = A^{-1} \left[ f - B^{\top} y \right] \,.\]
Parameters:
A (list, LinearOperator or BlockLinearOperator) – Upper left block.
Either the entries on the diagonals of block A are given as list of xp.ndarray or sc.sparse.csr_matrix.
Alternative: Give whole matrice A as LinearOperator or BlockLinearOperator.
list: Uzawa algorithm is used.
LinearOperator: A solver given in psydac.linalg.solvers is used. Specified by solver_name.
BlockLinearOperator: A solver given in psydac.linalg.solvers is used. Specified by solver_name.
B (list, LinearOperator or BlockLinearOperator) – Lower left block.
Uzwaw Algorithm: All entries of block B are given either as list of xp.ndarray or sc.sparse.csr_matrix.
Solver: Give whole B as LinearOperator or BlocklinearOperator
F (list) – Right hand side of the upper block.
Uzawa: Given as list of xp.ndarray or sc.sparse.csr_matrix.
Solver: Given as LinearOperator or BlockLinearOperator
Apre (list) – The non-inverted preconditioner for entries on the diagonals of block A are given as list of xp.ndarray or sc.sparse.csr_matrix. Only required for the Uzawa algorithm.
method_to_solve (str) – Method for the inverses. Choose from ‘DirectNPInverse’, ‘ScipySparse’, ‘InexactNPInverse’ ,’SparseSolver’. Only required for the Uzawa algorithm.
preconditioner (bool) – Wheter to use preconditioners given in Apre or not. Only required for the Uzawa algorithm.
spectralanalysis (bool) – Do the spectralanalyis for the matrices in A and if preconditioner given, compare them to the preconditioned matrices. Only possible if A is given as list.
dimension (str) – Which of the predefined manufactured solutions to use (‘1D’, ‘2D’ or ‘Restelli’)
tol (float) – Convergence tolerance for the potential residual.
max_iter (int) – Maximum number of iterations allowed.
a (array[float]) – The input array (matrix) of shape (4,4) of which the determinant shall be computed.
Returns:
det_a – The determinant of the 3x3 matrix a.
Return type:
float
Matrix-vector product and solvers for matrices with a 3D Kronecker product structure.
M_ijkmno = A_im * B_jn * C_ko
where matrices A, B, C stem from 1D problems.
COMMENT: the reshape of a matrix can be viewed as ravel+reshape.
Let r = (r_ijk) be a 3D matrix of size M*N*O.
ravel(r) = [r_111, r112, … , r_MNO] (row major always –> last index runs fastest)
reshape(ravel(r), (M, N*O)) = [[r_111, r112, … , r_1NO],
implemented as three matrix-matrix solve with intermediate reshape and transpose.
step1(r1*r2,r0) <= ( A(r0,r0)^-1 * reshaped_rhs(r0,r1*r2) )^T
step2(r2*r0,r1) <= ( B(r1,r1)^-1 * reshaped_step1(r1,r2*r0) )^T
step3(r0*r1*r2) <= ( C(r2,r2)^-1 * reshaped_step2(r2,r0*r1) )^T
res <= reshaped_step3(r0,r1,r2)
no overhead of numpy reshape command, as they do NOT copy the data.
COMMENT: the reshape of a matrix can be viewed as ravel+reshape.
Let r = (r_ijk) be a 3D matrix of size M*N*O.
ravel(r) = [r_111, r112, … , r_MNO] (row major always –> last index runs fastest)
reshape(ravel(r), (M, N*O)) = [[r_111, r112, … , r_1NO],