47 #include "Teko_TpetraBlockPreconditioner.hpp"
48 #include "Teko_Preconditioner.hpp"
51 #include "Thyra_DefaultLinearOpSource.hpp"
52 #include "Thyra_TpetraLinearOp.hpp"
55 #include "Teuchos_Time.hpp"
58 #include "Teko_TpetraBasicMappingStrategy.hpp"
62 namespace TpetraHelpers {
66 using Teuchos::rcp_dynamic_cast;
67 using Teuchos::rcpFromRef;
75 TpetraBlockPreconditioner::TpetraBlockPreconditioner(
76 const Teuchos::RCP<const PreconditionerFactory>& bfp)
77 : preconFactory_(bfp), firstBuildComplete_(false) {}
80 if ((not clearOld) && preconObj_ != Teuchos::null)
return;
81 preconObj_ = preconFactory_->createPrec();
97 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
bool clear) {
98 Teko_DEBUG_SCOPE(
"TBP::buildPreconditioner", 10);
101 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
111 RCP<const Thyra::LinearOpSourceBase<ST> > lOpSrc = Thyra::defaultLinearOpSource(thyraA);
112 preconFactory_->initializePrec(lOpSrc, &*preconObj_, Thyra::SUPPORT_SOLVE_UNSPECIFIED);
115 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
117 SetOperator(preconditioner,
false);
119 firstBuildComplete_ =
true;
121 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
122 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
124 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
141 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
142 const Tpetra::MultiVector<ST, LO, GO, NT>& tpetra_mv,
bool clear) {
143 Teko_DEBUG_SCOPE(
"TBP::buildPreconditioner - with solution", 10);
146 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
154 RCP<Thyra::MultiVectorBase<ST> > thyra_mv =
155 Thyra::createMembers(thyraA->range(), tpetra_mv.getNumVectors());
162 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
163 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
164 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
166 SetOperator(preconditioner,
false);
168 firstBuildComplete_ =
true;
170 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
171 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
173 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
190 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A) {
191 Teko_DEBUG_SCOPE(
"TBP::rebuildPreconditioner", 10);
194 if (not firstBuildComplete_) {
198 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
201 Teko_DEBUG_EXPR(timer.start(
true));
202 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
203 Teko_DEBUG_EXPR(timer.stop());
204 Teko_DEBUG_MSG(
"TBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
207 Teko_DEBUG_EXPR(timer.start(
true));
208 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), &*preconObj_,
209 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
210 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
211 Teko_DEBUG_EXPR(timer.stop());
212 Teko_DEBUG_MSG(
"TBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
214 Teko_DEBUG_EXPR(timer.start(
true));
215 SetOperator(preconditioner,
false);
216 Teko_DEBUG_EXPR(timer.stop());
217 Teko_DEBUG_MSG(
"TBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
219 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
220 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
221 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
238 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
239 const Tpetra::MultiVector<ST, LO, GO, NT>& tpetra_mv) {
240 Teko_DEBUG_SCOPE(
"TBP::rebuildPreconditioner - with solution", 10);
243 if (not firstBuildComplete_) {
247 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
250 Teko_DEBUG_EXPR(timer.start(
true));
251 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
252 Teko_DEBUG_EXPR(timer.stop());
253 Teko_DEBUG_MSG(
"TBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
256 Teko_DEBUG_EXPR(timer.start(
true));
257 RCP<Thyra::MultiVectorBase<ST> > thyra_mv =
258 Thyra::createMembers(thyraA->range(), tpetra_mv.getNumVectors());
260 Teko_DEBUG_EXPR(timer.stop());
261 Teko_DEBUG_MSG(
"TBP::rebuild vector copy time = " << timer.totalElapsedTime(), 2);
264 Teko_DEBUG_EXPR(timer.start(
true));
265 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
266 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
267 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
268 Teko_DEBUG_EXPR(timer.stop());
269 Teko_DEBUG_MSG(
"TBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
271 Teko_DEBUG_EXPR(timer.start(
true));
272 SetOperator(preconditioner,
false);
273 Teko_DEBUG_EXPR(timer.stop());
274 Teko_DEBUG_MSG(
"TBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
276 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
277 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
278 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
291 Teuchos::RCP<Preconditioner> bp = rcp_dynamic_cast<
Preconditioner>(preconObj_);
295 return Teuchos::null;
308 Teuchos::RCP<const Preconditioner> bp = rcp_dynamic_cast<
const Preconditioner>(preconObj_);
312 return Teuchos::null;
315 Teuchos::RCP<const Thyra::LinearOpBase<ST> > TpetraBlockPreconditioner::extractLinearOp(
316 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
321 if (tow != Teuchos::null)
return tow->
getThyraOp();
324 return Thyra::constTpetraLinearOp<ST, LO, GO, NT>(
325 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getDomainMap()),
326 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getRangeMap()), A);
329 Teuchos::RCP<const MappingStrategy> TpetraBlockPreconditioner::extractMappingStrategy(
330 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
332 const RCP<const TpetraOperatorWrapper>& tow = rcp_dynamic_cast<
const TpetraOperatorWrapper>(A);
335 if (tow != Teuchos::null)
return tow->getMapStrategy();
338 RCP<const Tpetra::Map<LO, GO, NT> > range = A->getRangeMap();
339 RCP<const Tpetra::Map<LO, GO, NT> > domain = A->getDomainMap();
341 new BasicMappingStrategy(range, domain, *Thyra::convertTpetraToThyraComm(range->getComm())));
virtual const RCP< PreconditionerState > getStateObject()
virtual void buildPreconditioner(const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &A, bool clear=true)
Build this preconditioner from an Epetra_Operator passed in to this object.
virtual Teuchos::RCP< PreconditionerState > getPreconditionerState()
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.
virtual void initPreconditioner(bool clearOld=false)
Build the underlying data structure for the preconditioner.
An extension of the Thyra::DefaultPreconditioner class with some specializations useful for use withi...
const RCP< const MappingStrategy > getMapStrategy() const
Get the mapping strategy for this wrapper (translate between Thyra and Epetra)
virtual void rebuildPreconditioner(const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &A)
Rebuild this preconditioner from an Epetra_Operator passed in this to object.
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...