10#ifndef MUELU_BELOSSMOOTHER_DEF_HPP
11#define MUELU_BELOSSMOOTHER_DEF_HPP
15#if defined(HAVE_MUELU_BELOS)
17#include <Teuchos_ParameterList.hpp>
19#include <Xpetra_CrsMatrix.hpp>
20#include <Xpetra_Matrix.hpp>
21#include <Xpetra_MultiVectorFactory.hpp>
22#ifdef HAVE_XPETRA_TPETRA
23#include <Xpetra_TpetraMultiVector.hpp>
28#include "MueLu_Utilities.hpp"
31#include <BelosLinearProblem.hpp>
32#include <BelosSolverFactory.hpp>
36template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
39 bool solverSupported =
false;
40 Belos::SolverFactory<Scalar, tMV, tOP> tFactory;
41 solverSupported = solverSupported || tFactory.isSupported(type);
62template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 this->Input(currentLevel,
"A");
72template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 A_ = Factory::Get<RCP<Matrix> >(currentLevel,
"A");
77 SetupBelos(currentLevel);
79 this->GetOStream(
Statistics1) << description() << std::endl;
82template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 bool useTpetra = A_->getRowMap()->lib() == Xpetra::UseTpetra;
87 tBelosProblem_ = rcp(
new Belos::LinearProblem<Scalar, tMV, tOP>());
88 RCP<const tOP> tA = toTpetra(A_);
89 tBelosProblem_->setOperator(tA);
91 Belos::SolverFactory<SC, tMV, tOP> solverFactory;
92 tSolver_ = solverFactory.create(type_, rcpFromRef(
const_cast<ParameterList&
>(this->GetParameterList())));
93 tSolver_->setProblem(tBelosProblem_);
95 TEUCHOS_ASSERT(
false);
99template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
103 if (A_->getRowMap()->lib() == Xpetra::UseTpetra) {
104 if (InitialGuessIsZero) {
107 RCP<Tpetra::MultiVector<SC, LO, GO, NO> > tpX = toTpetra(rcpFromRef(X));
108 RCP<const Tpetra::MultiVector<SC, LO, GO, NO> > tpB = toTpetra(rcpFromRef(B));
110 tBelosProblem_->setInitResVec(tpB);
111 tBelosProblem_->setProblem(tpX, tpB);
115 typedef Teuchos::ScalarTraits<Scalar> TST;
117 RCP<MultiVector> Correction = MultiVectorFactory::Build(A_->getDomainMap(), X.getNumVectors());
119 RCP<Tpetra::MultiVector<SC, LO, GO, NO> > tpX = toTpetra(Correction);
120 RCP<const Tpetra::MultiVector<SC, LO, GO, NO> > tpB = toTpetra(Residual);
122 tBelosProblem_->setInitResVec(tpB);
123 tBelosProblem_->setProblem(tpX, tpB);
126 X.update(TST::one(), *Correction, TST::one());
129 TEUCHOS_ASSERT(
false);
133template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136 smoother->SetParameterList(this->GetParameterList());
140template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
142 std::ostringstream out;
144 if (A_->getRowMap()->lib() == Xpetra::UseTpetra) {
145 out << tSolver_->description();
148 out <<
"BELOS {type = " << type_ <<
"}";
153template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 out0 <<
"Parameter list: " << std::endl;
159 Teuchos::OSTab tab2(out);
160 out << this->GetParameterList();
164 if (tSolver_ != Teuchos::null) {
165 Teuchos::OSTab tab2(out);
166 out << *tSolver_ << std::endl;
170 if (verbLevel &
Debug) {
171 if (A_->getRowMap()->lib() == Xpetra::UseTpetra) {
174 <<
"RCP<solver_>: " << tSolver_ << std::endl;
179template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
181 return Teuchos::OrdinalTraits<size_t>::invalid();
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Class that encapsulates Belos smoothers.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
friend class BelosSmoother
Constructor.
void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
void DeclareInput(Level ¤tLevel) const
Input.
void SetupBelos(Level ¤tLevel)
std::string description() const
Return a simple one-line description of this object.
size_t getNodeSmootherComplexity() const
For diagnostic purposes.
void Setup(Level ¤tLevel)
Set up the smoother.
RCP< SmootherPrototype > Copy() const
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)=0
Set parameters from a parameter list and return with default values.
void declareConstructionOutcome(bool fail, std::string msg)
bool IsSetup() const
Get the state of a smoother prototype.
static RCP< MultiVector > Residual(const Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const MultiVector &X, const MultiVector &RHS)
Namespace for MueLu classes and methods.
@ Debug
Print additional debugging information.
@ Statistics1
Print more statistics.
@ External
Print external lib objects.
@ Parameters1
Print class parameters (more parameters, more verbose)