9 #ifndef Thyra_AdjointLinearOpWithSolveFactory_hpp
10 #define Thyra_AdjointLinearOpWithSolveFactory_hpp
12 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
13 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
14 #include "Thyra_DefaultAdjointLinearOpWithSolve.hpp"
15 #include "Thyra_DefaultLinearOpSource.hpp"
23 template<
class Scalar>
25 :
virtual public LinearOpWithSolveFactoryBase<Scalar>
46 const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf
61 const RCP<
const LinearOpWithSolveFactoryBase<Scalar> > &lowsf
96 const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
97 const std::string &precFactoryName
101 virtual RCP<PreconditionerFactoryBase<Scalar> >
106 RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
107 std::string *precFactoryName
111 const LinearOpSourceBase<Scalar> &fwdOpSrc
114 virtual RCP<LinearOpWithSolveBase<Scalar> >
createOp()
const;
117 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
118 LinearOpWithSolveBase<Scalar> *Op,
119 const ESupportSolveUse supportSolveUse
123 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
124 LinearOpWithSolveBase<Scalar> *Op
128 LinearOpWithSolveBase<Scalar> *Op,
129 RCP<
const LinearOpSourceBase<Scalar> > *fwdOpSrc,
130 RCP<
const PreconditionerBase<Scalar> > *prec,
131 RCP<
const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
132 ESupportSolveUse *supportSolveUse
136 const EPreconditionerInputType precOpType
140 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
141 const RCP<
const PreconditionerBase<Scalar> > &prec,
142 LinearOpWithSolveBase<Scalar> *Op,
143 const ESupportSolveUse supportSolveUse
147 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
148 const RCP<
const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
149 LinearOpWithSolveBase<Scalar> *Op,
150 const ESupportSolveUse supportSolveUse
166 typedef Teuchos::ConstNonconstObjectContainer<LinearOpWithSolveFactoryBase<Scalar> >
LOWSF_t;
176 template<
class Scalar>
177 RCP<const AdjointLinearOpWithSolveFactory<Scalar> >
179 const RCP<
const LinearOpWithSolveFactoryBase<Scalar> > &lowsf
182 RCP<AdjointLinearOpWithSolveFactory<Scalar> > alowsf =
184 alowsf->initialize(lowsf);
192 template<
class Scalar>
193 RCP<AdjointLinearOpWithSolveFactory<Scalar> >
195 const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf
198 RCP<AdjointLinearOpWithSolveFactory<Scalar> > alowsf =
200 alowsf->nonconstInitialize(lowsf);
206 template<
class Scalar>
210 const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf
214 TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
216 lowsf_.initialize(lowsf);
219 template<
class Scalar>
223 const RCP<
const LinearOpWithSolveFactoryBase<Scalar> > &lowsf
227 TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
229 lowsf_.initialize(lowsf);
232 template<
class Scalar>
233 RCP<LinearOpWithSolveFactoryBase<Scalar> >
237 return lowsf_.getNonconstObj();
240 template<
class Scalar>
241 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
245 return lowsf_.getConstObj();
250 template<
class Scalar>
255 std::ostringstream oss;
256 oss << this->Teuchos::Describable::description()
259 if (!is_null(lowsf_.getConstObj()))
260 oss << lowsf_.getConstObj()->description();
269 template<
class Scalar>
273 RCP<ParameterList>
const& paramList
276 lowsf_.getNonconstObj()->setParameterList(paramList);
279 template<
class Scalar>
284 return lowsf_.getNonconstObj()->getNonconstParameterList();
287 template<
class Scalar>
292 return lowsf_.getNonconstObj()->unsetParameterList();
295 template<
class Scalar>
296 RCP<const ParameterList>
300 return lowsf_.getConstObj()->getParameterList();
303 template<
class Scalar>
304 RCP<const ParameterList>
308 return lowsf_.getConstObj()->getValidParameters();
313 template<
class Scalar>
318 return lowsf_.getConstObj()->acceptsPreconditionerFactory();
321 template<
class Scalar>
325 const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
326 const std::string &precFactoryName
330 RCP<APF> apf = Teuchos::rcp_dynamic_cast<APF>(precFactory);
331 lowsf_.getNonconstObj()->setPreconditionerFactory(
332 apf->getNonconstPreconditionerFactory(),
336 template<
class Scalar>
337 RCP<PreconditionerFactoryBase<Scalar> >
341 RCP<PreconditionerFactoryBase<Scalar> > prec_fac =
342 lowsf_.getConstObj()->getPreconditionerFactory();
343 if (prec_fac == Teuchos::null)
344 return Teuchos::null;
346 return nonconstAdjointPreconditionerFactory(prec_fac);
349 template<
class Scalar>
352 RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
353 std::string *precFactoryName
356 RCP<PreconditionerFactoryBase<Scalar> > inner_precFactory;
357 lowsf_.getNonconstObj()->unsetPreconditionerFactory(
358 precFactory ? &inner_precFactory : NULL,
361 *precFactory = nonconstAdjointPreconditionerFactory(inner_precFactory);
364 template<
class Scalar>
368 const LinearOpSourceBase<Scalar> &fwdOpSrc
371 typedef DefaultScaledAdjointLinearOp<Scalar> ALO;
373 Teuchos::rcp_dynamic_cast<
const ALO>(fwdOpSrc.getOp().assert_not_null());
374 RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc =
375 defaultLinearOpSource<Scalar>(alo->getOp());
376 return lowsf_.getConstObj()->isCompatible(*inner_fwdOpSrc);
379 template<
class Scalar>
380 RCP<LinearOpWithSolveBase<Scalar> >
384 return nonconstAdjointLows<Scalar>(lowsf_.getConstObj()->createOp());
387 template<
class Scalar>
391 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
392 LinearOpWithSolveBase<Scalar> *Op,
393 const ESupportSolveUse supportSolveUse
396 using Teuchos::dyn_cast;
397 using Teuchos::rcp_dynamic_cast;
400 TEUCHOS_TEST_FOR_EXCEPT(0==Op);
404 lowsf_.getConstObj()->setOStream(this->getOStream());
405 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
407 typedef DefaultScaledAdjointLinearOp<Scalar> ALO;
408 typedef DefaultAdjointLinearOpWithSolve<Scalar> ALOWS;
409 const RCP<const ALO> alo =
410 rcp_dynamic_cast<
const ALO>(fwdOpSrc->getOp().assert_not_null());
411 ALOWS &alows = dyn_cast<ALOWS>(*Op);
413 lowsf_.getConstObj()->initializeOp(
414 defaultLinearOpSource<Scalar>(alo->getOrigOp()),
415 alows.getNonconstOp().get(),
419 template<
class Scalar>
423 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
424 LinearOpWithSolveBase<Scalar> *Op
427 using Teuchos::dyn_cast;
428 using Teuchos::rcp_dynamic_cast;
431 TEUCHOS_TEST_FOR_EXCEPT(0==Op);
435 lowsf_.getConstObj()->setOStream(this->getOStream());
436 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
438 typedef DefaultScaledAdjointLinearOp<Scalar> ALO;
439 typedef DefaultAdjointLinearOpWithSolve<Scalar> ALOWS;
440 const RCP<const ALO> alo =
441 rcp_dynamic_cast<
const ALO>(fwdOpSrc->getOp().assert_not_null());
442 ALOWS &alows = dyn_cast<ALOWS>(*Op);
444 lowsf_.getConstObj()->initializeAndReuseOp(
445 defaultLinearOpSource<Scalar>(alo->getOrigOp()),
446 alows.getNonconstOp().get());
449 template<
class Scalar>
453 LinearOpWithSolveBase<Scalar> *Op,
454 RCP<
const LinearOpSourceBase<Scalar> > *fwdOpSrc,
455 RCP<
const PreconditionerBase<Scalar> > *prec,
456 RCP<
const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
457 ESupportSolveUse *supportSolveUse
460 using Teuchos::dyn_cast;
463 TEUCHOS_TEST_FOR_EXCEPT(0==Op);
465 typedef DefaultAdjointLinearOpWithSolve<Scalar> ALOWS;
466 ALOWS &alowsOp = dyn_cast<ALOWS>(*Op);
467 RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc;
468 RCP<const PreconditionerBase<Scalar> > inner_prec;
469 RCP<const LinearOpSourceBase<Scalar> > inner_approxFwdOpSrc;
470 lowsf_.getConstObj()->uninitializeOp(
471 alowsOp.getNonconstOp().get(),
472 fwdOpSrc ? &inner_fwdOpSrc : NULL,
473 prec ? &inner_prec : NULL,
474 approxFwdOpSrc ? &inner_approxFwdOpSrc : NULL,
478 defaultLinearOpSource<Scalar>(adjoint(inner_fwdOpSrc->getOp()));
480 *prec = adjointPreconditioner(inner_prec);
483 defaultLinearOpSource<Scalar>(adjoint(inner_approxFwdOpSrc->getOp()));
486 template<
class Scalar>
490 const EPreconditionerInputType precOpType
493 return lowsf_.getConstObj()->supportsPreconditionerInputType(precOpType);
496 template<
class Scalar>
500 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
501 const RCP<
const PreconditionerBase<Scalar> > &prec,
502 LinearOpWithSolveBase<Scalar> *Op,
503 const ESupportSolveUse supportSolveUse
506 using Teuchos::dyn_cast;
507 using Teuchos::rcp_dynamic_cast;
510 TEUCHOS_TEST_FOR_EXCEPT(0==Op);
514 lowsf_.getConstObj()->setOStream(this->getOStream());
515 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
517 typedef DefaultScaledAdjointLinearOp<Scalar> ALO;
519 typedef DefaultAdjointLinearOpWithSolve<Scalar> ALOWS;
520 const RCP<const ALO> alo =
521 rcp_dynamic_cast<
const ALO>(fwdOpSrc->getOp().assert_not_null());
522 const RCP<const AP> ap = rcp_dynamic_cast<
const AP>(prec);
523 ALOWS &alows = dyn_cast<ALOWS>(*Op);
525 lowsf_.getConstObj()->initializePreconditionedOp(
526 defaultLinearOpSource<Scalar>(alo->getOp()),
527 ap->getPreconditioner(),
528 alows.getNonconstOp().get(),
532 template<
class Scalar>
536 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
537 const RCP<
const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
538 LinearOpWithSolveBase<Scalar> *Op,
539 const ESupportSolveUse supportSolveUse
542 using Teuchos::dyn_cast;
543 using Teuchos::rcp_dynamic_cast;
546 TEUCHOS_TEST_FOR_EXCEPT(0==Op);
550 lowsf_.getConstObj()->setOStream(this->getOStream());
551 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
553 typedef DefaultAdjointLinearOpWithSolve<Scalar> ALO;
554 typedef DefaultAdjointLinearOpWithSolve<Scalar> ALOWS;
555 const RCP<const ALO> alo =
556 rcp_dynamic_cast<
const ALO>(fwdOpSrc->getOp().assert_not_null());
557 const RCP<const ALO> aalo =
558 rcp_dynamic_cast<
const ALO>(approxFwdOpSrc->getOp().assert_not_null());
559 ALOWS &alows = dyn_cast<ALOWS>(*Op);
561 lowsf_.getConstObj()->initializeApproxPreconditionedOp(
562 defaultLinearOpSource<Scalar>(alo->getOp()),
563 defaultLinearOpSource<Scalar>(aalo->getOp()),
564 alows.getNonconstOp().get(),
570 template<
class Scalar>
575 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
576 lowsf_.getConstObj()->setOStream(this->getOStream());
Concrete PreconditionerBase subclass that wraps a preconditioner operator in MultiVectorLinearOp.
RCP< ParameterList > unsetParameterList()
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, RCP< const PreconditionerBase< Scalar > > *prec, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
RCP< LinearOpWithSolveFactoryBase< Scalar > > getUnderlyingLOWSF()
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
std::string description() const
Create a LinearOpWithSolveFactory for an adjoint linear op.
RCP< AdjointLinearOpWithSolveFactory< Scalar > > nonconstAdjointLinearOpWithSolveFactory(const RCP< LinearOpWithSolveFactoryBase< Scalar > > &lowsf)
Nonmember constructor.
virtual bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Throws exception.
RCP< const ParameterList > getParameterList() const
RCP< ParameterList > getNonconstParameterList()
RCP< const AdjointLinearOpWithSolveFactory< Scalar > > adjointLinearOpWithSolveFactory(const RCP< const LinearOpWithSolveFactoryBase< Scalar > > &lowsf)
Nonmember constructor.
void informUpdatedVerbosityState() const
Overridden from Teuchos::VerboseObjectBase.
void setParameterList(RCP< ParameterList > const ¶mList)
AdjointLinearOpWithSolveFactory()
Construct to uninitialized.
void initialize(const RCP< const LinearOpWithSolveFactoryBase< Scalar > > &lowsf)
Initialize given a single const LOWSFB object.
virtual bool acceptsPreconditionerFactory() const
returns false.
virtual void setPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &precFactory, const std::string &precFactoryName)
Throws exception.
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Concrete PreconditionerFactoryBase subclass that wraps a preconditioner in AdjointPreconditioner.
Teuchos::ConstNonconstObjectContainer< LinearOpWithSolveFactoryBase< Scalar > > LOWSF_t
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual RCP< LinearOpWithSolveBase< Scalar > > createOp() const
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
void nonconstInitialize(const RCP< LinearOpWithSolveFactoryBase< Scalar > > &lowsf)
Initialize given a single non-const LOWSFB object.
RCP< const ParameterList > getValidParameters() const