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::rcp_dynamic_cast;
66 using Teuchos::rcpFromRef;
74 EpetraBlockPreconditioner::EpetraBlockPreconditioner(
75 const Teuchos::RCP<const PreconditionerFactory>& bfp)
76 : preconFactory_(bfp), firstBuildComplete_(false) {}
79 if ((not clearOld) && preconObj_ != Teuchos::null)
return;
80 preconObj_ = preconFactory_->createPrec();
97 Teko_DEBUG_SCOPE(
"EBP::buildPreconditioner", 10);
100 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
110 RCP<const Thyra::LinearOpSourceBase<double> > lOpSrc = Thyra::defaultLinearOpSource(thyraA);
111 preconFactory_->initializePrec(lOpSrc, &*preconObj_, Thyra::SUPPORT_SOLVE_UNSPECIFIED);
114 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
116 SetOperator(preconditioner,
false);
118 firstBuildComplete_ =
true;
120 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
121 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
123 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
140 const Epetra_MultiVector& epetra_mv,
142 Teko_DEBUG_SCOPE(
"EBP::buildPreconditioner - with solution", 10);
145 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
153 RCP<Thyra::MultiVectorBase<double> > thyra_mv =
154 Thyra::createMembers(thyraA->range(), epetra_mv.NumVectors());
161 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
162 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);
170 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
172 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
189 const Teuchos::RCP<const Epetra_Operator>& A) {
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_,
208 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
209 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
210 Teko_DEBUG_EXPR(timer.stop());
211 Teko_DEBUG_MSG(
"EBP::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(
"EBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
218 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
219 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
220 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
237 const Epetra_MultiVector& epetra_mv) {
238 Teko_DEBUG_SCOPE(
"EBP::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<double> > thyraA = extractLinearOp(A);
250 Teko_DEBUG_EXPR(timer.stop());
251 Teko_DEBUG_MSG(
"EBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
254 Teko_DEBUG_EXPR(timer.start(
true));
255 RCP<Thyra::MultiVectorBase<double> > thyra_mv =
256 Thyra::createMembers(thyraA->range(), epetra_mv.NumVectors());
258 Teko_DEBUG_EXPR(timer.stop());
259 Teko_DEBUG_MSG(
"EBP::rebuild vector copy time = " << timer.totalElapsedTime(), 2);
262 Teko_DEBUG_EXPR(timer.start(
true));
263 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
264 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
265 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
266 Teko_DEBUG_EXPR(timer.stop());
267 Teko_DEBUG_MSG(
"EBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
269 Teko_DEBUG_EXPR(timer.start(
true));
270 SetOperator(preconditioner,
false);
271 Teko_DEBUG_EXPR(timer.stop());
272 Teko_DEBUG_MSG(
"EBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
274 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
275 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
276 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
289 Teuchos::RCP<Preconditioner> bp = rcp_dynamic_cast<
Preconditioner>(preconObj_);
293 return Teuchos::null;
306 Teuchos::RCP<const Preconditioner> bp = rcp_dynamic_cast<
const Preconditioner>(preconObj_);
310 return Teuchos::null;
313 Teuchos::RCP<const Thyra::LinearOpBase<double> > EpetraBlockPreconditioner::extractLinearOp(
314 const Teuchos::RCP<const Epetra_Operator>& A)
const {
319 if (eow != Teuchos::null)
return eow->
getThyraOp();
322 return Thyra::epetraLinearOp(A);
325 Teuchos::RCP<const MappingStrategy> EpetraBlockPreconditioner::extractMappingStrategy(
326 const Teuchos::RCP<const Epetra_Operator>& A)
const {
328 const RCP<const EpetraOperatorWrapper>& eow = rcp_dynamic_cast<
const EpetraOperatorWrapper>(A);
331 if (eow != Teuchos::null)
return eow->getMapStrategy();
334 RCP<const Epetra_Map> range = rcpFromRef(A->OperatorRangeMap());
335 RCP<const Epetra_Map> domain = rcpFromRef(A->OperatorDomainMap());
336 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.