46 #ifndef THYRA_MUELU_PRECONDITIONER_FACTORY_DEF_HPP
47 #define THYRA_MUELU_PRECONDITIONER_FACTORY_DEF_HPP
51 #if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::MueLuPreconditionerFactory() :
64 paramList_(
rcp(new ParameterList()))
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 bool MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::isCompatible(
const LinearOpSourceBase<Scalar>& fwdOpSrc)
const {
71 const RCP<const LinearOpBase<Scalar> > fwdOp = fwdOpSrc.getOp();
73 #ifdef HAVE_MUELU_TPETRA
74 if (Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::isTpetra(fwdOp))
return true;
77 if (Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::isBlockedOperator(fwdOp))
return true;
83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 RCP<PreconditionerBase<Scalar> > MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::createPrec()
const {
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 void MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
90 initializePrec(
const RCP<
const LinearOpSourceBase<Scalar> >& fwdOpSrc, PreconditionerBase<Scalar>* prec,
const ESupportSolveUse supportSolveUse)
const {
91 using Teuchos::rcp_dynamic_cast;
94 typedef Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> XpMap;
95 typedef Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> XpOp;
96 typedef Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpThyUtils;
97 typedef Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpCrsMat;
98 typedef Xpetra::BlockedCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpBlockedCrsMat;
99 typedef Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpMat;
100 typedef Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> XpMultVec;
102 typedef Thyra::LinearOpBase<Scalar> ThyLinOpBase;
103 #ifdef HAVE_MUELU_TPETRA
105 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpOp;
106 typedef Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> ThyTpLinOp;
115 ParameterList paramList = *paramList_;
118 const RCP<const ThyLinOpBase> fwdOp = fwdOpSrc->getOp();
122 bool bIsEpetra = XpThyUtils::isEpetra(fwdOp);
123 bool bIsTpetra = XpThyUtils::isTpetra(fwdOp);
124 bool bIsBlocked = XpThyUtils::isBlockedOperator(fwdOp);
129 RCP<XpMat> A = Teuchos::null;
132 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(fwdOp);
140 RCP<const XpCrsMat > xpetraFwdCrsMat00 = XpThyUtils::toXpetra(b00);
144 RCP<XpCrsMat> xpetraFwdCrsMatNonConst00 = Teuchos::rcp_const_cast<XpCrsMat>(xpetraFwdCrsMat00);
148 RCP<XpMat> A00 =
rcp(
new Xpetra::CrsMatrixWrap<Scalar,LocalOrdinal,GlobalOrdinal,Node>(xpetraFwdCrsMatNonConst00));
151 RCP<const XpMap> rowmap00 = A00->getRowMap();
152 RCP< const Teuchos::Comm< int > > comm = rowmap00->getComm();
155 RCP<XpBlockedCrsMat> bMat =
Teuchos::rcp(
new XpBlockedCrsMat(ThyBlockedOp, comm));
161 RCP<const XpCrsMat > xpetraFwdCrsMat = XpThyUtils::toXpetra(fwdOp);
165 RCP<XpCrsMat> xpetraFwdCrsMatNonConst = Teuchos::rcp_const_cast<XpCrsMat>(xpetraFwdCrsMat);
169 A =
rcp(
new Xpetra::CrsMatrixWrap<Scalar,LocalOrdinal,GlobalOrdinal,Node>(xpetraFwdCrsMatNonConst));
178 RCP<ThyLinOpBase> thyra_precOp = Teuchos::null;
179 thyra_precOp = rcp_dynamic_cast<Thyra::LinearOpBase<Scalar> >(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
182 RCP<MueLu::Hierarchy<Scalar,LocalOrdinal,GlobalOrdinal,Node> > H = Teuchos::null;
187 const bool startingOver = (thyra_precOp.is_null() || !paramList.isParameter(
"reuse: type") || paramList.get<std::string>(
"reuse: type") ==
"none");
189 if (startingOver ==
true) {
191 RCP<XpMultVecDouble> coordinates = Teuchos::null;
195 RCP<XpMultVec> nullspace = Teuchos::null;
196 #ifdef HAVE_MUELU_TPETRA
198 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tMV;
199 RCP<tMV> tpetra_nullspace = Teuchos::null;
201 tpetra_nullspace = paramList.get<RCP<tMV> >(
"Nullspace");
202 paramList.remove(
"Nullspace");
203 nullspace = MueLu::TpetraMultiVector_To_XpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetra_nullspace);
209 ParameterList& userParamList = paramList.sublist(
"user data");
211 userParamList.set<RCP<XpMultVecDouble> >(
"Coordinates", coordinates);
214 userParamList.set<RCP<XpMultVec> >(
"Nullspace", nullspace);
222 #if defined(HAVE_MUELU_TPETRA)
225 RCP<ThyTpLinOp> tpetr_precOp = rcp_dynamic_cast<ThyTpLinOp>(thyra_precOp);
226 RCP<MueTpOp> muelu_precOp = rcp_dynamic_cast<MueTpOp>(tpetr_precOp->getTpetraOperator(),
true);
228 H = muelu_precOp->GetHierarchy();
234 "Thyra::MueLuPreconditionerFactory: Hierarchy has no levels in it");
236 "Thyra::MueLuPreconditionerFactory: Hierarchy has no fine level operator");
237 RCP<MueLu::Level> level0 = H->GetLevel(0);
238 RCP<XpOp> O0 = level0->Get<RCP<XpOp> >(
"A");
239 RCP<XpMat> A0 = rcp_dynamic_cast<XpMat>(O0);
245 A->SetFixedBlockSize(A0->GetFixedBlockSize());
255 RCP<ThyLinOpBase > thyraPrecOp = Teuchos::null;
256 #if defined(HAVE_MUELU_TPETRA)
258 RCP<MueTpOp> muelu_tpetraOp =
rcp(
new MueTpOp(H));
260 RCP<TpOp> tpOp = Teuchos::rcp_dynamic_cast<TpOp>(muelu_tpetraOp);
261 thyraPrecOp = Thyra::createLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpOp);
270 const RCP<MueXpOp> muelu_xpetraOp =
rcp(
new MueXpOp(H));
272 RCP<const VectorSpaceBase<Scalar> > thyraRangeSpace = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(muelu_xpetraOp->getRangeMap());
273 RCP<const VectorSpaceBase<Scalar> > thyraDomainSpace = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(muelu_xpetraOp->getDomainMap());
275 RCP <Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xpOp = Teuchos::rcp_dynamic_cast<Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(muelu_xpetraOp);
276 thyraPrecOp = Thyra::xpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node>(thyraRangeSpace, thyraDomainSpace,xpOp);
281 defaultPrec->initializeUnspecified(thyraPrecOp);
285 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
286 void MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
287 uninitializePrec(PreconditionerBase<Scalar>* prec, RCP<
const LinearOpSourceBase<Scalar> >* fwdOp, ESupportSolveUse* supportSolveUse)
const {
296 *fwdOp = Teuchos::null;
299 if (supportSolveUse) {
301 *supportSolveUse = Thyra::SUPPORT_SOLVE_UNSPECIFIED;
304 defaultPrec->uninitialize();
309 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
310 void MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::setParameterList(RCP<ParameterList>
const& paramList) {
312 paramList_ = paramList;
315 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
316 RCP<ParameterList> MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getNonconstParameterList() {
320 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
321 RCP<ParameterList> MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::unsetParameterList() {
322 RCP<ParameterList> savedParamList = paramList_;
323 paramList_ = Teuchos::null;
324 return savedParamList;
327 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
328 RCP<const ParameterList> MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getParameterList()
const {
332 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
333 RCP<const ParameterList> MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getValidParameters()
const {
334 static RCP<const ParameterList> validPL;
337 validPL =
rcp(
new ParameterList());
343 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
344 std::string MueLuPreconditionerFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::description()
const {
345 return "Thyra::MueLuPreconditionerFactory";
349 #endif // HAVE_MUELU_STRATIMIKOS
351 #endif // ifdef THYRA_MUELU_PRECONDITIONER_FACTORY_DEF_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > ExtractCoordinatesFromParameterList(ParameterList ¶mList)
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)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultGlobalOrdinal GlobalOrdinal
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...
Wraps an existing MueLu::Hierarchy as a Tpetra::Operator.
Exception throws to report errors in the internal logical of the program.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Wraps an existing MueLu::Hierarchy as a Xpetra::Operator.