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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
43 #define THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
44 
45 #include "Thyra_DefaultZeroLinearOp_decl.hpp"
46 #include "Thyra_MultiVectorStdOps.hpp"
47 #include "Thyra_VectorStdOps.hpp"
48 #include "Thyra_AssertOp.hpp"
49 
50 
51 namespace Thyra {
52 
53 
54 // Constructors/initializers/accessors
55 
56 
57 template<class Scalar>
59 {}
60 
61 
62 template<class Scalar>
64  const RCP<const VectorSpaceBase<Scalar> > &range_in,
65  const RCP<const VectorSpaceBase<Scalar> > &domain_in
66  )
67 {
68  initialize(range_in,domain_in);
69 }
70 
71 
72 template<class Scalar>
74  const RCP<const VectorSpaceBase<Scalar> > &range_in,
75  const RCP<const VectorSpaceBase<Scalar> > &domain_in
76  )
77 {
78  range_ = range_in.assert_not_null();
79  domain_ = domain_in.assert_not_null();
80 }
81 
82 
83 template<class Scalar>
85 {
86  range_ = Teuchos::null;
87  domain_ = Teuchos::null;
88 }
89 
90 
91 // Overridden from LinearOpBase
92 
93 
94 template<class Scalar>
97 {
98  return range_;
99 }
100 
101 
102 template<class Scalar>
105 {
106  return domain_;
107 }
108 
109 
110 template<class Scalar>
113 {
114  typedef DefaultZeroLinearOp<Scalar> this_t;
115  if(range_.get())
116  return Teuchos::rcp(new this_t(range_,domain_));
117  return Teuchos::rcp(new this_t());
118 }
119 
120 
121 // Overridden from Teuchos::Describable
122 
123 
124 template<class Scalar>
126 {
128  std::ostringstream oss;
129  oss
130  << "Thyra::DefaultZeroLinearOp<" << ST::name() << ">{"
131  << "range="<<(range_.get()?range_->description():"NULL")
132  << ",domain="<<(domain_.get()?domain_->description():"NULL")
133  << "}";
134  return oss.str();
135 }
136 
137 
138 // protected
139 
140 
141 // Overridden from LinearOpBase
142 
143 
144 template<class Scalar>
146 {
147  return true;
148 }
149 
150 
151 template<class Scalar>
153  const EOpTransp M_trans,
154  const MultiVectorBase<Scalar> &X,
155  const Ptr<MultiVectorBase<Scalar> > &Y,
156  const Scalar /* alpha */,
157  const Scalar beta
158  ) const
159 {
160 #ifdef TEUCHOS_DEBUG
162  "DefaultZeroLinearOp<Scalar>::apply(...)", *this, M_trans, X, &*Y
163  );
164 #else
165  (void)M_trans;
166  (void)X;
167 #endif // TEUCHOS_DEBUG
168  scale(beta, Y);
169 }
170 
171 template<class Scalar>
173 rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
174 {
175  if( rowStat==RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM
176  || rowStat==RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM)
177  return true;
178 
179  // else( rowStat==RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM
180  // || rowStat==RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM)
181 
182  // inverse of a zero diagonal is bad news, we won't allow it, return false
183  return false;
184 }
185 
186 template<class Scalar>
189  const RowStatLinearOpBaseUtils::ERowStat /* rowStat */,
190  const Teuchos::Ptr<VectorBase< Scalar> > &rowStatVec) const
191 {
192  Thyra::put_scalar(Teuchos::ScalarTraits<Scalar>::zero(),rowStatVec);
193 }
194 
195 
196 } // end namespace Thyra
197 
198 
199 template<class Scalar>
201 Thyra::zero(
202  const RCP<const VectorSpaceBase<Scalar> > &range_in,
203  const RCP<const VectorSpaceBase<Scalar> > &domain_in
204  )
205 {
206  return Teuchos::rcp(new DefaultZeroLinearOp<Scalar>(range_in, domain_in));
207 }
208 
209 template<class Scalar>
211 Thyra::nonconstZero(
212  const RCP<const VectorSpaceBase<Scalar> > &range_in,
213  const RCP<const VectorSpaceBase<Scalar> > &domain_in
214  )
215 {
216  return Teuchos::rcp(new DefaultZeroLinearOp<Scalar>(range_in, domain_in));
217 }
218 
219 
220 //
221 // Explicit instantaition
222 //
223 
224 
225 #define THYRA_DEFAULT_ZERO_LINEAR_OP_INSTANT(SCALAR) \
226  \
227  template class DefaultZeroLinearOp<SCALAR >; \
228  \
229  template RCP<const Thyra::LinearOpBase<SCALAR > > \
230  zero( \
231  const RCP<const VectorSpaceBase<SCALAR > > &range, \
232  const RCP<const VectorSpaceBase<SCALAR > > &domain \
233  ); \
234  \
235  template RCP<Thyra::LinearOpBase<SCALAR > > \
236  nonconstZero( \
237  const RCP<const VectorSpaceBase<SCALAR > > &range, \
238  const RCP<const VectorSpaceBase<SCALAR > > &domain \
239  ); \
240 
241 
242 #endif // THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
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