10 #include "Teko_TpetraBlockPreconditioner.hpp"
11 #include "Teko_Preconditioner.hpp"
14 #include "Thyra_DefaultLinearOpSource.hpp"
15 #include "Thyra_TpetraLinearOp.hpp"
18 #include "Teuchos_Time.hpp"
21 #include "Teko_TpetraBasicMappingStrategy.hpp"
25 namespace TpetraHelpers {
29 using Teuchos::rcp_dynamic_cast;
30 using Teuchos::rcpFromRef;
38 TpetraBlockPreconditioner::TpetraBlockPreconditioner(
39 const Teuchos::RCP<const PreconditionerFactory>& bfp)
40 : preconFactory_(bfp), firstBuildComplete_(false) {}
43 if ((not clearOld) && preconObj_ != Teuchos::null)
return;
44 preconObj_ = preconFactory_->createPrec();
60 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
bool clear) {
61 Teko_DEBUG_SCOPE(
"TBP::buildPreconditioner", 10);
64 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
74 RCP<const Thyra::LinearOpSourceBase<ST> > lOpSrc = Thyra::defaultLinearOpSource(thyraA);
75 preconFactory_->initializePrec(lOpSrc, &*preconObj_, Thyra::SUPPORT_SOLVE_UNSPECIFIED);
78 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
80 SetOperator(preconditioner,
false);
82 firstBuildComplete_ =
true;
84 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
87 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
104 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
105 const Tpetra::MultiVector<ST, LO, GO, NT>& tpetra_mv,
bool clear) {
106 Teko_DEBUG_SCOPE(
"TBP::buildPreconditioner - with solution", 10);
109 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
117 RCP<Thyra::MultiVectorBase<ST> > thyra_mv =
118 Thyra::createMembers(thyraA->range(), tpetra_mv.getNumVectors());
125 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
126 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
127 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
129 SetOperator(preconditioner,
false);
131 firstBuildComplete_ =
true;
133 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
134 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
136 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
153 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A) {
154 Teko_DEBUG_SCOPE(
"TBP::rebuildPreconditioner", 10);
157 if (not firstBuildComplete_) {
161 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
164 Teko_DEBUG_EXPR(timer.start(
true));
165 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
166 Teko_DEBUG_EXPR(timer.stop());
167 Teko_DEBUG_MSG(
"TBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
170 Teko_DEBUG_EXPR(timer.start(
true));
171 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), &*preconObj_,
172 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
173 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
174 Teko_DEBUG_EXPR(timer.stop());
175 Teko_DEBUG_MSG(
"TBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
177 Teko_DEBUG_EXPR(timer.start(
true));
178 SetOperator(preconditioner,
false);
179 Teko_DEBUG_EXPR(timer.stop());
180 Teko_DEBUG_MSG(
"TBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
182 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
183 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
184 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
201 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A,
202 const Tpetra::MultiVector<ST, LO, GO, NT>& tpetra_mv) {
203 Teko_DEBUG_SCOPE(
"TBP::rebuildPreconditioner - with solution", 10);
206 if (not firstBuildComplete_) {
210 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
213 Teko_DEBUG_EXPR(timer.start(
true));
214 RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
215 Teko_DEBUG_EXPR(timer.stop());
216 Teko_DEBUG_MSG(
"TBP::rebuild get thyraop time = " << timer.totalElapsedTime(), 2);
219 Teko_DEBUG_EXPR(timer.start(
true));
220 RCP<Thyra::MultiVectorBase<ST> > thyra_mv =
221 Thyra::createMembers(thyraA->range(), tpetra_mv.getNumVectors());
223 Teko_DEBUG_EXPR(timer.stop());
224 Teko_DEBUG_MSG(
"TBP::rebuild vector copy time = " << timer.totalElapsedTime(), 2);
227 Teko_DEBUG_EXPR(timer.start(
true));
228 preconFactory_->initializePrec(Thyra::defaultLinearOpSource(thyraA), thyra_mv, &*preconObj_,
229 Thyra::SUPPORT_SOLVE_UNSPECIFIED);
230 RCP<const Thyra::LinearOpBase<ST> > preconditioner = preconObj_->getUnspecifiedPrecOp();
231 Teko_DEBUG_EXPR(timer.stop());
232 Teko_DEBUG_MSG(
"TBP::rebuild initialize prec time = " << timer.totalElapsedTime(), 2);
234 Teko_DEBUG_EXPR(timer.start(
true));
235 SetOperator(preconditioner,
false);
236 Teko_DEBUG_EXPR(timer.stop());
237 Teko_DEBUG_MSG(
"TBP::rebuild set operator time = " << timer.totalElapsedTime(), 2);
239 TEUCHOS_ASSERT(preconObj_ != Teuchos::null);
240 TEUCHOS_ASSERT(
getThyraOp() != Teuchos::null);
241 TEUCHOS_ASSERT(firstBuildComplete_ ==
true);
254 Teuchos::RCP<Preconditioner> bp = rcp_dynamic_cast<
Preconditioner>(preconObj_);
258 return Teuchos::null;
271 Teuchos::RCP<const Preconditioner> bp = rcp_dynamic_cast<
const Preconditioner>(preconObj_);
275 return Teuchos::null;
278 Teuchos::RCP<const Thyra::LinearOpBase<ST> > TpetraBlockPreconditioner::extractLinearOp(
279 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
284 if (tow != Teuchos::null)
return tow->
getThyraOp();
287 return Thyra::constTpetraLinearOp<ST, LO, GO, NT>(
288 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getDomainMap()),
289 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(A->getRangeMap()), A);
292 Teuchos::RCP<const MappingStrategy> TpetraBlockPreconditioner::extractMappingStrategy(
293 const Teuchos::RCP<
const Tpetra::Operator<ST, LO, GO, NT> >& A)
const {
295 const RCP<const TpetraOperatorWrapper>& tow = rcp_dynamic_cast<
const TpetraOperatorWrapper>(A);
298 if (tow != Teuchos::null)
return tow->getMapStrategy();
301 RCP<const Tpetra::Map<LO, GO, NT> > range = A->getRangeMap();
302 RCP<const Tpetra::Map<LO, GO, NT> > domain = A->getDomainMap();
304 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...