10 #include "Teko_EpetraBlockPreconditioner.hpp"
11 #include "Teko_Preconditioner.hpp"
14 #include "Thyra_DefaultLinearOpSource.hpp"
15 #include "Thyra_EpetraLinearOp.hpp"
18 #include "Teuchos_Time.hpp"
21 #include "Teko_BasicMappingStrategy.hpp"
28 using Teuchos::rcp_dynamic_cast;
29 using Teuchos::rcpFromRef;
37 EpetraBlockPreconditioner::EpetraBlockPreconditioner(
38 const Teuchos::RCP<const PreconditionerFactory>& bfp)
39 : preconFactory_(bfp), firstBuildComplete_(false) {}
42 if ((not clearOld) && preconObj_ != Teuchos::null)
return;
43 preconObj_ = preconFactory_->createPrec();
60 Teko_DEBUG_SCOPE(
"EBP::buildPreconditioner", 10);
63 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
73 RCP<const Thyra::LinearOpSourceBase<double> > lOpSrc = Thyra::defaultLinearOpSource(thyraA);
74 preconFactory_->initializePrec(lOpSrc, &*preconObj_, Thyra::SUPPORT_SOLVE_UNSPECIFIED);
77 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
79 SetOperator(preconditioner,
false);
81 firstBuildComplete_ =
true;
83 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
86 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
103 const Epetra_MultiVector& epetra_mv,
105 Teko_DEBUG_SCOPE(
"EBP::buildPreconditioner - with solution", 10);
108 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
116 RCP<Thyra::MultiVectorBase<double> > thyra_mv =
117 Thyra::createMembers(thyraA->range(), epetra_mv.NumVectors());
124 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
125 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
126 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
128 SetOperator(preconditioner,
false);
130 firstBuildComplete_ =
true;
132 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
133 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
135 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
152 const Teuchos::RCP<const Epetra_Operator>& A) {
153 Teko_DEBUG_SCOPE(
"EBP::rebuildPreconditioner", 10);
156 if (not firstBuildComplete_) {
160 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
163 Teko_DEBUG_EXPR(timer.start(
true));
164 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
165 Teko_DEBUG_EXPR(timer.stop());
166 Teko_DEBUG_MSG(
"EBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
169 Teko_DEBUG_EXPR(timer.start(
true));
170 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), &*preconObj_,
171 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
172 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
173 Teko_DEBUG_EXPR(timer.stop());
174 Teko_DEBUG_MSG(
"EBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
176 Teko_DEBUG_EXPR(timer.start(
true));
177 SetOperator(preconditioner,
false);
178 Teko_DEBUG_EXPR(timer.stop());
179 Teko_DEBUG_MSG(
"EBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
181 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
182 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
183 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
200 const Epetra_MultiVector& epetra_mv) {
201 Teko_DEBUG_SCOPE(
"EBP::rebuildPreconditioner - with solution", 10);
204 if (not firstBuildComplete_) {
208 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
211 Teko_DEBUG_EXPR(timer.start(
true));
212 RCP<const Thyra::LinearOpBase<double> > thyraA = extractLinearOp(A);
213 Teko_DEBUG_EXPR(timer.stop());
214 Teko_DEBUG_MSG(
"EBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
217 Teko_DEBUG_EXPR(timer.start(
true));
218 RCP<Thyra::MultiVectorBase<double> > thyra_mv =
219 Thyra::createMembers(thyraA->range(), epetra_mv.NumVectors());
221 Teko_DEBUG_EXPR(timer.stop());
222 Teko_DEBUG_MSG(
"EBP::rebuild vector copy time = " << timer.totalElapsedTime(), 2);
225 Teko_DEBUG_EXPR(timer.start(
true));
226 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
227 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
228 RCP<const Thyra::LinearOpBase<double> > preconditioner = preconObj_->getUnspecifiedPrecOp();
229 Teko_DEBUG_EXPR(timer.stop());
230 Teko_DEBUG_MSG(
"EBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
232 Teko_DEBUG_EXPR(timer.start(
true));
233 SetOperator(preconditioner,
false);
234 Teko_DEBUG_EXPR(timer.stop());
235 Teko_DEBUG_MSG(
"EBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
237 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
238 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
239 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
252 Teuchos::RCP<Preconditioner> bp = rcp_dynamic_cast<
Preconditioner>(preconObj_);
256 return Teuchos::null;
269 Teuchos::RCP<const Preconditioner> bp = rcp_dynamic_cast<
const Preconditioner>(preconObj_);
273 return Teuchos::null;
276 Teuchos::RCP<const Thyra::LinearOpBase<double> > EpetraBlockPreconditioner::extractLinearOp(
277 const Teuchos::RCP<const Epetra_Operator>& A)
const {
282 if (eow != Teuchos::null)
return eow->
getThyraOp();
285 return Thyra::epetraLinearOp(A);
288 Teuchos::RCP<const MappingStrategy> EpetraBlockPreconditioner::extractMappingStrategy(
289 const Teuchos::RCP<const Epetra_Operator>& A)
const {
291 const RCP<const EpetraOperatorWrapper>& eow = rcp_dynamic_cast<
const EpetraOperatorWrapper>(A);
294 if (eow != Teuchos::null)
return eow->getMapStrategy();
297 RCP<const Epetra_Map> range = rcpFromRef(A->OperatorRangeMap());
298 RCP<const Epetra_Map> domain = rcpFromRef(A->OperatorDomainMap());
299 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.