Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_AdjointLinearOpWithSolveFactory.hpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
10 #ifndef Thyra_AdjointLinearOpWithSolveFactory_hpp
11 #define Thyra_AdjointLinearOpWithSolveFactory_hpp
12 
13 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
14 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
15 #include "Thyra_DefaultAdjointLinearOpWithSolve.hpp"
16 #include "Thyra_DefaultLinearOpSource.hpp"
19 
20 namespace Thyra {
21 
24 template <class Scalar>
26  : virtual public LinearOpWithSolveFactoryBase<Scalar> {
27  public:
30 
33 
44  void nonconstInitialize(
45  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf);
46 
57  void initialize(
58  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf);
59 
60  RCP<LinearOpWithSolveFactoryBase<Scalar> > getUnderlyingLOWSF();
61 
62  RCP<const LinearOpWithSolveFactoryBase<Scalar> > getUnderlyingLOWSF() const;
63 
65 
68 
69  std::string description() const;
70 
72 
76 
77  void setParameterList(RCP<ParameterList> const &paramList);
78  RCP<ParameterList> getNonconstParameterList();
79  RCP<ParameterList> unsetParameterList();
80  RCP<const ParameterList> getParameterList() const;
81  RCP<const ParameterList> getValidParameters() const;
82 
84 
87 
89  virtual bool acceptsPreconditionerFactory() const;
90 
92  virtual void setPreconditionerFactory(
93  const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
94  const std::string &precFactoryName);
95 
97  virtual RCP<PreconditionerFactoryBase<Scalar> > getPreconditionerFactory()
98  const;
99 
101  virtual void unsetPreconditionerFactory(
102  RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
103  std::string *precFactoryName);
104 
105  virtual bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const;
106 
107  virtual RCP<LinearOpWithSolveBase<Scalar> > createOp() const;
108 
109  virtual void initializeOp(
110  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
112  const ESupportSolveUse supportSolveUse) const;
113 
114  virtual void initializeAndReuseOp(
115  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
117 
118  virtual void uninitializeOp(
120  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
121  RCP<const PreconditionerBase<Scalar> > *prec,
122  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
123  ESupportSolveUse *supportSolveUse) const;
124 
125  virtual bool supportsPreconditionerInputType(
126  const EPreconditionerInputType precOpType) const;
127 
128  virtual void initializePreconditionedOp(
129  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
130  const RCP<const PreconditionerBase<Scalar> > &prec,
132  const ESupportSolveUse supportSolveUse) const;
133 
135  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
136  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
138  const ESupportSolveUse supportSolveUse) const;
139 
141 
142  protected:
145 
146  void informUpdatedVerbosityState() const;
147 
149 
150  private:
154 
156 };
157 
162 template <class Scalar>
163 RCP<const AdjointLinearOpWithSolveFactory<Scalar> >
165  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf)
166 {
167  RCP<AdjointLinearOpWithSolveFactory<Scalar> > alowsf =
169  alowsf->initialize(lowsf);
170  return alowsf;
171 }
172 
177 template <class Scalar>
178 RCP<AdjointLinearOpWithSolveFactory<Scalar> >
180  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf)
181 {
182  RCP<AdjointLinearOpWithSolveFactory<Scalar> > alowsf =
184  alowsf->nonconstInitialize(lowsf);
185  return alowsf;
186 }
187 
188 // Overridden from Constructors/Initializers/Accessors
189 
190 template <class Scalar>
192  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf)
193 {
194 #ifdef TEUCHOS_DEBUG
196 #endif
197  lowsf_.initialize(lowsf);
198 }
199 
200 template <class Scalar>
202  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf)
203 {
204 #ifdef TEUCHOS_DEBUG
206 #endif
207  lowsf_.initialize(lowsf);
208 }
209 
210 template <class Scalar>
211 RCP<LinearOpWithSolveFactoryBase<Scalar> >
213 {
214  return lowsf_.getNonconstObj();
215 }
216 
217 template <class Scalar>
218 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
220 {
221  return lowsf_.getConstObj();
222 }
223 
224 // Overridden from Teuchos::Describable
225 
226 template <class Scalar>
228 {
229  std::ostringstream oss;
230  oss << this->Teuchos::Describable::description() << "{"
231  << "lowsf=";
232  if (!is_null(lowsf_.getConstObj()))
233  oss << lowsf_.getConstObj()->description();
234  else
235  oss << "NULL";
236  oss << "}";
237  return oss.str();
238 }
239 
240 // Overridden from ParameterListAcceptor
241 
242 template <class Scalar>
244  RCP<ParameterList> const &paramList)
245 {
246  lowsf_.getNonconstObj()->setParameterList(paramList);
247 }
248 
249 template <class Scalar>
250 RCP<ParameterList>
252 {
253  return lowsf_.getNonconstObj()->getNonconstParameterList();
254 }
255 
256 template <class Scalar>
258 {
259  return lowsf_.getNonconstObj()->unsetParameterList();
260 }
261 
262 template <class Scalar>
263 RCP<const ParameterList>
265 {
266  return lowsf_.getConstObj()->getParameterList();
267 }
268 
269 template <class Scalar>
270 RCP<const ParameterList>
272 {
273  return lowsf_.getConstObj()->getValidParameters();
274 }
275 
276 // Overridden from LinearOpWithSolveFactoyBase
277 
278 template <class Scalar>
280  const
281 {
282  return lowsf_.getConstObj()->acceptsPreconditionerFactory();
283 }
284 
285 template <class Scalar>
287  const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
288  const std::string &precFactoryName)
289 {
291  RCP<APF> apf = Teuchos::rcp_dynamic_cast<APF>(precFactory);
292  lowsf_.getNonconstObj()->setPreconditionerFactory(
293  apf->getNonconstPreconditionerFactory(), precFactoryName);
294 }
295 
296 template <class Scalar>
297 RCP<PreconditionerFactoryBase<Scalar> >
299 {
300  RCP<PreconditionerFactoryBase<Scalar> > prec_fac =
301  lowsf_.getConstObj()->getPreconditionerFactory();
302  if (prec_fac == Teuchos::null)
303  return Teuchos::null;
304  else
305  return nonconstAdjointPreconditionerFactory(prec_fac);
306 }
307 
308 template <class Scalar>
310  RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
311  std::string *precFactoryName)
312 {
313  RCP<PreconditionerFactoryBase<Scalar> > inner_precFactory;
314  lowsf_.getNonconstObj()->unsetPreconditionerFactory(
315  precFactory ? &inner_precFactory : NULL, precFactoryName);
316  if (precFactory)
317  *precFactory = nonconstAdjointPreconditionerFactory(inner_precFactory);
318 }
319 
320 template <class Scalar>
322  const LinearOpSourceBase<Scalar> &fwdOpSrc) const
323 {
325  RCP<const ALO> alo =
326  Teuchos::rcp_dynamic_cast<const ALO>(fwdOpSrc.getOp().assert_not_null());
327  RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc =
328  defaultLinearOpSource<Scalar>(alo->getOp());
329  return lowsf_.getConstObj()->isCompatible(*inner_fwdOpSrc);
330 }
331 
332 template <class Scalar>
333 RCP<LinearOpWithSolveBase<Scalar> >
335 {
336  return nonconstAdjointLows<Scalar>(lowsf_.getConstObj()->createOp());
337 }
338 
339 template <class Scalar>
341  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
343  const ESupportSolveUse supportSolveUse) const
344 {
345  using Teuchos::dyn_cast;
346  using Teuchos::rcp_dynamic_cast;
347 
348 #ifdef TEUCHOS_DEBUG
349  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
350 #endif
351 
352  // Set the verbosity settings for the wrapped LOWSF object!
353  lowsf_.getConstObj()->setOStream(this->getOStream());
354  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
355 
358  const RCP<const ALO> alo =
359  rcp_dynamic_cast<const ALO>(fwdOpSrc->getOp().assert_not_null());
360  ALOWS &alows = dyn_cast<ALOWS>(*Op);
361 
362  lowsf_.getConstObj()->initializeOp(
363  defaultLinearOpSource<Scalar>(alo->getOrigOp()),
364  alows.getNonconstOp().get(), supportSolveUse);
365 }
366 
367 template <class Scalar>
369  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
371 {
372  using Teuchos::dyn_cast;
373  using Teuchos::rcp_dynamic_cast;
374 
375 #ifdef TEUCHOS_DEBUG
376  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
377 #endif
378 
379  // Set the verbosity settings for the wrapped LOWSF object!
380  lowsf_.getConstObj()->setOStream(this->getOStream());
381  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
382 
385  const RCP<const ALO> alo =
386  rcp_dynamic_cast<const ALO>(fwdOpSrc->getOp().assert_not_null());
387  ALOWS &alows = dyn_cast<ALOWS>(*Op);
388 
389  lowsf_.getConstObj()->initializeAndReuseOp(
390  defaultLinearOpSource<Scalar>(alo->getOrigOp()),
391  alows.getNonconstOp().get());
392 }
393 
394 template <class Scalar>
397  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
398  RCP<const PreconditionerBase<Scalar> > *prec,
399  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
400  ESupportSolveUse *supportSolveUse) const
401 {
402  using Teuchos::dyn_cast;
403 
404 #ifdef TEUCHOS_DEBUG
405  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
406 #endif
408  ALOWS &alowsOp = dyn_cast<ALOWS>(*Op);
409  RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc;
410  RCP<const PreconditionerBase<Scalar> > inner_prec;
411  RCP<const LinearOpSourceBase<Scalar> > inner_approxFwdOpSrc;
412  lowsf_.getConstObj()->uninitializeOp(
413  alowsOp.getNonconstOp().get(), fwdOpSrc ? &inner_fwdOpSrc : NULL,
414  prec ? &inner_prec : NULL, approxFwdOpSrc ? &inner_approxFwdOpSrc : NULL,
415  supportSolveUse);
416  if (fwdOpSrc)
417  *fwdOpSrc = defaultLinearOpSource<Scalar>(adjoint(inner_fwdOpSrc->getOp()));
418  if (prec) *prec = adjointPreconditioner(inner_prec);
419  if (fwdOpSrc)
420  *approxFwdOpSrc =
421  defaultLinearOpSource<Scalar>(adjoint(inner_approxFwdOpSrc->getOp()));
422 }
423 
424 template <class Scalar>
426  const EPreconditionerInputType precOpType) const
427 {
428  return lowsf_.getConstObj()->supportsPreconditionerInputType(precOpType);
429 }
430 
431 template <class Scalar>
433  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
434  const RCP<const PreconditionerBase<Scalar> > &prec,
436  const ESupportSolveUse supportSolveUse) const
437 {
438  using Teuchos::dyn_cast;
439  using Teuchos::rcp_dynamic_cast;
440 
441 #ifdef TEUCHOS_DEBUG
442  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
443 #endif
444 
445  // Set the verbosity settings for the wrapped LOWSF object!
446  lowsf_.getConstObj()->setOStream(this->getOStream());
447  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
448 
452  const RCP<const ALO> alo =
453  rcp_dynamic_cast<const ALO>(fwdOpSrc->getOp().assert_not_null());
454  const RCP<const AP> ap = rcp_dynamic_cast<const AP>(prec);
455  ALOWS &alows = dyn_cast<ALOWS>(*Op);
456 
457  lowsf_.getConstObj()->initializePreconditionedOp(
458  defaultLinearOpSource<Scalar>(alo->getOp()), ap->getPreconditioner(),
459  alows.getNonconstOp().get(), supportSolveUse);
460 }
461 
462 template <class Scalar>
464  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
465  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
467  const ESupportSolveUse supportSolveUse) const
468 {
469  using Teuchos::dyn_cast;
470  using Teuchos::rcp_dynamic_cast;
471 
472 #ifdef TEUCHOS_DEBUG
473  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
474 #endif
475 
476  // Set the verbosity settings for the wrapped LOWSF object!
477  lowsf_.getConstObj()->setOStream(this->getOStream());
478  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
479 
482  const RCP<const ALO> alo =
483  rcp_dynamic_cast<const ALO>(fwdOpSrc->getOp().assert_not_null());
484  const RCP<const ALO> aalo =
485  rcp_dynamic_cast<const ALO>(approxFwdOpSrc->getOp().assert_not_null());
486  ALOWS &alows = dyn_cast<ALOWS>(*Op);
487 
488  lowsf_.getConstObj()->initializeApproxPreconditionedOp(
489  defaultLinearOpSource<Scalar>(alo->getOp()),
490  defaultLinearOpSource<Scalar>(aalo->getOp()), alows.getNonconstOp().get(),
491  supportSolveUse);
492 }
493 
494 // protected
495 
496 template <class Scalar>
498  const
499 {
500  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
501  lowsf_.getConstObj()->setOStream(this->getOStream());
502 }
503 
504 } // namespace Thyra
505 
506 #endif
bool is_null(const boost::shared_ptr< T > &p)
Concrete PreconditionerBase subclass that wraps a preconditioner operator in MultiVectorLinearOp.
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()
T_To & dyn_cast(T_From &from)
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) 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
Teuchos::ConstNonconstObjectContainer< LinearOpWithSolveFactoryBase< Scalar > > LOWSF_t
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Throws exception.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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 &paramList)
virtual std::string description() const
ESupportSolveUse
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.
EPreconditionerInputType
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.
virtual Teuchos::RCP< const LinearOpBase< Scalar > > getOp() const =0
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
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.