18#ifndef BELOS_TFQMR_ITER_HPP
19#define BELOS_TFQMR_ITER_HPP
38#include "Teuchos_ScalarTraits.hpp"
39#include "Teuchos_ParameterList.hpp"
40#include "Teuchos_TimeMonitor.hpp"
59 template <
class ScalarType,
class MV>
63 Teuchos::RCP<const MV>
R;
64 Teuchos::RCP<const MV>
W;
65 Teuchos::RCP<const MV>
U;
67 Teuchos::RCP<const MV>
D;
68 Teuchos::RCP<const MV>
V;
71 Rtilde(Teuchos::null),
D(Teuchos::null),
V(Teuchos::null)
91 template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,ScalarType>>
99 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
109 Teuchos::ParameterList ¶ms );
178 state.solnUpdate = solnUpdate_;
218 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
219 "Belos::TFQMRIter::setBlockSize(): Cannot use a block size that is not one.");
239 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > lp_;
240 const Teuchos::RCP<OutputManager<ScalarType> > om_;
241 const Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > stest_;
248 std::vector<ScalarType> alpha_, rho_, rho_old_;
249 std::vector<MagnitudeType> tau_, cs_, theta_;
262 bool stateStorageInitialized_;
272 Teuchos::RCP<MV> U_, AU_;
273 Teuchos::RCP<MV> Rtilde_;
276 Teuchos::RCP<MV> solnUpdate_;
286 template <
class ScalarType,
class MV,
class OP,
class DM>
290 Teuchos::ParameterList &
302 stateStorageInitialized_(false),
309 template <
class ScalarType,
class MV,
class OP,
class DM>
310 Teuchos::RCP<const MV>
313 MagnitudeType one = Teuchos::ScalarTraits<MagnitudeType>::one();
315 (*normvec)[0] = Teuchos::ScalarTraits<MagnitudeType>::squareroot( 2*iter_ + one )*tau_[0];
317 return Teuchos::null;
323 template <
class ScalarType,
class MV,
class OP,
class DM>
324 void TFQMRIter<ScalarType,MV,OP,DM>::setStateSize ()
326 if (!stateStorageInitialized_) {
329 Teuchos::RCP<const MV> lhsMV = lp_->getLHS();
330 Teuchos::RCP<const MV> rhsMV = lp_->getRHS();
331 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
332 stateStorageInitialized_ =
false;
339 if (R_ == Teuchos::null) {
341 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
342 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::invalid_argument,
343 "Belos::TFQMRIter::setStateSize(): linear problem does not specify multivectors to clone from.");
344 R_ = MVT::Clone( *tmp, 1 );
345 D_ = MVT::Clone( *tmp, 1 );
346 V_ = MVT::Clone( *tmp, 1 );
347 solnUpdate_ = MVT::Clone( *tmp, 1 );
351 stateStorageInitialized_ =
true;
358 template <
class ScalarType,
class MV,
class OP,
class DM>
362 if (!stateStorageInitialized_)
365 TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
366 "Belos::TFQMRIter::initialize(): Cannot initialize state storage!");
370 std::string errstr(
"Belos::TFQMRIter::initialize(): Specified multivectors must have a consistent length and width.");
373 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
375 if (newstate.
R != Teuchos::null) {
378 std::invalid_argument, errstr );
380 std::invalid_argument, errstr );
383 if (newstate.
R != R_) {
399 lp_->apply( *U_, *V_ );
410 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
R == Teuchos::null,std::invalid_argument,
411 "Belos::TFQMRIter::initialize(): TFQMRIterState does not have initial residual.");
421 template <
class ScalarType,
class MV,
class OP,
class DM>
427 if (initialized_ ==
false) {
432 const ScalarType STone = Teuchos::ScalarTraits<ScalarType>::one();
433 const MagnitudeType MTone = Teuchos::ScalarTraits<MagnitudeType>::one();
434 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
435 const ScalarType STzero = Teuchos::ScalarTraits<ScalarType>::zero();
436 ScalarType eta = STzero, beta = STzero;
441 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
445 "Belos::TFQMRIter::iterate(): current linear system has more than one vector!" );
451 while (stest_->checkStatus(
this) !=
Passed) {
453 for (
int iIter=0; iIter<2; iIter++)
462 alpha_[0] = rho_old_[0]/alpha_[0];
477 MVT::MvAddMv( STone, *U_, (theta_[0]*theta_[0]/alpha_[0])*eta, *D_, *D_ );
491 lp_->apply( *U_, *AU_ );
499 theta_[0] /= tau_[0];
501 cs_[0] = MTone / Teuchos::ScalarTraits<MagnitudeType>::squareroot(MTone + theta_[0]*theta_[0]);
502 tau_[0] *= theta_[0]*cs_[0];
503 eta = cs_[0]*cs_[0]*alpha_[0];
510 MVT::MvAddMv( STone, *solnUpdate_, eta, *D_, *solnUpdate_ );
515 if ( tau_[0] == MTzero ) {
526 beta = rho_[0]/rho_old_[0];
527 rho_old_[0] = rho_[0];
540 lp_->apply( *U_, *AU_ );
Belos header file which uses auto-configuration information to include necessary C++ headers.
Pure virtual base class which describes the basic interface to the 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.
BelosError(const std::string &what_arg)
Iteration()
Default Constructor.
Traits class which defines basic operations on multivectors.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
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 void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
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.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
void iterate()
This method performs TFQMR iterations until the status test indicates the need to stop or an error oc...
TFQMRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
virtual ~TFQMRIter()
Belos::TFQMRIter destructor.
int getNumIters() const
Get the current iteration count.
void initializeTFQMR(const TFQMRIterState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
bool isInitialized()
States whether the solver has been initialized or not.
SCT::magnitudeType MagnitudeType
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
OperatorTraits< ScalarType, MV, OP > OPT
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Get a constant reference to the linear problem.
MultiVecTraits< ScalarType, MV, DM > MVT
TFQMRIter(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)
Belos::TFQMRIter constructor.
void setBlockSize(int blockSize)
Set the blocksize.
void resetNumIters(int iter=0)
Reset the iteration count.
Teuchos::ScalarTraits< ScalarType > SCT
TFQMRIterateFailure is thrown when the TFQMRIter object is unable to compute the next iterate in the ...
TFQMRIterateFailure(const std::string &what_arg)
Structure to contain pointers to TFQMRIter state variables.
Teuchos::RCP< const MV > W
Teuchos::RCP< const MV > V
Teuchos::RCP< const MV > Rtilde
Teuchos::RCP< const MV > R
The current residual basis.
Teuchos::RCP< const MV > D
Teuchos::RCP< const MV > U