Thyra  Version of the Day
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
152 #endif
153 
156 
173  virtual RCP< const VectorSpaceBase<Scalar> > space() const = 0;
174 
176 
179 
184  void applyOp(
185  const RTOpPack::RTOpT<Scalar> &op,
186  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
187  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
188  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
189  const Ordinal global_offset
190  ) const
191  {
192  applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
193  }
194 
196 
199 
214  virtual RCP<VectorBase<Scalar> > clone_v() const = 0;
215 
217 
220 
226  const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
227  ) const
228  { acquireDetachedVectorViewImpl(rng,sub_vec); }
229 
236  ) const
237  { releaseDetachedVectorViewImpl(sub_vec); }
238 
244  const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
245  )
246  { acquireNonconstDetachedVectorViewImpl(rng,sub_vec); }
247 
254  )
256 
263  )
264  { setSubVectorImpl(sub_vec); }
265 
267 
268 protected:
269 
272 
289  virtual void applyOpImpl(
290  const RTOpPack::RTOpT<Scalar> &op,
291  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
292  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
293  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
294  const Ordinal global_offset
295  ) const = 0;
296 
338  virtual void acquireDetachedVectorViewImpl(
339  const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
340  ) const = 0;
341 
361  virtual void releaseDetachedVectorViewImpl(
363  ) const = 0;
364 
414  const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
415  ) = 0;
416 
441  ) = 0;
442 
466  virtual void setSubVectorImpl(
468  ) = 0;
469 
471 
472 private:
473 
474  // Not defined and not to be called
476  operator=(const VectorBase<Scalar>&);
477 
478 };
479 
480 
551 template<class Scalar>
552 inline
553 void applyOp(
554  const RTOpPack::RTOpT<Scalar> &op,
555  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
556  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
557  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
558  const Ordinal global_offset = 0
559  )
560 {
561  if (vecs.size())
562  vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
563  else if (targ_vecs.size())
564  targ_vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
565 }
566 
567 
568 } // end namespace Thyra
569 
570 
571 #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 acquireDetachedView(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Calls acquireDetachedVectorViewImpl().
virtual void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const =0
Free an explicit view of a sub-vector.
virtual void setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)=0
Set a specific sub-vector.
void releaseDetachedView(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Calls releaseDetachedVectorViewImpl().
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
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)) -> z[0]...z[nz-1],(*reduct_obj).
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)) -> z[0]...z[nz-1],(*reduct_obj).
Abstract interface for finite-dimensional dense vectors.
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().
void commitDetachedView(RTOpPack::SubVectorView< Scalar > *sub_vec)
Calls commitDetachedView().
void apply(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Apply the linear operator to a multi-vector : Y = alpha*op(M)*X + beta*Y.
virtual void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)=0
Get a mutable explicit view of a sub-vector.
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 cloned copy of *this vector.
Teuchos::Range1D Range1D