18#ifndef BELOS_TFQMR_ITER_HPP
19#define BELOS_TFQMR_ITER_HPP
38#include "Teuchos_SerialDenseMatrix.hpp"
39#include "Teuchos_SerialDenseVector.hpp"
40#include "Teuchos_ScalarTraits.hpp"
41#include "Teuchos_ParameterList.hpp"
42#include "Teuchos_TimeMonitor.hpp"
61 template <
class ScalarType,
class MV>
65 Teuchos::RCP<const MV>
R;
66 Teuchos::RCP<const MV>
W;
67 Teuchos::RCP<const MV>
U;
69 Teuchos::RCP<const MV>
D;
70 Teuchos::RCP<const MV>
V;
94 template <
class ScalarType,
class MV,
class OP>
102 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
112 Teuchos::ParameterList &
params );
178 state.Rtilde = Rtilde_;
181 state.solnUpdate = solnUpdate_;
222 "Belos::TFQMRIter::setBlockSize(): Cannot use a block size that is not one.");
242 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
243 const Teuchos::RCP<OutputManager<ScalarType> > om_;
244 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
252 std::vector<ScalarType> alpha_, rho_, rho_old_;
253 std::vector<MagnitudeType> tau_, cs_, theta_;
266 bool stateStorageInitialized_;
276 Teuchos::RCP<MV> U_, AU_;
277 Teuchos::RCP<MV> Rtilde_;
280 Teuchos::RCP<MV> solnUpdate_;
290 template <
class ScalarType,
class MV,
class OP>
294 Teuchos::ParameterList &
306 stateStorageInitialized_(
false),
313 template <
class ScalarType,
class MV,
class OP>
314 Teuchos::RCP<const MV>
319 (*normvec)[0] = Teuchos::ScalarTraits<MagnitudeType>::squareroot( 2*iter_ +
one )*tau_[0];
321 return Teuchos::null;
327 template <
class ScalarType,
class MV,
class OP>
330 if (!stateStorageInitialized_) {
333 Teuchos::RCP<const MV>
lhsMV = lp_->getLHS();
334 Teuchos::RCP<const MV>
rhsMV = lp_->getRHS();
335 if (
lhsMV == Teuchos::null &&
rhsMV == Teuchos::null) {
336 stateStorageInitialized_ =
false;
343 if (R_ == Teuchos::null) {
347 "Belos::TFQMRIter::setStateSize(): linear problem does not specify multivectors to clone from.");
348 R_ = MVT::Clone( *
tmp, 1 );
349 D_ = MVT::Clone( *
tmp, 1 );
350 V_ = MVT::Clone( *
tmp, 1 );
351 solnUpdate_ = MVT::Clone( *
tmp, 1 );
355 stateStorageInitialized_ =
true;
362 template <
class ScalarType,
class MV,
class OP>
366 if (!stateStorageInitialized_)
370 "Belos::TFQMRIter::initialize(): Cannot initialize state storage!");
374 std::string
errstr(
"Belos::TFQMRIter::initialize(): Specified multivectors must have a consistent length and width.");
382 std::invalid_argument,
errstr );
384 std::invalid_argument,
errstr );
395 W_ = MVT::CloneCopy( *R_ );
396 U_ = MVT::CloneCopy( *R_ );
397 Rtilde_ = MVT::CloneCopy( *R_ );
399 MVT::MvInit( *solnUpdate_ );
403 lp_->apply( *U_, *V_ );
404 AU_ = MVT::CloneCopy( *V_ );
409 MVT::MvNorm( *R_, tau_ );
410 MVT::MvDot( *R_, *Rtilde_, rho_old_ );
415 "Belos::TFQMRIter::initialize(): TFQMRIterState does not have initial residual.");
425 template <
class ScalarType,
class MV,
class OP>
431 if (initialized_ ==
false) {
449 "Belos::TFQMRIter::iterate(): current linear system has more than one vector!" );
455 while (stest_->checkStatus(
this) !=
Passed) {
465 MVT::MvDot( *V_, *Rtilde_, alpha_ );
466 alpha_[0] = rho_old_[0]/alpha_[0];
474 MVT::MvAddMv(
STone, *W_, -alpha_[0], *AU_, *W_ );
481 MVT::MvAddMv(
STone, *U_, (theta_[0]*theta_[0]/alpha_[0])*eta, *D_, *D_ );
492 MVT::MvAddMv(
STone, *U_, -alpha_[0], *V_, *U_ );
495 lp_->apply( *U_, *AU_ );
502 MVT::MvNorm( *W_, theta_ );
503 theta_[0] /= tau_[0];
505 cs_[0] =
MTone / Teuchos::ScalarTraits<MagnitudeType>::squareroot(
MTone + theta_[0]*theta_[0]);
506 tau_[0] *= theta_[0]*cs_[0];
507 eta = cs_[0]*cs_[0]*alpha_[0];
514 MVT::MvAddMv(
STone, *solnUpdate_, eta, *D_, *solnUpdate_ );
519 if ( tau_[0] ==
MTzero ) {
529 MVT::MvDot( *W_, *Rtilde_, rho_ );
530 beta = rho_[0]/rho_old_[0];
531 rho_old_[0] = rho_[0];
538 MVT::MvAddMv(
STone, *W_, beta, *U_, *U_ );
541 MVT::MvAddMv(
STone, *AU_, beta, *V_, *V_ );
544 lp_->apply( *U_, *AU_ );
547 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...
Teuchos::ScalarTraits< ScalarType > SCT
void resetNumIters(int iter=0)
Reset the iteration count.
virtual ~TFQMRIter()
Belos::TFQMRIter destructor.
void setBlockSize(int blockSize)
Set the blocksize.
bool isInitialized()
States whether the solver has been initialized or not.
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
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...
SCT::magnitudeType MagnitudeType
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
TFQMRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
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.
MultiVecTraits< ScalarType, MV > MVT
TFQMRIter(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)
Belos::TFQMRIter constructor.
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.
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