47 #ifndef THYRA_MUELU_PRECONDITIONER_FACTORY_DECL_HPP
48 #define THYRA_MUELU_PRECONDITIONER_FACTORY_DECL_HPP
52 #ifdef HAVE_MUELU_STRATIMIKOS
55 #include "Thyra_DefaultPreconditioner.hpp"
56 #include "Thyra_BlockedLinearOpBase.hpp"
58 #ifdef HAVE_MUELU_TPETRA
59 #include "Thyra_TpetraLinearOp.hpp"
60 #include "Thyra_TpetraThyraWrappers.hpp"
62 #ifdef HAVE_MUELU_EPETRA
63 #include "Thyra_EpetraLinearOp.hpp"
66 #include "Teuchos_Ptr.hpp"
68 #include "Teuchos_Assert.hpp"
76 #include <MueLu_Hierarchy.hpp>
78 #include <MueLu_HierarchyUtils.hpp>
79 #include <MueLu_Utilities.hpp>
80 #include <MueLu_ParameterListInterpreter.hpp>
81 #include <MueLu_MLParameterListInterpreter.hpp>
85 #ifdef HAVE_MUELU_TPETRA
86 #include <MueLu_TpetraOperator.hpp>
88 #ifdef HAVE_MUELU_EPETRA
92 #include "Thyra_PreconditionerFactoryBase.hpp"
107 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node = KokkosClassic::DefaultNode::DefaultNodeType>
122 bool isCompatible(
const LinearOpSourceBase<Scalar>& fwdOp)
const;
127 PreconditionerBase<Scalar>* prec,
128 const ESupportSolveUse supportSolveUse
133 ESupportSolveUse* supportSolveUse
171 #ifdef HAVE_MUELU_EPETRA
202 #ifdef HAVE_MUELU_TPETRA
203 if (Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::isTpetra(fwdOp))
return true;
206 #ifdef HAVE_MUELU_EPETRA
207 if (Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::isEpetra(fwdOp))
return true;
210 if (Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::isBlockedOperator(fwdOp))
return true;
222 PreconditionerBase<Scalar>* prec,
223 const ESupportSolveUse
225 using Teuchos::rcp_dynamic_cast;
230 typedef Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpThyUtils;
236 typedef Thyra::LinearOpBase<Scalar> ThyLinOpBase;
237 #ifdef HAVE_MUELU_TPETRA
239 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
240 (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
242 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpOp;
243 typedef Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> ThyTpLinOp;
246 #if defined(HAVE_MUELU_EPETRA)
247 typedef MueLu::EpetraOperator MueEpOp;
248 typedef Thyra::EpetraLinearOp ThyEpLinOp;
268 bool bIsEpetra = XpThyUtils::isEpetra(fwdOp);
269 bool bIsTpetra = XpThyUtils::isTpetra(fwdOp);
270 bool bIsBlocked = XpThyUtils::isBlockedOperator(fwdOp);
278 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(fwdOp);
281 TEUCHOS_TEST_FOR_EXCEPT(ThyBlockedOp->blockExists(0,0)==
false);
290 RCP<XpCrsMat> xpetraFwdCrsMatNonConst00 = Teuchos::rcp_const_cast<XpCrsMat>(xpetraFwdCrsMat00);
311 RCP<XpCrsMat> xpetraFwdCrsMatNonConst = Teuchos::rcp_const_cast<XpCrsMat>(xpetraFwdCrsMat);
325 thyra_precOp = rcp_dynamic_cast<Thyra::LinearOpBase<Scalar> >(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
333 const bool startingOver = (thyra_precOp.
is_null() || !paramList.
isParameter(
"reuse: type") || paramList.
get<std::string>(
"reuse: type") ==
"none");
335 if (startingOver ==
true) {
342 #ifdef HAVE_MUELU_TPETRA
344 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
345 (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
346 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tMV;
347 RCP<tMV> tpetra_nullspace = Teuchos::null;
349 tpetra_nullspace = paramList.
get<
RCP<tMV> >(
"Nullspace");
350 paramList.
remove(
"Nullspace");
351 nullspace = MueLu::TpetraMultiVector_To_XpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetra_nullspace);
356 "Thyra::MueLuPreconditionerFactory: Tpetra does not support GO=int and or EpetraNode.");
360 #ifdef HAVE_MUELU_EPETRA
365 paramList.
remove(
"Nullspace");
368 nullspace = rcp_dynamic_cast<XpMultVec>(xpEpNullspaceMult);
374 const std::string userName =
"user data";
388 #if defined(HAVE_MUELU_TPETRA)
390 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
391 (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
392 RCP<ThyTpLinOp> tpetr_precOp = rcp_dynamic_cast<ThyTpLinOp>(thyra_precOp);
393 RCP<MueTpOp> muelu_precOp = rcp_dynamic_cast<MueTpOp>(tpetr_precOp->getTpetraOperator(),
true);
395 H = muelu_precOp->GetHierarchy();
398 "Thyra::MueLuPreconditionerFactory: Tpetra does not support GO=int and or EpetraNode.");
402 #if defined(HAVE_MUELU_EPETRA)// && defined(HAVE_MUELU_SERIAL)
404 RCP<ThyEpLinOp> epetr_precOp = rcp_dynamic_cast<ThyEpLinOp>(thyra_precOp);
405 RCP<MueEpOp> muelu_precOp = rcp_dynamic_cast<MueEpOp>(epetr_precOp->epetra_op(),
true);
413 "Thyra::MueLuPreconditionerFactory: Hierarchy has no levels in it");
415 "Thyra::MueLuPreconditionerFactory: Hierarchy has no fine level operator");
424 A->SetFixedBlockSize(A0->GetFixedBlockSize());
435 #if defined(HAVE_MUELU_TPETRA)
437 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
438 (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
441 RCP<TpOp> tpOp = Teuchos::rcp_dynamic_cast<TpOp>(muelu_tpetraOp);
442 thyraPrecOp = Thyra::createLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpOp);
445 "Thyra::MueLuPreconditionerFactory: Tpetra does not support GO=int and or EpetraNode.");
450 #if defined(HAVE_MUELU_EPETRA)
455 "Thyra::MueLuPreconditionerFactory: Failed to cast Hierarchy to Hierarchy<double,int,int,Xpetra::EpetraNode>. Epetra runs only on the Serial node.");
459 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(muelu_epetraOp), Teuchos::POST_DESTROY,
false);
460 RCP<ThyEpLinOp> thyra_epetraOp = Thyra::nonconstEpetraLinearOp(muelu_epetraOp, NOTRANS, EPETRA_OP_APPLY_APPLY_INVERSE, EPETRA_OP_ADJOINT_UNSUPPORTED);
462 thyraPrecOp = rcp_dynamic_cast<ThyLinOpBase>(thyra_epetraOp);
476 thyraPrecOp = Thyra::xpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node>(thyraRangeSpace, thyraDomainSpace,xpOp);
481 defaultPrec->initializeUnspecified(thyraPrecOp);
487 ESupportSolveUse* supportSolveUse
497 *fwdOp = Teuchos::null;
500 if (supportSolveUse) {
502 *supportSolveUse = Thyra::SUPPORT_SOLVE_UNSPECIFIED;
505 defaultPrec->uninitialize();
522 return savedParamList;
543 std::string
description()
const {
return "Thyra::MueLuPreconditionerFactory"; }
553 #endif // HAVE_MUELU_EPETRA
557 #endif // #ifdef HAVE_MUELU_STRATIMIKOS
559 #endif // THYRA_MUELU_PRECONDITIONER_FACTORY_DECL_HPP
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
MueLuPreconditionerFactory()
Various adapters that will create a MueLu preconditioner that is an Xpetra::Matrix.
Teuchos::RCP< PreconditionerBase< Scalar > > createPrec() const
std::string description() const
T & get(const std::string &name, T def_value)
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > ExtractCoordinatesFromParameterList(ParameterList ¶mList)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool nonnull(const std::shared_ptr< T > &p)
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initializePrec(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOp, PreconditionerBase< Scalar > *prec, const ESupportSolveUse supportSolveUse) const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< Teuchos::ParameterList > paramList_
void uninitializePrec(PreconditionerBase< Scalar > *prec, Teuchos::RCP< const LinearOpSourceBase< Scalar > > *fwdOp, ESupportSolveUse *supportSolveUse) const
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
bool isParameter(const std::string &name) const
bool remove(std::string const &name, bool throwIfNotExists=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Teuchos::ParameterList > paramList_
Concrete preconditioner factory subclass for Thyra based on MueLu.Add support for MueLu preconditione...
Teuchos::RCP< MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node > > CreateXpetraPreconditioner(Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > op, const Teuchos::ParameterList &inParamList)
Helper function to create a MueLu preconditioner that can be used by Xpetra.Given an Xpetra::Matrix...
void uninitializePrec(PreconditionerBase< Scalar > *prec, Teuchos::RCP< const LinearOpSourceBase< Scalar > > *fwdOp, ESupportSolveUse *supportSolveUse) const
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOp) const
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
MueLuPreconditionerFactory()
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
std::string description() const
Teuchos::RCP< PreconditionerBase< Scalar > > createPrec() const
bool isType(const std::string &name) const
Wraps an existing MueLu::Hierarchy as a Tpetra::Operator.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void initializePrec(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, PreconditionerBase< Scalar > *prec, const ESupportSolveUse) const
Exception throws to report errors in the internal logical of the program.
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
Wraps an existing MueLu::Hierarchy as a Xpetra::Operator.