Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_ReuseLinearOpWithSolveFactory.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_ReuseLinearOpWithSolveFactory_hpp
11 #define Thyra_ReuseLinearOpWithSolveFactory_hpp
12 
13 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
15 
16 namespace Thyra {
17 
21 template <class Scalar>
23  : virtual public LinearOpWithSolveFactoryBase<Scalar> {
24  public:
27 
30 
42  void nonconstInitialize(
43  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
44  const RCP<PreconditionerBase<Scalar> > &prec);
45 
57  void initialize(const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
58  const RCP<PreconditionerBase<Scalar> > &prec);
59 
60  RCP<LinearOpWithSolveFactoryBase<Scalar> > getUnderlyingLOWSF();
61 
62  RCP<const LinearOpWithSolveFactoryBase<Scalar> > getUnderlyingLOWSF() const;
63 
64  RCP<PreconditionerBase<Scalar> > getUnderlyingPreconditioner();
65 
66  RCP<const PreconditionerBase<Scalar> > getUnderlyingPreconditioner() const;
67 
69 
72 
73  std::string description() const;
74 
76 
80 
81  void setParameterList(RCP<ParameterList> const &paramList);
82  RCP<ParameterList> getNonconstParameterList();
83  RCP<ParameterList> unsetParameterList();
84  RCP<const ParameterList> getParameterList() const;
85  RCP<const ParameterList> getValidParameters() const;
86 
88 
91 
93  virtual bool acceptsPreconditionerFactory() const;
94 
96  virtual void setPreconditionerFactory(
97  const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
98  const std::string &precFactoryName);
99 
101  virtual RCP<PreconditionerFactoryBase<Scalar> > getPreconditionerFactory()
102  const;
103 
105  virtual void unsetPreconditionerFactory(
106  RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
107  std::string *precFactoryName);
108 
109  virtual bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const;
110 
111  virtual RCP<LinearOpWithSolveBase<Scalar> > createOp() const;
112 
113  virtual void initializeOp(
114  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
116  const ESupportSolveUse supportSolveUse) const;
117 
118  virtual void initializeAndReuseOp(
119  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
121 
122  virtual void uninitializeOp(
124  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
125  RCP<const PreconditionerBase<Scalar> > *prec,
126  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
127  ESupportSolveUse *supportSolveUse) const;
128 
129  virtual bool supportsPreconditionerInputType(
130  const EPreconditionerInputType precOpType) const;
131 
132  virtual void initializePreconditionedOp(
133  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
134  const RCP<const PreconditionerBase<Scalar> > &prec,
136  const ESupportSolveUse supportSolveUse) const;
137 
139  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
140  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
142  const ESupportSolveUse supportSolveUse) const;
143 
145 
146  protected:
149 
150  void informUpdatedVerbosityState() const;
151 
153 
154  private:
158 
160  RCP<PreconditionerBase<Scalar> > prec_;
161 };
162 
167 template <class Scalar>
168 RCP<ReuseLinearOpWithSolveFactory<Scalar> >
170  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
171  const RCP<PreconditionerBase<Scalar> > &prec)
172 {
173  RCP<ReuseLinearOpWithSolveFactory<Scalar> > rlowsf =
175  rlowsf->nonconstInitialize(lowsf, prec);
176  return rlowsf;
177 }
178 
183 template <class Scalar>
184 RCP<ReuseLinearOpWithSolveFactory<Scalar> > reuseLinearOpWithSolveFactory(
185  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
186  const RCP<PreconditionerBase<Scalar> > &prec)
187 {
188  RCP<ReuseLinearOpWithSolveFactory<Scalar> > rlowsf =
190  rlowsf->initialize(lowsf, prec);
191  return rlowsf;
192 }
193 
194 // Overridden from Constructors/Initializers/Accessors
195 
196 template <class Scalar>
198  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
199  const RCP<PreconditionerBase<Scalar> > &prec)
200 {
201 #ifdef TEUCHOS_DEBUG
204 #endif
205  lowsf_.initialize(lowsf);
206  prec_ = prec;
207 }
208 
209 template <class Scalar>
211  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
212  const RCP<PreconditionerBase<Scalar> > &prec)
213 {
214 #ifdef TEUCHOS_DEBUG
217 #endif
218  lowsf_.initialize(lowsf);
219  prec_ = prec;
220 }
221 
222 template <class Scalar>
223 RCP<LinearOpWithSolveFactoryBase<Scalar> >
225 {
226  return lowsf_.getNonconstObj();
227 }
228 
229 template <class Scalar>
230 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
232 {
233  return lowsf_.getConstObj();
234 }
235 
236 template <class Scalar>
237 RCP<PreconditionerBase<Scalar> >
239 {
240  return prec_;
241 }
242 
243 template <class Scalar>
244 RCP<const PreconditionerBase<Scalar> >
246 {
247  return prec_;
248 }
249 
250 // Overridden from Teuchos::Describable
251 
252 template <class Scalar>
254 {
255  std::ostringstream oss;
256  oss << this->Teuchos::Describable::description() << "{"
257  << "lowsf=";
258  if (!is_null(lowsf_.getConstObj()))
259  oss << lowsf_.getConstObj()->description();
260  else
261  oss << "NULL";
262  oss << std::endl
263  << "prec=";
264  if (!is_null(prec_))
265  oss << prec_->description();
266  else
267  oss << "NULL";
268  oss << "}";
269  return oss.str();
270 }
271 
272 // Overridden from ParameterListAcceptor
273 
274 template <class Scalar>
276  RCP<ParameterList> const &paramList)
277 {
278  lowsf_.getNonconstObj()->setParameterList(paramList);
279 }
280 
281 template <class Scalar>
282 RCP<ParameterList>
284 {
285  return lowsf_.getNonconstObj()->getNonconstParameterList();
286 }
287 
288 template <class Scalar>
290 {
291  return lowsf_.getNonconstObj()->unsetParameterList();
292 }
293 
294 template <class Scalar>
295 RCP<const ParameterList>
297 {
298  return lowsf_.getConstObj()->getParameterList();
299 }
300 
301 template <class Scalar>
302 RCP<const ParameterList>
304 {
305  return lowsf_.getConstObj()->getValidParameters();
306 }
307 
308 // Overridden from LinearOpWithSolveFactoyBase
309 
310 template <class Scalar>
312 {
313  return false;
314 }
315 
316 template <class Scalar>
318  const RCP<PreconditionerFactoryBase<Scalar> > & /* precFactory */,
319  const std::string & /* precFactoryName */
320 )
321 {
322 }
323 
324 template <class Scalar>
325 RCP<PreconditionerFactoryBase<Scalar> >
327 {
328  return Thyra::reusePreconditionerFactory<Scalar>(prec_);
329 }
330 
331 template <class Scalar>
333  RCP<PreconditionerFactoryBase<Scalar> > * /* precFactory */,
334  std::string * /* precFactoryName */
335 )
336 {
337 }
338 
339 template <class Scalar>
341  const LinearOpSourceBase<Scalar> &fwdOpSrc) const
342 {
343  return lowsf_.getConstObj()->isCompatible(fwdOpSrc);
344 }
345 
346 template <class Scalar>
347 RCP<LinearOpWithSolveBase<Scalar> >
349 {
350  return lowsf_.getConstObj()->createOp();
351 }
352 
353 template <class Scalar>
355  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
357  const ESupportSolveUse supportSolveUse) const
358 {
359  lowsf_.getConstObj()->initializeOp(fwdOpSrc, Op, supportSolveUse);
360 }
361 
362 template <class Scalar>
364  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
366 {
367  lowsf_.getConstObj()->initializeAndReuseOp(fwdOpSrc, Op);
368 }
369 
370 template <class Scalar>
373  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
374  RCP<const PreconditionerBase<Scalar> > *prec,
375  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
376  ESupportSolveUse *supportSolveUse) const
377 {
378  lowsf_.getConstObj()->uninitializeOp(Op, fwdOpSrc, prec, approxFwdOpSrc,
379  supportSolveUse);
380 }
381 
382 template <class Scalar>
384  const EPreconditionerInputType precOpType) const
385 {
386  return lowsf_.getConstObj()->supportsPreconditionerInputType(precOpType);
387 }
388 
389 template <class Scalar>
391  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
392  const RCP<const PreconditionerBase<Scalar> > &prec,
394  const ESupportSolveUse supportSolveUse) const
395 {
396  lowsf_.getConstObj()->initializePreconditionedOp(fwdOpSrc, prec, Op,
397  supportSolveUse);
398 }
399 
400 template <class Scalar>
402  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
403  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
405  const ESupportSolveUse supportSolveUse) const
406 {
407  lowsf_.getConstObj()->initializeApproxPreconditionedOp(
408  fwdOpSrc, approxFwdOpSrc, Op, supportSolveUse);
409 }
410 
411 // protected
412 
413 template <class Scalar>
415 {
416  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
417  lowsf_.getConstObj()->setOStream(this->getOStream());
418 }
419 
420 } // namespace Thyra
421 
422 #endif
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Throws exception.
RCP< LinearOpWithSolveFactoryBase< Scalar > > getUnderlyingLOWSF()
virtual void setPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &precFactory, const std::string &precFactoryName)
Throws exception.
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, RCP< const PreconditionerBase< Scalar > > *prec, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
bool is_null(const boost::shared_ptr< T > &p)
A LinearOpWithSolveFactory that is designed to reuse an already created/initialized preconditioner...
Teuchos::ConstNonconstObjectContainer< LinearOpWithSolveFactoryBase< Scalar > > LOWSF_t
virtual bool acceptsPreconditionerFactory() const
returns false.
RCP< const ParameterList > getValidParameters() const
RCP< ReuseLinearOpWithSolveFactory< Scalar > > reuseLinearOpWithSolveFactory(const RCP< const LinearOpWithSolveFactoryBase< Scalar > > &lowsf, const RCP< PreconditionerBase< Scalar > > &prec)
Nonmember constructor.
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
void informUpdatedVerbosityState() const
Overridden from Teuchos::VerboseObjectBase.
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual std::string description() const
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
RCP< PreconditionerBase< Scalar > > getUnderlyingPreconditioner()
virtual bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
ESupportSolveUse
RCP< ReuseLinearOpWithSolveFactory< Scalar > > nonconstReuseLinearOpWithSolveFactory(const RCP< LinearOpWithSolveFactoryBase< Scalar > > &lowsf, const RCP< PreconditionerBase< Scalar > > &prec)
Nonmember constructor.
EPreconditionerInputType
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
void nonconstInitialize(const RCP< LinearOpWithSolveFactoryBase< Scalar > > &lowsf, const RCP< PreconditionerBase< Scalar > > &prec)
Initialize given a single non-const LOWSFB object.
void setParameterList(RCP< ParameterList > const &paramList)
void initialize(const RCP< const LinearOpWithSolveFactoryBase< Scalar > > &lowsf, const RCP< PreconditionerBase< Scalar > > &prec)
Initialize given a single const LOWSFB object.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual RCP< LinearOpWithSolveBase< Scalar > > createOp() const
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .