Thyra Version of the Day
Loading...
Searching...
No Matches
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
21namespace Thyra {
22
23
24// Constructors/initializers/accessors
25
26
27template<class Scalar>
30
31
32template<class Scalar>
34 const RCP<const VectorSpaceBase<Scalar> > &space
35 )
36{
37 initialize(space);
38}
39
40
41template<class Scalar>
43 const RCP<VectorBase<Scalar> > &diag
44 )
45{
46 initialize(diag);
47}
48
49
50template<class Scalar>
52 const RCP<const VectorBase<Scalar> > &diag
53 )
54{
55 initialize(diag);
56}
57
58
59template<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
71template<class Scalar>
73 const RCP<VectorBase<Scalar> > &diag
74 )
75{
76 diag_.initialize(diag);
77}
78
79
80template<class Scalar>
82 const RCP<const VectorBase<Scalar> > &diag
83 )
84{
85 diag_.initialize(diag);
86}
87
88
89template<class Scalar>
91{
92 diag_.uninitialize();
93}
94
95
96// Overridden from DiagonalLinearOpBase
97
98
99template<class Scalar>
101{
102 return diag_.isConst();
103}
104
105
106template<class Scalar>
109{
110 return diag_.getNonconstObj();
111}
112
113
114template<class Scalar>
117{
118 return diag_.getConstObj();
119}
120
121
122// Overridden from LinearOpBase
123
124
125template<class Scalar>
128{
129 return diag_.getConstObj()->space();
130}
131
132
133template<class Scalar>
136{
137 return diag_.getConstObj()->space();
138}
139
140
141template<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
155template<class Scalar>
157{
158 return true;
159}
160
161
162template<class Scalar>
164 const EOpTransp M_trans,
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
Ptr< T > ptr() const
Default concrete LinearOpBase subclass for diagonal linear operators.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getDiag()->space().
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space)
Initialize given a vector space which allocates a vector internally.
RCP< const VectorBase< Scalar > > getDiag() const
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getDiag()->space().
DefaultDiagonalLinearOp()
Constructs to uninitialized.
RCP< const LinearOpBase< Scalar > > clone() const
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
Interface for a collection of column vectors called a multi-vector.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
Abstract interface for finite-dimensional dense vectors.
Abstract interface for objects that represent a space for vectors.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#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...
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
@ TRANS
Use the transposed operator.
@ NOTRANS
Use the non-transposed operator.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)