47 #include "Teko_EpetraBlockPreconditioner.hpp"
48 #include "Teko_Preconditioner.hpp"
51 #include "Thyra_DefaultLinearOpSource.hpp"
52 #include "Thyra_EpetraLinearOp.hpp"
55 #include "Teuchos_Time.hpp"
58 #include "Teko_BasicMappingStrategy.hpp"
65 using Teuchos::rcpFromRef;
66 using Teuchos::rcp_dynamic_cast;
74 EpetraBlockPreconditioner::EpetraBlockPreconditioner(
const Teuchos::RCP<const PreconditionerFactory> & bfp)
75 : preconFactory_(bfp), firstBuildComplete_(false)
81 if((not clearOld) && preconObj_!=Teuchos::null)
83 preconObj_ = preconFactory_->createPrec();
100 Teko_DEBUG_SCOPE(
"EBP::buildPreconditioner",10);
103 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
113 RCP<const Thyra::LinearOpSourceBase<double> > lOpSrc = Thyra::defaultLinearOpSource(thyraA);
114 preconFactory_->initializePrec(lOpSrc,&*preconObj_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
117 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
119 SetOperator(preconditioner,
false);
121 firstBuildComplete_ =
true;
123 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
126 TEUCHOS_ASSERT(firstBuildComplete_==
true);
144 Teko_DEBUG_SCOPE(
"EBP::buildPreconditioner - with solution",10);
147 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
155 RCP<Thyra::MultiVectorBase<double> > thyra_mv = Thyra::createMembers(thyraA->range(),epetra_mv.NumVectors());
162 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA),thyra_mv,&*preconObj_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
163 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
165 SetOperator(preconditioner,
false);
167 firstBuildComplete_ =
true;
169 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
172 TEUCHOS_ASSERT(firstBuildComplete_==
true);
190 Teko_DEBUG_SCOPE(
"EBP::rebuildPreconditioner",10);
193 if(not firstBuildComplete_) {
197 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
200 Teko_DEBUG_EXPR(timer.start(
true));
201 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
202 Teko_DEBUG_EXPR(timer.stop());
203 Teko_DEBUG_MSG(
"EBP::rebuild get thyraop time = " << timer.totalElapsedTime(),2);
206 Teko_DEBUG_EXPR(timer.start(
true));
207 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA),&*preconObj_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
208 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
209 Teko_DEBUG_EXPR(timer.stop());
210 Teko_DEBUG_MSG(
"EBP::rebuild initialize prec time = " << timer.totalElapsedTime(),2);
212 Teko_DEBUG_EXPR(timer.start(
true));
213 SetOperator(preconditioner,
false);
214 Teko_DEBUG_EXPR(timer.stop());
215 Teko_DEBUG_MSG(
"EBP::rebuild set operator time = " << timer.totalElapsedTime(),2);
217 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
219 TEUCHOS_ASSERT(firstBuildComplete_==
true);
237 Teko_DEBUG_SCOPE(
"EBP::rebuildPreconditioner - with solution",10);
240 if(not firstBuildComplete_) {
244 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
247 Teko_DEBUG_EXPR(timer.start(
true));
248 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
249 Teko_DEBUG_EXPR(timer.stop());
250 Teko_DEBUG_MSG(
"EBP::rebuild get thyraop time = " << timer.totalElapsedTime(),2);
253 Teko_DEBUG_EXPR(timer.start(
true));
254 RCP<Thyra::MultiVectorBase<double> > thyra_mv = Thyra::createMembers(thyraA->range(),epetra_mv.NumVectors());
256 Teko_DEBUG_EXPR(timer.stop());
257 Teko_DEBUG_MSG(
"EBP::rebuild vector copy time = " << timer.totalElapsedTime(),2);
260 Teko_DEBUG_EXPR(timer.start(
true));
261 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA),thyra_mv,&*preconObj_,Thyra::SUPPORT_SOLVE_UNSPECIFIED);
262 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
263 Teko_DEBUG_EXPR(timer.stop());
264 Teko_DEBUG_MSG(
"EBP::rebuild initialize prec time = " << timer.totalElapsedTime(),2);
266 Teko_DEBUG_EXPR(timer.start(
true));
267 SetOperator(preconditioner,
false);
268 Teko_DEBUG_EXPR(timer.stop());
269 Teko_DEBUG_MSG(
"EBP::rebuild set operator time = " << timer.totalElapsedTime(),2);
271 TEUCHOS_ASSERT(preconObj_!=Teuchos::null);
273 TEUCHOS_ASSERT(firstBuildComplete_==
true);
287 Teuchos::RCP<Preconditioner> bp = rcp_dynamic_cast<
Preconditioner>(preconObj_);
289 if(bp!=Teuchos::null)
292 return Teuchos::null;
306 Teuchos::RCP<const Preconditioner> bp = rcp_dynamic_cast<
const Preconditioner>(preconObj_);
308 if(bp!=Teuchos::null)
311 return Teuchos::null;
314 Teuchos::RCP<const Thyra::LinearOpBase<double> > EpetraBlockPreconditioner::extractLinearOp(
const Teuchos::RCP<const Epetra_Operator> & A)
const
320 if(eow!=Teuchos::null)
324 return Thyra::epetraLinearOp(A);
327 Teuchos::RCP<const MappingStrategy> EpetraBlockPreconditioner::extractMappingStrategy(
const Teuchos::RCP<const Epetra_Operator> & A)
const
330 const RCP<const EpetraOperatorWrapper> & eow = rcp_dynamic_cast<
const EpetraOperatorWrapper>(A);
333 if(eow!=Teuchos::null)
334 return eow->getMapStrategy();
337 RCP<const Epetra_Map> range = rcpFromRef(A->OperatorRangeMap());
338 RCP<const Epetra_Map> domain = rcpFromRef(A->OperatorDomainMap());
339 return rcp(
new BasicMappingStrategy(range,domain,A->Comm()));
virtual const RCP< PreconditionerState > getStateObject()
virtual void buildPreconditioner(const Teuchos::RCP< const Epetra_Operator > &A, bool clear=true)
Build this preconditioner from an Epetra_Operator passed in to this object.
virtual void initPreconditioner(bool clearOld=false)
Build the underlying data structure for the preconditioner.
virtual void rebuildPreconditioner(const Teuchos::RCP< const Epetra_Operator > &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...
virtual Teuchos::RCP< PreconditionerState > getPreconditionerState()
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)
An extension of the Thyra::DefaultPreconditioner class with some specializations useful for use withi...
const RCP< const Thyra::LinearOpBase< double > > getThyraOp() const
Return the thyra operator associated with this wrapper.