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::rcpFromRef;
67 using Teuchos::rcp_dynamic_cast;
75 TpetraBlockPreconditioner::TpetraBlockPreconditioner(
const Teuchos::RCP<const PreconditionerFactory> & bfp)
76 : preconFactory_(bfp), firstBuildComplete_(false)
82 if((not clearOld) && preconObj_!=Teuchos::null)
84 preconObj_ = preconFactory_->createPrec();
101 Teko_DEBUG_SCOPE(
"TBP::buildPreconditioner",10);
104 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
114 RCP<const Thyra::LinearOpSourceBase<ST> > lOpSrc = Thyra::defaultLinearOpSource(thyraA);
115 preconFactory_->initializePrec(lOpSrc,&*preconObj_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
118 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
120 SetOperator(preconditioner,
false);
122 firstBuildComplete_ =
true;
124 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
127 TEUCHOS_ASSERT(firstBuildComplete_==
true);
145 Teko_DEBUG_SCOPE(
"TBP::buildPreconditioner - with solution",10);
148 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
156 RCP<Thyra::MultiVectorBase<ST> > thyra_mv = Thyra::createMembers(thyraA->range(),tpetra_mv.getNumVectors());
163 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA),thyra_mv,&*preconObj_,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);
173 TEUCHOS_ASSERT(firstBuildComplete_==
true);
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_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
209 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
210 Teko_DEBUG_EXPR(timer.stop());
211 Teko_DEBUG_MSG(
"TBP::rebuild initialize prec time = " << timer.totalElapsedTime(),2);
213 Teko_DEBUG_EXPR(timer.start(
true));
214 SetOperator(preconditioner,
false);
215 Teko_DEBUG_EXPR(timer.stop());
216 Teko_DEBUG_MSG(
"TBP::rebuild set operator time = " << timer.totalElapsedTime(),2);
218 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
220 TEUCHOS_ASSERT(firstBuildComplete_==
true);
238 Teko_DEBUG_SCOPE(
"TBP::rebuildPreconditioner - with solution",10);
241 if(not firstBuildComplete_) {
245 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
248 Teko_DEBUG_EXPR(timer.start(
true));
249 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
250 Teko_DEBUG_EXPR(timer.stop());
251 Teko_DEBUG_MSG(
"TBP::rebuild get thyraop time = " << timer.totalElapsedTime(),2);
254 Teko_DEBUG_EXPR(timer.start(
true));
255 RCP<Thyra::MultiVectorBase<ST> > thyra_mv = Thyra::createMembers(thyraA->range(),tpetra_mv.getNumVectors());
257 Teko_DEBUG_EXPR(timer.stop());
258 Teko_DEBUG_MSG(
"TBP::rebuild vector copy time = " << timer.totalElapsedTime(),2);
261 Teko_DEBUG_EXPR(timer.start(
true));
262 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA),thyra_mv,&*preconObj_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
263 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
264 Teko_DEBUG_EXPR(timer.stop());
265 Teko_DEBUG_MSG(
"TBP::rebuild initialize prec time = " << timer.totalElapsedTime(),2);
267 Teko_DEBUG_EXPR(timer.start(
true));
268 SetOperator(preconditioner,
false);
269 Teko_DEBUG_EXPR(timer.stop());
270 Teko_DEBUG_MSG(
"TBP::rebuild set operator time = " << timer.totalElapsedTime(),2);
272 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
274 TEUCHOS_ASSERT(firstBuildComplete_==
true);
288 Teuchos::RCP<Preconditioner> bp = rcp_dynamic_cast<
Preconditioner>(preconObj_);
290 if(bp!=Teuchos::null)
293 return Teuchos::null;
307 Teuchos::RCP<const Preconditioner> bp = rcp_dynamic_cast<
const Preconditioner>(preconObj_);
309 if(bp!=Teuchos::null)
312 return Teuchos::null;
315 Teuchos::RCP<const Thyra::LinearOpBase<ST> > TpetraBlockPreconditioner::extractLinearOp(
const Teuchos::RCP<
const Tpetra::Operator<ST,LO,GO,NT> > & A)
const
321 if(tow!=Teuchos::null)
325 return Thyra::constTpetraLinearOp<ST,LO,GO,NT>(Thyra::tpetraVectorSpace<ST,LO,GO,NT>(A->getDomainMap()),Thyra::tpetraVectorSpace<ST,LO,GO,NT>(A->getRangeMap()),A);
328 Teuchos::RCP<const MappingStrategy> TpetraBlockPreconditioner::extractMappingStrategy(
const Teuchos::RCP<
const Tpetra::Operator<ST,LO,GO,NT> > & A)
const
331 const RCP<const TpetraOperatorWrapper> & tow = rcp_dynamic_cast<
const TpetraOperatorWrapper>(A);
334 if(tow!=Teuchos::null)
335 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();
340 return rcp(
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...