Thyra  Version of the Day
Thyra_MultiVectorStdOps_decl.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_MULTI_VECTOR_STD_OPS_DECL_HPP
43 #define THYRA_MULTI_VECTOR_STD_OPS_DECL_HPP
44 
45 #include "Thyra_MultiVectorBase.hpp"
46 #include "RTOpPack_ROpNorm1.hpp"
47 #include "RTOpPack_ROpNorm2.hpp"
48 #include "RTOpPack_ROpNormInf.hpp"
49 
50 namespace Thyra {
51 
52 
63 template<class Scalar>
65  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
66 
67 
81 template<class Scalar, class NormOp>
82 void reductions( const MultiVectorBase<Scalar>& V, const NormOp &op,
83  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
84 
85 
96 template<class Scalar>
98  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
99 
100 
111 template<class Scalar>
113  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
114 
115 
126 template<class Scalar>
128  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
129 
130 
135 template<class Scalar>
138 
139 
152 template<class Scalar>
154  const ArrayView<Scalar> &dots );
155 
156 
167 template<class Scalar>
168 void sums( const MultiVectorBase<Scalar>& V, const ArrayView<Scalar> &sums );
169 
170 
175 template<class Scalar>
178 
179 
187 template<class Scalar>
188 void scale( Scalar alpha, const Ptr<MultiVectorBase<Scalar> > &V );
189 
190 
195 template<class Scalar>
197  const Ptr<MultiVectorBase<Scalar> > &V );
198 
203 template<class Scalar>
204 void assign( const Ptr<MultiVectorBase<Scalar> > &V, Scalar alpha );
205 
210 template<class Scalar>
212  const MultiVectorBase<Scalar>& U );
213 
214 
219 template<class Scalar>
220 void update( Scalar alpha, const MultiVectorBase<Scalar>& U,
221  const Ptr<MultiVectorBase<Scalar> > &V );
222 
223 
229 template<class Scalar>
230 void update(
231  const ArrayView<const Scalar> &alpha,
232  Scalar beta,
233  const MultiVectorBase<Scalar>& U,
234  const Ptr<MultiVectorBase<Scalar> > &V
235  );
236 
237 
243 template<class Scalar>
244 void update(
245  const MultiVectorBase<Scalar>& U,
246  const ArrayView<const Scalar> &alpha,
247  Scalar beta,
248  const Ptr<MultiVectorBase<Scalar> > &V
249  );
250 
251 
278 template<class Scalar>
280  const ArrayView<const Scalar> &alpha,
281  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &X,
282  const Scalar &beta,
283  const Ptr<MultiVectorBase<Scalar> > &Y
284  );
285 
286 
297 template<class Scalar>
298 void randomize( Scalar l, Scalar u, const Ptr<MultiVectorBase<Scalar> > &V );
299 
300 
306 template<class Scalar>
307 void Vt_S( const Ptr<MultiVectorBase<Scalar> > &Z, const Scalar& alpha );
308 
309 
315 template<class Scalar>
316 void Vp_S( const Ptr<MultiVectorBase<Scalar> > &Z, const Scalar& alpha );
317 
318 
324 template<class Scalar>
326  const MultiVectorBase<Scalar>& X );
327 
328 
334 template<class Scalar>
337 
338 
344 template<class Scalar>
347 
348 
354 template<class Scalar>
355 void V_StVpV( const Ptr<MultiVectorBase<Scalar> > &Z, const Scalar &alpha,
357 
358 
359 } // end namespace Thyra
360 
361 
362 // /////////////////////////////////////
363 // Inline functions
364 
365 
366 template<class Scalar>
367 inline
368 void Thyra::norms_1( const MultiVectorBase<Scalar>& V,
370 {
371  V.norms_1(norms);
372 }
373 
374 
375 template<class Scalar>
376 inline
377 void Thyra::norms_2( const MultiVectorBase<Scalar>& V,
378  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
379 {
380  V.norms_2(norms);
381 }
382 
383 
384 template<class Scalar>
385 inline
386 void Thyra::norms_inf( const MultiVectorBase<Scalar>& V,
387  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
388 {
389  V.norms_inf(norms);
390 }
391 
392 
393 template<class Scalar>
395 Thyra::norms_inf( const MultiVectorBase<Scalar>& V )
396 {
397  typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
398  Array<ScalarMag> norms(V.domain()->dim());
399  Thyra::norms_inf<Scalar>(V, norms());
400  return norms;
401 }
402 
403 
404 // /////////////////////////////////////////////
405 // Other implementations
406 
407 
408 template<class Scalar, class NormOp>
409 void Thyra::reductions( const MultiVectorBase<Scalar>& V, const NormOp &op,
410  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
411 {
412  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
413  const int m = V.domain()->dim();
414  Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
415  Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
416  for( int kc = 0; kc < m; ++kc ) {
417  rcp_op_targs[kc] = op.reduct_obj_create();
418  op_targs[kc] = rcp_op_targs[kc].ptr();
419  }
420  applyOp<Scalar>(op, tuple(ptrInArg(V)),
421  ArrayView<Ptr<MultiVectorBase<Scalar> > >(null),
422  op_targs );
423  for( int kc = 0; kc < m; ++kc ) {
424  norms[kc] = op(*op_targs[kc]);
425  }
426 }
427 
428 
429 #endif // THYRA_MULTI_VECTOR_STD_OPS_DECL_HPP
Interface for a collection of column vectors called a multi-vector.
void update(const ArrayView< const Scalar > &alpha, Scalar beta, const MultiVectorBase< Scalar > &U, const Ptr< MultiVectorBase< Scalar > > &V)
alpha[j]*beta*U(j) + V(j) - > V(j), for j = 0 ,,,
void linear_combination(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &X, const Scalar &beta, const Ptr< MultiVectorBase< Scalar > > &Y)
Y.col(j)(i) = beta*Y.col(j)(i) + sum( alpha[k]*X[k].col(j)(i), k=0...m-1 ), for i = 0....
void norms_1(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector one norm.
void assign(const Ptr< MultiVectorBase< Scalar > > &V, Scalar alpha)
V = alpha.
void update(const MultiVectorBase< Scalar > &U, const ArrayView< const Scalar > &alpha, Scalar beta, const Ptr< MultiVectorBase< Scalar > > &V)
U(j) + alpha[j]*beta*V(j) - > V(j), for j = 0 ,,, U.domain()->dim()-1.
void scale(Scalar alpha, const Ptr< MultiVectorBase< Scalar > > &V)
V = alpha*V.
void sums(const MultiVectorBase< Scalar > &V, const ArrayView< Scalar > &sums)
Multi-vector column sum.
Array< typename ScalarTraits< Scalar >::magnitudeType > norms_inf(const MultiVectorBase< Scalar > &V)
Column-wise multi-vector infinity norm.
void V_StVpV(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = alpha*X(i,j) + Y(i), i = 0...z->space()->dim()-1, , j = 0...Z->domain()->dim()-1.
ScalarTraits< Scalar >::magnitudeType norm_1(const MultiVectorBase< Scalar > &V)
Take the induced matrix one norm of a multi-vector.
void norms(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector natural norm.
void norms_2(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector 2 (Euclidean) norm.
void dots(const MultiVectorBase< Scalar > &V1, const MultiVectorBase< Scalar > &V2, const ArrayView< Scalar > &dots)
Multi-vector dot product.
void V_VmV(const Ptr< MultiVectorBase< Scalar > > &Z, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = X(i,j) - Y(i,j), i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void Vp_V(const Ptr< MultiVectorBase< Scalar > > &Z, const MultiVectorBase< Scalar > &X)
Z(i,j) += X(i,j), i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void norms_1(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Column-wise 1-norms.
void reductions(const MultiVectorBase< Scalar > &V, const NormOp &op, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector reductions.
void randomize(Scalar l, Scalar u, const Ptr< MultiVectorBase< Scalar > > &V)
Generate a random multi-vector with elements uniformly distributed elements.
void norms_inf(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector infinity norm.
void assign(const Ptr< MultiVectorBase< Scalar > > &V, const MultiVectorBase< Scalar > &U)
V = U.
void V_VpV(const Ptr< MultiVectorBase< Scalar > > &Z, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = X(i,j) + Y(i,j), i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void update(Scalar alpha, const MultiVectorBase< Scalar > &U, const Ptr< MultiVectorBase< Scalar > > &V)
alpha*U + V -> V.
void scaleUpdate(const VectorBase< Scalar > &a, const MultiVectorBase< Scalar > &U, const Ptr< MultiVectorBase< Scalar > > &V)
A*U + V -> V (where A is a diagonal matrix with diagonal a).
void Vt_S(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha)
Z(i,j) *= alpha, i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void Vp_S(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha)
Z(i,j) += alpha, i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
Abstract interface for finite-dimensional dense vectors.