42 #ifndef BELOS_FIXEDPOINT_ITER_HPP
43 #define BELOS_FIXEDPOINT_ITER_HPP
59 #include "Teuchos_SerialDenseMatrix.hpp"
60 #include "Teuchos_SerialDenseVector.hpp"
61 #include "Teuchos_ScalarTraits.hpp"
62 #include "Teuchos_ParameterList.hpp"
63 #include "Teuchos_TimeMonitor.hpp"
76 template<
class ScalarType,
class MV,
class OP>
86 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
100 Teuchos::ParameterList ¶ms );
213 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
214 const Teuchos::RCP<OutputManager<ScalarType> > om_;
215 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
233 bool stateStorageInitialized_;
252 template<
class ScalarType,
class MV,
class OP>
256 Teuchos::ParameterList ¶ms ):
262 stateStorageInitialized_(false),
270 template <
class ScalarType,
class MV,
class OP>
273 if (!stateStorageInitialized_) {
275 Teuchos::RCP<const MV> lhsMV = lp_->getLHS();
276 Teuchos::RCP<const MV> rhsMV = lp_->getRHS();
277 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
278 stateStorageInitialized_ =
false;
285 if (R_ == Teuchos::null) {
287 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
288 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::invalid_argument,
289 "Belos::FixedPointIter::setStateSize(): linear problem does not specify multivectors to clone from.");
290 R_ = MVT::Clone( *tmp, numRHS_ );
291 Z_ = MVT::Clone( *tmp, numRHS_ );
295 stateStorageInitialized_ =
true;
302 template <
class ScalarType,
class MV,
class OP>
308 TEUCHOS_TEST_FOR_EXCEPTION(blockSize != MVT::GetNumberVecs(*lp_->getCurrRHSVec()), std::invalid_argument,
"Belos::FixedPointIter::setBlockSize size must match # RHS.");
310 TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0, std::invalid_argument,
"Belos::FixedPointIter::setBlockSize was passed a non-positive argument.");
311 if (blockSize == numRHS_) {
316 if (blockSize!=numRHS_)
317 stateStorageInitialized_ =
false;
321 initialized_ =
false;
330 template <
class ScalarType,
class MV,
class OP>
334 if (!stateStorageInitialized_)
337 TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
338 "Belos::FixedPointIter::initialize(): Cannot initialize state storage!");
342 std::string errstr(
"Belos::FixedPointIter::initialize(): Specified multivectors must have a consistent length and width.");
345 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
346 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
348 if (newstate.
R != Teuchos::null) {
349 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*R_) != MVT::GetNumberVecs(*newstate.
R),
350 std::invalid_argument, errstr );
352 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetGlobalLength(*newstate.
R) != MVT::GetGlobalLength(*R_),
353 std::invalid_argument, errstr );
354 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
R) != numRHS_,
355 std::invalid_argument, errstr );
358 if (newstate.
R != R_) {
360 MVT::MvAddMv( one, *newstate.
R, zero, *newstate.
R, *R_ );
365 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
R == Teuchos::null,std::invalid_argument,
366 "Belos::FixedPointIter::initialize(): FixedPointIterationState does not have initial residual.");
369 TEUCHOS_TEST_FOR_EXCEPTION(!lp_->getRightPrec().is_null(),std::invalid_argument,
370 "Belos::FixedPointIter::initialize(): Does not work with right preconditioning");
379 template <
class ScalarType,
class MV,
class OP>
385 if (initialized_ ==
false) {
390 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
394 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
395 Teuchos::RCP<const MV> rhs = lp_->getCurrRHSVec();
398 Teuchos::RCP<MV> tmp = MVT::Clone( *R_, numRHS_ );
403 while (stest_->checkStatus(
this) !=
Passed) {
409 if ( lp_->getLeftPrec() != Teuchos::null ) {
410 lp_->applyLeftPrec( *R_, *Z_ );
417 MVT::Assign(*cur_soln_vec,*tmp);
418 MVT::MvAddMv(one,*tmp,one,*Z_,*cur_soln_vec);
419 lp_->updateSolution();
422 lp_->applyOp(*cur_soln_vec,*tmp);
423 MVT::MvAddMv(one,*rhs,-one,*tmp,*R_);