Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_VectorBase.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_VECTOR_BASE_DECL_HPP
43 #define THYRA_VECTOR_BASE_DECL_HPP
44 
45 
46 #include "Thyra_OperatorVectorTypes.hpp"
47 #include "Thyra_MultiVectorBase_decl.hpp"
48 #include "RTOpPack_RTOpT.hpp"
49 #include "RTOpPack_SparseSubVectorT.hpp"
50 
51 
52 namespace Thyra {
53 
54 
145 template<class Scalar>
146 class VectorBase : virtual public MultiVectorBase<Scalar>
147 {
148 public:
149 
150 #ifdef THYRA_INJECT_USING_DECLARATIONS
151  using MultiVectorBase<Scalar>::apply;
152 #endif
153 
156 
157  // Overloading assign for VectorBase argument
158  using MultiVectorBase<Scalar>::assign;
159 
166  void assign(const VectorBase<Scalar>& x)
167  { assignVecImpl(x); }
168 
178  void randomize(Scalar l, Scalar u)
179  { randomizeImpl(l,u); }
180 
181  // Overloading update for VectorBase argument.
183 
190  void update(
191  Scalar alpha,
192  const VectorBase<Scalar>& x)
193  { updateVecImpl(alpha, x); }
194 
195  // Overloading linear_combination for VectorBase arguments.
197 
222  const ArrayView<const Scalar>& alpha,
223  const ArrayView<const Ptr<const VectorBase<Scalar> > >& x,
224  const Scalar& beta
225  )
226  { linearCombinationVecImpl(alpha, x, beta); }
227 
231  Scalar dot(const VectorBase<Scalar>& x) const
232  { return dotImpl(x); }
233 
238  norm_1() const
239  { return norm1Impl(); }
240 
246  norm_2() const
247  { return norm2Impl(); }
248 
254  norm_2(const VectorBase<Scalar>& x) const
255  { return norm2WeightedImpl(x); }
256 
262  norm_inf() const
263  { return normInfImpl(); }
264 
266 
269 
286  virtual RCP< const VectorSpaceBase<Scalar> > space() const = 0;
287 
289 
292 
297  void applyOp(
298  const RTOpPack::RTOpT<Scalar> &op,
299  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
300  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
301  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
302  const Ordinal global_offset
303  ) const
304  {
305  applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
306  }
307 
309 
312 
338  virtual RCP<VectorBase<Scalar> > clone_v() const = 0;
339 
341 
344 
350  const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
351  ) const
352  { acquireDetachedVectorViewImpl(rng,sub_vec); }
353 
360  ) const
361  { releaseDetachedVectorViewImpl(sub_vec); }
362 
368  const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
369  )
370  { acquireNonconstDetachedVectorViewImpl(rng,sub_vec); }
371 
378  )
380 
387  )
388  { setSubVectorImpl(sub_vec); }
389 
391 
392 protected:
393 
396 
400  virtual void assignVecImpl(const VectorBase<Scalar>& x) = 0;
401 
405  virtual void randomizeImpl(Scalar l, Scalar u) = 0;
406 
410  virtual void absImpl(const VectorBase<Scalar>& x) = 0;
411 
415  virtual void reciprocalImpl(const VectorBase<Scalar>& x) = 0;
416 
420  virtual void eleWiseScaleImpl(const VectorBase<Scalar>& x) = 0;
421 
425  virtual void updateVecImpl(
426  Scalar alpha,
427  const VectorBase<Scalar>& x) = 0;
428 
432  virtual void linearCombinationVecImpl(
433  const ArrayView<const Scalar>& alpha,
434  const ArrayView<const Ptr<const VectorBase<Scalar> > >& x,
435  const Scalar& beta
436  ) = 0;
437 
441  virtual Scalar dotImpl(const VectorBase<Scalar>& x) const = 0;
442 
447  norm1Impl() const = 0;
448 
453  norm2Impl() const = 0;
454 
459  norm2WeightedImpl(const VectorBase<Scalar>& x) const = 0;
460 
465  normInfImpl() const = 0;
466 
483  virtual void applyOpImpl(
484  const RTOpPack::RTOpT<Scalar> &op,
485  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
486  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
487  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
488  const Ordinal global_offset
489  ) const = 0;
490 
532  virtual void acquireDetachedVectorViewImpl(
533  const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
534  ) const = 0;
535 
555  virtual void releaseDetachedVectorViewImpl(
557  ) const = 0;
558 
608  const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
609  ) = 0;
610 
635  ) = 0;
636 
660  virtual void setSubVectorImpl(
662  ) = 0;
663 
665 
666 private:
667 
668  // Not defined and not to be called
670  operator=(const VectorBase<Scalar>&);
671 
672 public:
673 
674  // These are functions that may be removed in the future and should not be
675  // called by client code.
676 
677  // Don't call this directly. Use non-member Thyra::abs(). This is because
678  // this member function may disappear in the future. (see Trilinos GitHub
679  // issue #330)
680  void abs(const VectorBase<Scalar>& x)
681  { absImpl(x); }
682 
683  // Don't call this directly. Use non-member Thyra::reciprocal(). This is because
684  // this member function may disappear in the future. (see Trilinos GitHub
685  // issue #330)
686  void reciprocal(const VectorBase<Scalar>& x)
687  { reciprocalImpl(x); }
688 
689  // Don't call this directly. Use non-member Thyra::ele_wise_scale(). This
690  // is because this member function may disappear in the future. (see
691  // Trilinos GitHub issue #330)
692  void ele_wise_scale(const VectorBase<Scalar>& x)
693  { eleWiseScaleImpl(x); }
694 
695 };
696 
697 
768 template<class Scalar>
769 inline
770 void applyOp(
771  const RTOpPack::RTOpT<Scalar> &op,
772  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
773  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
774  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
775  const Ordinal global_offset = 0
776  )
777 {
778  if (vecs.size())
779  vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
780  else if (targ_vecs.size())
781  targ_vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
782 }
783 
784 
785 } // end namespace Thyra
786 
787 
788 #endif // THYRA_VECTOR_BASE_DECL_HPP
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
void setSubVector(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)
Calls setSubVectorImpl().
virtual void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)=0
Commit changes for a mutable explicit view of a sub-vector.
void applyOp(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
Calls applyOpImpl().
virtual void randomizeImpl(Scalar l, Scalar u)=0
Virtual implementation for NVI randomize.
virtual void assignVecImpl(const VectorBase< Scalar > &x)=0
Virtual implementation for NVI assign.
void releaseDetachedView(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Calls releaseDetachedVectorViewImpl().
virtual void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const =0
Free an explicit view of a sub-vector.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)=0
Virtual implementation for NVI reciprocal.
void randomize(Scalar l, Scalar u)
Random vector generation:
virtual void setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)=0
Set a specific sub-vector.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType normInfImpl() const =0
Virtual implementation for NVI norm_inf.
void assign(const VectorBase< Scalar > &x)
Vector assignment:
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
virtual void linearCombinationVecImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const VectorBase< Scalar > > > &x, const Scalar &beta)=0
Virtual implementation for NVI linear_combination.
Interface for a collection of column vectors called a multi-vector.
void applyOp(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset=0)
Apply a reduction/transformation operator over a set of vectors: op(op(v[0]...v[nv-1],z[0]...z[nz-1]),(*reduct_obj)) -&gt; z[0]...z[nz-1],(*reduct_obj).
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_inf() const
Infinity norm: result = ||v||inf.
virtual void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const =0
Apply a reduction/transformation operator over a set of vectors: op(op(v[0]...v[nv-1],z[0]...z[nz-1]),(*reduct_obj)) -&gt; z[0]...z[nz-1],(*reduct_obj).
virtual void updateVecImpl(Scalar alpha, const VectorBase< Scalar > &x)=0
Virtual implementation for NVI update.
Abstract interface for finite-dimensional dense vectors.
void acquireDetachedView(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Calls acquireDetachedVectorViewImpl().
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const =0
Virtual implementation for NVI norm_2 (weighted).
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_2() const
Euclidean (2) norm: result = ||v||2.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_1() const
One (1) norm: result = ||v||1.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm1Impl() const =0
Virtual implementation for NVI norm_1.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2Impl() const =0
Virtual implementation for NVI norm_2.
void commitDetachedView(RTOpPack::SubVectorView< Scalar > *sub_vec)
Calls commitDetachedView().
void linear_combination(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const VectorBase< Scalar > > > &x, const Scalar &beta)
Linear combination:
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)=0
Virtual implementation for NVI ele_wise_scale.
virtual void absImpl(const VectorBase< Scalar > &x)=0
Virtual implementation for NVI abs.
void update(Scalar alpha, const VectorBase< Scalar > &x)
AXPY:
virtual void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)=0
Get a mutable explicit view of a sub-vector.
Scalar dot(const VectorBase< Scalar > &x) const
Euclidean dot product: result = x^H * this.
void acquireDetachedView(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Calls acquireNonconstDetachedVectorViewImpl().
virtual void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const =0
Get a non-mutable explicit view of a sub-vector.
virtual RCP< VectorBase< Scalar > > clone_v() const =0
Returns a seprate cloned copy of *this vector with the same values but different storage.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_2(const VectorBase< Scalar > &x) const
Weighted Euclidean (2) norm: result = ||v||2.
virtual Scalar dotImpl(const VectorBase< Scalar > &x) const =0
Virtual implementation for NVI dot.