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: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Thyra_AdjointPreconditionerFactory_hpp
10 #define Thyra_AdjointPreconditionerFactory_hpp
11 
12 #include "Thyra_PreconditionerFactoryBase.hpp"
13 #include "Teuchos_ConstNonconstObjectContainer.hpp"
14 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
16 
17 namespace Thyra {
18 
22 template<class Scalar>
24  : virtual public PreconditionerFactoryBase<Scalar>
25 {
26 public:
27 
30 
33 
35  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac) {
36  validateInitialize(prec_fac);
37  prec_fac_ = prec_fac;
38  }
39 
40  void initialize(
41  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac) {
42  validateInitialize(prec_fac);
43  prec_fac_ = prec_fac;
44  }
45 
46  RCP<PreconditionerFactoryBase<Scalar> >
48 
49  RCP<const PreconditionerFactoryBase<Scalar> >
51 
52  void uninitialize() {
54  }
55 
58 
59  std::string description() const
60  {
61  std::ostringstream oss;
63  << "{"
64  << "prec_fac=";
66  oss << prec_fac_.getConstObj()->description();
67  else
68  oss << "NULL";
69  oss << "}";
70  return oss.str();
71  }
72 
74 
77 
78  void setParameterList(RCP<ParameterList> const& paramList)
79  {
80  prec_fac_.getNonconstObj()->setParameterList(paramList);
81  }
82 
83  RCP<ParameterList> getNonconstParameterList()
84  {
85  return prec_fac_.getNonconstObj()->getNonconstParameterList();
86  }
87 
88  RCP<ParameterList> unsetParameterList()
89  {
90  return prec_fac_.getNonconstObj()->unsetParameterList();
91  }
92 
93  RCP<const ParameterList> getParameterList() const
94  {
95  return prec_fac_.getConstObj()->getParameterList();
96  }
97 
98  RCP<const ParameterList> getValidParameters() const
99  {
100  return prec_fac_.getConstObj()->getValidParameters();
101  }
102 
104 
106 
109 
110  bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const
111  { return prec_fac_.getConstObj()->isCompatible(fwdOpSrc); }
112 
113  RCP<PreconditionerBase<Scalar> > createPrec() const
114  { return nonconstAdjointPreconditioner(
115  prec_fac_.getConstObj()->createPrec()); }
116 
118  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
120  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
121  ) const
122  {
123  using Teuchos::dyn_cast;
124  using Teuchos::rcp_dynamic_cast;
125 
128  const RCP<const ALO> alo =
129  rcp_dynamic_cast<const ALO>(fwdOpSrc->getOp().assert_not_null());
130  AP &ap = dyn_cast<AP>(*precOp);
131  prec_fac_.getConstObj()->initializePrec(
132  defaultLinearOpSource<Scalar>(alo->getOp()),
133  ap.getNonconstPreconditioner().get(),
134  supportSolveUse);
135  }
136 
139  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc = NULL,
140  ESupportSolveUse *supportSolveUse = NULL
141  ) const
142  {
143  using Teuchos::dyn_cast;
144 
145 #ifdef TEUCHOS_DEBUG
146  TEUCHOS_TEST_FOR_EXCEPT(0==precOp);
147 #endif
149  AP &ap = dyn_cast<AP>(*precOp);
150  RCP<const LinearOpSourceBase<Scalar> > inner_fwdOpSrc;
151  prec_fac_.getConstObj()->uninitializePrec(
152  ap.getNonconstPreconditioner().get(),
153  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  // //////////////////////////////
165  // Private types
166 
168 
169  // //////////////////////////////
170  // Private data members
171 
173 
174  // //////////////////////////////
175  // Private member functions
176 
177  static void validateInitialize(
178  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac) {
179 #ifdef TEUCHOS_DEBUG
180  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec_fac));
181 #else
182  (void)prec_fac;
183 #endif
184  }
185 
186 };
187 
192 template<class Scalar>
193 RCP<AdjointPreconditionerFactory<Scalar> >
195 {
197 }
198 
203 template<class Scalar>
204 RCP<AdjointPreconditionerFactory<Scalar> >
206  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac)
207 {
208  RCP<AdjointPreconditionerFactory<Scalar> >
210  afac->nonconstInitialize(prec_fac);
211  return afac;
212 }
213 
218 template<class Scalar>
219 RCP<AdjointPreconditionerFactory<Scalar> >
221  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac)
222 {
223  RCP<AdjointPreconditionerFactory<Scalar> >
225  afac->initialize(prec_fac);
226  return afac;
227 }
228 
229 } // end namespace Thyra
230 
231 #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)
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.
Teuchos::ConstNonconstObjectContainer< PreconditionerFactoryBase< Scalar > > CNPFB
RCP< ObjType > getNonconstObj() const
Concrete PreconditionerFactoryBase subclass that wraps a preconditioner in AdjointPreconditioner.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)