Advanced Multi-Physics (AMP)
On-Line Documentation
SolverStrategy.h
Go to the documentation of this file.
1#ifndef included_AMP_SolverStrategy
2#define included_AMP_SolverStrategy
3
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"
9
10#include <memory>
11
12
13// Declare some classes
14namespace AMP::IO {
15class Writer;
16} // namespace AMP::IO
17
18
19namespace AMP::Solver {
20
28{
29public:
30 typedef std::shared_ptr<AMP::Solver::SolverStrategy> shared_ptr;
31
36
52 explicit SolverStrategy( std::shared_ptr<const SolverStrategyParameters> parameters );
53
57 virtual ~SolverStrategy();
58
60 virtual std::string type() const = 0;
61
74
75 static std::string statusToString( SolverStatus status )
76 {
77 switch ( status ) {
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";
96 default:
97 return "DivergedOther";
98 }
99 }
100
107 virtual void apply( std::shared_ptr<const AMP::LinearAlgebra::Vector> f,
108 std::shared_ptr<AMP::LinearAlgebra::Vector> u ) = 0;
109
115 virtual void initialize( std::shared_ptr<const SolverStrategyParameters> parameters );
116
123 virtual void setInitialGuess( std::shared_ptr<AMP::LinearAlgebra::Vector> initialGuess );
124
133
138
142 virtual int getIterations( void ) const { return ( d_iNumberIterations ); }
143
154
159 virtual void setNestedSolver( std::shared_ptr<SolverStrategy> solver )
160 {
162 d_pNestedSolver->setIsNestedSolver( true );
163 }
164
167
172 virtual std::shared_ptr<SolverStrategy> getNestedSolver( void ) { return d_pNestedSolver; }
173
178 virtual void registerOperator( std::shared_ptr<AMP::Operator::Operator> op );
179
186 virtual void registerWriter( std::shared_ptr<AMP::IO::Writer> writer ) { d_writer = writer; }
187
193 virtual void
194 resetOperator( std::shared_ptr<const AMP::Operator::OperatorParameters> parameters );
195
201 virtual void reset( std::shared_ptr<SolverStrategyParameters> parameters );
202
206 virtual std::shared_ptr<AMP::Operator::Operator> getOperator( void );
207
209
211
213
215
217
218 int getMaxIterations( void ) const { return d_iMaxIterations; }
219
220 virtual void printStatistics( std::ostream &os = AMP::pout )
221 {
222 os << "Not implemented for this solver!" << std::endl;
223 }
224
225 bool getConverged( void ) const
226 {
228 }
229
231
232 std::string getConvergenceStatusString( void ) const
233 {
235 }
236
237 virtual void print( std::ostream & ) {}
238
239 virtual AMP::Scalar getResidualNorm( void ) const { return d_dResidualNorm; }
240
241 virtual AMP::Scalar getInitialResidual( void ) const { return d_dInitialResidual; }
242
243 virtual const std::vector<int> &getIterationHistory( void ) { return d_iterationHistory; }
244
246
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 );
250
252 std::ostream & = AMP::pout ) const
253 {
254 }
255
257 // and nonlinear function for correct solution.
258 // The first vector is for solution scaling, the second for function
259 void setComponentScalings( std::shared_ptr<AMP::LinearAlgebra::Vector> s,
260 std::shared_ptr<AMP::LinearAlgebra::Vector> f )
261 {
264 }
265
266 std::shared_ptr<AMP::LinearAlgebra::Vector> getSolutionScaling() { return d_pSolutionScaling; }
267 std::shared_ptr<AMP::LinearAlgebra::Vector> getFunctionScaling() { return d_pFunctionScaling; }
268
271
272protected:
273 void getBaseFromInput( std::shared_ptr<AMP::Database> db );
275
277
278 std::string d_sName;
279
280 int d_iNumberIterations = 0; // iterations in solver
281
283
286
289
291
293
294 bool d_bIsNestedSolver = false;
295 bool d_bComputeResidual = false;
296
298
299 static int d_iInstanceId; // used to differentiate between different instances of the class
300
302 std::vector<int> d_iterationHistory;
303
304 std::shared_ptr<AMP::Database> d_db = nullptr;
305
311 std::shared_ptr<AMP::Database> d_global_db = nullptr;
312
313 std::shared_ptr<AMP::LinearAlgebra::Vector> d_pSolutionScaling;
314 std::shared_ptr<AMP::LinearAlgebra::Vector> d_pFunctionScaling;
315
316 std::shared_ptr<AMP::Operator::Operator> d_pOperator = nullptr;
317
319 std::shared_ptr<AMP::Solver::SolverStrategy> d_pNestedSolver = nullptr;
320
321 std::shared_ptr<AMP::IO::Writer> d_writer = nullptr;
322
325
328
329private:
330};
331
332} // namespace AMP::Solver
333
334#endif
Scalar is a class used to store a scalar variable that may be different types/precision.
Definition Scalar.h:21
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
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
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 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
virtual void apply(std::shared_ptr< const AMP::LinearAlgebra::Vector > f, std::shared_ptr< AMP::LinearAlgebra::Vector > u)=0
SolverStatus getConvergenceStatus(void) const
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)
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)
MemoryType
Enum to store pointer type.
Definition Memory.h:21
std::ostream pout



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