48 #ifndef MUELU_TEKOSMOOTHER_DECL_HPP_
49 #define MUELU_TEKOSMOOTHER_DECL_HPP_
51 #ifdef HAVE_MUELU_TEKO
53 #include "Teko_Utilities.hpp"
55 #include "Teko_InverseLibrary.hpp"
56 #include "Teko_InverseFactory.hpp"
60 #include <Teuchos_ParameterList.hpp>
62 #include <Xpetra_MapExtractor_fwd.hpp>
65 #include "MueLu_SmootherPrototype.hpp"
82 template <class Scalar = SmootherPrototype<>::scalar_type,
90 #undef MUELU_TEKOSMOOTHER_SHORT
101 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::TekoSmoother: Teko can only be used with SC=double. For more information refer to the doxygen documentation of TekoSmoother.");
111 RCP<ParameterList> validParamList = rcp(
new ParameterList());
112 return validParamList;
133 void Apply(MultiVector& X,
const MultiVector& B,
bool InitialGuessIsZero =
false)
const { }
136 RCP<SmootherPrototype>
Copy()
const {
return Teuchos::null; }
143 std::ostringstream out;
145 out <<
"{type = " <<
type_ <<
"}";
155 out0 <<
"Prec. type: " <<
type_ << std::endl;
157 if (verbLevel &
Debug)
187 template <
class GlobalOrdinal,
195 #undef MUELU_TEKOSMOOTHER_SHORT
214 RCP<ParameterList> validParamList = rcp(
new ParameterList());
216 validParamList->set< RCP<const FactoryBase> >(
"A",
null,
"Generating factory of the matrix A");
217 validParamList->set< std::string > (
"Inverse Type",
"",
"Name of parameter list within 'Teko parameters' containing the Teko smoother parameters.");
219 return validParamList;
223 this->
Input(currentLevel,
"A");
235 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
239 this->
GetOStream(
Warnings0) <<
"MueLu::TekoSmoother::Setup(): Setup() has already been called";
242 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
243 bA_ = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(A_);
245 "MueLu::TekoSmoother::Build: input matrix A is not of type BlockedCrsMatrix.");
247 bThyOp_ = bA_->getThyraOperator();
249 "MueLu::TekoSmoother::Build: Could not extract thyra operator from BlockedCrsMatrix.");
251 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > thyOp = Teuchos::rcp_dynamic_cast<
const Thyra::LinearOpBase<Scalar> >(bThyOp_);
253 "MueLu::TekoSmoother::Build: Downcast of Thyra::BlockedLinearOpBase to Teko::LinearOp failed.");
257 std::string smootherType = pL.get<std::string>(
"Inverse Type");
259 "MueLu::TekoSmoother::Build: You must provide a 'Smoother Type' name that is defined in the 'Teko parameters' sublist.");
260 type_ = smootherType;
263 "MueLu::TekoSmoother::Build: No Teko parameters have been set.");
265 Teuchos::RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromParameterList(*tekoParams_);
266 Teuchos::RCP<Teko::InverseFactory>
inverse = invLib->getInverseFactory(smootherType);
268 inverseOp_ = Teko::buildInverse(*
inverse, thyOp);
270 "MueLu::TekoSmoother::Build: Failed to build Teko inverse operator. Probably a problem with the Teko parameters.");
281 void Apply(MultiVector& X,
const MultiVector& B,
bool InitialGuessIsZero =
false)
const {
283 "MueLu::TekoSmoother::Apply(): Setup() has not been called");
285 Teuchos::RCP<const Teuchos::Comm<int> > comm = X.getMap()->getComm();
287 Teuchos::RCP<const MapExtractor> rgMapExtractor = bA_->getRangeMapExtractor();
288 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgMapExtractor));
293 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > thyB = Thyra::createMembers(Teuchos::rcp_dynamic_cast<
const Thyra::VectorSpaceBase<Scalar> >(bThyOp_->productRange()),Teuchos::as<int>(B.getNumVectors()));
294 Teuchos::RCP<Thyra::ProductMultiVectorBase<Scalar> > thyProdB =
295 Teuchos::rcp_dynamic_cast<Thyra::ProductMultiVectorBase<Scalar> >(thyB);
297 "MueLu::TekoSmoother::Apply: Failed to cast range space to product range space.");
300 Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::updateThyra(Teuchos::rcpFromRef(B), rgMapExtractor, thyProdB);
303 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > thyX = Thyra::createMembers(Teuchos::rcp_dynamic_cast<
const Thyra::VectorSpaceBase<Scalar> >(bThyOp_->productDomain()),Teuchos::as<int>(X.getNumVectors()));
304 Teuchos::RCP<Thyra::ProductMultiVectorBase<Scalar> > thyProdX =
305 Teuchos::rcp_dynamic_cast<Thyra::ProductMultiVectorBase<Scalar> >(thyX);
307 "MueLu::TekoSmoother::Apply: Failed to cast domain space to product domain space.");
310 Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::updateThyra(Teuchos::rcpFromRef(X), rgMapExtractor, thyProdX);
320 Teuchos::RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > XX =
321 Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toXpetra(thyX, comm);
323 X.update(Teuchos::ScalarTraits<Scalar>::one(), *XX, Teuchos::ScalarTraits<Scalar>::zero());
334 std::ostringstream out;
336 out <<
"{type = " <<
type_ <<
"}";
346 out0 <<
"Prec. type: " <<
type_ << std::endl;
348 if (verbLevel &
Debug)
364 RCP<BlockedCrsMatrix>
bA_;
365 RCP<const Thyra::BlockedLinearOpBase<Scalar> >
bThyOp_;
374 #define MUELU_TEKOSMOOTHER_SHORT
376 #endif // HAVE_MUELU_TEKO