10#include "Teko_TpetraInverseFactoryOperator.hpp"
13#include "Teko_TpetraBasicMappingStrategy.hpp"
16#include "Thyra_TpetraLinearOp.hpp"
17#include "Thyra_TpetraThyraWrappers.hpp"
21using Teuchos::rcp_dynamic_cast;
22using Teuchos::rcpFromRef;
25namespace TpetraHelpers {
33InverseFactoryOperator::InverseFactoryOperator(
const Teuchos::RCP<const InverseFactory>& ifp)
34 : inverseFactory_(ifp), firstBuildComplete_(false), setConstFwdOp_(true) {}
49 if (not clearOld)
return;
50 invOperator_ = Teuchos::null;
66 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
bool clear) {
67 Teko_DEBUG_SCOPE(
"InverseFactoryOperator::buildInverseOperator", 10);
70 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
80 SetOperator(invOperator_,
false);
82 firstBuildComplete_ =
true;
84 if (setConstFwdOp_) fwdOp_ = A;
86 setConstFwdOp_ =
true;
88 TEUCHOS_ASSERT(invOperator_ != Teuchos::null);
92 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
96 const Teuchos::RCP<Tpetra::Operator<ST, LO, GO, NT> >& A,
bool ) {
97 setConstFwdOp_ =
false;
103 TEUCHOS_ASSERT(setConstFwdOp_ ==
true);
119 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A) {
120 Teko_DEBUG_SCOPE(
"InverseFactoryOperator::rebuildPreconditioner", 10);
123 if (not firstBuildComplete_) {
128 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
131 if (setConstFwdOp_) fwdOp_.initialize(A);
133 SetOperator(invOperator_,
false);
135 setConstFwdOp_ =
true;
138 TEUCHOS_ASSERT(invOperator_ != Teuchos::null);
139 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
140 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
144 const Teuchos::RCP<Tpetra::Operator<ST, LO, GO, NT> >& A) {
145 setConstFwdOp_ =
false;
147 fwdOp_.initialize(A);
152 TEUCHOS_ASSERT(setConstFwdOp_ ==
true);
155Teuchos::RCP<const Thyra::LinearOpBase<ST> > InverseFactoryOperator::extractLinearOp(
156 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
158 const RCP<const TpetraOperatorWrapper>& eow = rcp_dynamic_cast<const TpetraOperatorWrapper>(A);
161 if (eow != Teuchos::null)
return eow->getThyraOp();
164 return Thyra::constTpetraLinearOp<ST, LO, GO, NT>(
165 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getRangeMap()),
166 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getDomainMap()), A);
169Teuchos::RCP<const MappingStrategy> InverseFactoryOperator::extractMappingStrategy(
170 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
172 const RCP<const TpetraOperatorWrapper>& eow = rcp_dynamic_cast<const TpetraOperatorWrapper>(A);
175 if (eow != Teuchos::null)
return eow->getMapStrategy();
178 RCP<const Tpetra::Map<LO, GO, NT> > range = A->getRangeMap();
179 RCP<const Tpetra::Map<LO, GO, NT> > domain = A->getDomainMap();
181 new BasicMappingStrategy(range, domain, *Thyra::convertTpetraToThyraComm(range->getComm())));
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
virtual void buildInverseOperator(const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &A, bool clear=true)
Build this inverse operator from a Tpetra::Operator passed in to this object.
virtual void rebuildInverseOperator(const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &A)
Rebuild this inverse from a Tpetra::Operator passed in this to object.
virtual void initInverse(bool clearOld=false)
Build the underlying data structure for the inverse operator.
Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > getForwardOp() const
Flip a mapping strategy object around to give the "inverse" mapping strategy.
const RCP< const MappingStrategy > getMapStrategy() const
Get the mapping strategy for this wrapper (translate between Thyra and Tpetra)
const RCP< const Thyra::LinearOpBase< ST > > getThyraOp() const
Return the thyra operator associated with this wrapper.