10#include "Teko_TpetraInverseFactoryOperator.hpp"
13#include "Teko_TpetraBasicMappingStrategy.hpp"
16#include "Thyra_TpetraLinearOp.hpp"
20using Teuchos::rcp_dynamic_cast;
21using Teuchos::rcpFromRef;
24namespace TpetraHelpers {
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);
77 invOperator_ = Teko::buildInverse(*inverseFactory_, thyraA);
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);
128 Teko::rebuildInverse(*inverseFactory_, thyraA, invOperator_);
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);
154Teuchos::RCP<const Thyra::LinearOpBase<ST> > InverseFactoryOperator::extractLinearOp(
155 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
157 const RCP<const TpetraOperatorWrapper>& eow = rcp_dynamic_cast<const TpetraOperatorWrapper>(A);
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);
168Teuchos::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())));
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.
InverseFactoryOperator(const Teuchos::RCP< const InverseFactory > &bfp)
Constructor that takes the InverseFactory that will build the operator.
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.
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 Epetra).
const RCP< const Thyra::LinearOpBase< ST > > getThyraOp() const
Return the thyra operator associated with this wrapper.