Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultZeroLinearOp_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
11 #define THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
12 
13 #include "Thyra_DefaultZeroLinearOp_decl.hpp"
14 #include "Thyra_MultiVectorStdOps.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 #include "Thyra_AssertOp.hpp"
17 
18 
19 namespace Thyra {
20 
21 
22 // Constructors/initializers/accessors
23 
24 
25 template<class Scalar>
27 {}
28 
29 
30 template<class Scalar>
32  const RCP<const VectorSpaceBase<Scalar> > &range_in,
33  const RCP<const VectorSpaceBase<Scalar> > &domain_in
34  )
35 {
36  initialize(range_in,domain_in);
37 }
38 
39 
40 template<class Scalar>
42  const RCP<const VectorSpaceBase<Scalar> > &range_in,
43  const RCP<const VectorSpaceBase<Scalar> > &domain_in
44  )
45 {
46  range_ = range_in.assert_not_null();
47  domain_ = domain_in.assert_not_null();
48 }
49 
50 
51 template<class Scalar>
53 {
54  range_ = Teuchos::null;
55  domain_ = Teuchos::null;
56 }
57 
58 
59 // Overridden from LinearOpBase
60 
61 
62 template<class Scalar>
65 {
66  return range_;
67 }
68 
69 
70 template<class Scalar>
73 {
74  return domain_;
75 }
76 
77 
78 template<class Scalar>
81 {
82  typedef DefaultZeroLinearOp<Scalar> this_t;
83  if(range_.get())
84  return Teuchos::rcp(new this_t(range_,domain_));
85  return Teuchos::rcp(new this_t());
86 }
87 
88 
89 // Overridden from Teuchos::Describable
90 
91 
92 template<class Scalar>
94 {
96  std::ostringstream oss;
97  oss
98  << "Thyra::DefaultZeroLinearOp<" << ST::name() << ">{"
99  << "range="<<(range_.get()?range_->description():"NULL")
100  << ",domain="<<(domain_.get()?domain_->description():"NULL")
101  << "}";
102  return oss.str();
103 }
104 
105 
106 // protected
107 
108 
109 // Overridden from LinearOpBase
110 
111 
112 template<class Scalar>
114 {
115  return true;
116 }
117 
118 
119 template<class Scalar>
121  const EOpTransp M_trans,
122  const MultiVectorBase<Scalar> &X,
123  const Ptr<MultiVectorBase<Scalar> > &Y,
124  const Scalar /* alpha */,
125  const Scalar beta
126  ) const
127 {
128 #ifdef TEUCHOS_DEBUG
130  "DefaultZeroLinearOp<Scalar>::apply(...)", *this, M_trans, X, &*Y
131  );
132 #else
133  (void)M_trans;
134  (void)X;
135 #endif // TEUCHOS_DEBUG
136  scale(beta, Y);
137 }
138 
139 template<class Scalar>
141 rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
142 {
143  if( rowStat==RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM
144  || rowStat==RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM)
145  return true;
146 
147  // else( rowStat==RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM
148  // || rowStat==RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM)
149 
150  // inverse of a zero diagonal is bad news, we won't allow it, return false
151  return false;
152 }
153 
154 template<class Scalar>
157  const RowStatLinearOpBaseUtils::ERowStat /* rowStat */,
158  const Teuchos::Ptr<VectorBase< Scalar> > &rowStatVec) const
159 {
160  Thyra::put_scalar(Teuchos::ScalarTraits<Scalar>::zero(),rowStatVec);
161 }
162 
163 
164 } // end namespace Thyra
165 
166 
167 template<class Scalar>
169 Thyra::zero(
170  const RCP<const VectorSpaceBase<Scalar> > &range_in,
171  const RCP<const VectorSpaceBase<Scalar> > &domain_in
172  )
173 {
174  return Teuchos::rcp(new DefaultZeroLinearOp<Scalar>(range_in, domain_in));
175 }
176 
177 template<class Scalar>
179 Thyra::nonconstZero(
180  const RCP<const VectorSpaceBase<Scalar> > &range_in,
181  const RCP<const VectorSpaceBase<Scalar> > &domain_in
182  )
183 {
184  return Teuchos::rcp(new DefaultZeroLinearOp<Scalar>(range_in, domain_in));
185 }
186 
187 
188 //
189 // Explicit instantaition
190 //
191 
192 
193 #define THYRA_DEFAULT_ZERO_LINEAR_OP_INSTANT(SCALAR) \
194  \
195  template class DefaultZeroLinearOp<SCALAR >; \
196  \
197  template RCP<const Thyra::LinearOpBase<SCALAR > > \
198  zero( \
199  const RCP<const VectorSpaceBase<SCALAR > > &range, \
200  const RCP<const VectorSpaceBase<SCALAR > > &domain \
201  ); \
202  \
203  template RCP<Thyra::LinearOpBase<SCALAR > > \
204  nonconstZero( \
205  const RCP<const VectorSpaceBase<SCALAR > > &range, \
206  const RCP<const VectorSpaceBase<SCALAR > > &domain \
207  ); \
208 
209 
210 #endif // THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
void initialize(int *argc, char ***argv)
void uninitialize()
Set to uninitialized.
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Teuchos::Ptr< VectorBase< Scalar > > &rowStatVec) const
#define THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(FUNC_NAME, M, M_T, X, Y)
This is a very useful macro that should be used to validate that the spaces for the multi-vector vers...
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns Teuchos::null if uninitialized.
Abstract interface for objects that represent a space for vectors.
bool opSupportedImpl(EOpTransp M_trans) const
Returns true .
RCP< const LinearOpBase< Scalar > > clone() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Interface for a collection of column vectors called a multi-vector.
DefaultZeroLinearOp()
Construct to uninitialized.
Abstract interface for finite-dimensional dense vectors.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns Teuchos::null if uninitialized.
Represents a zero linear operator M = 0.
std::string description() const
Prints just the name DefaultZeroLinearOp along with the overall dimensions.
void initialize(const RCP< const VectorSpaceBase< Scalar > > &range, const RCP< const VectorSpaceBase< Scalar > > &domain)
Initialize given a list of non-const linear operators.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const