Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_ScaledIdentityLinearOpWithSolveFactory.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_ScaledIdentityLinearOpWithSolveFactory_hpp
11 #define Thyra_ScaledIdentityLinearOpWithSolveFactory_hpp
12 
13 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
18 #include "Thyra_DefaultLinearOpSource.hpp"
19 
20 namespace Thyra {
21 
24 template <class Scalar>
26  : virtual public LinearOpWithSolveFactoryBase<Scalar> {
27  public:
30 
33 
36  void initialize(const RCP<const VectorSpaceBase<Scalar> > &space,
37  const Scalar &s)
38  {
39  space_ = space;
40  s_ = s;
41  }
42 
44 
47 
48  void setParameterList(RCP<ParameterList> const & /* paramList */) {}
49  RCP<ParameterList> getNonconstParameterList()
50  {
51  return Teuchos::parameterList();
52  }
53  RCP<ParameterList> unsetParameterList() { return Teuchos::parameterList(); }
54  RCP<const ParameterList> getParameterList() const
55  {
56  return Teuchos::parameterList();
57  }
58  RCP<const ParameterList> getValidParameters() const
59  {
60  return Teuchos::parameterList();
61  }
62 
64 
67 
69  virtual bool acceptsPreconditionerFactory() const { return false; }
70 
73  const RCP<PreconditionerFactoryBase<Scalar> > & /* precFactory */,
74  const std::string & /* precFactoryName */
75  )
76  {
77  }
78 
80  virtual RCP<PreconditionerFactoryBase<Scalar> > getPreconditionerFactory()
81  const
82  {
83  return Teuchos::null;
84  }
85 
88  RCP<PreconditionerFactoryBase<Scalar> > * /* precFactory */,
89  std::string * /* precFactoryName */
90  )
91  {
92  }
93 
94  virtual bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const
95  {
96  return !is_null(
97  Teuchos::rcp_dynamic_cast<
99  }
100 
101  virtual RCP<LinearOpWithSolveBase<Scalar> > createOp() const
102  {
103  return scaledIdentity(space_, s_);
104  }
105 
106  virtual void initializeOp(
107  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
109  const ESupportSolveUse supportSolveUse) const;
110 
111  virtual void initializeAndReuseOp(
112  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
114  {
116  }
117 
118  virtual void uninitializeOp(
120  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
121  RCP<const PreconditionerBase<Scalar> > *prec,
122  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
123  ESupportSolveUse *supportSolveUse) const;
124 
126  const EPreconditionerInputType /* precOpType */
127  ) const
128  {
129  return false;
130  }
131 
133  const RCP<const LinearOpSourceBase<Scalar> > & /* fwdOpSrc */,
134  const RCP<const PreconditionerBase<Scalar> > & /* prec */,
136  const ESupportSolveUse /* supportSolveUse */
137  ) const
138  {
139  }
140 
142  const RCP<const LinearOpSourceBase<Scalar> > & /* fwdOpSrc */,
143  const RCP<const LinearOpSourceBase<Scalar> > & /* approxFwdOpSrc */,
145  const ESupportSolveUse /* supportSolveUse */
146  ) const
147  {
148  }
149 
151 
152  protected:
155 
157 
159 
160  private:
161  RCP<const VectorSpaceBase<Scalar> > space_;
162  Scalar s_;
163 };
164 
169 template <class Scalar>
170 RCP<ScaledIdentityLinearOpWithSolveFactory<Scalar> > scaledIdentitySolveFactory(
171  const RCP<const VectorSpaceBase<Scalar> > &space, const Scalar &s)
172 {
173  RCP<ScaledIdentityLinearOpWithSolveFactory<Scalar> > lowsf =
175  lowsf->initialize(space, s);
176  return lowsf;
177 }
178 
179 // Overridden from LinearOpWithSolveFactoyBase
180 
181 template <class Scalar>
183  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
185  const ESupportSolveUse /* supportSolveUse */
186 ) const
187 {
188  using Teuchos::dyn_cast;
189  using Teuchos::rcp_dynamic_cast;
190 
191 #ifdef TEUCHOS_DEBUG
192  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
193 #endif
194 
195  const RCP<const LinearOpBase<Scalar> > tmpFwdOp = fwdOpSrc->getOp();
196  RCP<const LinearOpBase<Scalar> > fwdOp;
197  Scalar fwdOp_scalar = 0.0;
198  EOpTransp fwdOp_transp;
199  unwrap<Scalar>(tmpFwdOp, &fwdOp_scalar, &fwdOp_transp, &fwdOp);
200 
201  const RCP<const ScaledIdentityLinearOpWithSolve<Scalar> > fwdSi =
202  rcp_dynamic_cast<const ScaledIdentityLinearOpWithSolve<Scalar> >(fwdOp,
203  true);
204 
206  fwdSi->space(), fwdSi->scale());
207 }
208 
209 template <class Scalar>
212  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
213  RCP<const PreconditionerBase<Scalar> > *prec,
214  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
215  ESupportSolveUse * /* supportSolveUse */
216 ) const
217 {
218  using Teuchos::dyn_cast;
219  using Teuchos::is_null;
220 #ifdef TEUCHOS_DEBUG
221  TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
222 #else
223  (void)Op;
224 #endif // TEUCHOS_DEBUG
225  if (fwdOpSrc) *fwdOpSrc = Teuchos::null;
226  if (prec) *prec = Teuchos::null;
227  if (approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null;
228 }
229 
230 } // namespace Thyra
231 
232 #endif
virtual bool supportsPreconditionerInputType(const EPreconditionerInputType) const
Implicit concrete LinearOpBase subclass that takes a flattended out multi-vector and performs a multi...
bool is_null(const boost::shared_ptr< T > &p)
EOpTransp
bool is_null(const std::shared_ptr< T > &p)
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
T_To & dyn_cast(T_From &from)
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, RCP< const PreconditionerBase< Scalar > > *prec, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
Initialize.
virtual RCP< LinearOpWithSolveBase< Scalar > > createOp() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Create a LinearOpWithSolveFactory for a flattened-out multi-vector.
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &, const RCP< const LinearOpSourceBase< Scalar > > &, LinearOpWithSolveBase< Scalar > *, const ESupportSolveUse) const
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .
ESupportSolveUse
void informUpdatedVerbosityState() const
Overridden from Teuchos::VerboseObjectBase.
EPreconditionerInputType
RCP< ScaledIdentityLinearOpWithSolveFactory< Scalar > > scaledIdentitySolveFactory(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
Nonmember constructor.
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
virtual void setPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &, const std::string &)
Throws exception.
virtual Teuchos::RCP< const LinearOpBase< Scalar > > getOp() const =0
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *, std::string *)
Throws exception.
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &, const RCP< const PreconditionerBase< Scalar > > &, LinearOpWithSolveBase< Scalar > *, const ESupportSolveUse) const