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>
64 void norms( const MultiVectorBase<Scalar>& V,
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 
99 template<class Scalar>
100 void norms_1( const MultiVectorBase<Scalar>& V,
101  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
102 
103 
117 template<class Scalar>
118 void norms_2( const MultiVectorBase<Scalar>& V,
119  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
120 
121 
135 template<class Scalar>
136 void norms_inf( const MultiVectorBase<Scalar>& V,
137  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms );
138 
139 
144 template<class Scalar>
145 Array<typename ScalarTraits<Scalar>::magnitudeType>
146 norms_inf( const MultiVectorBase<Scalar>& V );
147 
148 
161 template<class Scalar>
162 void dots( const MultiVectorBase<Scalar>& V1, const MultiVectorBase<Scalar>& V2,
163  const ArrayView<Scalar> &dots );
164 
165 
176 template<class Scalar>
177 void sums( const MultiVectorBase<Scalar>& V, const ArrayView<Scalar> &sums );
178 
179 
184 template<class Scalar>
185 typename ScalarTraits<Scalar>::magnitudeType
186 norm_1( const MultiVectorBase<Scalar>& V );
187 
188 
196 template<class Scalar>
197 void scale( Scalar alpha, const Ptr<MultiVectorBase<Scalar> > &V );
198 
199 
204 template<class Scalar>
205 void scaleUpdate( const VectorBase<Scalar>& a, const MultiVectorBase<Scalar>& U,
206  const Ptr<MultiVectorBase<Scalar> > &V );
207 
212 template<class Scalar>
213 void assign( const Ptr<MultiVectorBase<Scalar> > &V, Scalar alpha );
214 
219 template<class Scalar>
220 void assign( const Ptr<MultiVectorBase<Scalar> > &V,
221  const MultiVectorBase<Scalar>& U );
222 
223 
228 template<class Scalar>
229 void update( Scalar alpha, const MultiVectorBase<Scalar>& U,
230  const Ptr<MultiVectorBase<Scalar> > &V );
231 
232 
238 template<class Scalar>
239 void update(
240  const ArrayView<const Scalar> &alpha,
241  Scalar beta,
242  const MultiVectorBase<Scalar>& U,
243  const Ptr<MultiVectorBase<Scalar> > &V
244  );
245 
246 
252 template<class Scalar>
253 void update(
254  const MultiVectorBase<Scalar>& U,
255  const ArrayView<const Scalar> &alpha,
256  Scalar beta,
257  const Ptr<MultiVectorBase<Scalar> > &V
258  );
259 
260 
287 template<class Scalar>
288 void linear_combination(
289  const ArrayView<const Scalar> &alpha,
290  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &X,
291  const Scalar &beta,
292  const Ptr<MultiVectorBase<Scalar> > &Y
293  );
294 
295 
306 template<class Scalar>
307 void randomize( Scalar l, Scalar u, const Ptr<MultiVectorBase<Scalar> > &V );
308 
309 
315 template<class Scalar>
316 void Vt_S( const Ptr<MultiVectorBase<Scalar> > &Z, const Scalar& alpha );
317 
318 
324 template<class Scalar>
325 void Vp_S( const Ptr<MultiVectorBase<Scalar> > &Z, const Scalar& alpha );
326 
327 
333 template<class Scalar>
334 void Vp_V( const Ptr<MultiVectorBase<Scalar> > &Z,
335  const MultiVectorBase<Scalar>& X );
336 
337 
343 template<class Scalar>
344 void V_VpV( const Ptr<MultiVectorBase<Scalar> > &Z,
345  const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y );
346 
347 
353 template<class Scalar>
354 void V_VmV( const Ptr<MultiVectorBase<Scalar> > &Z,
355  const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y );
356 
357 
363 template<class Scalar>
364 void V_StVpV( const Ptr<MultiVectorBase<Scalar> > &Z, const Scalar &alpha,
365  const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y );
366 
367 
368 } // end namespace Thyra
369 
370 
371 // /////////////////////////////////////
372 // Inline functions
373 
374 
375 template<class Scalar>
376 inline
377 void Thyra::norms_1( const MultiVectorBase<Scalar>& V,
378  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
379 {
380  reductions<Scalar>(V, RTOpPack::ROpNorm1<Scalar>(), norms);
381 }
382 
383 
384 template<class Scalar>
385 inline
386 void Thyra::norms_2( const MultiVectorBase<Scalar>& V,
387  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
388 {
389  reductions<Scalar>(V, RTOpPack::ROpNorm2<Scalar>(), norms);
390 }
391 
392 
393 template<class Scalar>
394 inline
395 void Thyra::norms_inf( const MultiVectorBase<Scalar>& V,
396  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
397 {
398  reductions<Scalar>(V, RTOpPack::ROpNormInf<Scalar>(), norms);
399 }
400 
401 
402 template<class Scalar>
403 Teuchos::Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>
404 Thyra::norms_inf( const MultiVectorBase<Scalar>& V )
405 {
406  typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
407  Array<ScalarMag> norms(V.domain()->dim());
408  Thyra::norms_inf<Scalar>(V, norms());
409  return norms;
410 }
411 
412 
413 // /////////////////////////////////////////////
414 // Other implementations
415 
416 
417 template<class Scalar, class NormOp>
418 void Thyra::reductions( const MultiVectorBase<Scalar>& V, const NormOp &op,
419  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType> &norms )
420 {
421  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
422  const int m = V.domain()->dim();
423  Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
424  Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
425  for( int kc = 0; kc < m; ++kc ) {
426  rcp_op_targs[kc] = op.reduct_obj_create();
427  op_targs[kc] = rcp_op_targs[kc].ptr();
428  }
429  applyOp<Scalar>(op, tuple(ptrInArg(V)),
430  ArrayView<Ptr<MultiVectorBase<Scalar> > >(null),
431  op_targs );
432  for( int kc = 0; kc < m; ++kc ) {
433  norms[kc] = op(*op_targs[kc]);
434  }
435 }
436 
437 
438 #endif // THYRA_MULTI_VECTOR_STD_OPS_DECL_HPP
void norms(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector natural norm.