23 #ifndef __DOLFIN_PETSC_KRYLOV_SOLVER_H 24 #define __DOLFIN_PETSC_KRYLOV_SOLVER_H 32 #include <dolfin/common/types.h> 33 #include "GenericLinearSolver.h" 34 #include "PETScObject.h" 42 class PETScBaseMatrix;
45 class PETScPreconditioner;
46 class PETScSNESSolver;
47 class VectorSpaceBasis;
49 class PETScDMCollection;
62 enum class norm_type {none, default_norm, preconditioned, unpreconditioned, natural};
67 std::string method=
"default",
68 std::string preconditioner=
"default");
73 std::string preconditioner=
"default");
79 std::shared_ptr<PETScPreconditioner> preconditioner);
84 std::shared_ptr<PETScPreconditioner> preconditioner);
93 void set_operator(std::shared_ptr<const GenericLinearOperator> A);
100 void set_operators(std::shared_ptr<const GenericLinearOperator> A,
101 std::shared_ptr<const GenericLinearOperator> P);
119 bool transpose=
false);
137 void set_tolerances(
double relative,
double absolute,
double diverged,
148 void monitor(
bool monitor_convergence);
162 std::string
str(
bool verbose)
const;
171 static std::map<std::string, std::string>
methods();
181 {
return "krylov_solver"; }
202 void write_report(
int num_iterations, KSPConvergedReason reason);
208 static const std::map<std::string, const KSPType> _methods;
211 static const std::map<std::string, std::string> _methods_descr;
217 std::shared_ptr<PETScPreconditioner> _preconditioner;
219 bool preconditioner_set;
std::string get_options_prefix() const
Definition: PETScKrylovSolver.cpp:520
std::size_t solve(GenericVector &x, const GenericVector &b)
Solve linear system Ax = b and return number of iterations.
Definition: PETScKrylovSolver.cpp:220
Definition: PETScVector.h:60
void set_norm_type(norm_type type)
Definition: PETScKrylovSolver.cpp:416
static std::map< std::string, std::string > preconditioners()
Return a list of available named preconditioners.
Definition: PETScKrylovSolver.cpp:75
void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set operator (matrix) and preconditioner matrix.
Definition: PETScKrylovSolver.cpp:200
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: PETScKrylovSolver.cpp:536
PETScKrylovSolver(MPI_Comm comm, std::string method="default", std::string preconditioner="default")
Definition: PETScKrylovSolver.cpp:92
Definition: PETScKrylovSolver.h:54
Definition: PETScTAOSolver.h:51
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: PETScKrylovSolver.cpp:553
void monitor(bool monitor_convergence)
Monitor residual at each iteration.
Definition: PETScKrylovSolver.cpp:489
Definition: GenericLinearOperator.h:42
KSP ksp() const
Return PETSc KSP pointer.
Definition: PETScKrylovSolver.cpp:561
double norm(const GenericVector &x, std::string norm_type="l2")
Definition: solve.cpp:173
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition: PETScKrylovSolver.cpp:70
void set_options_prefix(std::string options_prefix)
Definition: PETScKrylovSolver.cpp:512
void set_dm(DM dm)
Set the DM.
Definition: PETScKrylovSolver.cpp:446
virtual ~PETScKrylovSolver()
Destructor.
Definition: PETScKrylovSolver.cpp:181
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: PETScKrylovSolver.h:180
Definition: Parameters.h:94
Definition: PETScSNESSolver.h:45
norm_type get_norm_type() const
Get norm type used in convergence testing.
Definition: PETScKrylovSolver.cpp:461
void set_from_options() const
Set options from PETSc options database.
Definition: PETScKrylovSolver.cpp:529
Definition: PETScBaseMatrix.h:49
void set_tolerances(double relative, double absolute, double diverged, int max_iter)
Definition: PETScKrylovSolver.cpp:407
void set_nonzero_guess(bool nonzero_guess)
Definition: PETScKrylovSolver.cpp:391
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set operator (matrix)
Definition: PETScKrylovSolver.cpp:190
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
Definition: PETScObject.h:33
static Parameters default_parameters()
Default parameter values.
Definition: PETScKrylovSolver.cpp:80
This class defines a common interface for vectors.
Definition: GenericVector.h:47
norm_type
Definition: PETScKrylovSolver.h:62
void set_dm_active(bool val)
Activate/deactivate DM.
Definition: PETScKrylovSolver.cpp:452
void set_reuse_preconditioner(bool reuse_pc)
Definition: PETScKrylovSolver.cpp:399