Tempus  Version of the Day
Time Integration
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 #endif
137 }
138 
139 };
140 
141 /** \brief Nonmember constructor function.
142  *
143  * \relates ScaledIdentityLinearOpWithSolve
144  */
145 template<class Scalar>
146 RCP<ScaledIdentityLinearOpWithSolve<Scalar> >
148 {
149  return Teuchos::rcp(new ScaledIdentityLinearOpWithSolve<Scalar>());
150 }
151 
152 /** \brief Nonmember constructor function.
153  *
154  * \relates ScaledIdentityLinearOpWithSolve
155  */
156 template<class Scalar>
157 RCP<ScaledIdentityLinearOpWithSolve<Scalar> >
158 scaledIdentity(const RCP<const VectorSpaceBase<Scalar> >& space,
159  const Scalar& s)
160 {
161  RCP<ScaledIdentityLinearOpWithSolve<Scalar> >
162  op = Teuchos::rcp(new ScaledIdentityLinearOpWithSolve<Scalar>());
163  op->initialize(space, s);
164  return op;
165 }
166 
167 } // end namespace Thyra
168 
169 
170 #endif
Thyra::ScaledIdentityLinearOpWithSolve::space_
RCP< const VectorSpaceBase< Scalar > > space_
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:126
Thyra::ScaledIdentityLinearOpWithSolve::range
RCP< const VectorSpaceBase< Scalar > > range() const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:55
Thyra::ScaledIdentityLinearOpWithSolve::opSupportedImpl
bool opSupportedImpl(EOpTransp M_trans) const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:72
Thyra::ScaledIdentityLinearOpWithSolve::uninitialize
void uninitialize()
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:41
Thyra::ScaledIdentityLinearOpWithSolve::solveSupportsSolveMeasureTypeImpl
bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:98
Thyra::ScaledIdentityLinearOpWithSolve::scale
Scalar scale() const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:47
Thyra::ScaledIdentityLinearOpWithSolve::clone
RCP< const LinearOpBase< Scalar > > clone() const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:59
Thyra::ScaledIdentityLinearOpWithSolve::solveSupportsNewImpl
bool solveSupportsNewImpl(EOpTransp M_trans, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:93
Thyra::ScaledIdentityLinearOpWithSolve::scaledIdentity
RCP< ScaledIdentityLinearOpWithSolve< Scalar > > scaledIdentity()
Nonmember constructor function.
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:147
Thyra::ScaledIdentityLinearOpWithSolve::s_
Scalar s_
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:127
Thyra::ScaledIdentityLinearOpWithSolve::setScale
void setScale(const Scalar &s)
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:48
Thyra::ScaledIdentityLinearOpWithSolve::space
RCP< const VectorSpaceBase< Scalar > > space() const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:46
Thyra::ScaledIdentityLinearOpWithSolve::applyImpl
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:74
Thyra::ScaledIdentityLinearOpWithSolve::solveImpl
SolveStatus< Scalar > solveImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:103
Thyra::ScaledIdentityLinearOpWithSolve::solveSupportsImpl
bool solveSupportsImpl(EOpTransp M_trans) const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:91
Thyra::ScaledIdentityLinearOpWithSolve::validateInitialize
static void validateInitialize(const RCP< const VectorSpaceBase< Scalar > > &space)
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:132
Thyra::ScaledIdentityLinearOpWithSolve::scaledIdentity
RCP< ScaledIdentityLinearOpWithSolve< Scalar > > scaledIdentity(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
Nonmember constructor function.
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:158
Thyra::ScaledIdentityLinearOpWithSolve::domain
RCP< const VectorSpaceBase< Scalar > > domain() const
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:57
Thyra::ScaledIdentityLinearOpWithSolve
Implicit concrete LinearOpBase subclass that takes a flattended out multi-vector and performs a multi...
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:22
Thyra::ScaledIdentityLinearOpWithSolve::ScaledIdentityLinearOpWithSolve
ScaledIdentityLinearOpWithSolve()
Construct to uninitialized.
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:31
Thyra
Definition: Thyra_AdjointLinearOpWithSolveFactory.hpp:19
Thyra::ScaledIdentityLinearOpWithSolve::initialize
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space, const Scalar &s)
Definition: Thyra_ScaledIdentityLinearOpWithSolve.hpp:33