10 #ifndef MUELU_XPETRA_THYRALINEAROP_HPP
11 #define MUELU_XPETRA_THYRALINEAROP_HPP
13 #if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
21 #include <Thyra_VectorBase.hpp>
22 #include <Thyra_SolveSupportTypes.hpp>
23 #include <Thyra_LinearOpWithSolveBase.hpp>
24 #include <Teuchos_AbstractFactoryStd.hpp>
25 #include <Stratimikos_LinearSolverBuilder.hpp>
36 class XpetraThyraLinearOp :
public Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
38 XpetraThyraLinearOp() =
default;
46 RCP<ParameterList> params)
48 throw Exceptions::RuntimeError(
"Interface not supported");
52 ~XpetraThyraLinearOp() =
default;
58 throw Exceptions::RuntimeError(
"Interface not supported");
63 throw Exceptions::RuntimeError(
"Interface not supported");
76 throw Exceptions::RuntimeError(
"Interface not supported");
80 bool hasTransposeApply()
const {
return false; }
86 throw Exceptions::RuntimeError(
"Interface not supported");
90 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A_;
102 XpetraThyraLinearOp() =
default;
110 RCP<ParameterList> params)
115 Stratimikos::LinearSolverBuilder<Scalar> linearSolverBuilder;
116 typedef Thyra::PreconditionerFactoryBase<Scalar> Base;
117 typedef Thyra::MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> ImplMueLu;
118 linearSolverBuilder.setPreconditioningStrategyFactory(Teuchos::abstractFactoryStd<Base, ImplMueLu>(),
"MueLu");
120 linearSolverBuilder.setParameterList(params);
125 auto precFactory = Thyra::createPreconditioningStrategy(linearSolverBuilder);
126 auto prec = precFactory->createPrec();
128 precFactory->initializePrec(Thyra::defaultLinearOpSource(thyraA), prec.get(), Thyra::SUPPORT_SOLVE_UNSPECIFIED);
133 ~XpetraThyraLinearOp() =
default;
139 return A_->getDomainMap();
144 return A_->getRangeMap();
157 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rcpX = Teuchos::rcpFromRef(X);
158 RCP<const Thyra::MultiVectorBase<Scalar>> thyraX = Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::toThyraMultiVector(rcpX);
160 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rcpY = Teuchos::rcpFromRef(Y);
161 RCP<Thyra::MultiVectorBase<Scalar>> thyraY = Teuchos::rcp_const_cast<Thyra::MultiVectorBase<Scalar>>(Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::toThyraMultiVector(rcpY));
163 prec_->getUnspecifiedPrecOp()->apply(Thyra::NOTRANS, *thyraX, thyraY.ptr(), alpha, beta);
164 Y = *Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::toXpetra(thyraY, Y.
getMap()->getComm());
168 bool hasTransposeApply()
const {
return false; }
175 R.
update(STS::one(), B, STS::zero());
180 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A_;
181 RCP<Thyra::PreconditionerBase<Scalar>> prec_;
186 #endif // defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
188 #endif // MUELU_XPETRA_THYRALINEAROP_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
MueLu::DefaultScalar Scalar
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
void residual(const Operator< SC, LO, GO, NO > &Aop, const MultiVector< SC, LO, GO, NO > &X_in, const MultiVector< SC, LO, GO, NO > &B_in, MultiVector< SC, LO, GO, NO > &R_in)