-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up linear solvers, add StencilDiagonalMatrix
and diagonal()
, require pc to be LinearOperator
#360
Conversation
The option `pc` must now take as value a `LinearOperator`, which is the preconditioner. If `pc=None`, an `IdentityOperator` of the domain space is created automatically. The class `InverseLinearOperators` could be deprecated, since the Jacobi preconditiner should be implemented as a `LinearOperator`. The new solver `PBiConjugateGradientStabilized` (preconditioned) has been added from Struphy. `test_solvers.py` has been updated. The Jacobi preconditioner is not tested at the moment.
…e base class `InverseLinearOperator`. All solvers call now `super().__init__` which takes the base arguments for any iterative solver. Additional arguments must be checked in the individual solvers. The base class now has the setter method for `linop`, which allows to change tha matrix A of the solver. Moreover, there is the abstract property `solver` which is the name string of the solver.
InverseLinearOperator
InverseLinearOperator
, require pc to be LinearOperator
InverseLinearOperator
, require pc to be LinearOperator
StencilDiagonalMatrix
and diagonal()
, require pc to be LinearOperator
The text clarifies that replacing the original linear operator through the setter is a dangerous operation which should only be made in extreme cases.
The In the case of solvers like GMRES, we could easily pass a (left) preconditioner |
AFAIK this was the original behavior prior to this PR. I suggest to defer any further improvements or fixes to a future PR. Please feel free to open new issues. |
Fix regression bug in file `psydac/examples/maxwell_2d_multi_patch.py`: Pass a `LinearOperator` object as preconditioner to the PCG solver, instead of just a string with the method name 'jacobi' (which is not possible since PR #360). To achieve this we follow the approach in `psydac/api/tests/test_2d_multipatch_mapping_maxwell.py`: 1. Assemble the linear system explicitly; 2. Extract the diagonal linear operator from the matrix; 3. Pass the linear operator above as preconditioner to the solver.
Reduce code duplication in the linear solvers by adding the method
__init__
to the common base classInverseLinearOperator
. Add new classStencilDiagonalMatrix
to be used in combination with the new methoddiagonal
ofStencilMatrix
andBlockLinearOperator
-- this fixes #369. Require all preconditioners to beLinearOperator
objects -- this fixes #343.Detailed list of changes
All solvers are sub-classes of
InverseLinearOperator
. As such, they now call nowsuper().__init__
which takes the base arguments for any iterative solver. The method_check_options
is moved to the base class and checks the common parametersx0
,tol
,maxiter
andverbose
. Additional arguments must be checked in the individual solvers.The methods
get_options
,set_options
andtranspose
are also moved to the base class. In particularget_options
has been improved as it accepts now a specific option name. The propertyoptions
has been removed because unsafe (it gave direct access to the underlying dictionary without performing any check). The methodset_options
must be used instead.The base class now has a setter method for
linop
, which allows to change the matrix A of the solver.Moreover, changed the handling of preconditioners in
InverseLinearOperator
s. The optionpc
must now take as value aLinearOperator
, which is the preconditioner. Ifpc=None
, anIdentityOperator
of the domain space is created automatically.The new class
StencilDiagonalMatrix
has been added. This represents a linear operator acting between twoStencilVectorSpace
s, and which corresponds to a diagonal matrix. This linear operator is completely local.The method
diagonal
has been added to the classesStencilDiagonalMatrix
andBlockLinearOperator
(for which it returns an object of the same class), and to the classStencilMatrix
(for which it returns aStencilDiagonalMatrix
object). As well as anout
optional argument, this method accepts theinverse
boolean flag which is useful for creating a Jacobi preconditioner.The new solver
PBiConjugateGradientStabilized
(preconditioned BiCGSTAB) has been added from Struphy (does not work for complex).test_solvers.py
has been updated, as well as several API unit tests.Notes
When passing a preconditioner to
DiscreteEquation.set_solver()
, this also has to be aLinearOperator
now. This means that in the case of a Jacobi preconditioner one needs first to assemble the linear system, then extract its diagonal, and finally pass the newLinearOperator
as thepc
solver option.