Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
19 /** \brief Concrete <tt>PreconditionerFactoryBase</tt> subclass that
20  * wraps a preconditioner in AdjointPreconditioner.
21  */
22 template<class Scalar>
24  : virtual public PreconditionerFactoryBase<Scalar>
25 {
26 public:
27 
28  /** @name Constructors/initializers/accessors */
29  //@{
30 
31  /** \brief Construct to uninitialized. */
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> >
47  getNonconstPreconditionerFactory() { return prec_fac_.getNonconstObj(); }
48 
49  RCP<const PreconditionerFactoryBase<Scalar> >
50  getPreconditionerFactory() const { return prec_fac_.getConstObj(); }
51 
52  void uninitialize() {
53  prec_fac_.uninitialize();
54  }
55 
56  /** \name Overridden from Teuchos::Describable. */
57  //@{
58 
59  std::string description() const
60  {
61  std::ostringstream oss;
62  oss << this->Teuchos::Describable::description()
63  << "{"
64  << "prec_fac=";
65  if (!is_null(prec_fac_.getConstObj()))
66  oss << prec_fac_.getConstObj()->description();
67  else
68  oss << "NULL";
69  oss << "}";
70  return oss.str();
71  }
72 
73  //@}
74 
75  /** @name Overridden from ParameterListAcceptor (simple forwarding functions) */
76  //@{
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 
103  //@}
104 
105  //@}
106 
107  /** @name Overridden from PreconditionerFactoryBase */
108  //@{
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,
119  PreconditionerBase<Scalar> *precOp,
120  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
121  ) const
122  {
123  using Teuchos::dyn_cast;
124  using Teuchos::rcp_dynamic_cast;
125 
126  typedef DefaultScaledAdjointLinearOp<Scalar> ALO;
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 
138  PreconditionerBase<Scalar> *precOp,
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 
160  //@}
161 
162 private:
163 
164  // //////////////////////////////
165  // Private types
166 
167  typedef Teuchos::ConstNonconstObjectContainer<PreconditionerFactoryBase<Scalar> > CNPFB;
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 
188 /** \brief Nonmember constructor function.
189  *
190  * \relates AdjointPreconditionerFactory
191  */
192 template<class Scalar>
193 RCP<AdjointPreconditionerFactory<Scalar> >
195 {
196  return Teuchos::rcp(new AdjointPreconditionerFactory<Scalar>());
197 }
198 
199 /** \brief Nonmember constructor function.
200  *
201  * \relates AdjointPreconditionerFactory
202  */
203 template<class Scalar>
204 RCP<AdjointPreconditionerFactory<Scalar> >
206  const RCP<PreconditionerFactoryBase<Scalar> > &prec_fac)
207 {
208  RCP<AdjointPreconditionerFactory<Scalar> >
209  afac = Teuchos::rcp(new AdjointPreconditionerFactory<Scalar>());
210  afac->nonconstInitialize(prec_fac);
211  return afac;
212 }
213 
214 /** \brief Nonmember constructor function.
215  *
216  * \relates AdjointPreconditionerFactory
217  */
218 template<class Scalar>
219 RCP<AdjointPreconditionerFactory<Scalar> >
221  const RCP<const PreconditionerFactoryBase<Scalar> > &prec_fac)
222 {
223  RCP<AdjointPreconditionerFactory<Scalar> >
224  afac = Teuchos::rcp(new 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
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)
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.
void setParameterList(RCP< ParameterList > const &paramList)
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
Concrete PreconditionerFactoryBase subclass that wraps a preconditioner in AdjointPreconditioner.