Thyra  Version of the Day
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>
95 RCP< const VectorSpaceBase<Scalar> >
97 {
98  return range_;
99 }
100 
101 
102 template<class Scalar>
103 RCP< const VectorSpaceBase<Scalar> >
105 {
106  return domain_;
107 }
108 
109 
110 template<class Scalar>
111 RCP<const LinearOpBase<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 {
127  typedef Teuchos::ScalarTraits<Scalar> ST;
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 #endif // TEUCHOS_DEBUG
165  scale(beta, Y);
166 }
167 
168 template<class Scalar>
170 rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
171 {
172  if( rowStat==RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM
173  || rowStat==RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM)
174  return true;
175 
176  // else( rowStat==RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM
177  // || rowStat==RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM)
178 
179  // inverse of a zero diagonal is bad news, we won't allow it, return false
180  return false;
181 }
182 
183 template<class Scalar>
186  const RowStatLinearOpBaseUtils::ERowStat rowStat,
187  const Teuchos::Ptr<VectorBase< Scalar> > &rowStatVec) const
188 {
189  Thyra::put_scalar(Teuchos::ScalarTraits<Scalar>::zero(),rowStatVec);
190 }
191 
192 
193 } // end namespace Thyra
194 
195 
196 template<class Scalar>
197 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
198 Thyra::zero(
199  const RCP<const VectorSpaceBase<Scalar> > &range_in,
200  const RCP<const VectorSpaceBase<Scalar> > &domain_in
201  )
202 {
203  return Teuchos::rcp(new DefaultZeroLinearOp<Scalar>(range_in, domain_in));
204 }
205 
206 template<class Scalar>
207 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
208 Thyra::nonconstZero(
209  const RCP<const VectorSpaceBase<Scalar> > &range_in,
210  const RCP<const VectorSpaceBase<Scalar> > &domain_in
211  )
212 {
213  return Teuchos::rcp(new DefaultZeroLinearOp<Scalar>(range_in, domain_in));
214 }
215 
216 
217 //
218 // Explicit instantaition
219 //
220 
221 
222 #define THYRA_DEFAULT_ZERO_LINEAR_OP_INSTANT(SCALAR) \
223  \
224  template class DefaultZeroLinearOp<SCALAR >; \
225  \
226  template RCP<const Thyra::LinearOpBase<SCALAR > > \
227  zero( \
228  const RCP<const VectorSpaceBase<SCALAR > > &range, \
229  const RCP<const VectorSpaceBase<SCALAR > > &domain \
230  ); \
231  \
232  template RCP<Thyra::LinearOpBase<SCALAR > > \
233  nonconstZero( \
234  const RCP<const VectorSpaceBase<SCALAR > > &range, \
235  const RCP<const VectorSpaceBase<SCALAR > > &domain \
236  ); \
237 
238 
239 #endif // THYRA_DEFAULT_ZERO_LINEAR_OP_DEF_HPP
bool opSupportedImpl(EOpTransp M_trans) const
Returns true .
void uninitialize()
Set to uninitialized.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns Teuchos::null if uninitialized.
#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.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Interface for a collection of column vectors called a multi-vector.
DefaultZeroLinearOp()
Construct to uninitialized.
Abstract interface for finite-dimensional dense vectors.
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Teuchos::Ptr< VectorBase< Scalar > > &rowStatVec) const
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
Represents a zero linear operator M = 0.
std::string description() const
Prints just the name DefaultZeroLinearOp along with the overall dimensions.
RCP< const LinearOpBase< Scalar > > clone() const
void initialize(const RCP< const VectorSpaceBase< Scalar > > &range, const RCP< const VectorSpaceBase< Scalar > > &domain)
Initialize given a list of non-const linear operators.