OGS
PETScLinearSolver.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <petscksp.h>
20
21#include <algorithm>
22#include <array>
23#include <string>
24
25#include "PETScMatrix.h"
26#include "PETScVector.h"
27
28namespace MathLib
29{
38{
39public:
49 PETScLinearSolver(std::string const& prefix,
50 std::string const& petsc_options);
51
52 ~PETScLinearSolver() { KSPDestroy(&solver_); }
53 // TODO check if some args in LinearSolver interface can be made const&.
55
57 PetscInt getNumberOfIterations() const
58 {
59 PetscInt its = 0;
60 KSPGetIterationNumber(solver_, &its);
61 return its;
62 }
63
65 double getElapsedTime() const { return elapsed_ctime_; }
66
69
70private:
71 bool canSolverHandleRectangular(std::string_view ksp_type)
72 {
73 // List of KSP types that can handle rectangular matrices
74 constexpr auto rectangular_solvers = std::to_array<std::string_view>(
75 {KSPGMRES, KSPFGMRES, KSPBCGS, KSPBCGSL, KSPTFQMR, KSPCGS});
76
77 return std::ranges::any_of(rectangular_solvers,
78 [&](const auto& solver)
79 { return solver == ksp_type; });
80 }
81
82 KSP solver_;
83 PC pc_;
84
86
87 double elapsed_ctime_ = 0.0;
88};
89
90} // namespace MathLib
Declaration of class PETScMatrix, which provides an interface to PETSc matrix routines.
Declaration of class PETScVector, which provides an interface to PETSc vector routines.
double elapsed_ctime_
Clock time.
PETScLinearSolver(std::string const &prefix, std::string const &petsc_options)
PetscInt getNumberOfIterations() const
Get number of iterations.
PC pc_
Preconditioner type.
bool solve(PETScMatrix &A, PETScVector &b, PETScVector &x)
double getElapsedTime() const
Get elapsed wall clock time.
bool canSolverHandleRectangular(std::string_view ksp_type)
bool canSolveRectangular() const
Get, if the solver can handle rectangular equation systems.
Wrapper class for PETSc matrix routines for matrix.
Definition PETScMatrix.h:32
Wrapper class for PETSc vector.
Definition PETScVector.h:40