1#ifndef included_AMP_PetscSNESSolver
2#define included_AMP_PetscSNESSolver
4#include "AMP/solvers/SolverStrategy.h"
5#include "AMP/solvers/SolverStrategyParameters.h"
6#include "AMP/solvers/petsc/PetscKrylovSolver.h"
7#include "AMP/solvers/petsc/PetscMonitor.h"
8#include "AMP/utils/AMP_MPI.h"
9#include "AMP/vectors/petsc/PetscHelpers.h"
13#ifdef MPICH_SKIP_MPICXX
14 #define _FIX_FOR_PETSC_MPI_CXX
15 #undef MPICH_SKIP_MPICXX
18#ifdef OMPI_SKIP_MPICXX
19 #define _FIX_FOR_PETSC_OMPI_CXX
20 #undef OMPI_SKIP_MPICXX
23#undef PETSC_VERSION_DATE_GIT
24#undef PETSC_VERSION_GIT
29#ifdef _FIX_FOR_PETSC_OMPI_CXX
30 #ifndef OMPI_SKIP_MPICXX
31 #define OMPI_SKIP_MPICXX
35#ifdef _FIX_FOR_PETSC_MPI_CXX
36 #ifndef MPICH_SKIP_MPICXX
37 #define MPICH_SKIP_MPICXX
109 std::string
type()
const override {
return "PetscSNESSolver"; }
112 static std::unique_ptr<SolverStrategy>
123 void apply( std::shared_ptr<const AMP::LinearAlgebra::Vector> f,
124 std::shared_ptr<AMP::LinearAlgebra::Vector>
u )
override;
179 std::shared_ptr<AMP::LinearAlgebra::Vector>,
182 std::function<
int( std::shared_ptr<AMP::LinearAlgebra::Vector>,
183 std::shared_ptr<AMP::LinearAlgebra::Vector>,
191 void reset( std::shared_ptr<AMP::Solver::SolverStrategyParameters> )
override;
202 std::shared_ptr<SolverStrategy>
207 void preApply( std::shared_ptr<const AMP::LinearAlgebra::Vector>
v );
216 std::shared_ptr<AMP::LinearAlgebra::Vector> y,
239 std::function<
int( std::shared_ptr<AMP::LinearAlgebra::Vector>,
240 std::shared_ptr<AMP::LinearAlgebra::Vector>,
Provides C++ wrapper around MPI routines.
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
void setConvergenceStatus(void)
virtual ~PetscSNESSolver()
double d_dInitialForcingTerm
std::shared_ptr< SolverStrategy > getNestedSolver(void) override
bool d_bPetscInterfaceInitialized
std::shared_ptr< PetscMonitor > d_PetscMonitor
std::shared_ptr< AMP::LinearAlgebra::Vector > getScratchVector(void)
double d_dEWSafeguardDisableThreshold
int getNumberOfLineSearchPreCheckAttempts(void)
int d_iForcingTermFlag
string is for input
void setInitialGuess(std::shared_ptr< AMP::LinearAlgebra::Vector > initialGuess) override
void apply(std::shared_ptr< const AMP::LinearAlgebra::Vector > f, std::shared_ptr< AMP::LinearAlgebra::Vector > u) override
std::vector< int > d_iLinearIterationHistory
keeps track of linear iteration statistics over solver lifetime
static PetscErrorCode applyPreconditioner(PC pc, Vec xin, Vec xout)
int d_iNumberOfLineSearchPreCheckAttempts
void createPetscObjects(std::shared_ptr< const SolverStrategyParameters > params)
int d_iMaximumFunctionEvals
static PetscErrorCode mffdCheckBounds(void *checkctx, Vec U, Vec a, PetscScalar *h)
double d_dMaximumForcingTerm
double d_dConstantForcingTerm
int is for passing choice to PETSc
static PetscErrorCode wrapperLineSearchPreCheck(SNESLineSearch snes, Vec x, Vec y, PetscBool *changed_y, void *ctx)
static PetscErrorCode KSPPostSolve_SNESEW(KSP ksp, Vec b, Vec x, SNES snes)
void printConvergenceStatus(SolverStrategy::SolverStatus status, std::ostream &os=AMP::pout) const override
static PetscErrorCode setJacobian(SNES, Vec x, Mat A, Mat, void *ctx)
void reset(std::shared_ptr< AMP::Solver::SolverStrategyParameters >) override
pointer to line search function
bool d_bDestroyCachedVecs
void getFromInput(std::shared_ptr< const AMP::Database > db)
std::function< int(std::shared_ptr< AMP::LinearAlgebra::Vector >, std::shared_ptr< AMP::LinearAlgebra::Vector >, bool &)> d_lineSearchPreCheckPtr
PetscSNESSolver(std::shared_ptr< SolverStrategyParameters > parameters)
static PetscErrorCode setupPreconditioner(PC pc)
std::string type() const override
Return the name of the solver.
std::shared_ptr< PetscKrylovSolver > getKrylovSolver(void)
void setLineSearchPreCheck(std::function< int(std::shared_ptr< AMP::LinearAlgebra::Vector >, std::shared_ptr< AMP::LinearAlgebra::Vector >, bool &)> lineSearchPreCheckPtr)
set the pointer to the user function that does the line search pre-check if provided
int getTotalNumberOfLinearIterations(void) const
std::shared_ptr< AMP::LinearAlgebra::Vector > d_pSolutionVector
void resetPetscObjects(std::shared_ptr< AMP::Solver::SolverStrategyParameters > params)
void initializePetscObjects(void)
static bool isVectorValid(std::shared_ptr< AMP::Operator::Operator > &op, AMP::LinearAlgebra::Vector::shared_ptr &v, const AMP_MPI &comm)
bool d_bPrintNonlinearResiduals
std::shared_ptr< AMP::LinearAlgebra::Vector > d_pScratchVector
std::string d_SNESAppendOptionsPrefix
int defaultLineSearchPreCheck(std::shared_ptr< AMP::LinearAlgebra::Vector > x, std::shared_ptr< AMP::LinearAlgebra::Vector > y, bool &changed_y)
bool getUsesJacobian(void)
double d_dEWSafeguardExponent
bool d_bPrintLinearResiduals
std::shared_ptr< SolverStrategy > createPreconditioner(std::shared_ptr< AMP::Database > pc_solver_db)
static PetscErrorCode apply(SNES snes, Vec x, Vec f, void *ctx)
std::shared_ptr< AMP::LinearAlgebra::Vector > d_pResidualVector
static PetscErrorCode KSPPreSolve_SNESEW(KSP ksp, Vec b, Vec x, SNES snes)
double d_dMFFDFunctionDifferencingError
std::string d_sForcingTermStrategy
std::shared_ptr< PetscKrylovSolver > d_pKrylovSolver
int d_operatorComponentToEnableBoundsCheck
std::function< int(std::shared_ptr< AMP::LinearAlgebra::Vector >, std::shared_ptr< AMP::LinearAlgebra::Vector >, bool &)> getLineSearchPreCheckAdaptor()
std::string d_sMFFDDifferencingStrategy
static std::unique_ptr< SolverStrategy > createSolver(std::shared_ptr< SolverStrategyParameters > solverStrategyParameters)
static create routine that is used by SolverFactory
std::shared_ptr< AMP::LinearAlgebra::Vector > getSolution(void)
void destroyPetscObjects(void)
bool d_bEnableMFFDBoundsCheck
SNESConvergedReason d_SNES_completion_code
bool d_bEnableLineSearchPreCheck
void preApply(std::shared_ptr< const AMP::LinearAlgebra::Vector > v)
int getBoundsCheckComponent(void)
std::shared_ptr< AMP::Solver::SolverStrategy > shared_ptr
#define AMP_ASSERT(EXP)
Assert error.