KrylovSolver

class KrylovSolver : public godzilla::PetscObjectWrapper<KSP>

Wrapper around KSP.

Public Functions

KrylovSolver()

Construct empty Krylov solver.

explicit KrylovSolver(KSP ksp)

Construct a Krylov solver from a PETSc KSP object.

void create(MPI_Comm comm)

Create a solver.

void destroy()

Destroy the solver.

void set_dm(DM dm)

Sets the DM that may be used by some preconditioners and that may be used to construct the linear system.

Parameters:

dm – The DM

void set_operators(const Matrix &A, const Matrix &B) const

Sets the matrix associated with the linear system and a different one from which the preconditioner will be built.

Parameters:
  • A – The matrix that defines the linear system

  • B – The matrix to be used in constructing the preconditioner

void set_operator(const Matrix &A) const

Sets the matrix associated with the linear system.

Parameters:

A – The matrix that defines the linear system

Matrix get_operator() const

Gets the matrix associated with the linear system.

Returns:

The matrix associated with the linear system

std::tuple<Matrix, Matrix> get_operators() const

Gets the matrix associated with the linear system and a (possibly) different one used to construct the preconditioner.

Returns:

A tuple containing the matrix associated with the linear system and the matrix used to construct the preconditioner

void set_from_options()

Sets KSP options from the options database.

void set_tolerances(Real rel_tol, Real abs_tol, Real div_tol, Int max_its)

Sets the relative, absolute, divergence, and maximum iteration tolerances used by the default convergence testers.

Parameters:
  • rel_tol – The relative convergence tolerance, relative decrease in the (possibly preconditioned) residual norm

  • abs_tol – The absolute convergence tolerance absolute size of the (possibly preconditioned) residual norm

  • div_tol – The divergence tolerance, amount (possibly preconditioned) residual norm can increase before KSPConvergedDefault concludes that the method is diverging

  • max_its – Maximum number of iterations to use

void get_tolerances(Real *rel_tol, Real *abs_tol, Real *div_tol, Int *max_its) const

Gets the relative, absolute, divergence, and maximum iteration tolerances used by the default KSP convergence tests.

Parameters:
  • rel_tol – The relative convergence tolerance

  • abs_tol – The absolute convergence tolerance

  • div_tol – The divergence tolerance

  • max_its – The maximum number of iterations

Vector get_rhs() const

Gets the right-hand-side vector for the linear system to be solved.

Returns:

The right-hand-side vector

std::tuple<Real, Real, Real, Int> get_tolerances() const

Gets the relative, absolute, divergence, and maximum iteration tolerances used by the default KSP convergence tests.

Returns:

A tuple containing the relative, absolute, divergence, and maximum number of iterations

template<class T>
inline void set_compute_rhs(Ref<T> instance, void (T::* method)(Vector&))

Set member function to compute the right hand side of the linear system.

Template Parameters:

T – C++ class type

Parameters:
  • instance – Instance of class T

  • method – Member function in class T

template<class T>
inline void set_compute_operators(Ref<T> instance, void (T::* method)(Matrix&, Matrix&))

Set member function to compute operators of the linear system.

Template Parameters:

T – C++ class type

Parameters:
  • instance – Instance of class T

  • method – Member function in class T

template<class T>
inline void monitor_set(Ref<T> instance, void (T::* method)(Int, Real))

Sets an additional member function to be called at every iteration to monitor the residual/error etc.

Template Parameters:

T – C++ class type

Parameters:
  • instance – Instance of class T

  • method – Member function in class T

void solve(const Vector &b, Vector &x) const

Solve a linear system.

Parameters:
  • b – The right-hand-side vector

  • x – The solution

void solve(Vector &x) const

Solve a linear system.

Parameters:

x – The right-hand-side, after the solve it will contain the solution

ConvergedReason get_converged_reason() const

Gets the reason the KSP iteration was stopped.

Returns:

template<class PCTYPE>
inline PCTYPE set_pc_type() const

Set preconditioner type.

Template Parameters:

PCTYPE – C++ class of a Preconditioner type

Returns:

Preconditioner class

void set_pc_side(PCSide side)

Sets the preconditioning side.

Parameters:

side – The preconditioning side, where side is one of PC_LEFT, PC_RIGHT, PC_SYMMETRIC

void set_initial_guess_nonzero(bool flag)

Tells the iterative solver that the initial guess is nonzero; otherwise KSP assumes the initial guess is to be zero (and thus zeros it out before solving).

Parameters:

flagtrue indicates the guess is non-zero, false indicates the guess is zero

void set_up()

Sets up the internal data structures for the later use of an iterative solver.

void set_type(const char *type)

Builds the KSP data structure for a particular KSPType.

Parameters:

type – A krylov method

void set_type(String type)

Builds the KSP data structure for a particular KSPType.

Parameters:

type – A krylov method

void view(PetscViewer viewer = PETSC_VIEWER_STDOUT_WORLD) const

View the KSP object.

Parameters:

viewer – PETSc viewer