Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Thyra_ReuseLinearOpWithSolveFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Thyra_ReuseLinearOpWithSolveFactory_hpp
10 #define Thyra_ReuseLinearOpWithSolveFactory_hpp
11 
12 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
14 
15 namespace Thyra {
16 
17 /** \brief A LinearOpWithSolveFactory that is designed to reuse an already
18  * created/initialized preconditioner.
19  */
20 template<class Scalar>
22  : virtual public LinearOpWithSolveFactoryBase<Scalar>
23 {
24 public:
25 
26  /** @name Overridden from Constructors/Initializers/Accessors */
27  //@{
28 
29  /** \brief Construct to uninitialized. */
31 
32  /** \brief Initialize given a single non-const LOWSFB object.
33  *
34  * \param lowsf [in,persisting] The LOWSFB object that will be used to
35  * create the LOWSB object for the diagonal blocks.
36  * \param prec [?] Description.
37  *
38  * <b>Preconditions:</b><ul>
39  * <li><tt>!is_null(lowsf)</tt>
40  * </ul>
41  *
42  */
43  void nonconstInitialize(
44  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
45  const RCP<PreconditionerBase<Scalar> > &prec
46  );
47 
48 
49  /** \brief Initialize given a single const LOWSFB object.
50  *
51  * \param lowsf [in,persisting] The LOWSFB object that will be used to
52  * create the LOWSB object for the diagonal blocks.
53  * \param prec [?] Description.
54  *
55  * <b>Preconditions:</b><ul>
56  * <li><tt>!is_null(lowsf)</tt>
57  * </ul>
58  *
59  */
60  void initialize(
61  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
62  const RCP<PreconditionerBase<Scalar> > &prec
63  );
64 
65  RCP<LinearOpWithSolveFactoryBase<Scalar> > getUnderlyingLOWSF();
66 
67  RCP<const LinearOpWithSolveFactoryBase<Scalar> > getUnderlyingLOWSF() const;
68 
69  RCP<PreconditionerBase<Scalar> > getUnderlyingPreconditioner();
70 
71  RCP<const PreconditionerBase<Scalar> > getUnderlyingPreconditioner() const;
72 
73  //@}
74 
75  /** \name Overridden from Teuchos::Describable. */
76  //@{
77 
78  std::string description() const;
79 
80  //@}
81 
82  /** @name Overridden from ParameterListAcceptor (simple forwarding functions) */
83  //@{
84 
85  void setParameterList(RCP<ParameterList> const& paramList);
86  RCP<ParameterList> getNonconstParameterList();
87  RCP<ParameterList> unsetParameterList();
88  RCP<const ParameterList> getParameterList() const;
89  RCP<const ParameterList> getValidParameters() const;
90 
91  //@}
92 
93  /** \name Overridden from LinearOpWithSolveFactoyBase */
94  //@{
95 
96  /** \brief returns false. */
97  virtual bool acceptsPreconditionerFactory() const;
98 
99  /** \brief Throws exception. */
100  virtual void setPreconditionerFactory(
101  const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
102  const std::string &precFactoryName
103  );
104 
105  /** \brief Returns null . */
106  virtual RCP<PreconditionerFactoryBase<Scalar> >
107  getPreconditionerFactory() const;
108 
109  /** \brief Throws exception. */
110  virtual void unsetPreconditionerFactory(
111  RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
112  std::string *precFactoryName
113  );
114 
115  virtual bool isCompatible(
116  const LinearOpSourceBase<Scalar> &fwdOpSrc
117  ) const;
118 
119  virtual RCP<LinearOpWithSolveBase<Scalar> > createOp() const;
120 
121  virtual void initializeOp(
122  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
123  LinearOpWithSolveBase<Scalar> *Op,
124  const ESupportSolveUse supportSolveUse
125  ) const;
126 
127  virtual void initializeAndReuseOp(
128  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
129  LinearOpWithSolveBase<Scalar> *Op
130  ) const;
131 
132  virtual void uninitializeOp(
133  LinearOpWithSolveBase<Scalar> *Op,
134  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
135  RCP<const PreconditionerBase<Scalar> > *prec,
136  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
137  ESupportSolveUse *supportSolveUse
138  ) const;
139 
140  virtual bool supportsPreconditionerInputType(
141  const EPreconditionerInputType precOpType
142  ) const;
143 
144  virtual void initializePreconditionedOp(
145  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
146  const RCP<const PreconditionerBase<Scalar> > &prec,
147  LinearOpWithSolveBase<Scalar> *Op,
148  const ESupportSolveUse supportSolveUse
149  ) const;
150 
152  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
153  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
154  LinearOpWithSolveBase<Scalar> *Op,
155  const ESupportSolveUse supportSolveUse
156  ) const;
157 
158  //@}
159 
160 protected:
161 
162  /** \brief Overridden from Teuchos::VerboseObjectBase */
163  //@{
164 
165  void informUpdatedVerbosityState() const;
166 
167  //@}
168 
169 private:
170 
171  typedef Teuchos::ConstNonconstObjectContainer<LinearOpWithSolveFactoryBase<Scalar> > LOWSF_t;
172 
174  RCP< PreconditionerBase<Scalar> > prec_;
175 
176 };
177 
178 /** \brief Nonmember constructor.
179  *
180  * \relates ReuseLinearOpWithSolveFactory
181  */
182 template<class Scalar>
183 RCP<ReuseLinearOpWithSolveFactory<Scalar> >
185  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
186  const RCP<PreconditionerBase<Scalar> > &prec
187  )
188 {
189  RCP<ReuseLinearOpWithSolveFactory<Scalar> > rlowsf =
190  Teuchos::rcp(new ReuseLinearOpWithSolveFactory<Scalar>);
191  rlowsf->nonconstInitialize(lowsf, prec);
192  return rlowsf;
193 }
194 
195 /** \brief Nonmember constructor.
196  *
197  * \relates ReuseLinearOpWithSolveFactory
198  */
199 template<class Scalar>
200 RCP<ReuseLinearOpWithSolveFactory<Scalar> >
202  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
203  const RCP<PreconditionerBase<Scalar> > &prec
204  )
205 {
206  RCP<ReuseLinearOpWithSolveFactory<Scalar> > rlowsf =
207  Teuchos::rcp(new ReuseLinearOpWithSolveFactory<Scalar>);
208  rlowsf->initialize(lowsf, prec);
209  return rlowsf;
210 }
211 
212 // Overridden from Constructors/Initializers/Accessors
213 
214 template<class Scalar>
215 void
218  const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
219  const RCP<PreconditionerBase<Scalar> > &prec
220  )
221 {
222 #ifdef TEUCHOS_DEBUG
223  TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
224  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec));
225 #endif
226  lowsf_.initialize(lowsf);
227  prec_ = prec;
228 }
229 
230 template<class Scalar>
231 void
234  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf,
235  const RCP<PreconditionerBase<Scalar> > &prec
236  )
237 {
238 #ifdef TEUCHOS_DEBUG
239  TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
240  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec));
241 #endif
242  lowsf_.initialize(lowsf);
243  prec_ = prec;
244 }
245 
246 template<class Scalar>
247 RCP<LinearOpWithSolveFactoryBase<Scalar> >
250 {
251  return lowsf_.getNonconstObj();
252 }
253 
254 template<class Scalar>
255 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
258 {
259  return lowsf_.getConstObj();
260 }
261 
262 template<class Scalar>
263 RCP<PreconditionerBase<Scalar> >
266 {
267  return prec_;
268 }
269 
270 template<class Scalar>
271 RCP<const PreconditionerBase<Scalar> >
274 {
275  return prec_;
276 }
277 
278 // Overridden from Teuchos::Describable
279 
280 template<class Scalar>
281 std::string
283 description() const
284 {
285  std::ostringstream oss;
286  oss << this->Teuchos::Describable::description()
287  << "{"
288  << "lowsf=";
289  if (!is_null(lowsf_.getConstObj()))
290  oss << lowsf_.getConstObj()->description();
291  else
292  oss << "NULL";
293  oss << std::endl
294  << "prec=";
295  if (!is_null(prec_))
296  oss << prec_->description();
297  else
298  oss << "NULL";
299  oss << "}";
300  return oss.str();
301 }
302 
303 // Overridden from ParameterListAcceptor
304 
305 template<class Scalar>
306 void
309  RCP<ParameterList> const& paramList
310  )
311 {
312  lowsf_.getNonconstObj()->setParameterList(paramList);
313 }
314 
315 template<class Scalar>
316 RCP<ParameterList>
319 {
320  return lowsf_.getNonconstObj()->getNonconstParameterList();
321 }
322 
323 template<class Scalar>
324 RCP<ParameterList>
327 {
328  return lowsf_.getNonconstObj()->unsetParameterList();
329 }
330 
331 template<class Scalar>
332 RCP<const ParameterList>
335 {
336  return lowsf_.getConstObj()->getParameterList();
337 }
338 
339 template<class Scalar>
340 RCP<const ParameterList>
343 {
344  return lowsf_.getConstObj()->getValidParameters();
345 }
346 
347 // Overridden from LinearOpWithSolveFactoyBase
348 
349 template<class Scalar>
350 bool
353 {
354  return false;
355 }
356 
357 template<class Scalar>
358 void
361  const RCP<PreconditionerFactoryBase<Scalar> > &/* precFactory */,
362  const std::string &/* precFactoryName */
363  )
364 {
365 }
366 
367 template<class Scalar>
368 RCP<PreconditionerFactoryBase<Scalar> >
371 {
372  return Thyra::reusePreconditionerFactory<Scalar>(prec_);
373 }
374 
375 template<class Scalar>
378  RCP<PreconditionerFactoryBase<Scalar> > * /* precFactory */,
379  std::string * /* precFactoryName */
380  )
381 {
382 }
383 
384 template<class Scalar>
385 bool
388  const LinearOpSourceBase<Scalar> &fwdOpSrc
389  ) const
390 {
391  return lowsf_.getConstObj()->isCompatible(fwdOpSrc);
392 }
393 
394 template<class Scalar>
395 RCP<LinearOpWithSolveBase<Scalar> >
397 createOp() const
398 {
399  return lowsf_.getConstObj()->createOp();
400 }
401 
402 template<class Scalar>
403 void
406  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
407  LinearOpWithSolveBase<Scalar> *Op,
408  const ESupportSolveUse supportSolveUse
409  ) const
410 {
411  lowsf_.getConstObj()->initializeOp(fwdOpSrc, Op, supportSolveUse);
412 }
413 
414 template<class Scalar>
415 void
418  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
419  LinearOpWithSolveBase<Scalar> *Op
420  ) const
421 {
422  lowsf_.getConstObj()->initializeAndReuseOp(fwdOpSrc, Op);
423 }
424 
425 template<class Scalar>
426 void
429  LinearOpWithSolveBase<Scalar> *Op,
430  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
431  RCP<const PreconditionerBase<Scalar> > *prec,
432  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
433  ESupportSolveUse *supportSolveUse
434  ) const
435 {
436  lowsf_.getConstObj()->uninitializeOp(Op, fwdOpSrc, prec, approxFwdOpSrc,
437  supportSolveUse);
438 }
439 
440 template<class Scalar>
441 bool
444  const EPreconditionerInputType precOpType
445  ) const
446 {
447  return lowsf_.getConstObj()->supportsPreconditionerInputType(precOpType);
448 }
449 
450 template<class Scalar>
451 void
454  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
455  const RCP<const PreconditionerBase<Scalar> > &prec,
456  LinearOpWithSolveBase<Scalar> *Op,
457  const ESupportSolveUse supportSolveUse
458  ) const
459 {
460  lowsf_.getConstObj()->initializePreconditionedOp(fwdOpSrc, prec, Op,
461  supportSolveUse);
462 }
463 
464 template<class Scalar>
465 void
468  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
469  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
470  LinearOpWithSolveBase<Scalar> *Op,
471  const ESupportSolveUse supportSolveUse
472  ) const
473 {
474  lowsf_.getConstObj()->initializeApproxPreconditionedOp(fwdOpSrc,
475  approxFwdOpSrc,
476  Op,
477  supportSolveUse);
478 }
479 
480 // protected
481 
482 template<class Scalar>
483 void
486 {
487  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
488  lowsf_.getConstObj()->setOStream(this->getOStream());
489 }
490 
491 } // namespace Thyra
492 
493 
494 #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
A LinearOpWithSolveFactory that is designed to reuse an already created/initialized preconditioner...
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
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 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
RCP< ReuseLinearOpWithSolveFactory< Scalar > > nonconstReuseLinearOpWithSolveFactory(const RCP< LinearOpWithSolveFactoryBase< Scalar > > &lowsf, const RCP< PreconditionerBase< Scalar > > &prec)
Nonmember constructor.
Teuchos::ConstNonconstObjectContainer< LinearOpWithSolveFactoryBase< Scalar > > LOWSF_t
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.
virtual RCP< LinearOpWithSolveBase< Scalar > > createOp() const
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .