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;
91 template<
class ScalarType,
class MV,
class OP,
class DM>
99 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
109 Teuchos::ParameterList &
params );
175 state.Rtilde = Rtilde_;
178 state.solnUpdate = solnUpdate_;
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>
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>
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) {
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_)
366 "Belos::TFQMRIter::initialize(): Cannot initialize state storage!");
370 std::string
errstr(
"Belos::TFQMRIter::initialize(): Specified multivectors must have a consistent length and width.");
378 std::invalid_argument,
errstr );
380 std::invalid_argument,
errstr );
391 W_ = MVT::CloneCopy( *R_ );
392 U_ = MVT::CloneCopy( *R_ );
393 Rtilde_ = MVT::CloneCopy( *R_ );
395 MVT::MvInit( *solnUpdate_ );
399 lp_->apply( *U_, *V_ );
400 AU_ = MVT::CloneCopy( *V_ );
405 MVT::MvNorm( *R_, tau_ );
406 MVT::MvDot( *R_, *Rtilde_, rho_old_ );
411 "Belos::TFQMRIter::initialize(): TFQMRIterState does not have initial residual.");
421 template <
class ScalarType,
class MV,
class OP,
class DM>
427 if (initialized_ ==
false) {
445 "Belos::TFQMRIter::iterate(): current linear system has more than one vector!" );
451 while (stest_->checkStatus(
this) !=
Passed) {
461 MVT::MvDot( *V_, *Rtilde_, alpha_ );
462 alpha_[0] = rho_old_[0]/alpha_[0];
470 MVT::MvAddMv(
STone, *W_, -alpha_[0], *AU_, *W_ );
477 MVT::MvAddMv(
STone, *U_, (theta_[0]*theta_[0]/alpha_[0])*eta, *D_, *D_ );
488 MVT::MvAddMv(
STone, *U_, -alpha_[0], *V_, *U_ );
491 lp_->apply( *U_, *AU_ );
498 MVT::MvNorm( *W_, theta_ );
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 ) {
525 MVT::MvDot( *W_, *Rtilde_, rho_ );
526 beta = rho_[0]/rho_old_[0];
527 rho_old_[0] = rho_[0];
534 MVT::MvAddMv(
STone, *W_, beta, *U_, *U_ );
537 MVT::MvAddMv(
STone, *AU_, beta, *V_, *V_ );
540 lp_->apply( *U_, *AU_ );
543 MVT::MvAddMv(
STone, *AU_, beta, *V_, *V_ );
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.
Parent class to all Belos exceptions.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
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
Get the norms of the residuals native to the solver.
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