10#ifndef BELOS_FIXEDPOINT_ITER_HPP
11#define BELOS_FIXEDPOINT_ITER_HPP
27#include "Teuchos_ScalarTraits.hpp"
28#include "Teuchos_ParameterList.hpp"
29#include "Teuchos_TimeMonitor.hpp"
42template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,ScalarType>>
52 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
66 Teuchos::ParameterList ¶ms );
179 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > lp_;
180 const Teuchos::RCP<OutputManager<ScalarType> > om_;
181 const Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > stest_;
199 bool stateStorageInitialized_;
218 template<
class ScalarType,
class MV,
class OP,
class DM>
222 Teuchos::ParameterList ¶ms ):
228 stateStorageInitialized_(false),
236 template<
class ScalarType,
class MV,
class OP,
class DM>
237 void FixedPointIter<ScalarType,MV,OP,DM>::setStateSize ()
239 if (!stateStorageInitialized_) {
241 Teuchos::RCP<const MV> lhsMV = lp_->getLHS();
242 Teuchos::RCP<const MV> rhsMV = lp_->getRHS();
243 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
244 stateStorageInitialized_ =
false;
251 if (R_ == Teuchos::null) {
253 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
254 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::invalid_argument,
255 "Belos::FixedPointIter::setStateSize(): linear problem does not specify multivectors to clone from.");
256 R_ = MVT::Clone( *tmp, numRHS_ );
257 Z_ = MVT::Clone( *tmp, numRHS_ );
261 stateStorageInitialized_ =
true;
268 template<
class ScalarType,
class MV,
class OP,
class DM>
274 TEUCHOS_TEST_FOR_EXCEPTION(blockSize !=
MVT::GetNumberVecs(*lp_->getCurrRHSVec()), std::invalid_argument,
"Belos::FixedPointIter::setBlockSize size must match # RHS.");
276 TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0, std::invalid_argument,
"Belos::FixedPointIter::setBlockSize was passed a non-positive argument.");
277 if (blockSize == numRHS_) {
282 if (blockSize!=numRHS_)
283 stateStorageInitialized_ =
false;
287 initialized_ =
false;
296 template<
class ScalarType,
class MV,
class OP,
class DM>
300 if (!stateStorageInitialized_)
303 TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
304 "Belos::FixedPointIter::initialize(): Cannot initialize state storage!");
308 std::string errstr(
"Belos::FixedPointIter::initialize(): Specified multivectors must have a consistent length and width.");
310 if (newstate.
R != Teuchos::null) {
312 std::invalid_argument, errstr );
315 std::invalid_argument, errstr );
317 std::invalid_argument, errstr );
320 if (newstate.
R != R_) {
327 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
R == Teuchos::null,std::invalid_argument,
328 "Belos::FixedPointIter::initialize(): FixedPointIterationState does not have initial residual.");
338 template<
class ScalarType,
class MV,
class OP,
class DM>
344 if (initialized_ ==
false) {
349 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
350 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
353 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
356 Teuchos::RCP<MV> tmp =
MVT::Clone( *R_, numRHS_ );
358 if (lp_->getRightPrec() != Teuchos::null) {
368 while (stest_->checkStatus(
this) !=
Passed) {
374 lp_->applyRightPrec( *R_, *tmp );
377 MVT::MvAddMv( one, *cur_soln_vec, one, *tmp, *cur_soln_vec );
378 lp_->updateSolution();
384 lp_->applyOp (*Z_, *tmp );
390 Teuchos::RCP<const MV> rhs = lp_->getCurrRHSVec();
395 while (stest_->checkStatus(
this) !=
Passed) {
401 if ( lp_->getLeftPrec() != Teuchos::null ) {
402 lp_->applyLeftPrec( *R_, *Z_ );
410 lp_->updateSolution();
413 lp_->applyOp(*cur_soln_vec,*tmp);
Belos header file which uses auto-configuration information to include necessary C++ headers.
Pure virtual base class which augments the basic interface for a fixed point linear solver iteration.
Class which describes the linear problem to be solved by the iterative solver.
Declaration of basic traits for the multivector type.
Class which defines basic traits for the operator type.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class for defining the status testing capabilities of Belos.
Collection of types and exceptions used within the Belos solvers.
void resetNumIters(int iter=0)
Reset the iteration count.
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
FixedPointIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
void iterate()
This method performs Fixed Point iterations until the status test indicates the need to stop or an er...
int getNumIters() const
Get the current iteration count.
MultiVecTraits< ScalarType, MV, DM > MVT
FixedPointIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &tester, Teuchos::ParameterList ¶ms)
FixedPointIter constructor with linear problem, solver utilities, and parameter list of solver option...
OperatorTraits< ScalarType, MV, OP > OPT
SCT::magnitudeType MagnitudeType
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Get a constant reference to the linear problem.
bool isInitialized()
States whether the solver has been initialized or not.
void initializeFixedPoint(FixedPointIterationState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
virtual ~FixedPointIter()
Destructor.
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
Traits class which defines basic operations on multivectors.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
static void Assign(const MV &A, MV &mv)
static ptrdiff_t GetGlobalLength(const MV &mv)
static int GetNumberVecs(const MV &mv)
Class which defines basic traits for the operator type.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
A pure virtual class for defining the status tests for the Belos iterative solvers.
Structure to contain pointers to FixedPointIteration state variables.
Teuchos::RCP< const MV > R
The current residual.
Teuchos::RCP< const MV > Z
The current preconditioned residual.