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> 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)
185 template <
class GlobalOrdinal,
193 #undef MUELU_TEKOSMOOTHER_SHORT 212 RCP<ParameterList> validParamList = rcp(
new ParameterList());
214 validParamList->set< RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A");
215 validParamList->set< std::string > (
"Inverse Type",
"",
"Name of parameter list within 'Teko parameters' containing the Teko smoother parameters.");
217 return validParamList;
221 this->
Input(currentLevel,
"A");
233 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
237 this->
GetOStream(
Warnings0) <<
"MueLu::TekoSmoother::Setup(): Setup() has already been called";
240 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
241 bA_ = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(A_);
243 "MueLu::TekoSmoother::Build: input matrix A is not of type BlockedCrsMatrix.");
245 bThyOp_ = bA_->getThyraOperator();
247 "MueLu::TekoSmoother::Build: Could not extract thyra operator from BlockedCrsMatrix.");
249 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > thyOp = Teuchos::rcp_dynamic_cast<
const Thyra::LinearOpBase<Scalar> >(bThyOp_);
251 "MueLu::TekoSmoother::Build: Downcast of Thyra::BlockedLinearOpBase to Teko::LinearOp failed.");
255 std::string smootherType = pL.get<std::string>(
"Inverse Type");
257 "MueLu::TekoSmoother::Build: You must provide a 'Smoother Type' name that is defined in the 'Teko parameters' sublist.");
258 type_ = smootherType;
261 "MueLu::TekoSmoother::Build: No Teko parameters have been set.");
263 Teuchos::RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromParameterList(*tekoParams_);
264 Teuchos::RCP<Teko::InverseFactory> inverse = invLib->getInverseFactory(smootherType);
266 inverseOp_ = Teko::buildInverse(*inverse, thyOp);
268 "MueLu::TekoSmoother::Build: Failed to build Teko inverse operator. Probably a problem with the Teko parameters.");
279 void Apply(MultiVector& X,
const MultiVector& B,
bool InitialGuessIsZero =
false)
const {
281 "MueLu::TekoSmoother::Apply(): Setup() has not been called");
283 Teuchos::RCP<const Teuchos::Comm<int> > comm = X.getMap()->getComm();
285 Teuchos::RCP<const MapExtractor> rgMapExtractor = bA_->getRangeMapExtractor();
286 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgMapExtractor));
291 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > thyB = Thyra::createMembers(Teuchos::rcp_dynamic_cast<
const Thyra::VectorSpaceBase<Scalar> >(bThyOp_->productRange()),Teuchos::as<int>(B.getNumVectors()));
292 Teuchos::RCP<Thyra::ProductMultiVectorBase<Scalar> > thyProdB =
293 Teuchos::rcp_dynamic_cast<Thyra::ProductMultiVectorBase<Scalar> >(thyB);
295 "MueLu::TekoSmoother::Apply: Failed to cast range space to product range space.");
298 Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::updateThyra(Teuchos::rcpFromRef(B), rgMapExtractor, thyProdB);
301 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > thyX = Thyra::createMembers(Teuchos::rcp_dynamic_cast<
const Thyra::VectorSpaceBase<Scalar> >(bThyOp_->productDomain()),Teuchos::as<int>(X.getNumVectors()));
302 Teuchos::RCP<Thyra::ProductMultiVectorBase<Scalar> > thyProdX =
303 Teuchos::rcp_dynamic_cast<Thyra::ProductMultiVectorBase<Scalar> >(thyX);
305 "MueLu::TekoSmoother::Apply: Failed to cast domain space to product domain space.");
308 Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::updateThyra(Teuchos::rcpFromRef(X), rgMapExtractor, thyProdX);
318 Teuchos::RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > XX =
319 Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toXpetra(thyX, comm);
321 X.update(Teuchos::ScalarTraits<Scalar>::one(), *XX, Teuchos::ScalarTraits<Scalar>::zero());
332 std::ostringstream out;
334 out <<
"{type = " <<
type_ <<
"}";
344 out0 <<
"Prec. type: " <<
type_ << std::endl;
346 if (verbLevel &
Debug)
359 RCP<BlockedCrsMatrix>
bA_;
360 RCP<const Thyra::BlockedLinearOpBase<Scalar> >
bThyOp_;
369 #define MUELU_TEKOSMOOTHER_SHORT 371 #endif // HAVE_MUELU_TEKO Important warning messages (one line)
Exception indicating invalid cast attempted.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
void DeclareInput(Level ¤tLevel) const
Input.
RCP< SmootherPrototype > Copy() const
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > MapExtractorClass
bool IsSetup() const
Get the state of a smoother prototype.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
RCP< const ParameterList > GetValidParameterList() const
Input.
virtual ~TekoSmoother()
Destructor.
Timer to be used in factories. Similar to Monitor but with additional timers.
RCP< Matrix > A_
block operator
virtual ~TekoSmoother()
Destructor.
Base class for smoother prototypes.
Print additional debugging information.
TekoSmoother()
Constructor.
Namespace for MueLu classes and methods.
LocalOrdinal local_ordinal_type
std::string description() const
Return a simple one-line description of this object.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the Teko smoother.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
void SetTekoParameters(RCP< ParameterList > tekoParams)
std::string description() const
Return a simple one-line description of this object.
RCP< SmootherPrototype > Copy() const
Class that holds all level-specific information.
void Setup(Level ¤tLevel)
Setup routine.
TekoSmoother()
Constructor.
void SetTekoParameters(RCP< ParameterList > tekoParams)
std::string type_
smoother type
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
void DeclareInput(Level ¤tLevel) const
Input.
virtual const Teuchos::ParameterList & GetParameterList() const
RCP< const ParameterList > GetValidParameterList() const
Input.
void Setup(Level ¤tLevel)
Setup routine.
GlobalOrdinal global_ordinal_type
void Input(Level &level, const std::string &varName) const
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the Teko smoother.
RCP< const Thyra::BlockedLinearOpBase< Scalar > > bThyOp_
RCP< BlockedCrsMatrix > bA_
Exception throws to report errors in the internal logical of the program.
Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > MapExtractorClass
std::string type_
smoother type
Teko::LinearOp inverseOp_
virtual std::string description() const
Return a simple one-line description of this object.
RCP< ParameterList > tekoParams_
Teko parameters.
Interface to block smoothers in Teko package.