Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_MultiVectorPreconditionerFactory.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_MultiVectorPreconditionerFactory_hpp
11 #define Thyra_MultiVectorPreconditionerFactory_hpp
12 
13 #include "Thyra_PreconditionerFactoryBase.hpp"
14 #include "Teuchos_ConstNonconstObjectContainer.hpp"
17 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
18 
19 namespace Thyra {
20 
24 template <class Scalar>
26  : virtual public PreconditionerFactoryBase<Scalar> {
27  public:
30 
33 
35  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac,
37  &multiVecRange,
39  &multiVecDomain)
40  {
41  validateInitialize(prec_fac, multiVecRange, multiVecDomain);
42  prec_fac_ = prec_fac;
43  multiVecRange_ = multiVecRange;
44  multiVecDomain_ = multiVecDomain;
45  }
46 
47  void initialize(const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac,
49  &multiVecRange,
51  &multiVecDomain)
52  {
53  validateInitialize(prec_fac, multiVecRange, multiVecDomain);
54  prec_fac_ = prec_fac;
55  multiVecRange_ = multiVecRange;
56  multiVecDomain_ = multiVecDomain;
57  }
58 
59  RCP<PreconditionerFactoryBase<Scalar> > getNonconstPreconditionerFactory()
60  {
61  return prec_fac_.getNonconstObj();
62  }
63 
64  RCP<const PreconditionerFactoryBase<Scalar> > getPreconditionerFactory() const
65  {
66  return prec_fac_.getConstObj();
67  }
68 
69  void uninitialize()
70  {
72  multiVecRange_ = Teuchos::null;
73  multiVecDomain_ = Teuchos::null;
74  }
75 
78 
79  std::string description() const
80  {
81  std::ostringstream oss;
82  oss << this->Teuchos::Describable::description() << "{"
83  << "prec_fac=";
85  oss << prec_fac_.getConstObj()->description();
86  else
87  oss << "NULL";
88  oss << "}";
89  return oss.str();
90  }
91 
93 
97 
98  void setParameterList(RCP<ParameterList> const &paramList)
99  {
100  prec_fac_.getNonconstObj()->setParameterList(paramList);
101  }
102 
103  RCP<ParameterList> getNonconstParameterList()
104  {
105  return prec_fac_.getNonconstObj()->getNonconstParameterList();
106  }
107 
108  RCP<ParameterList> unsetParameterList()
109  {
110  return prec_fac_.getNonconstObj()->unsetParameterList();
111  }
112 
113  RCP<const ParameterList> getParameterList() const
114  {
115  return prec_fac_.getConstObj()->getParameterList();
116  }
117 
118  RCP<const ParameterList> getValidParameters() const
119  {
120  return prec_fac_.getConstObj()->getValidParameters();
121  }
122 
124 
126 
129 
130  bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const
131  {
132  return prec_fac_.getConstObj()->isCompatible(fwdOpSrc);
133  }
134 
135  RCP<PreconditionerBase<Scalar> > createPrec() const
136  {
137  return nonconstMultiVectorPreconditioner(
139  }
140 
142  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
144  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED) const
145  {
146  using Teuchos::dyn_cast;
147  using Teuchos::rcp_dynamic_cast;
148 
149  typedef MultiVectorLinearOp<Scalar> MVLO;
151  const RCP<const MVLO> mvlo =
152  rcp_dynamic_cast<const MVLO>(fwdOpSrc->getOp().assert_not_null());
153  MVP &mvp = dyn_cast<MVP>(*precOp);
154  prec_fac_.getConstObj()->initializePrec(
155  defaultLinearOpSource<Scalar>(mvlo->getLinearOp()),
156  mvp.getNonconstPreconditioner().get(), supportSolveUse);
157  }
158 
160  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc = NULL,
161  ESupportSolveUse *supportSolveUse = NULL) const
162  {
163  using Teuchos::dyn_cast;
164 
165 #ifdef TEUCHOS_DEBUG
166  TEUCHOS_TEST_FOR_EXCEPT(0 == precOp);
167 #endif
169  MVP &mvp = dyn_cast<MVP>(*precOp);
170  RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc;
171  prec_fac_.getConstObj()->uninitializePrec(
172  mvp.getNonconstPreconditioner().get(),
173  fwdOpSrc ? &inner_fwdOpSrc : NULL, supportSolveUse);
174  if (fwdOpSrc)
175  *fwdOpSrc = defaultLinearOpSource<Scalar>(multiVectorLinearOp(
176  inner_fwdOpSrc->getOp(), multiVecRange_, multiVecDomain_));
177  }
178 
180 
181  private:
182  // //////////////////////////////
183  // Private types
184 
188 
189  // //////////////////////////////
190  // Private data members
191 
193  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecRange_;
194  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecDomain_;
195 
196  // //////////////////////////////
197  // Private member functions
198 
199  static void validateInitialize(
200  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac,
202  &multiVecRange,
204  &multiVecDomain)
205  {
206 #ifdef TEUCHOS_DEBUG
207  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec_fac));
208  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecRange));
209  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecDomain));
210  TEUCHOS_TEST_FOR_EXCEPT(multiVecRange->numBlocks() !=
211  multiVecDomain->numBlocks());
212 #else
213  (void)prec_fac;
214  (void)multiVecRange;
215  (void)multiVecDomain;
216 #endif
217  }
218 };
219 
224 template <class Scalar>
225 RCP<MultiVectorPreconditionerFactory<Scalar> >
227 {
229 }
230 
235 template <class Scalar>
236 RCP<MultiVectorPreconditionerFactory<Scalar> >
238  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac,
240  &multiVecRange,
242  &multiVecDomain)
243 {
244  RCP<MultiVectorPreconditionerFactory<Scalar> > mvfac =
246  mvfac->nonconstInitialize(prec_fac, multiVecRange, multiVecDomain);
247  return mvfac;
248 }
249 
254 template <class Scalar>
255 RCP<MultiVectorPreconditionerFactory<Scalar> > multiVectorPreconditionerFactory(
256  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac,
258  &multiVecRange,
260  &multiVecDomain)
261 {
262  RCP<MultiVectorPreconditionerFactory<Scalar> > mvfac =
264  mvfac->initialize(prec_fac, multiVecRange, multiVecDomain);
265  return mvfac;
266 }
267 
268 } // end namespace Thyra
269 
270 #endif
Concrete PreconditionerFactoryBase subclass that wraps a preconditioner in MultiVectorPreconditioner...
RCP< PreconditionerFactoryBase< Scalar > > getNonconstPreconditionerFactory()
bool is_null(const boost::shared_ptr< T > &p)
RCP< const PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
void initializePrec(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, PreconditionerBase< Scalar > *precOp, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED) const
RCP< MultiVectorPreconditionerFactory< Scalar > > multiVectorPreconditionerFactory(const RCP< const PreconditionerFactoryBase< Scalar > > &prec_fac, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
Nonmember constructor function.
T_To & dyn_cast(T_From &from)
RCP< MultiVectorPreconditionerFactory< Scalar > > nonconstMultiVectorPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &prec_fac, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
Nonmember constructor function.
RCP< PreconditionerBase< Scalar > > createPrec() const
void nonconstInitialize(const RCP< PreconditionerFactoryBase< Scalar > > &prec_fac, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< const ObjType > getConstObj() const
void setParameterList(RCP< ParameterList > const &paramList)
virtual std::string description() const
RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > multiVecRange_
Teuchos::ConstNonconstObjectContainer< PreconditionerFactoryBase< Scalar > > CNPFB
RCP< MultiVectorPreconditionerFactory< Scalar > > multiVectorPreconditionerFactory()
Nonmember constructor function.
ESupportSolveUse
Implicit concrete LinearOpBase subclass that takes a flattended out multi-vector and performs a multi...
Concrete PreconditionerBase subclass that wraps a preconditioner operator in MultiVectorLinearOp.
void initialize(const RCP< const PreconditionerFactoryBase< Scalar > > &prec_fac, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > multiVecDomain_
void uninitializePrec(PreconditionerBase< Scalar > *precOp, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc=NULL, ESupportSolveUse *supportSolveUse=NULL) const
static void validateInitialize(const RCP< const PreconditionerFactoryBase< Scalar > > &prec_fac, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
RCP< ObjType > getNonconstObj() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const