46 #ifndef MUELU_STRATIMIKOSSMOOTHER_DEF_HPP
47 #define MUELU_STRATIMIKOSSMOOTHER_DEF_HPP
51 #if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_THYRA)
55 #include <Xpetra_CrsMatrix.hpp>
56 #include <Xpetra_CrsMatrixWrap.hpp>
57 #include <Xpetra_Matrix.hpp>
62 #include "MueLu_Utilities.hpp"
65 #include <Stratimikos_DefaultLinearSolverBuilder.hpp>
66 #include "Teuchos_AbstractFactoryStd.hpp"
67 #if defined(HAVE_MUELU_THYRATPETRAADAPTERS) && defined(HAVE_MUELU_IFPACK2)
68 #include <Thyra_Ifpack2PreconditionerFactory.hpp>
74 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::StratimikosSmoother(
const std::string type,
const Teuchos::ParameterList& paramList)
78 bool isSupported = type ==
"STRATIMIKOS";
79 this->declareConstructionOutcome(!isSupported,
"Stratimikos does not provide the smoother '" + type_ +
"'.");
81 SetParameterList(paramList);
84 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
85 void StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::SetParameterList(
const Teuchos::ParameterList& paramList) {
86 Factory::SetParameterList(paramList);
89 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 void StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel)
const {
91 this->Input(currentLevel,
"A");
94 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
95 void StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::Setup(Level& currentLevel) {
96 FactoryMonitor m(*
this,
"Setup Smoother", currentLevel);
98 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
99 SetupStratimikos(currentLevel);
100 SmootherPrototype::IsSetup(
true);
101 this->GetOStream(
Statistics1) << description() << std::endl;
104 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
105 void StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::SetupStratimikos(Level& ) {
107 RCP<const Thyra::LinearOpBase<Scalar> > thyraA = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(A_)->getCrsMatrix());
110 Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
111 typedef Thyra::PreconditionerFactoryBase<Scalar> Base;
112 #if defined(HAVE_MUELU_THYRATPETRAADAPTERS) && defined(HAVE_MUELU_IFPACK2)
113 typedef Thyra::Ifpack2PreconditionerFactory<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Impl;
114 linearSolverBuilder.setPreconditioningStrategyFactory(Teuchos::abstractFactoryStd<Base, Impl>(),
"Ifpack2");
116 linearSolverBuilder.setParameterList(rcpFromRef(const_cast<ParameterList&>(this->GetParameterList())));
120 RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > solverFactory = Thyra::createLinearSolveStrategy(linearSolverBuilder);
121 solver_ = Thyra::linearOpWithSolve(*solverFactory, thyraA);
124 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
125 void StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X,
const MultiVector& B,
bool InitialGuessIsZero)
const {
126 TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() ==
false, Exceptions::RuntimeError,
"MueLu::StratimikosSmoother::Apply(): Setup() has not been called");
129 if (InitialGuessIsZero) {
131 RCP< Thyra::VectorBase<Scalar> >thyraX = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyraVector(X.getVectorNonConst(0)));
132 RCP<const Thyra::VectorBase<Scalar> >thyraB = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyraVector(B.getVector(0));
133 Thyra::SolveStatus<Scalar> status = Thyra::solve<Scalar>(*solver_, Thyra::NOTRANS, *thyraB, thyraX.ptr());
137 RCP<MultiVector> Residual = Utilities::Residual(*A_, X, B);
138 RCP<MultiVector> Correction = MultiVectorFactory::Build(A_->getDomainMap(), X.getNumVectors());
140 RCP< Thyra::VectorBase<Scalar> >thyraX = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyraVector(Correction->getVectorNonConst(0)));
141 RCP<const Thyra::VectorBase<Scalar> >thyraB = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyraVector(Residual->getVector(0));
142 Thyra::SolveStatus<Scalar> status = Thyra::solve<Scalar>(*solver_, Thyra::NOTRANS, *thyraB, thyraX.ptr());
144 X.update(TST::one(), *Correction, TST::one());
149 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
150 RCP<MueLu::SmootherPrototype<double, LocalOrdinal, GlobalOrdinal, Node> > StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::Copy()
const {
151 RCP<StratimikosSmoother> smoother =
rcp(
new StratimikosSmoother(*
this) );
152 smoother->SetParameterList(this->GetParameterList());
156 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
157 std::string StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::description()
const {
158 std::ostringstream out;
159 if (SmootherPrototype::IsSetup()) {
160 out << solver_->description();
162 out <<
"STRATIMIKOS {type = " << type_ <<
"}";
167 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
172 out0 <<
"Parameter list: " << std::endl;
174 out << this->GetParameterList();
178 if (solver_ != Teuchos::null) {
180 out << *solver_ << std::endl;
183 if (verbLevel &
Debug) {
184 out0 <<
"IsSetup: " <<
Teuchos::toString(SmootherPrototype::IsSetup()) << std::endl
186 <<
"RCP<solver_>: " << solver_ << std::endl;
190 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
191 size_t StratimikosSmoother<double, LocalOrdinal, GlobalOrdinal, Node>::getNodeSmootherComplexity()
const {
198 #endif // HAVE_MUELU_STRATIMIKOS
199 #endif // MUELU_STRATIMIKOSSMOOTHER_DEF_HPP
Print external lib objects.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Print additional debugging information.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Print class parameters (more parameters, more verbose)
std::string toString(const T &t)