Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultDiagonalLinearOp_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_DIAGONAL_LINEAR_OP_DEF_HPP
11 #define THYRA_DIAGONAL_LINEAR_OP_DEF_HPP
12 
13 
14 #include "Thyra_DefaultDiagonalLinearOp_decl.hpp"
15 #include "Thyra_MultiVectorStdOps.hpp"
16 #include "Thyra_VectorStdOps.hpp"
17 #include "Thyra_VectorBase.hpp"
18 #include "Thyra_AssertOp.hpp"
19 
20 
21 namespace Thyra {
22 
23 
24 // Constructors/initializers/accessors
25 
26 
27 template<class Scalar>
29 {}
30 
31 
32 template<class Scalar>
34  const RCP<const VectorSpaceBase<Scalar> > &space
35  )
36 {
37  initialize(space);
38 }
39 
40 
41 template<class Scalar>
43  const RCP<VectorBase<Scalar> > &diag
44  )
45 {
46  initialize(diag);
47 }
48 
49 
50 template<class Scalar>
52  const RCP<const VectorBase<Scalar> > &diag
53  )
54 {
55  initialize(diag);
56 }
57 
58 
59 template<class Scalar>
61  const RCP<const VectorSpaceBase<Scalar> > &space
62  )
63 {
64 #ifdef TEUCHOS_DEBUG
65  TEUCHOS_TEST_FOR_EXCEPT(space.get()==NULL);
66 #endif
67  initialize(createMember(space)); // Note that the space is guaranteed to be remembered here!
68 }
69 
70 
71 template<class Scalar>
73  const RCP<VectorBase<Scalar> > &diag
74  )
75 {
76  diag_.initialize(diag);
77 }
78 
79 
80 template<class Scalar>
82  const RCP<const VectorBase<Scalar> > &diag
83  )
84 {
85  diag_.initialize(diag);
86 }
87 
88 
89 template<class Scalar>
91 {
92  diag_.uninitialize();
93 }
94 
95 
96 // Overridden from DiagonalLinearOpBase
97 
98 
99 template<class Scalar>
101 {
102  return diag_.isConst();
103 }
104 
105 
106 template<class Scalar>
109 {
110  return diag_.getNonconstObj();
111 }
112 
113 
114 template<class Scalar>
117 {
118  return diag_.getConstObj();
119 }
120 
121 
122 // Overridden from LinearOpBase
123 
124 
125 template<class Scalar>
128 {
129  return diag_.getConstObj()->space();
130 }
131 
132 
133 template<class Scalar>
136 {
137  return diag_.getConstObj()->space();
138 }
139 
140 
141 template<class Scalar>
144 {
145  return Teuchos::rcp(new DefaultDiagonalLinearOp<Scalar>(diag_.getConstObj()->clone_v()));
146 }
147 
148 
149 // protected
150 
151 
152 // Protected functions overridden from LinearOpBase
153 
154 
155 template<class Scalar>
157 {
158  return true;
159 }
160 
161 
162 template<class Scalar>
164  const EOpTransp M_trans,
165  const MultiVectorBase<Scalar> &X,
166  const Ptr<MultiVectorBase<Scalar> > &Y,
167  const Scalar alpha,
168  const Scalar beta
169  ) const
170 {
172 
173 #ifdef TEUCHOS_DEBUG
175  "DefaultDiagonalLinearOp<Scalar>::apply(...)",*this, M_trans, X, &*Y
176  );
177 #endif // TEUCHOS_DEBUG
178 
179  // Y = beta * Y
180 
181  if( beta != ST::one() ) scale<Scalar>(beta, Y);
182 
183  // Y += alpha *op(M) * X
184 
185  const Ordinal m = X.domain()->dim();
186 
187  for (Ordinal col_j = 0; col_j < m; ++col_j) {
188  const RCP<const VectorBase<Scalar> > x = X.col(col_j);
189  const RCP<VectorBase<Scalar> > y = Y->col(col_j);
190  if (ST::isComplex) {
191  if ( M_trans==NOTRANS || M_trans==TRANS ) {
192  ele_wise_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
193  }
194  else {
195  ele_wise_conj_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
196  }
197  }
198  else {
199  ele_wise_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
200  }
201  }
202 
203 }
204 
205 
206 } // end namespace Thyra
207 
208 
209 #endif // THYRA_DIAGONAL_LINEAR_OP_DEF_HPP
void initialize(int *argc, char ***argv)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this-&gt;getDiag()-&gt;space().
#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 VectorBase< Scalar > > getDiag() const
Use the non-transposed operator.
Abstract interface for objects that represent a space for vectors.
Use the transposed operator.
RCP< const LinearOpBase< Scalar > > clone() const
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space)
Initialize given a vector space which allocates a vector internally.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
Ptr< T > ptr() const
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
Abstract interface for finite-dimensional dense vectors.
DefaultDiagonalLinearOp()
Constructs to uninitialized.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this-&gt;getDiag()-&gt;space().
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Default concrete LinearOpBase subclass for diagonal linear operators.