Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_DefaultDiagonalLinearOp_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_DIAGONAL_LINEAR_OP_DEF_HPP
43#define THYRA_DIAGONAL_LINEAR_OP_DEF_HPP
44
45
46#include "Thyra_DefaultDiagonalLinearOp_decl.hpp"
47#include "Thyra_MultiVectorStdOps.hpp"
48#include "Thyra_VectorStdOps.hpp"
49#include "Thyra_VectorBase.hpp"
50#include "Thyra_AssertOp.hpp"
51
52
53namespace Thyra {
54
55
56// Constructors/initializers/accessors
57
58
59template<class Scalar>
61{}
62
63
64template<class Scalar>
66 const RCP<const VectorSpaceBase<Scalar> > &space
67 )
68{
69 initialize(space);
70}
71
72
73template<class Scalar>
75 const RCP<VectorBase<Scalar> > &diag
76 )
77{
78 initialize(diag);
79}
80
81
82template<class Scalar>
84 const RCP<const VectorBase<Scalar> > &diag
85 )
86{
87 initialize(diag);
88}
89
90
91template<class Scalar>
93 const RCP<const VectorSpaceBase<Scalar> > &space
94 )
95{
96#ifdef TEUCHOS_DEBUG
97 TEUCHOS_TEST_FOR_EXCEPT(space.get()==NULL);
98#endif
99 initialize(createMember(space)); // Note that the space is guaranteed to be remembered here!
100}
101
102
103template<class Scalar>
105 const RCP<VectorBase<Scalar> > &diag
106 )
107{
108 diag_.initialize(diag);
109}
110
111
112template<class Scalar>
114 const RCP<const VectorBase<Scalar> > &diag
115 )
116{
117 diag_.initialize(diag);
118}
119
120
121template<class Scalar>
123{
124 diag_.uninitialize();
125}
126
127
128// Overridden from DiagonalLinearOpBase
129
130
131template<class Scalar>
133{
134 return diag_.isConst();
135}
136
137
138template<class Scalar>
141{
142 return diag_.getNonconstObj();
143}
144
145
146template<class Scalar>
149{
150 return diag_.getConstObj();
151}
152
153
154// Overridden from LinearOpBase
155
156
157template<class Scalar>
160{
161 return diag_.getConstObj()->space();
162}
163
164
165template<class Scalar>
168{
169 return diag_.getConstObj()->space();
170}
171
172
173template<class Scalar>
176{
177 return Teuchos::rcp(new DefaultDiagonalLinearOp<Scalar>(diag_.getConstObj()->clone_v()));
178}
179
180
181// protected
182
183
184// Protected functions overridden from LinearOpBase
185
186
187template<class Scalar>
189{
190 return true;
191}
192
193
194template<class Scalar>
196 const EOpTransp M_trans,
198 const Ptr<MultiVectorBase<Scalar> > &Y,
199 const Scalar alpha,
200 const Scalar beta
201 ) const
202{
204
205#ifdef TEUCHOS_DEBUG
207 "DefaultDiagonalLinearOp<Scalar>::apply(...)",*this, M_trans, X, &*Y
208 );
209#endif // TEUCHOS_DEBUG
210
211 // Y = beta * Y
212
213 if( beta != ST::one() ) scale<Scalar>(beta, Y);
214
215 // Y += alpha *op(M) * X
216
217 const Ordinal m = X.domain()->dim();
218
219 for (Ordinal col_j = 0; col_j < m; ++col_j) {
220 const RCP<const VectorBase<Scalar> > x = X.col(col_j);
221 const RCP<VectorBase<Scalar> > y = Y->col(col_j);
222 if (ST::isComplex) {
223 if ( M_trans==NOTRANS || M_trans==TRANS ) {
224 ele_wise_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
225 }
226 else {
227 ele_wise_conj_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
228 }
229 }
230 else {
231 ele_wise_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
232 }
233 }
234
235}
236
237
238} // end namespace Thyra
239
240
241#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)