Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
92 {
93  return space_;
94 }
95 
96 
97 template<class Scalar>
100 {
101  return space_;
102 }
103 
104 
105 template<class 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 {
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 #else
161  (void)M_trans;
162 #endif // TEUCHOS_DEBUG
163  Thyra::linear_combination<Scalar>(
164  tuple<Scalar>(alpha)(),
165  tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrFromRef(X))(),
166  beta, Y
167  );
168 }
169 
170 
171 } // end namespace Thyra
172 
173 
174 template<class Scalar>
176 Thyra::identity(
177  const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space,
178  const std::string &label
179  )
180 {
181  RCP<Thyra::LinearOpBase<Scalar> > ilo =
182  Teuchos::rcp(new DefaultIdentityLinearOp<Scalar>(space));
183  if (label.length())
184  ilo->setObjectLabel(label);
185  return ilo;
186 }
187 
188 
189 //
190 // Explicit instantaition
191 //
192 
193 
194 #define THYRA_DEFAULT_IDENTITY_LINEAR_OP_INSTANT(SCALAR) \
195  \
196  template class DefaultIdentityLinearOp<SCALAR >; \
197  \
198  template RCP<const LinearOpBase<SCALAR > > \
199  identity( \
200  const RCP<const VectorSpaceBase<SCALAR > > &space, \
201  const std::string &label \
202  ); \
203 
204 
205 #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.
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.
Abstract interface for objects that represent a space for vectors.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Interface for a collection of column vectors called a multi-vector.
bool opSupportedImpl(EOpTransp M_trans) const
Returns true .
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space)
Initialize given a list of non-const linear operators.
RCP< const LinearOpBase< Scalar > > clone() const
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns Teuchos::null if uninitialized.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns Teuchos::null if uninitialized.
DefaultIdentityLinearOp()
Constructs to uninitialized.