Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Thyra_ScaledIdentityLinearOpWithSolve.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_ScaledIdentityLinearOpWithSolve_hpp
10 #define Thyra_ScaledIdentityLinearOpWithSolve_hpp
11 
12 #include "Thyra_LinearOpWithSolveBase.hpp"
13 #include "Thyra_MultiVectorStdOps.hpp"
14 
15 namespace Thyra {
16 
17 /**
18  * \brief Implicit concrete <tt>LinearOpBase</tt> subclass that
19  * takes a flattended out multi-vector and performs a multi-RHS apply with it.
20  */
21 template<class Scalar>
23  virtual public LinearOpWithSolveBase<Scalar>
24 {
25 public:
26 
27  /** @name Constructors/initializers/accessors */
28  //@{
29 
30  /** \brief Construct to uninitialized. */
32 
33  void initialize(const RCP<const VectorSpaceBase<Scalar> >& space,
34  const Scalar& s)
35  {
37  space_ = space;
38  s_ = s;
39  }
40 
41  void uninitialize()
42  {
43  space_ = Teuchos::null;
44  }
45 
46  RCP< const VectorSpaceBase<Scalar> > space() const { return space_; }
47  Scalar scale() const { return s_; }
48  void setScale(const Scalar& s) { s_ = s; }
49 
50  //@}
51 
52  /** @name Overridden from LinearOpBase */
53  //@{
54 
55  RCP< const VectorSpaceBase<Scalar> > range() const { return space_; }
56 
57  RCP< const VectorSpaceBase<Scalar> > domain() const { return space_; }
58 
59  RCP<const LinearOpBase<Scalar> > clone() const
60  {
61  RCP<ScaledIdentityLinearOpWithSolve<Scalar> > op =
63  op->initialize(space_, s_);
64  return op;
65  }
66  //@}
67 
68 protected:
69 
70  /** @name Overridden from LinearOpBase */
71  //@{
72  bool opSupportedImpl(EOpTransp /* M_trans */) const { return true; }
73 
74  void applyImpl(const EOpTransp M_trans,
75  const MultiVectorBase<Scalar>& X,
76  const Ptr<MultiVectorBase<Scalar> >& Y,
77  const Scalar alpha,
78  const Scalar beta) const
79  {
80  typedef Teuchos::ScalarTraits<Scalar> ST;
81  Thyra::scale(beta, Y);
82  if (M_trans == CONJ || M_trans == CONJTRANS)
83  V_StVpV(Y, ST::conjugate(s_)*alpha, X, *Y);
84  else
85  V_StVpV(Y, s_*alpha, X, *Y);
86  }
87  //@}
88 
89  /** @name Overridden from LinearOpWithSolveBase */
90  //@{
91  bool solveSupportsImpl(EOpTransp /* M_trans */) const { return true; }
92 
94  EOpTransp /* M_trans */,
95  const Ptr< const SolveCriteria< Scalar > > /* solveCriteria */) const
96  { return true; }
97 
99  EOpTransp /* M_trans */,
100  const SolveMeasureType &/* solveMeasureType */) const
101  { return true; }
102 
103  SolveStatus< Scalar > solveImpl(
104  const EOpTransp M_trans,
105  const MultiVectorBase<Scalar>& B,
106  const Ptr<MultiVectorBase<Scalar> >& X,
107  const Ptr< const SolveCriteria< Scalar > > /* solveCriteria */) const
108  {
109  typedef Teuchos::ScalarTraits<Scalar> ST;
110  assign(X, ST::zero());
111  if (M_trans == CONJ || M_trans == CONJTRANS)
112  V_StVpV(X, ST::one()/ST::conjugate(s_), B, *X);
113  else
114  V_StVpV(X, ST::one()/s_, B, *X);
115  SolveStatus<Scalar> solveStatus;
116  solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;
117  return solveStatus;
118  }
119  //@}
120 
121 private:
122 
123  // //////////////////////////////
124  // Private data members
125 
126  RCP<const VectorSpaceBase<Scalar> > space_;
127  Scalar s_;
128 
129  // //////////////////////////////
130  // Private member functions
131 
132  static void validateInitialize(
133  const RCP<const VectorSpaceBase<Scalar> >& space) {
134 #ifdef TEUCHOS_DEBUG
135  TEUCHOS_TEST_FOR_EXCEPT(is_null(space));
136 #else
137  (void)space;
138 #endif
139 }
140 
141 };
142 
143 /** \brief Nonmember constructor function.
144  *
145  * \relates ScaledIdentityLinearOpWithSolve
146  */
147 template<class Scalar>
148 RCP<ScaledIdentityLinearOpWithSolve<Scalar> >
150 {
151  return Teuchos::rcp(new ScaledIdentityLinearOpWithSolve<Scalar>());
152 }
153 
154 /** \brief Nonmember constructor function.
155  *
156  * \relates ScaledIdentityLinearOpWithSolve
157  */
158 template<class Scalar>
159 RCP<ScaledIdentityLinearOpWithSolve<Scalar> >
160 scaledIdentity(const RCP<const VectorSpaceBase<Scalar> >& space,
161  const Scalar& s)
162 {
163  RCP<ScaledIdentityLinearOpWithSolve<Scalar> >
164  op = Teuchos::rcp(new ScaledIdentityLinearOpWithSolve<Scalar>());
165  op->initialize(space, s);
166  return op;
167 }
168 
169 } // end namespace Thyra
170 
171 
172 #endif
Implicit concrete LinearOpBase subclass that takes a flattended out multi-vector and performs a multi...
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
bool solveSupportsNewImpl(EOpTransp, const Ptr< const SolveCriteria< Scalar > >) const
SolveStatus< Scalar > solveImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > >) const
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
RCP< const LinearOpBase< Scalar > > clone() const
bool solveSupportsSolveMeasureTypeImpl(EOpTransp, const SolveMeasureType &) const
RCP< const VectorSpaceBase< Scalar > > domain() const
RCP< const VectorSpaceBase< Scalar > > range() const
RCP< ScaledIdentityLinearOpWithSolve< Scalar > > scaledIdentity()
Nonmember constructor function.