Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_AdjointPreconditionerFactory.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_AdjointPreconditionerFactory_hpp
11 #define Thyra_AdjointPreconditionerFactory_hpp
12 
13 #include "Thyra_PreconditionerFactoryBase.hpp"
14 #include "Teuchos_ConstNonconstObjectContainer.hpp"
15 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
17 
18 namespace Thyra {
19 
23 template <class Scalar>
25  : virtual public PreconditionerFactoryBase<Scalar> {
26  public:
29 
32 
34  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac)
35  {
36  validateInitialize(prec_fac);
37  prec_fac_ = prec_fac;
38  }
39 
40  void initialize(const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac)
41  {
42  validateInitialize(prec_fac);
43  prec_fac_ = prec_fac;
44  }
45 
46  RCP<PreconditionerFactoryBase<Scalar> > getNonconstPreconditionerFactory()
47  {
48  return prec_fac_.getNonconstObj();
49  }
50 
51  RCP<const PreconditionerFactoryBase<Scalar> > getPreconditionerFactory() const
52  {
53  return prec_fac_.getConstObj();
54  }
55 
57 
60 
61  std::string description() const
62  {
63  std::ostringstream oss;
64  oss << this->Teuchos::Describable::description() << "{"
65  << "prec_fac=";
67  oss << prec_fac_.getConstObj()->description();
68  else
69  oss << "NULL";
70  oss << "}";
71  return oss.str();
72  }
73 
75 
79 
80  void setParameterList(RCP<ParameterList> const &paramList)
81  {
82  prec_fac_.getNonconstObj()->setParameterList(paramList);
83  }
84 
85  RCP<ParameterList> getNonconstParameterList()
86  {
87  return prec_fac_.getNonconstObj()->getNonconstParameterList();
88  }
89 
90  RCP<ParameterList> unsetParameterList()
91  {
92  return prec_fac_.getNonconstObj()->unsetParameterList();
93  }
94 
95  RCP<const ParameterList> getParameterList() const
96  {
97  return prec_fac_.getConstObj()->getParameterList();
98  }
99 
100  RCP<const ParameterList> getValidParameters() const
101  {
102  return prec_fac_.getConstObj()->getValidParameters();
103  }
104 
106 
108 
111 
112  bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const
113  {
114  return prec_fac_.getConstObj()->isCompatible(fwdOpSrc);
115  }
116 
117  RCP<PreconditionerBase<Scalar> > createPrec() const
118  {
119  return nonconstAdjointPreconditioner(prec_fac_.getConstObj()->createPrec());
120  }
121 
123  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
125  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED) const
126  {
127  using Teuchos::dyn_cast;
128  using Teuchos::rcp_dynamic_cast;
129 
132  const RCP<const ALO> alo =
133  rcp_dynamic_cast<const ALO>(fwdOpSrc->getOp().assert_not_null());
134  AP &ap = dyn_cast<AP>(*precOp);
135  prec_fac_.getConstObj()->initializePrec(
136  defaultLinearOpSource<Scalar>(alo->getOp()),
137  ap.getNonconstPreconditioner().get(), supportSolveUse);
138  }
139 
141  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc = NULL,
142  ESupportSolveUse *supportSolveUse = NULL) const
143  {
144  using Teuchos::dyn_cast;
145 
146 #ifdef TEUCHOS_DEBUG
147  TEUCHOS_TEST_FOR_EXCEPT(0 == precOp);
148 #endif
150  AP &ap = dyn_cast<AP>(*precOp);
151  RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc;
152  prec_fac_.getConstObj()->uninitializePrec(
153  ap.getNonconstPreconditioner().get(), fwdOpSrc ? &inner_fwdOpSrc : NULL,
154  supportSolveUse);
155  if (fwdOpSrc)
156  *fwdOpSrc =
157  defaultLinearOpSource<Scalar>(adjoint(inner_fwdOpSrc->getOp()));
158  }
159 
161 
162  private:
163  // //////////////////////////////
164  // Private types
165 
169 
170  // //////////////////////////////
171  // Private data members
172 
174 
175  // //////////////////////////////
176  // Private member functions
177 
178  static void validateInitialize(
179  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac)
180  {
181 #ifdef TEUCHOS_DEBUG
182  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec_fac));
183 #else
184  (void)prec_fac;
185 #endif
186  }
187 };
188 
193 template <class Scalar>
194 RCP<AdjointPreconditionerFactory<Scalar> > adjointPreconditionerFactory()
195 {
197 }
198 
203 template <class Scalar>
204 RCP<AdjointPreconditionerFactory<Scalar> > nonconstAdjointPreconditionerFactory(
205  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac)
206 {
207  RCP<AdjointPreconditionerFactory<Scalar> > afac =
209  afac->nonconstInitialize(prec_fac);
210  return afac;
211 }
212 
217 template <class Scalar>
218 RCP<AdjointPreconditionerFactory<Scalar> > adjointPreconditionerFactory(
219  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac)
220 {
221  RCP<AdjointPreconditionerFactory<Scalar> > afac =
223  afac->initialize(prec_fac);
224  return afac;
225 }
226 
227 } // end namespace Thyra
228 
229 #endif
void initializePrec(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, PreconditionerBase< Scalar > *precOp, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED) const
void uninitializePrec(PreconditionerBase< Scalar > *precOp, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc=NULL, ESupportSolveUse *supportSolveUse=NULL) const
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
bool is_null(const boost::shared_ptr< T > &p)
Concrete PreconditionerBase subclass that wraps a preconditioner operator in MultiVectorLinearOp.
RCP< PreconditionerFactoryBase< Scalar > > getNonconstPreconditionerFactory()
RCP< const ParameterList > getParameterList() const
void nonconstInitialize(const RCP< PreconditionerFactoryBase< Scalar > > &prec_fac)
T_To & dyn_cast(T_From &from)
Teuchos::ConstNonconstObjectContainer< PreconditionerFactoryBase< Scalar > > CNPFB
RCP< const PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
RCP< const ParameterList > getValidParameters() const
RCP< AdjointPreconditionerFactory< Scalar > > nonconstAdjointPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &prec_fac)
Nonmember constructor function.
void initialize(const RCP< const PreconditionerFactoryBase< Scalar > > &prec_fac)
RCP< AdjointPreconditionerFactory< Scalar > > adjointPreconditionerFactory(const RCP< const PreconditionerFactoryBase< Scalar > > &prec_fac)
Nonmember constructor function.
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
ESupportSolveUse
RCP< PreconditionerBase< Scalar > > createPrec() const
static void validateInitialize(const RCP< const PreconditionerFactoryBase< Scalar > > &prec_fac)
RCP< AdjointPreconditionerFactory< Scalar > > adjointPreconditionerFactory()
Nonmember constructor function.
RCP< ObjType > getNonconstObj() const
Concrete PreconditionerFactoryBase subclass that wraps a preconditioner in AdjointPreconditioner.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)