10#ifndef BELOS_MINRES_ITER_HPP
11#define BELOS_MINRES_ITER_HPP
40#include "Teuchos_SerialDenseMatrix.hpp"
41#include "Teuchos_SerialDenseVector.hpp"
42#include "Teuchos_ScalarTraits.hpp"
43#include "Teuchos_ParameterList.hpp"
44#include "Teuchos_TimeMonitor.hpp"
61template<
class ScalarType,
class MV,
class OP>
71 typedef Teuchos::ScalarTraits< ScalarType >
SCT;
73 typedef Teuchos::ScalarTraits< MagnitudeType >
SMT;
89 const Teuchos::ParameterList&
params);
150 throw std::logic_error(
"getState() cannot be called unless "
151 "the state has been initialized");
176 Teuchos::RCP<const MV>
186 return Teuchos::null;
211 "Belos::MinresIter::setBlockSize(): Cannot use a block size that is not one.");
231 const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_;
232 const Teuchos::RCP< OutputManager< ScalarType > > om_;
233 const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_;
251 bool stateStorageInitialized_;
267 Teuchos::RCP< MV > Y_;
269 Teuchos::RCP< MV > R1_;
271 Teuchos::RCP< MV > R2_;
273 Teuchos::RCP< MV > W_;
275 Teuchos::RCP< MV > W1_;
277 Teuchos::RCP< MV > W2_;
286 Teuchos::SerialDenseMatrix<int,ScalarType> beta1_;
292 template<
class ScalarType,
class MV,
class OP>
296 const Teuchos::ParameterList & ):
301 stateStorageInitialized_(
false),
309 template <
class ScalarType,
class MV,
class OP>
312 if (!stateStorageInitialized_) {
315 Teuchos::RCP< const MV >
lhsMV = lp_->getLHS();
316 Teuchos::RCP< const MV >
rhsMV = lp_->getRHS();
317 if (
lhsMV == Teuchos::null &&
rhsMV == Teuchos::null) {
318 stateStorageInitialized_ =
false;
325 if (Y_ == Teuchos::null) {
329 std::invalid_argument,
330 "Belos::MinresIter::setStateSize(): linear problem does not specify multivectors to clone from.");
331 Y_ = MVT::Clone( *
tmp, 1 );
332 R1_ = MVT::Clone( *
tmp, 1 );
333 R2_ = MVT::Clone( *
tmp, 1 );
334 W_ = MVT::Clone( *
tmp, 1 );
335 W1_ = MVT::Clone( *
tmp, 1 );
336 W2_ = MVT::Clone( *
tmp, 1 );
339 stateStorageInitialized_ =
true;
347 template <
class ScalarType,
class MV,
class OP>
351 if (!stateStorageInitialized_)
355 std::invalid_argument,
356 "Belos::MinresIter::initialize(): Cannot initialize state storage!" );
359 std::invalid_argument,
360 "Belos::MinresIter::initialize(): MinresIterationState does not have initial residual.");
362 std::string
errstr(
"Belos::MinresIter::initialize(): Specified multivectors must have a consistent length and width.");
364 std::invalid_argument,
367 std::invalid_argument,
382 MVT::MvInit ( *W2_ );
384 if ( lp_->getLeftPrec() != Teuchos::null ) {
385 lp_->applyLeftPrec( *
newstate.Y, *Y_ );
386 if ( lp_->getRightPrec() != Teuchos::null ) {
387 Teuchos::RCP<MV>
tmp = MVT::CloneCopy( *Y_ );
388 lp_->applyRightPrec( *
tmp, *Y_ );
391 else if ( lp_->getRightPrec() != Teuchos::null ) {
392 lp_->applyRightPrec( *
newstate.Y, *Y_ );
402 beta1_ = Teuchos::SerialDenseMatrix<int,ScalarType>( 1, 1 );
406 std::invalid_argument,
407 "The preconditioner is not positive definite." );
409 if( SCT::magnitude(beta1_(0,0)) ==
m_zero )
416 beta1_(0,0) = SCT::squareroot( beta1_(0,0) );
425 template <
class ScalarType,
class MV,
class OP>
431 if (initialized_ ==
false) {
441 Teuchos::SerialDenseMatrix<int,ScalarType> alpha( 1, 1 );
442 Teuchos::SerialDenseMatrix<int,ScalarType> beta( beta1_ );
443 phibar_ = Teuchos::ScalarTraits<ScalarType>::magnitude( beta1_(0,0) );
460 Teuchos::RCP<MV> V = MVT::Clone( *Y_, 1 );
469 "Belos::MinresIter::iterate(): current linear system has more than one vector!" );
474 while (stest_->checkStatus(
this) !=
Passed) {
481 MVT::MvAddMv (
one / beta(0,0), *Y_,
zero, *Y_, *V);
484 lp_->applyOp (*V, *Y_);
487 MVT::MvAddMv (
one, *Y_, -beta(0,0)/
oldBeta, *R1_, *Y_);
490 MVT::MvTransMv (
one, *V, *Y_, alpha);
493 MVT::MvAddMv (
one, *Y_, -alpha(0,0)/beta(0,0), *R2_, *Y_);
503 if ( lp_->getLeftPrec() != Teuchos::null ) {
504 lp_->applyLeftPrec( *R2_, *Y_ );
505 if ( lp_->getRightPrec() != Teuchos::null ) {
506 Teuchos::RCP<MV>
tmp = MVT::CloneCopy( *Y_ );
507 lp_->applyRightPrec( *
tmp, *Y_ );
510 else if ( lp_->getRightPrec() != Teuchos::null ) {
511 lp_->applyRightPrec( *R2_, *Y_ );
514 MVT::Assign( *R2_, *Y_ );
519 MVT::MvTransMv(
one, *R2_, *Y_, beta );
533 "Belos::MinresIter::iterate(): Encountered negative "
534 "value " << beta(0,0) <<
" for r2^H*M*r2 at itera"
535 "tion " << iter_ <<
": MINRES cannot continue." );
536 beta(0,0) = SCT::squareroot( beta(0,0) );
546 epsln = sn*beta(0,0);
547 dbar = - cs*beta(0,0);
550 this->symOrtho(
gbar, beta(0,0), &cs, &sn, &
gamma);
553 phibar_ = Teuchos::ScalarTraits<ScalarType>::magnitude( sn * phibar_ );
557 MVT::Assign( *W_, *W1_ );
564 MVT::MvAddMv(
one, *V, -
oldeps, *W1_, *W_ );
565 MVT::MvAddMv(
one, *W_, -
delta, *W2_, *W_ );
571 lp_->updateSolution();
581 template <
class ScalarType,
class MV,
class OP>
604 if ( Teuchos::ScalarTraits<ScalarType>::real(
b) <
m_zero )
605 *
s = -
one / SCT::squareroot(
one+tau*tau );
607 *
s =
one / SCT::squareroot(
one+tau*tau );
612 if ( Teuchos::ScalarTraits<ScalarType>::real(
a) <
m_zero )
613 *
c = -
one / SCT::squareroot(
one+tau*tau );
615 *
c =
one / SCT::squareroot(
one+tau*tau );
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which describes the linear problem to be solved by the iterative solver.
Pure virtual base class which augments the basic interface for a minimal residual linear solver itera...
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.
void initializeMinres(const MinresIterationState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
MinresIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::ParameterList ¶ms)
Constructor.
bool isInitialized()
States whether the solver has been initialized or not.
int getNumIters() const
Get the current iteration count.
bool isInitialized() const
States whether the solver has been initialized or not.
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
MinresIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
MultiVecTraits< ScalarType, MV > MVT
Teuchos::ScalarTraits< MagnitudeType > SMT
void initialize()
Initialize the solver.
void symOrtho(ScalarType a, ScalarType b, ScalarType *c, ScalarType *s, ScalarType *r)
void iterate()
Perform MINRES iterations until convergence or error.
SCT::magnitudeType MagnitudeType
Teuchos::ScalarTraits< ScalarType > SCT
OperatorTraits< ScalarType, MV, OP > OPT
void resetNumIters(int iter=0)
Reset the iteration count.
virtual ~MinresIter()
Destructor.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
MinresIterateFailure is thrown when the MinresIteration object is unable to compute the next iterate ...
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).