50#ifndef BELOS_TFQMR_ITER_HPP
51#define BELOS_TFQMR_ITER_HPP
70#include "Teuchos_SerialDenseMatrix.hpp"
71#include "Teuchos_SerialDenseVector.hpp"
72#include "Teuchos_ScalarTraits.hpp"
73#include "Teuchos_ParameterList.hpp"
74#include "Teuchos_TimeMonitor.hpp"
93 template <
class ScalarType,
class MV>
97 Teuchos::RCP<const MV>
R;
98 Teuchos::RCP<const MV>
W;
99 Teuchos::RCP<const MV>
U;
101 Teuchos::RCP<const MV>
D;
102 Teuchos::RCP<const MV>
V;
105 Rtilde(Teuchos::null),
D(Teuchos::null),
V(Teuchos::null)
126 template <
class ScalarType,
class MV,
class OP>
134 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
144 Teuchos::ParameterList ¶ms );
253 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
254 "Belos::TFQMRIter::setBlockSize(): Cannot use a block size that is not one.");
274 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >
lp_;
275 const Teuchos::RCP<OutputManager<ScalarType> >
om_;
276 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
stest_;
322 template <
class ScalarType,
class MV,
class OP>
326 Teuchos::ParameterList &
345 template <
class ScalarType,
class MV,
class OP>
346 Teuchos::RCP<const MV>
349 MagnitudeType one = Teuchos::ScalarTraits<MagnitudeType>::one();
351 (*normvec)[0] = Teuchos::ScalarTraits<MagnitudeType>::squareroot( 2*
iter_ + one )*
tau_[0];
353 return Teuchos::null;
359 template <
class ScalarType,
class MV,
class OP>
365 Teuchos::RCP<const MV> lhsMV =
lp_->getLHS();
366 Teuchos::RCP<const MV> rhsMV =
lp_->getRHS();
367 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
375 if (
R_ == Teuchos::null) {
377 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
378 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::invalid_argument,
379 "Belos::TFQMRIter::setStateSize(): linear problem does not specify multivectors to clone from.");
394 template <
class ScalarType,
class MV,
class OP>
402 "Belos::TFQMRIter::initialize(): Cannot initialize state storage!");
406 std::string errstr(
"Belos::TFQMRIter::initialize(): Specified multivectors must have a consistent length and width.");
409 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
411 if (newstate.
R != Teuchos::null) {
414 std::invalid_argument, errstr );
416 std::invalid_argument, errstr );
419 if (newstate.
R !=
R_) {
446 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
R == Teuchos::null,std::invalid_argument,
447 "Belos::TFQMRIter::initialize(): TFQMRIterState does not have initial residual.");
457 template <
class ScalarType,
class MV,
class OP>
468 const ScalarType STone = Teuchos::ScalarTraits<ScalarType>::one();
469 const MagnitudeType MTone = Teuchos::ScalarTraits<MagnitudeType>::one();
470 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
471 const ScalarType STzero = Teuchos::ScalarTraits<ScalarType>::zero();
472 ScalarType eta = STzero, beta = STzero;
477 Teuchos::RCP<MV> cur_soln_vec =
lp_->getCurrLHSVec();
481 "Belos::TFQMRIter::iterate(): current linear system has more than one vector!" );
489 for (
int iIter=0; iIter<2; iIter++)
537 cs_[0] = MTone / Teuchos::ScalarTraits<MagnitudeType>::squareroot(MTone +
theta_[0]*
theta_[0]);
551 if (
tau_[0] == MTzero ) {
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 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 void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
Compute the norm of each individual vector of mv. Upon return, normvec[i] holds the value of ,...
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
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.
static void Assign(const MV &A, MV &mv)
mv := A
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.
Teuchos::ScalarTraits< ScalarType > SCT
void resetNumIters(int iter=0)
Reset the iteration count.
std::vector< MagnitudeType > theta_
Teuchos::RCP< MV > Rtilde_
virtual ~TFQMRIter()
Belos::TFQMRIter destructor.
void setBlockSize(int blockSize)
Set the blocksize.
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_
bool isInitialized()
States whether the solver has been initialized or not.
OperatorTraits< ScalarType, MV, OP > OPT
std::vector< ScalarType > rho_
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
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
std::vector< ScalarType > rho_old_
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
bool stateStorageInitialized_
TFQMRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
Teuchos::RCP< MV > solnUpdate_
const Teuchos::RCP< OutputManager< ScalarType > > om_
void setStateSize()
Method for initalizing the state storage needed by TFQMR.
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
const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_
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.
std::vector< MagnitudeType > cs_
std::vector< MagnitudeType > tau_
std::vector< ScalarType > alpha_
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