Thyra  Version of the Day
Thyra_DefaultIdentityLinearOp_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_IDENTITY_LINEAR_OP_DEF_HPP
43 #define THYRA_DEFAULT_IDENTITY_LINEAR_OP_DEF_HPP
44 
45 #include "Thyra_DefaultIdentityLinearOp_decl.hpp"
46 #include "Thyra_MultiVectorStdOps.hpp"
47 #include "Thyra_AssertOp.hpp"
48 
49 
50 namespace Thyra {
51 
52 
53 // Constructors/initializers/accessors
54 
55 
56 template<class Scalar>
58 {}
59 
60 
61 template<class Scalar>
63  const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space
64  )
65 {
66  initialize(space);
67 }
68 
69 
70 template<class Scalar>
72  const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space
73  )
74 {
75  space_ = space.assert_not_null();
76 }
77 
78 
79 template<class Scalar>
81 {
82  space_ = Teuchos::null;
83 }
84 
85 
86 // Overridden from LinearOpBase
87 
88 
89 template<class Scalar>
90 Teuchos::RCP< const VectorSpaceBase<Scalar> >
92 {
93  return space_;
94 }
95 
96 
97 template<class Scalar>
98 Teuchos::RCP< const VectorSpaceBase<Scalar> >
100 {
101  return space_;
102 }
103 
104 
105 template<class Scalar>
106 Teuchos::RCP<const LinearOpBase<Scalar> >
108 {
109  typedef DefaultIdentityLinearOp<Scalar> this_t;
110  if(space_.get())
111  return Teuchos::rcp(new this_t(space_));
112  return Teuchos::rcp(new this_t());
113 }
114 
115 
116 // Overridden from Teuchos::Describable
117 
118 
119 template<class Scalar>
121 {
122  typedef Teuchos::ScalarTraits<Scalar> ST;
123  std::ostringstream oss;
124  oss
125  << "Thyra::DefaultIdentityLinearOp<" << ST::name() << ">{"
126  << "space="<<(space_.get()?space_->description():"NULL")
127  << "}";
128  return oss.str();
129 }
130 
131 
132 // protected
133 
134 
135 // Overridden from LinearOpBase
136 
137 
138 template<class Scalar>
140 {
141  return true;
142 }
143 
144 
145 template<class Scalar>
147  const EOpTransp M_trans,
148  const MultiVectorBase<Scalar> &X,
149  const Ptr<MultiVectorBase<Scalar> > &Y,
150  const Scalar alpha,
151  const Scalar beta
152  ) const
153 {
154  using Teuchos::tuple;
155  using Teuchos::ptrFromRef;
156 #ifdef TEUCHOS_DEBUG
158  "DefaultIdentityLinearOp<Scalar>::apply(...)", *this, M_trans, X, &*Y
159  );
160 #endif // TEUCHOS_DEBUG
161  Thyra::linear_combination<Scalar>(
162  tuple<Scalar>(alpha)(),
163  tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrFromRef(X))(),
164  beta, Y
165  );
166 }
167 
168 
169 } // end namespace Thyra
170 
171 
172 template<class Scalar>
173 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
174 Thyra::identity(
175  const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space,
176  const std::string &label
177  )
178 {
179  RCP<Thyra::LinearOpBase<Scalar> > ilo =
180  Teuchos::rcp(new DefaultIdentityLinearOp<Scalar>(space));
181  if (label.length())
182  ilo->setObjectLabel(label);
183  return ilo;
184 }
185 
186 
187 //
188 // Explicit instantaition
189 //
190 
191 
192 #define THYRA_DEFAULT_IDENTITY_LINEAR_OP_INSTANT(SCALAR) \
193  \
194  template class DefaultIdentityLinearOp<SCALAR >; \
195  \
196  template RCP<const LinearOpBase<SCALAR > > \
197  identity( \
198  const RCP<const VectorSpaceBase<SCALAR > > &space, \
199  const std::string &label \
200  ); \
201 
202 
203 #endif // THYRA_DEFAULT_IDENTITY_LINEAR_OP_DEF_HPP
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
#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...
Represents a identity linear operator M = I.
RCP< const LinearOpBase< Scalar > > clone() const
bool opSupportedImpl(EOpTransp M_trans) const
Returns true .
Abstract interface for objects that represent a space for vectors.
Interface for a collection of column vectors called a multi-vector.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns Teuchos::null if uninitialized.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
std::string description() const
Prints just the name DefaultIdentityLinearOp along with the overall dimensions.
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space)
Initialize given a list of non-const linear operators.
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns Teuchos::null if uninitialized.
DefaultIdentityLinearOp()
Constructs to uninitialized.