Advanced Multi-Physics (AMP)
On-Line Documentation
PetscKrylovSolver.h
Go to the documentation of this file.
1#ifndef included_AMP_PetscKrylovSolver
2#define included_AMP_PetscKrylovSolver
3
4#include "AMP/solvers/SolverStrategy.h"
5#include "AMP/solvers/petsc/PetscMonitor.h"
6#include "AMP/utils/AMP_MPI.h"
7#include "AMP/vectors/petsc/PetscHelpers.h"
8
9
10// Forward declare a few types for PETSc
11typedef int PetscErrorCode;
12typedef struct _p_SNES *SNES;
13typedef struct _p_KSP *KSP;
14typedef struct _p_PC *PC;
15
16
17namespace AMP::Solver {
18
26{
27public:
32
81 explicit PetscKrylovSolver( std::shared_ptr<SolverStrategyParameters> parameters );
82
87
88 std::string type() const override { return "PetscKrylovSolver"; }
89
91 static std::unique_ptr<SolverStrategy>
92 createSolver( std::shared_ptr<SolverStrategyParameters> solverStrategyParameters )
93 {
94 return std::make_unique<PetscKrylovSolver>( solverStrategyParameters );
95 }
96
102 void apply( std::shared_ptr<const AMP::LinearAlgebra::Vector> f,
103 std::shared_ptr<AMP::LinearAlgebra::Vector> u ) override;
104
105 void reset( std::shared_ptr<AMP::Solver::SolverStrategyParameters> ) override;
106
110 inline KSP getKrylovSolver( void ) { return d_KrylovSolver; }
111
117
122 void initialize( std::shared_ptr<const SolverStrategyParameters> parameters ) override;
123
128 void registerOperator( std::shared_ptr<AMP::Operator::Operator> op ) override;
129
134 void
135 resetOperator( std::shared_ptr<const AMP::Operator::OperatorParameters> parameters ) override;
136
138
139 void setZeroInitialGuess( bool use_zero_guess ) override;
140
141protected:
142 void getFromInput( std::shared_ptr<AMP::Database> db );
143 void initializePreconditioner( std::shared_ptr<const SolverStrategyParameters> parameters );
144 std::shared_ptr<AMP::Operator::Operator> createPCOperator();
145 void setupPetscMatInterface( std::shared_ptr<AMP::Operator::Operator> op, Mat &mat );
146
147private:
148 // static functions to interface with PETSc
149 // the signatures of these functions currently vary depending on whether the dev or release
150 // release version of PETSc is being used
151
154 static PetscErrorCode matVec( Mat mat, Vec x, Vec y );
155
157
158 std::string d_sKspType;
159
161
163
165 bool d_bMatrixFree = false;
166
167 std::string d_sPcType;
169
170 std::string d_PcSide;
171
172 // FGMRES specific options
175
176 std::shared_ptr<PetscMonitor> d_PetscMonitor;
177
179
181};
182} // namespace AMP::Solver
183
184#endif
struct _p_Mat * Mat
struct _p_PC * PC
struct _p_SNES * SNES
struct _p_KSP * KSP
int PetscErrorCode
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
void getFromInput(std::shared_ptr< AMP::Database > db)
static PetscErrorCode matVec(Mat mat, Vec x, Vec y)
PetscKrylovSolver(std::shared_ptr< SolverStrategyParameters > parameters)
std::shared_ptr< PetscMonitor > d_PetscMonitor
void registerOperator(std::shared_ptr< AMP::Operator::Operator > op) override
void initializePreconditioner(std::shared_ptr< const SolverStrategyParameters > parameters)
static PetscErrorCode setupPreconditioner(PC pc)
void resetOperator(std::shared_ptr< const AMP::Operator::OperatorParameters > parameters) override
void initialize(std::shared_ptr< const SolverStrategyParameters > parameters) override
void setZeroInitialGuess(bool use_zero_guess) override
void setupPetscMatInterface(std::shared_ptr< AMP::Operator::Operator > op, Mat &mat)
static PetscErrorCode applyPreconditioner(PC pc, Vec r, Vec z)
static std::unique_ptr< SolverStrategy > createSolver(std::shared_ptr< SolverStrategyParameters > solverStrategyParameters)
static create routine that is used by SolverFactory
void apply(std::shared_ptr< const AMP::LinearAlgebra::Vector > f, std::shared_ptr< AMP::LinearAlgebra::Vector > u) override
void reset(std::shared_ptr< AMP::Solver::SolverStrategyParameters >) override
std::string type() const override
Return the name of the solver.
std::shared_ptr< AMP::Operator::Operator > createPCOperator()
std::shared_ptr< AMP::Solver::SolverStrategy > shared_ptr
PETSc vector.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page