Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_ScaledIdentityLinearOpWithSolve.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_ScaledIdentityLinearOpWithSolve_hpp
11 #define Thyra_ScaledIdentityLinearOpWithSolve_hpp
12 
13 #include "Thyra_LinearOpWithSolveBase.hpp"
14 #include "Thyra_MultiVectorStdOps.hpp"
15 
16 namespace Thyra {
17 
22 template <class Scalar>
24  : virtual public LinearOpWithSolveBase<Scalar> {
25  public:
28 
31 
32  void initialize(const RCP<const VectorSpaceBase<Scalar> >& space,
33  const Scalar& s)
34  {
36  space_ = space;
37  s_ = s;
38  }
39 
40  void uninitialize() { space_ = Teuchos::null; }
41 
42  RCP<const VectorSpaceBase<Scalar> > space() const { return space_; }
43  Scalar scale() const { return s_; }
44  void setScale(const Scalar& s) { s_ = s; }
45 
47 
50 
51  RCP<const VectorSpaceBase<Scalar> > range() const { return space_; }
52 
53  RCP<const VectorSpaceBase<Scalar> > domain() const { return space_; }
54 
55  RCP<const LinearOpBase<Scalar> > clone() const
56  {
57  RCP<ScaledIdentityLinearOpWithSolve<Scalar> > op =
59  op->initialize(space_, s_);
60  return op;
61  }
63 
64  protected:
67  bool opSupportedImpl(EOpTransp /* M_trans */) const { return true; }
68 
69  void applyImpl(const EOpTransp M_trans, const MultiVectorBase<Scalar>& X,
70  const Ptr<MultiVectorBase<Scalar> >& Y, const Scalar alpha,
71  const Scalar beta) const
72  {
74  Thyra::scale(beta, Y);
75  if (M_trans == CONJ || M_trans == CONJTRANS)
76  V_StVpV(Y, ST::conjugate(s_) * alpha, X, *Y);
77  else
78  V_StVpV(Y, s_ * alpha, X, *Y);
79  }
81 
84  bool solveSupportsImpl(EOpTransp /* M_trans */) const { return true; }
85 
87  EOpTransp /* M_trans */,
88  const Ptr<const SolveCriteria<Scalar> > /* solveCriteria */) const
89  {
90  return true;
91  }
92 
94  EOpTransp /* M_trans */,
95  const SolveMeasureType& /* solveMeasureType */) const
96  {
97  return true;
98  }
99 
101  const EOpTransp M_trans, const MultiVectorBase<Scalar>& B,
102  const Ptr<MultiVectorBase<Scalar> >& X,
103  const Ptr<const SolveCriteria<Scalar> > /* solveCriteria */) const
104  {
106  assign(X, ST::zero());
107  if (M_trans == CONJ || M_trans == CONJTRANS)
108  V_StVpV(X, ST::one() / ST::conjugate(s_), B, *X);
109  else
110  V_StVpV(X, ST::one() / s_, B, *X);
111  SolveStatus<Scalar> solveStatus;
112  solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;
113  return solveStatus;
114  }
116 
117  private:
118  // //////////////////////////////
119  // Private data members
120 
121  RCP<const VectorSpaceBase<Scalar> > space_;
122  Scalar s_;
123 
124  // //////////////////////////////
125  // Private member functions
126 
127  static void validateInitialize(
128  const RCP<const VectorSpaceBase<Scalar> >& space)
129  {
130 #ifdef TEUCHOS_DEBUG
132 #else
133  (void)space;
134 #endif
135  }
136 };
137 
142 template <class Scalar>
143 RCP<ScaledIdentityLinearOpWithSolve<Scalar> > scaledIdentity()
144 {
146 }
147 
152 template <class Scalar>
153 RCP<ScaledIdentityLinearOpWithSolve<Scalar> > scaledIdentity(
154  const RCP<const VectorSpaceBase<Scalar> >& space, const Scalar& s)
155 {
156  RCP<ScaledIdentityLinearOpWithSolve<Scalar> > op =
158  op->initialize(space, s);
159  return op;
160 }
161 
162 } // end namespace Thyra
163 
164 #endif
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
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
RCP< ScaledIdentityLinearOpWithSolve< Scalar > > scaledIdentity(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
Nonmember constructor function.
static void validateInitialize(const RCP< const VectorSpaceBase< Scalar > > &space)
RCP< const VectorSpaceBase< Scalar > > space() const
RCP< const VectorSpaceBase< Scalar > > domain() const
bool solveSupportsNewImpl(EOpTransp, const Ptr< const SolveCriteria< Scalar > >) const
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
RCP< const LinearOpBase< Scalar > > clone() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool solveSupportsSolveMeasureTypeImpl(EOpTransp, const SolveMeasureType &) const
RCP< const VectorSpaceBase< Scalar > > range() const
ESolveStatus solveStatus
RCP< ScaledIdentityLinearOpWithSolve< Scalar > > scaledIdentity()
Nonmember constructor function.
SolveStatus< Scalar > solveImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > >) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)