LAMA
|
Superclass for all solvers. More...
#include <Solver.hpp>
Data Structures | |
struct | SolverRuntime |
Status independent solver informations. More... | |
Public Member Functions | |
Solver (const std::string &id) | |
Creates a solver with a given ID. | |
Solver (const std::string &id, LoggerPtr logger) | |
Create a solver with a given ID and a given logger. | |
Solver (const Solver &other) | |
Copy constructor that copies the status independent solver information. | |
virtual | ~Solver () |
Solver destructor. | |
virtual void | initialize (const Matrix &coefficients) |
Used to initialize a solver with a certain matrix A from A*u=f. | |
virtual void | solve (Vector &solution, const Vector &rhs) |
Solves the equation system based on the given rhs. | |
virtual void | solveInit (Vector &solution, const Vector &rhs) |
Initializes the solver with rhs and solution. | |
virtual void | solveImpl ()=0 |
Solves the equation system. | |
virtual void | solveFinalize () |
Finalizes the solving process. | |
const std::string & | getId () const |
Returns the ID of this solver. | |
const Vector & | getResidual () const |
Contingently calculates the current residual based on the coefficients, rhs and solution currently associated with this. | |
const Matrix & | getCoefficients () const |
Gets the matrix A from A*u=f. | |
void | setLogger (LoggerPtr logger) |
Redefines mLogger. | |
void | setLogLevel (LogLevel::LogLevel level) |
Switches the loglevel of mLogger. | |
virtual void | setContext (ContextPtr context) |
Sets the context where this solver should be executed. | |
virtual SolverPtr | copy ()=0 |
Copies the status independent solver informations to create a new instance of the same type. | |
virtual SolverRuntime & | getRuntime ()=0 |
Returns the complete configuration of the derived class. | |
virtual const SolverRuntime & | getConstRuntime () const =0 |
Returns the complete const configuration of the derived class. | |
Protected Member Functions | |
virtual void | writeAt (std::ostream &stream) const |
Overrides Printable::writeAt with more useful stuff. | |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
Protected Attributes | |
std::string | mId |
The ID of this solver. | |
LoggerPtr | mLogger |
The solver logger. | |
ContextPtr | mContext |
For forcing the context solver dependent. |
Superclass for all solvers.
This class acts as a superclass for all solver. It offers basic functionality for coefficient, rhs and solution storing, provides a custom ID for a solver and a residual calculation capabilities.
lama::Solver::Solver | ( | const std::string & | id | ) |
lama::Solver::Solver | ( | const std::string & | id, |
LoggerPtr | logger | ||
) |
Create a solver with a given ID and a given logger.
id | The ID of the solver. |
logger | The logger which shall be used by the solver |
References mId.
lama::Solver::Solver | ( | const Solver & | other | ) |
Copy constructor that copies the status independent solver information.
lama::Solver::~Solver | ( | ) | [virtual] |
virtual SolverPtr lama::Solver::copy | ( | ) | [pure virtual] |
Copies the status independent solver informations to create a new instance of the same type.
Implemented in lama::MetaSolver, lama::LUSolver, lama::IterativeSolver, lama::OmegaSolver, lama::SimpleAMG, lama::InverseSolver, lama::SpecializedJacobi, lama::DefaultJacobi, lama::SOR, lama::GMRES, lama::CG, and lama::TrivialPreconditioner.
const Matrix & lama::Solver::getCoefficients | ( | ) | const |
Gets the matrix A from A*u=f.
References getConstRuntime(), LAMA_ASSERT_DEBUG, and lama::Solver::SolverRuntime::mCoefficients.
Referenced by lama::InverseSolver::invert(), and lama::LUSolver::piamax_own().
virtual const SolverRuntime& lama::Solver::getConstRuntime | ( | ) | const [pure virtual] |
Returns the complete const configuration of the derived class.
Implemented in lama::MetaSolver, lama::IterativeSolver, lama::LUSolver, lama::OmegaSolver, lama::GMRES, lama::SimpleAMG, lama::InverseSolver, lama::DefaultJacobi, lama::CG, lama::SpecializedJacobi, lama::SOR, and lama::TrivialPreconditioner.
Referenced by getCoefficients(), getResidual(), initialize(), and solve().
const std::string & lama::Solver::getId | ( | ) | const |
Returns the ID of this solver.
References mId.
Referenced by lama::IterativeSolver::criteriaAreSatisfied(), lama::IterativeSolver::solveImpl(), and lama::SolverConfigGrammar::SolverConfigGrammar().
const Vector & lama::Solver::getResidual | ( | ) | const |
Contingently calculates the current residual based on the coefficients, rhs and solution currently associated with this.
Should be used internally only, because the three vectors mentioned above have to be initialized.
References lama::LogLevel::completeInformation, lama::Vector::create(), lama::SolutionProxy::getConstReference(), getConstRuntime(), lama::SolutionProxy::isDirty(), LAMA_ASSERT_DEBUG, lama::Solver::SolverRuntime::mCoefficients, mLogger, lama::Solver::SolverRuntime::mResidual, lama::Solver::SolverRuntime::mRhs, lama::Solver::SolverRuntime::mSolution, and lama::SolutionProxy::setDirty().
Referenced by lama::ResidualStagnation::isSatisfied(), lama::ResidualThreshold::isSatisfied(), lama::CG::iterate(), lama::GMRES::iterate(), and lama::Logger::logResidual().
virtual SolverRuntime& lama::Solver::getRuntime | ( | ) | [pure virtual] |
Returns the complete configuration of the derived class.
Implemented in lama::MetaSolver, lama::IterativeSolver, lama::LUSolver, lama::OmegaSolver, lama::GMRES, lama::SimpleAMG, lama::InverseSolver, lama::DefaultJacobi, lama::CG, lama::SpecializedJacobi, lama::SOR, and lama::TrivialPreconditioner.
Referenced by initialize(), and solveInit().
void lama::Solver::initialize | ( | const Matrix & | coefficients | ) | [virtual] |
Used to initialize a solver with a certain matrix A from A*u=f.
This method initializes a solver with a certain coefficient-matrix. The only thing it does is storing the matrix pointer as a member for derived solver classes to use it. The caller delegates the property of the pointer to the Solver instance.
This method may be overwritten by base classes which desire more complex initialization.
coefficients | The matrix A from A*u=f. |
Reimplemented in lama::DefaultJacobi, lama::MetaSolver, lama::OmegaSolver, lama::LUSolver, lama::IterativeSolver, lama::InverseSolver, lama::GMRES, lama::DefaultJacobi, lama::CG, lama::SOR, lama::SimpleAMG, lama::SpecializedJacobi, and lama::TrivialPreconditioner.
References getConstRuntime(), getRuntime(), lama::Solver::SolverRuntime::mCoefficients, lama::Solver::SolverRuntime::mInitialized, mLogger, and lama::LogLevel::solverInformation.
lama::Solver::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
Reimplemented in lama::LUSolver, lama::IterativeSolver, lama::MetaSolver, lama::OmegaSolver, lama::SimpleAMG, lama::GMRES, lama::InverseSolver, lama::DefaultJacobi, lama::CG, and lama::SOR.
void lama::Solver::setContext | ( | ContextPtr | context | ) | [virtual] |
Sets the context where this solver should be executed.
Sets the context where this solver should be executed. Caution: This overrides the context of the coefficients matrix A from A * u = f used to inializ this solver.
[in] | context | the context where this solver should be executed. |
Reimplemented in lama::InverseSolver.
References mContext.
Referenced by lama::GMRES::initialize().
void lama::Solver::setLogger | ( | LoggerPtr | logger | ) |
Redefines mLogger.
References mLogger.
void lama::Solver::setLogLevel | ( | LogLevel::LogLevel | level | ) |
void lama::Solver::solve | ( | Vector & | solution, |
const Vector & | rhs | ||
) | [virtual] |
Solves the equation system based on the given rhs.
The solver needs to be initialized first with the matrix from the equation to solve, e.g. A from A*u=f (call solver::initialize(A) for example) This method is abstract. It has to be implemented by a class which inherits from this class.
rhs | The right hand side of A*u=f. |
solution | The solution from A*u=f. Mostly used as starting solution for an IterativeSolver. |
Reimplemented in lama::LUSolver, lama::DefaultJacobi, and lama::SpecializedJacobi.
References getConstRuntime(), LAMA_REGION, solveFinalize(), solveImpl(), and solveInit().
Referenced by lama::SimpleAMG::cycle().
void lama::Solver::solveFinalize | ( | ) | [virtual] |
Finalizes the solving process.
Reimplemented in lama::DefaultJacobi, and lama::SpecializedJacobi.
Referenced by solve().
virtual void lama::Solver::solveImpl | ( | ) | [pure virtual] |
Solves the equation system.
Rhs and starting solution have to be initialized first! (call solveInit( rhs, solution ) ). The solver needs to be initialized first with the matrix from the equation to solve, e.g. A from A*u=f (call solver::initialize(A) for example)
This method solves the equation system by using the given rhs and solution. For most solvers the solution-vector is used as a starting solution for the solve process. This class does not take responsibility for deleting the vectors after the solver! Make sure you do not delete the vectors during the solver process.
Implemented in lama::MetaSolver, lama::IterativeSolver, lama::InverseSolver, and lama::TrivialPreconditioner.
Referenced by solve().
void lama::Solver::solveInit | ( | Vector & | solution, |
const Vector & | rhs | ||
) | [virtual] |
Initializes the solver with rhs and solution.
[in] | rhs | The right hand side of the system of equations |
[out] | solution | The allocated memory and starting solution for the system |
Reimplemented in lama::DefaultJacobi, and lama::SpecializedJacobi.
References lama::Matrix::getColDistribution(), lama::Distributed::getDistribution(), lama::Matrix::getNumColumns(), lama::Matrix::getNumRows(), getRuntime(), LAMA_THROWEXCEPTION, lama::Solver::SolverRuntime::mCoefficients, lama::Solver::SolverRuntime::mRhs, lama::Solver::SolverRuntime::mSolution, lama::Solver::SolverRuntime::mSolveInit, and lama::Vector::size().
Referenced by solve().
void lama::Solver::writeAt | ( | std::ostream & | stream | ) | const [protected, virtual] |
ContextPtr lama::Solver::mContext [protected] |
For forcing the context solver dependent.
If the context for a solver is set, the context of the input matrix will be ignored
Referenced by lama::SpecializedJacobi::iterateTyped(), lama::InverseSolver::setContext(), and setContext().
std::string lama::Solver::mId [protected] |
The ID of this solver.
Referenced by getId(), lama::InverseSolver::InverseSolver(), Solver(), writeAt(), and ~Solver().
LoggerPtr lama::Solver::mLogger [protected] |
The solver logger.
May be the NullLogger if no logger has been specified.
Referenced by getResidual(), lama::IterativeSolver::initialize(), initialize(), lama::InverseSolver::logEndSolve(), lama::IterativeSolver::logEndSolve(), lama::IterativeSolver::logIterationEndAndResidual(), lama::IterativeSolver::logIterationStart(), lama::SimpleAMG::logSetupDetails(), lama::SimpleAMG::logSetupInfo(), lama::SimpleAMG::logSetupSettings(), lama::SimpleAMG::logSolverInfo(), lama::InverseSolver::logStartSolve(), lama::IterativeSolver::logStartSolve(), lama::MetaSolver::parseConfiguration(), setLogger(), and setLogLevel().