10 #include "Teko_TpetraInverseFactoryOperator.hpp"
13 #include "Teko_TpetraBasicMappingStrategy.hpp"
16 #include "Thyra_TpetraLinearOp.hpp"
20 using Teuchos::rcp_dynamic_cast;
21 using Teuchos::rcpFromRef;
24 namespace TpetraHelpers {
32 InverseFactoryOperator::InverseFactoryOperator(
const Teuchos::RCP<const InverseFactory>& ifp)
33 : inverseFactory_(ifp), firstBuildComplete_(false), setConstFwdOp_(true) {}
48 if (not clearOld)
return;
49 invOperator_ = Teuchos::null;
65 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
bool clear) {
66 Teko_DEBUG_SCOPE(
"InverseFactoryOperator::buildInverseOperator", 10);
69 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
79 SetOperator(invOperator_,
false);
81 firstBuildComplete_ =
true;
83 if (setConstFwdOp_) fwdOp_ = A;
85 setConstFwdOp_ =
true;
87 TEUCHOS_ASSERT(invOperator_ != Teuchos::null);
91 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
95 const Teuchos::RCP<Tpetra::Operator<ST, LO, GO, NT> >& A,
bool ) {
96 setConstFwdOp_ =
false;
102 TEUCHOS_ASSERT(setConstFwdOp_ ==
true);
118 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A) {
119 Teko_DEBUG_SCOPE(
"InverseFactoryOperator::rebuildPreconditioner", 10);
122 if (not firstBuildComplete_) {
127 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
130 if (setConstFwdOp_) fwdOp_.initialize(A);
132 SetOperator(invOperator_,
false);
134 setConstFwdOp_ =
true;
137 TEUCHOS_ASSERT(invOperator_ != Teuchos::null);
138 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
139 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
143 const Teuchos::RCP<Tpetra::Operator<ST, LO, GO, NT> >& A) {
144 setConstFwdOp_ =
false;
146 fwdOp_.initialize(A);
151 TEUCHOS_ASSERT(setConstFwdOp_ ==
true);
154 Teuchos::RCP<const Thyra::LinearOpBase<ST> > InverseFactoryOperator::extractLinearOp(
155 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
160 if (eow != Teuchos::null)
return eow->
getThyraOp();
163 return Thyra::constTpetraLinearOp<ST, LO, GO, NT>(
164 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getRangeMap()),
165 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getDomainMap()), A);
168 Teuchos::RCP<const MappingStrategy> InverseFactoryOperator::extractMappingStrategy(
169 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
171 const RCP<const TpetraOperatorWrapper>& eow = rcp_dynamic_cast<
const TpetraOperatorWrapper>(A);
174 if (eow != Teuchos::null)
return eow->getMapStrategy();
177 RCP<const Tpetra::Map<LO, GO, NT> > range = A->getRangeMap();
178 RCP<const Tpetra::Map<LO, GO, NT> > domain = A->getDomainMap();
180 new BasicMappingStrategy(range, domain, *Thyra::convertTpetraToThyraComm(range->getComm())));
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
virtual void initInverse(bool clearOld=false)
Build the underlying data structure for the inverse operator.
virtual void buildInverseOperator(const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &A, bool clear=true)
Build this inverse operator from an Epetra_Operator passed in to this object.
Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > getForwardOp() const
const RCP< const Thyra::LinearOpBase< ST > > getThyraOp() const
Return the thyra operator associated with this wrapper.
Flip a mapping strategy object around to give the "inverse" mapping strategy.
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
const RCP< const MappingStrategy > getMapStrategy() const
Get the mapping strategy for this wrapper (translate between Thyra and Epetra)
virtual void rebuildInverseOperator(const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &A)
Rebuild this inverse from an Epetra_Operator passed in this to object.
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...