1#ifndef included_AMP_SolverStrategy
2#define included_AMP_SolverStrategy
4#include "AMP/operators/Operator.h"
5#include "AMP/solvers/SolverStrategyParameters.h"
6#include "AMP/utils/Backend.h"
7#include "AMP/utils/Memory.h"
8#include "AMP/vectors/Vector.h"
30 typedef std::shared_ptr<AMP::Solver::SolverStrategy>
shared_ptr;
52 explicit SolverStrategy( std::shared_ptr<const SolverStrategyParameters> parameters );
60 virtual std::string
type()
const = 0;
79 return "ConvergedOnAbsTol";
81 return "ConvergedOnRelTol";
83 return "ConvergedUserCondition";
85 return "MaxIterations";
87 return "DivergedLineSearch";
89 return "DivergedStepSize";
91 return "DivergedFunctionCount";
93 return "DivergedOnNan";
95 return "DivergedNestedSolver";
97 return "DivergedOther";
107 virtual void apply( std::shared_ptr<const AMP::LinearAlgebra::Vector> f,
108 std::shared_ptr<AMP::LinearAlgebra::Vector>
u ) = 0;
115 virtual void initialize( std::shared_ptr<const SolverStrategyParameters> parameters );
194 resetOperator( std::shared_ptr<const AMP::Operator::OperatorParameters> parameters );
201 virtual void reset( std::shared_ptr<SolverStrategyParameters> parameters );
206 virtual std::shared_ptr<AMP::Operator::Operator>
getOperator(
void );
222 os <<
"Not implemented for this solver!" << std::endl;
237 virtual void print( std::ostream & ) {}
247 virtual void residual( std::shared_ptr<const AMP::LinearAlgebra::Vector> f,
248 std::shared_ptr<const AMP::LinearAlgebra::Vector>
u,
249 std::shared_ptr<AMP::LinearAlgebra::Vector> r );
260 std::shared_ptr<AMP::LinearAlgebra::Vector> f )
304 std::shared_ptr<AMP::Database>
d_db =
nullptr;
321 std::shared_ptr<AMP::IO::Writer>
d_writer =
nullptr;
Scalar is a class used to store a scalar variable that may be different types/precision.
AMP::Scalar d_dAbsoluteTolerance
bool d_bUseZeroInitialGuess
virtual void initialize(std::shared_ptr< const SolverStrategyParameters > parameters)
void setComponentScalings(std::shared_ptr< AMP::LinearAlgebra::Vector > s, std::shared_ptr< AMP::LinearAlgebra::Vector > f)
for multiphysics problems it may be necessary to scale the solution
int getMaxIterations(void) const
AMP::Scalar getRelativeTolerance() const
virtual void printConvergenceStatus(SolverStrategy::SolverStatus, std::ostream &=AMP::pout) const
AMP::Scalar getAbsoluteTolerance() const
static std::string statusToString(SolverStatus status)
AMP::Utilities::ExecutionSpace d_exec_space
execution space for the solver
std::shared_ptr< AMP::IO::Writer > d_writer
virtual void setMaxIterations(const int max_iterations)
void setIsNestedSolver(bool is_nested)
Tell a solver that it is nested inside some outer solver.
std::shared_ptr< AMP::LinearAlgebra::Vector > d_pSolutionScaling
virtual void setNestedSolver(std::shared_ptr< SolverStrategy > solver)
std::vector< int > d_iterationHistory
keeps track of iteration statistics over solver lifetime
AMP::Utilities::MemoryType d_memory_location
memory storage address space
virtual void setRelativeTolerance(AMP::Scalar rel_tol)
virtual void setZeroInitialGuess(bool use_zero_guess)
virtual bool checkStoppingCriteria(AMP::Scalar res_norm, bool check_iters=true)
std::shared_ptr< AMP::LinearAlgebra::Vector > getSolutionScaling()
virtual void registerWriter(std::shared_ptr< AMP::IO::Writer > writer)
Registers a writer with the solver.
std::shared_ptr< AMP::Solver::SolverStrategy > d_pNestedSolver
nested solver used by this solver
virtual void setDebugPrintInfoLevel(int print_level)
SolverStrategy(std::shared_ptr< const SolverStrategyParameters > parameters)
std::shared_ptr< AMP::LinearAlgebra::Vector > getFunctionScaling()
std::shared_ptr< AMP::LinearAlgebra::Vector > d_pFunctionScaling
AMP::Scalar d_dResidualNorm
void setExecutionSpace(AMP::Utilities::ExecutionSpace space)
virtual void print(std::ostream &)
virtual void setAbsoluteTolerance(AMP::Scalar abs_tol)
std::shared_ptr< AMP::Solver::SolverStrategy > shared_ptr
virtual void reset(std::shared_ptr< SolverStrategyParameters > parameters)
virtual const std::vector< int > & getIterationHistory(void)
virtual void printStatistics(std::ostream &os=AMP::pout)
std::shared_ptr< AMP::Database > d_db
virtual std::shared_ptr< SolverStrategy > getNestedSolver(void)
virtual std::shared_ptr< AMP::Operator::Operator > getOperator(void)
virtual ~SolverStrategy()
virtual void resetOperator(std::shared_ptr< const AMP::Operator::OperatorParameters > parameters)
std::shared_ptr< AMP::Database > d_global_db
std::shared_ptr< AMP::Operator::Operator > d_pOperator
int d_iDebugPrintInfoLevel
virtual void apply(std::shared_ptr< const AMP::LinearAlgebra::Vector > f, std::shared_ptr< AMP::LinearAlgebra::Vector > u)=0
SolverStatus getConvergenceStatus(void) const
bool getConverged(void) const
int getTotalNumberOfIterations(void)
AMP::Scalar d_dRelativeTolerance
AMP::Utilities::ExecutionSpace getExecutionSpace() const
virtual void setInitialGuess(std::shared_ptr< AMP::LinearAlgebra::Vector > initialGuess)
virtual void registerOperator(std::shared_ptr< AMP::Operator::Operator > op)
SolverStatus d_ConvergenceStatus
AMP::Scalar d_dInitialResidual
virtual void residual(std::shared_ptr< const AMP::LinearAlgebra::Vector > f, std::shared_ptr< const AMP::LinearAlgebra::Vector > u, std::shared_ptr< AMP::LinearAlgebra::Vector > r)
virtual AMP::Scalar getResidualNorm(void) const
virtual std::string type() const =0
Return the name of the solver.
virtual int getIterations(void) const
virtual AMP::Scalar getInitialResidual(void) const
std::string getConvergenceStatusString(void) const
void getBaseFromInput(std::shared_ptr< AMP::Database > db)
int getDebugPrintInfoLevel(void)
MemoryType
Enum to store pointer type.