47 #include "Teko_TpetraInverseFactoryOperator.hpp"
50 #include "Teko_TpetraBasicMappingStrategy.hpp"
53 #include "Thyra_TpetraLinearOp.hpp"
57 using Teuchos::rcp_dynamic_cast;
58 using Teuchos::rcpFromRef;
61 namespace TpetraHelpers {
69 InverseFactoryOperator::InverseFactoryOperator(
const Teuchos::RCP<const InverseFactory>& ifp)
70 : inverseFactory_(ifp), firstBuildComplete_(false), setConstFwdOp_(true) {}
85 if (not clearOld)
return;
86 invOperator_ = Teuchos::null;
102 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
bool clear) {
103 Teko_DEBUG_SCOPE(
"InverseFactoryOperator::buildInverseOperator", 10);
106 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
116 SetOperator(invOperator_,
false);
118 firstBuildComplete_ =
true;
120 if (setConstFwdOp_) fwdOp_ = A;
122 setConstFwdOp_ =
true;
124 TEUCHOS_ASSERT(invOperator_ != Teuchos::null);
126 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
128 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
132 const Teuchos::RCP<Tpetra::Operator<ST, LO, GO, NT> >& A,
bool ) {
133 setConstFwdOp_ =
false;
135 fwdOp_.initialize(A);
139 TEUCHOS_ASSERT(setConstFwdOp_ ==
true);
155 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A) {
156 Teko_DEBUG_SCOPE(
"InverseFactoryOperator::rebuildPreconditioner", 10);
159 if (not firstBuildComplete_) {
164 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
167 if (setConstFwdOp_) fwdOp_.initialize(A);
169 SetOperator(invOperator_,
false);
171 setConstFwdOp_ =
true;
174 TEUCHOS_ASSERT(invOperator_ != Teuchos::null);
175 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
176 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
180 const Teuchos::RCP<Tpetra::Operator<ST, LO, GO, NT> >& A) {
181 setConstFwdOp_ =
false;
183 fwdOp_.initialize(A);
188 TEUCHOS_ASSERT(setConstFwdOp_ ==
true);
191 Teuchos::RCP<const Thyra::LinearOpBase<ST> > InverseFactoryOperator::extractLinearOp(
192 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
197 if (eow != Teuchos::null)
return eow->
getThyraOp();
200 return Thyra::constTpetraLinearOp<ST, LO, GO, NT>(
201 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getRangeMap()),
202 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getDomainMap()), A);
205 Teuchos::RCP<const MappingStrategy> InverseFactoryOperator::extractMappingStrategy(
206 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
208 const RCP<const TpetraOperatorWrapper>& eow = rcp_dynamic_cast<
const TpetraOperatorWrapper>(A);
211 if (eow != Teuchos::null)
return eow->getMapStrategy();
214 RCP<const Tpetra::Map<LO, GO, NT> > range = A->getRangeMap();
215 RCP<const Tpetra::Map<LO, GO, NT> > domain = A->getDomainMap();
217 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...