18#ifndef BELOS_PSEUDO_BLOCK_TFQMR_ITER_HPP
19#define BELOS_PSEUDO_BLOCK_TFQMR_ITER_HPP
38#include "Teuchos_ScalarTraits.hpp"
39#include "Teuchos_ParameterList.hpp"
40#include "Teuchos_TimeMonitor.hpp"
59 template <
class ScalarType,
class MV>
62 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
66 Teuchos::RCP<const MV>
W;
67 Teuchos::RCP<const MV>
U;
68 Teuchos::RCP<const MV>
AU;
70 Teuchos::RCP<const MV>
D;
71 Teuchos::RCP<const MV>
V;
81 template <
class ScalarType,
class MV,
class OP>
89 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
99 Teuchos::ParameterList &
params );
167 state.Rtilde = Rtilde_;
172 state.alpha = alpha_;
176 state.theta = theta_;
218 "Belos::PseudoBlockTFQMRIter::setBlockSize(): Cannot use a block size that is not one.");
232 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
233 const Teuchos::RCP<OutputManager<ScalarType> > om_;
234 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
244 std::vector<ScalarType> alpha_, eta_, rho_, rho_old_;
245 std::vector<MagnitudeType> tau_, theta_;
262 Teuchos::RCP<MV> U_, AU_;
263 Teuchos::RCP<MV> Rtilde_;
266 Teuchos::RCP<MV> solnUpdate_;
277 template <
class ScalarType,
class MV,
class OP>
281 Teuchos::ParameterList &
294 template <
class ScalarType,
class MV,
class OP>
295 Teuchos::RCP<const MV>
301 if ((
int)
normvec->size() < numRHS_)
305 for (
int i=0;
i<numRHS_;
i++) {
306 (*normvec)[
i] = Teuchos::ScalarTraits<MagnitudeType>::squareroot( 2*iter_ +
one )*tau_[
i];
310 return Teuchos::null;
315 template <
class ScalarType,
class MV,
class OP>
325 "Belos::PseudoBlockTFQMRIter::initialize(): PseudoBlockTFQMRIterState does not have initial residual.");
333 if ( Teuchos::is_null(Rtilde_) || (MVT::GetNumberVecs(*Rtilde_) == numRHS_) )
336 if ( Teuchos::is_null(D_) )
337 D_ = MVT::Clone( *
newstate.Rtilde, numRHS_ );
338 MVT::MvInit( *D_,
STzero );
341 if ( Teuchos::is_null(solnUpdate_) )
342 solnUpdate_ = MVT::Clone( *
newstate.Rtilde, numRHS_ );
343 MVT::MvInit( *solnUpdate_,
STzero );
347 Rtilde_ = MVT::CloneCopy( *
newstate.Rtilde );
348 W_ = MVT::CloneCopy( *Rtilde_ );
349 U_ = MVT::CloneCopy( *Rtilde_ );
350 V_ = MVT::Clone( *Rtilde_, numRHS_ );
354 lp_->apply( *U_, *V_ );
355 AU_ = MVT::CloneCopy( *V_ );
358 alpha_.resize( numRHS_,
STone );
359 eta_.resize( numRHS_,
STzero );
360 rho_.resize( numRHS_ );
361 rho_old_.resize( numRHS_ );
362 tau_.resize( numRHS_ );
363 theta_.resize( numRHS_,
MTzero );
365 MVT::MvNorm( *Rtilde_, tau_ );
366 MVT::MvDot( *Rtilde_, *Rtilde_, rho_ );
371 Rtilde_ = MVT::CloneCopy( *
newstate.Rtilde );
374 AU_ = MVT::CloneCopy( *
newstate.AU );
380 solnUpdate_ = MVT::Clone( *Rtilde_, numRHS_ );
381 MVT::MvInit( *solnUpdate_,
STzero );
398 template <
class ScalarType,
class MV,
class OP>
404 if (initialized_ ==
false) {
413 std::vector< ScalarType > beta(numRHS_,
STzero);
414 std::vector<int> index(1);
422 while (stest_->checkStatus(
this) !=
Passed) {
432 MVT::MvDot( *V_, *Rtilde_, alpha_ );
433 for (
int i=0;
i<numRHS_;
i++) {
434 rho_old_[
i] = rho_[
i];
435 alpha_[
i] = rho_old_[
i]/alpha_[
i];
443 for (
int i=0;
i<numRHS_; ++
i) {
452 Teuchos::RCP<const MV>
AU_i = MVT::CloneView( *AU_, index );
453 Teuchos::RCP<MV>
W_i = MVT::CloneViewNonConst( *W_, index );
461 Teuchos::RCP<const MV>
U_i = MVT::CloneView( *U_, index );
462 Teuchos::RCP<MV>
D_i = MVT::CloneViewNonConst( *D_, index );
474 Teuchos::RCP<const MV>
V_i = MVT::CloneView( *V_, index );
475 Teuchos::RCP<MV>
U2_i = MVT::CloneViewNonConst( *U_, index );
485 lp_->apply( *U_, *AU_ );
492 MVT::MvNorm( *W_, theta_ );
495 for (
int i=0;
i<numRHS_; ++
i) {
496 theta_[
i] /= tau_[
i];
499 tau_[
i] *= theta_[
i]*cs;
503 eta_[
i] = cs*cs*alpha_[
i];
510 for (
int i=0;
i<numRHS_; ++
i) {
512 Teuchos::RCP<const MV>
D_i = MVT::CloneView( *D_, index );
513 Teuchos::RCP<MV>
update_i = MVT::CloneViewNonConst( *solnUpdate_, index );
531 MVT::MvDot( *W_, *Rtilde_, rho_ );
533 for (
int i=0;
i<numRHS_; ++
i) {
534 beta[
i] = rho_[
i]/rho_old_[
i];
543 Teuchos::RCP<const MV>
W_i = MVT::CloneView( *W_, index );
544 Teuchos::RCP<MV>
U_i = MVT::CloneViewNonConst( *U_, index );
548 Teuchos::RCP<const MV>
AU_i = MVT::CloneView( *AU_, index );
549 Teuchos::RCP<MV>
V_i = MVT::CloneViewNonConst( *V_, index );
554 lp_->apply( *U_, *AU_ );
557 for (
int i=0;
i<numRHS_; ++
i) {
559 Teuchos::RCP<const MV>
AU_i = MVT::CloneView( *AU_, index );
560 Teuchos::RCP<MV>
V_i = MVT::CloneViewNonConst( *V_, index );
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.
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...
int getNumIters() const
Get the current iteration count.
void iterate()
This method performs pseudo-block TFQMR iterations until the status test indicates the need to stop o...
void resetNumIters(int iter=0)
Reset the iteration count.
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.
virtual ~PseudoBlockTFQMRIter()
Belos::PseudoBlockTFQMRIter destructor.
PseudoBlockTFQMRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
MultiVecTraits< ScalarType, MV > MVT
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
PseudoBlockTFQMRIter(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::PseudoBlockTFQMRIter constructor.
Teuchos::ScalarTraits< ScalarType > SCT
void initializeTFQMR(const PseudoBlockTFQMRIterState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
SCT::magnitudeType MagnitudeType
void setBlockSize(int blockSize)
Set the blocksize.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
OperatorTraits< ScalarType, MV, OP > OPT
Structure to contain pointers to PseudoBlockTFQMRIter state variables.
std::vector< MagnitudeType > theta
std::vector< MagnitudeType > tau
SCT::magnitudeType MagnitudeType
Teuchos::RCP< const MV > AU
std::vector< ScalarType > rho
Teuchos::RCP< const MV > D
std::vector< ScalarType > alpha
Teuchos::RCP< const MV > Rtilde
Teuchos::RCP< const MV > W
The current residual basis.
Teuchos::RCP< const MV > U
Teuchos::RCP< const MV > V
PseudoBlockTFQMRIterState()
Teuchos::ScalarTraits< ScalarType > SCT
std::vector< ScalarType > eta