42#ifndef BELOS_BICGSTAB_SOLMGR_HPP
43#define BELOS_BICGSTAB_SOLMGR_HPP
61#ifdef BELOS_TEUCHOS_TIME_MONITOR
62#include "Teuchos_TimeMonitor.hpp"
96 template<
class ScalarType,
class MV,
class OP>
102 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
103 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
MagnitudeType;
104 typedef Teuchos::ScalarTraits<MagnitudeType>
MT;
128 const Teuchos::RCP<Teuchos::ParameterList> &pl );
134 Teuchos::RCP<SolverManager<ScalarType, MV, OP> >
clone ()
const override {
159 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
197 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms )
override;
244 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >
problem_;
251 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
sTest_;
253 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> >
convTest_;
292template<
class ScalarType,
class MV,
class OP>
309template<
class ScalarType,
class MV,
class OP>
312 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
327 TEUCHOS_TEST_FOR_EXCEPTION(
328 problem_.is_null (), std::invalid_argument,
329 "Belos::BiCGStabSolMgr two-argument constructor: "
330 "'problem' is null. You must supply a non-null Belos::LinearProblem "
331 "instance when calling this constructor.");
333 if (! pl.is_null ()) {
339template<
class ScalarType,
class MV,
class OP>
342 using Teuchos::ParameterList;
343 using Teuchos::parameterList;
350 params_ = parameterList (*defaultParams);
352 params->validateParameters (*defaultParams);
356 if (params->isParameter(
"Maximum Iterations")) {
366 if (params->isParameter(
"Timer Label")) {
367 std::string tempLabel = params->get(
"Timer Label",
label_default_);
370 if (tempLabel !=
label_) {
373 std::string solveLabel =
label_ +
": BiCGStabSolMgr total solve time";
374#ifdef BELOS_TEUCHOS_TIME_MONITOR
375 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
381 if (params->isParameter(
"Verbosity")) {
382 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
385 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
395 if (params->isParameter(
"Output Style")) {
396 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
399 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
408 if (params->isParameter(
"Output Stream")) {
409 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
419 if (params->isParameter(
"Output Frequency")) {
439 if (params->isParameter(
"Convergence Tolerance")) {
440 if (params->isType<
MagnitudeType> (
"Convergence Tolerance")) {
441 convtol_ = params->get (
"Convergence Tolerance",
454 if (params->isParameter(
"Show Maximum Residual Norm Only")) {
455 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
464 bool newResTest =
false;
470 bool implicitResidualScalingName =
false;
471 if (params->isParameter (
"Residual Scaling")) {
472 tempResScale = params->get<std::string> (
"Residual Scaling");
474 else if (params->isParameter (
"Implicit Residual Scaling")) {
475 tempResScale = params->get<std::string> (
"Implicit Residual Scaling");
476 implicitResidualScalingName =
true;
486 if (implicitResidualScalingName) {
497 catch (std::exception& e) {
506 if (params->isParameter(
"Deflation Quorum")) {
520 if (
convTest_ == Teuchos::null || newResTest) {
525 if (
sTest_ == Teuchos::null || newResTest)
536 std::string solverDesc =
" Pseudo Block BiCGStab ";
543 std::string solveLabel =
label_ +
": BiCGStabSolMgr total solve time";
544#ifdef BELOS_TEUCHOS_TIME_MONITOR
545 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
554template<
class ScalarType,
class MV,
class OP>
555Teuchos::RCP<const Teuchos::ParameterList>
558 using Teuchos::ParameterList;
559 using Teuchos::parameterList;
564 RCP<ParameterList> pl = parameterList ();
569 "The relative residual tolerance that needs to be achieved by the\n"
570 "iterative solver in order for the linera system to be declared converged.");
572 "The maximum number of block iterations allowed for each\n"
573 "set of RHS solved.");
575 "What type(s) of solver information should be outputted\n"
576 "to the output stream.");
578 "What style is used for the solver information outputted\n"
579 "to the output stream.");
581 "How often convergence information should be outputted\n"
582 "to the output stream.");
584 "The number of linear systems that need to converge before\n"
585 "they are deflated. This number should be <= block size.");
586 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
587 "A reference-counted pointer to the output stream where all\n"
588 "solver output is sent.");
590 "When convergence information is printed, only show the maximum\n"
591 "relative residual norm when the block size is greater than one.");
592 pl->set(
"Implicit Residual Scaling",
static_cast<const char *
>(
resScale_default_),
593 "The type of scaling used in the residual convergence test.");
600 "The type of scaling used in the residual convergence test. This "
601 "name is deprecated; the new name is \"Implicit Residual Scaling\".");
603 "The string to use as a prefix for the timer labels.");
610template<
class ScalarType,
class MV,
class OP>
620 TEUCHOS_TEST_FOR_EXCEPTION
622 "Belos::BiCGStabSolMgr::solve: Linear problem is not ready. "
623 "You must call setProblem() on the LinearProblem before you may solve it.");
624 TEUCHOS_TEST_FOR_EXCEPTION
625 (
problem_->isLeftPrec (), std::logic_error,
"Belos::BiCGStabSolMgr::solve: "
626 "The left-preconditioned case has not yet been implemented. Please use "
627 "right preconditioning for now. If you need to use left preconditioning, "
628 "please contact the Belos developers. Left preconditioning is more "
629 "interesting in BiCGStab because whether it works depends on the initial "
630 "guess (e.g., an initial guess of all zeros might NOT work).");
635 int numCurrRHS = numRHS2Solve;
637 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
638 for (
int i=0; i<numRHS2Solve; ++i) {
639 currIdx[i] = startPtr+i;
648 Teuchos::ParameterList plist;
654 bool isConverged =
true;
659 Teuchos::RCP<BiCGStabIter<ScalarType,MV,OP> > bicgstab_iter
664#ifdef BELOS_TEUCHOS_TIME_MONITOR
669 while ( numRHS2Solve > 0 ) {
671 std::vector<int> convRHSIdx;
672 std::vector<int> currRHSIdx( currIdx );
673 currRHSIdx.resize(numCurrRHS);
676 bicgstab_iter->resetNumIters();
687 bicgstab_iter->initializeBiCGStab(newState);
694 bicgstab_iter->iterate();
704 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP> >(
convTest_)->convIndices();
708 if (convIdx.size() == currRHSIdx.size())
716 std::vector<int> unconvIdx(currRHSIdx.size());
717 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
719 for (
unsigned int j=0; j<convIdx.size(); ++j) {
720 if (currRHSIdx[i] == convIdx[j]) {
726 currIdx2[have] = currIdx2[i];
727 currRHSIdx[have++] = currRHSIdx[i];
730 currRHSIdx.resize(have);
731 currIdx2.resize(have);
737 std::vector<MagnitudeType> norms;
738 R_0 =
MVT::CloneCopy( *(bicgstab_iter->getNativeResiduals(&norms)),currIdx2 );
739 for (
int i=0; i<have; ++i) { currIdx2[i] = i; }
744 bicgstab_iter->initializeBiCGStab(defstate);
765 else if ( bicgstab_iter->breakdownDetected() ) {
769 "Belos::BiCGStabSolMgr::solve(): Warning! Solver has experienced a breakdown!" << std::endl;
781 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
782 "Belos::BiCGStabSolMgr::solve(): Invalid return from BiCGStabIter::iterate().");
785 catch (
const std::exception &e) {
786 printer_->stream(
Errors) <<
"Error! Caught std::exception in BiCGStabIter::iterate() at iteration "
787 << bicgstab_iter->getNumIters() << std::endl
788 << e.what() << std::endl;
797 startPtr += numCurrRHS;
798 numRHS2Solve -= numCurrRHS;
800 if ( numRHS2Solve > 0 ) {
802 numCurrRHS = numRHS2Solve;
803 currIdx.resize( numCurrRHS );
804 currIdx2.resize( numCurrRHS );
805 for (
int i=0; i<numCurrRHS; ++i)
806 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
812 currIdx.resize( numRHS2Solve );
824#ifdef BELOS_TEUCHOS_TIME_MONITOR
838 const std::vector<MagnitudeType>* pTestValues =
convTest_->getTestValue();
839 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
849template<
class ScalarType,
class MV,
class OP>
852 std::ostringstream oss;
853 oss <<
"Belos::BiCGStabSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
Belos concrete class for performing the pseudo-block BiCGStab iteration.
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.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class which describes the basic interface for a solver manager.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Collection of types and exceptions used within the Belos solvers.
BelosError(const std::string &what_arg)
This class implements the pseudo-block BiCGStab iteration, where the basic BiCGStab algorithm is perf...
BiCGStabSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
BiCGStabSolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::ParameterList > validParams_
List of valid parameters and their default values.
Teuchos::RCP< Teuchos::ParameterList > params_
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
Teuchos::ScalarTraits< MagnitudeType > MT
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Teuchos::RCP< Teuchos::Time > timerSolve_
MultiVecTraits< ScalarType, MV > MVT
virtual ~BiCGStabSolMgr()
Destructor.
OperatorTraits< ScalarType, MV, OP > OPT
BiCGStabSolMgr()
Empty constructor for BiCGStabSolMgr. This constructor takes no arguments and sets the default values...
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Teuchos::ScalarTraits< ScalarType > SCT
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > convTest_
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
static constexpr int defQuorum_default_
static constexpr int verbosity_default_
MagnitudeType achievedTol_
Teuchos::RCP< OutputManager< ScalarType > > printer_
static constexpr bool showMaxResNormOnly_default_
static constexpr const char * resScale_default_
static constexpr int outputFreq_default_
std::string description() const override
Method to return description of the block BiCGStab solver manager.
static constexpr int maxIters_default_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
static constexpr const char * label_default_
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
static constexpr int outputStyle_default_
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Teuchos::RCP< std::ostream > outputStream_
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
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 Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
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...
SolverManager()
Empty constructor.
A class for extending the status testing capabilities of Belos via logical combinations.
An implementation of StatusTestResNorm using a family of residual norms.
A Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
ReturnType
Whether the Belos solve converged for all linear systems.
ScaleType
The type of scaling to use on the residual norm value.
ResetType
How to reset the solver.
Structure to contain pointers to BiCGStabIteration state variables.
Teuchos::RCP< const MV > R
The current residual.
Default parameters common to most Belos solvers.
static const double convTol
Default convergence tolerance.