Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Thyra_MultiVectorPreconditionerFactory.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_MultiVectorPreconditionerFactory_hpp
10 #define Thyra_MultiVectorPreconditionerFactory_hpp
11 
12 #include "Thyra_PreconditionerFactoryBase.hpp"
13 #include "Teuchos_ConstNonconstObjectContainer.hpp"
16 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
17 
18 namespace Thyra {
19 
20 /** \brief Concrete <tt>PreconditionerFactoryBase</tt> subclass that
21  * wraps a preconditioner in MultiVectorPreconditioner.
22  */
23 template<class Scalar>
25  : virtual public PreconditionerFactoryBase<Scalar>
26 {
27 public:
28 
29  /** @name Constructors/initializers/accessors */
30  //@{
31 
32  /** \brief Construct to uninitialized. */
34 
36  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac,
37  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
38  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
39  ) {
40  validateInitialize(prec_fac,multiVecRange,multiVecDomain);
41  prec_fac_ = prec_fac;
42  multiVecRange_ = multiVecRange;
43  multiVecDomain_ = multiVecDomain;
44  }
45 
46  void initialize(
47  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac,
48  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
49  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain) {
50  validateInitialize(prec_fac,multiVecRange,multiVecDomain);
51  prec_fac_ = prec_fac;
52  multiVecRange_ = multiVecRange;
53  multiVecDomain_ = multiVecDomain;
54  }
55 
56  RCP<PreconditionerFactoryBase<Scalar> >
57  getNonconstPreconditionerFactory() { return prec_fac_.getNonconstObj(); }
58 
59  RCP<const PreconditionerFactoryBase<Scalar> >
60  getPreconditionerFactory() const { return prec_fac_.getConstObj(); }
61 
62  void uninitialize() {
63  prec_fac_.uninitialize();
64  multiVecRange_ = Teuchos::null;
65  multiVecDomain_ = Teuchos::null;
66  }
67 
68  /** \name Overridden from Teuchos::Describable. */
69  //@{
70 
71  std::string description() const
72  {
73  std::ostringstream oss;
74  oss << this->Teuchos::Describable::description()
75  << "{"
76  << "prec_fac=";
77  if (!is_null(prec_fac_.getConstObj()))
78  oss << prec_fac_.getConstObj()->description();
79  else
80  oss << "NULL";
81  oss << "}";
82  return oss.str();
83  }
84 
85  //@}
86 
87  /** @name Overridden from ParameterListAcceptor (simple forwarding functions) */
88  //@{
89 
90  void setParameterList(RCP<ParameterList> const& paramList)
91  {
92  prec_fac_.getNonconstObj()->setParameterList(paramList);
93  }
94 
95  RCP<ParameterList> getNonconstParameterList()
96  {
97  return prec_fac_.getNonconstObj()->getNonconstParameterList();
98  }
99 
100  RCP<ParameterList> unsetParameterList()
101  {
102  return prec_fac_.getNonconstObj()->unsetParameterList();
103  }
104 
105  RCP<const ParameterList> getParameterList() const
106  {
107  return prec_fac_.getConstObj()->getParameterList();
108  }
109 
110  RCP<const ParameterList> getValidParameters() const
111  {
112  return prec_fac_.getConstObj()->getValidParameters();
113  }
114 
115  //@}
116 
117  //@}
118 
119  /** @name Overridden from PreconditionerFactoryBase */
120  //@{
121 
122  bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const
123  { return prec_fac_.getConstObj()->isCompatible(fwdOpSrc); }
124 
125  RCP<PreconditionerBase<Scalar> > createPrec() const
126  { return nonconstMultiVectorPreconditioner(
127  prec_fac_.getConstObj()->createPrec(),
129  multiVecDomain_); }
130 
132  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
133  PreconditionerBase<Scalar> *precOp,
134  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
135  ) const
136  {
137  using Teuchos::dyn_cast;
138  using Teuchos::rcp_dynamic_cast;
139 
140  typedef MultiVectorLinearOp<Scalar> MVLO;
142  const RCP<const MVLO> mvlo =
143  rcp_dynamic_cast<const MVLO>(fwdOpSrc->getOp().assert_not_null());
144  MVP &mvp = dyn_cast<MVP>(*precOp);
145  prec_fac_.getConstObj()->initializePrec(
146  defaultLinearOpSource<Scalar>(mvlo->getLinearOp()),
147  mvp.getNonconstPreconditioner().get(),
148  supportSolveUse);
149  }
150 
152  PreconditionerBase<Scalar> *precOp,
153  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc = NULL,
154  ESupportSolveUse *supportSolveUse = NULL
155  ) const
156  {
157  using Teuchos::dyn_cast;
158 
159 #ifdef TEUCHOS_DEBUG
160  TEUCHOS_TEST_FOR_EXCEPT(0==precOp);
161 #endif
163  MVP &mvp = dyn_cast<MVP>(*precOp);
164  RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc;
165  prec_fac_.getConstObj()->uninitializePrec(
166  mvp.getNonconstPreconditioner().get(),
167  fwdOpSrc ? &inner_fwdOpSrc : NULL,
168  supportSolveUse);
169  if (fwdOpSrc)
170  *fwdOpSrc =
171  defaultLinearOpSource<Scalar>(multiVectorLinearOp(inner_fwdOpSrc->getOp(),
173  multiVecDomain_));
174  }
175 
176  //@}
177 
178 private:
179 
180  // //////////////////////////////
181  // Private types
182 
183  typedef Teuchos::ConstNonconstObjectContainer<PreconditionerFactoryBase<Scalar> > CNPFB;
184 
185  // //////////////////////////////
186  // Private data members
187 
189  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecRange_;
190  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecDomain_;
191 
192  // //////////////////////////////
193  // Private member functions
194 
195  static void validateInitialize(
196  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac,
197  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
198  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
199  ) {
200 #ifdef TEUCHOS_DEBUG
201  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec_fac));
202  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecRange));
203  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecDomain));
204  TEUCHOS_TEST_FOR_EXCEPT( multiVecRange->numBlocks() != multiVecDomain->numBlocks() );
205 #else
206  (void)prec_fac;
207  (void)multiVecRange;
208  (void)multiVecDomain;
209 #endif
210  }
211 
212 };
213 
214 /** \brief Nonmember constructor function.
215  *
216  * \relates MultiVectorPreconditionerFactory
217  */
218 template<class Scalar>
219 RCP<MultiVectorPreconditionerFactory<Scalar> >
221 {
222  return Teuchos::rcp(new MultiVectorPreconditionerFactory<Scalar>());
223 }
224 
225 /** \brief Nonmember constructor function.
226  *
227  * \relates MultiVectorPreconditionerFactory
228  */
229 template<class Scalar>
230 RCP<MultiVectorPreconditionerFactory<Scalar> >
232  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac,
233  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
234  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
235  )
236 {
237  RCP<MultiVectorPreconditionerFactory<Scalar> >
238  mvfac = Teuchos::rcp(new MultiVectorPreconditionerFactory<Scalar>());
239  mvfac->nonconstInitialize(prec_fac,multiVecRange,multiVecDomain);
240  return mvfac;
241 }
242 
243 /** \brief Nonmember constructor function.
244  *
245  * \relates MultiVectorPreconditionerFactory
246  */
247 template<class Scalar>
248 RCP<MultiVectorPreconditionerFactory<Scalar> >
250  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac,
251  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
252  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
253  )
254 {
255  RCP<MultiVectorPreconditionerFactory<Scalar> >
256  mvfac = Teuchos::rcp(new MultiVectorPreconditionerFactory<Scalar>());
257  mvfac->initialize(prec_fac,multiVecRange,multiVecDomain);
258  return mvfac;
259 }
260 
261 } // end namespace Thyra
262 
263 #endif
Teuchos::ConstNonconstObjectContainer< PreconditionerFactoryBase< Scalar > > CNPFB
Concrete PreconditionerFactoryBase subclass that wraps a preconditioner in MultiVectorPreconditioner...
RCP< PreconditionerFactoryBase< Scalar > > getNonconstPreconditionerFactory()
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.
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)
void setParameterList(RCP< ParameterList > const &paramList)
RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > multiVecRange_
RCP< MultiVectorPreconditionerFactory< Scalar > > multiVectorPreconditionerFactory()
Nonmember constructor function.
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)
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const