10#ifndef BELOS_FIXEDPOINT_ITER_HPP
11#define BELOS_FIXEDPOINT_ITER_HPP
27#include "Teuchos_SerialDenseMatrix.hpp"
28#include "Teuchos_SerialDenseVector.hpp"
29#include "Teuchos_ScalarTraits.hpp"
30#include "Teuchos_ParameterList.hpp"
31#include "Teuchos_TimeMonitor.hpp"
44template<
class ScalarType,
class MV,
class OP>
54 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
68 Teuchos::ParameterList ¶ms );
181 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
182 const Teuchos::RCP<OutputManager<ScalarType> > om_;
183 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
201 bool stateStorageInitialized_;
220 template<
class ScalarType,
class MV,
class OP>
224 Teuchos::ParameterList ¶ms ):
230 stateStorageInitialized_(false),
238 template <
class ScalarType,
class MV,
class OP>
239 void FixedPointIter<ScalarType,MV,OP>::setStateSize ()
241 if (!stateStorageInitialized_) {
243 Teuchos::RCP<const MV> lhsMV = lp_->getLHS();
244 Teuchos::RCP<const MV> rhsMV = lp_->getRHS();
245 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
246 stateStorageInitialized_ =
false;
253 if (R_ == Teuchos::null) {
255 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
256 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::invalid_argument,
257 "Belos::FixedPointIter::setStateSize(): linear problem does not specify multivectors to clone from.");
258 R_ = MVT::Clone( *tmp, numRHS_ );
259 Z_ = MVT::Clone( *tmp, numRHS_ );
263 stateStorageInitialized_ =
true;
270 template <
class ScalarType,
class MV,
class OP>
276 TEUCHOS_TEST_FOR_EXCEPTION(blockSize !=
MVT::GetNumberVecs(*lp_->getCurrRHSVec()), std::invalid_argument,
"Belos::FixedPointIter::setBlockSize size must match # RHS.");
278 TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0, std::invalid_argument,
"Belos::FixedPointIter::setBlockSize was passed a non-positive argument.");
279 if (blockSize == numRHS_) {
284 if (blockSize!=numRHS_)
285 stateStorageInitialized_ =
false;
289 initialized_ =
false;
298 template <
class ScalarType,
class MV,
class OP>
302 if (!stateStorageInitialized_)
305 TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
306 "Belos::FixedPointIter::initialize(): Cannot initialize state storage!");
310 std::string errstr(
"Belos::FixedPointIter::initialize(): Specified multivectors must have a consistent length and width.");
313 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
314 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
316 if (newstate.
R != Teuchos::null) {
318 std::invalid_argument, errstr );
321 std::invalid_argument, errstr );
323 std::invalid_argument, errstr );
326 if (newstate.
R != R_) {
333 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
R == Teuchos::null,std::invalid_argument,
334 "Belos::FixedPointIter::initialize(): FixedPointIterationState does not have initial residual.");
344 template <
class ScalarType,
class MV,
class OP>
350 if (initialized_ ==
false) {
355 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
356 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
359 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
362 Teuchos::RCP<MV> tmp =
MVT::Clone( *R_, numRHS_ );
364 if (lp_->getRightPrec() != Teuchos::null) {
374 while (stest_->checkStatus(
this) !=
Passed) {
380 lp_->applyRightPrec( *R_, *tmp );
383 MVT::MvAddMv( one, *cur_soln_vec, one, *tmp, *cur_soln_vec );
384 lp_->updateSolution();
390 lp_->applyOp (*Z_, *tmp );
396 Teuchos::RCP<const MV> rhs = lp_->getCurrRHSVec();
401 while (stest_->checkStatus(
this) !=
Passed) {
407 if ( lp_->getLeftPrec() != Teuchos::null ) {
408 lp_->applyLeftPrec( *R_, *Z_ );
416 lp_->updateSolution();
419 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.
Teuchos::ScalarTraits< ScalarType > SCT
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
SCT::magnitudeType MagnitudeType
void resetNumIters(int iter=0)
Reset the iteration count.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
virtual ~FixedPointIter()
Destructor.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
bool isInitialized()
States whether the solver has been initialized or not.
int getNumIters() const
Get the current iteration count.
FixedPointIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, Teuchos::ParameterList ¶ms)
FixedPointIter constructor with linear problem, solver utilities, and parameter list of solver option...
void initializeFixedPoint(FixedPointIterationState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
OperatorTraits< ScalarType, MV, OP > OPT
void iterate()
This method performs Fixed Point iterations until the status test indicates the need to stop or an er...
MultiVecTraits< ScalarType, MV > MVT
FixedPointIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in 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.