Thyra  Version of the Day
Thyra_MultiVectorBase_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_BASE_DECL_HPP
43 #define THYRA_MULTI_VECTOR_BASE_DECL_HPP
44 
45 #include "Thyra_LinearOpBase_decl.hpp"
46 #include "Thyra_RowStatLinearOpBase.hpp"
47 #include "Thyra_ScaledLinearOpBase.hpp"
48 #include "RTOpPack_RTOpT.hpp"
49 
50 
51 namespace Thyra {
52 
53 
492 template<class Scalar>
493 class MultiVectorBase : virtual public LinearOpBase<Scalar>,
494  virtual public RowStatLinearOpBase<Scalar>,
495  virtual public ScaledLinearOpBase<Scalar>
496 {
497 public:
498 
499 #ifdef THYRA_INJECT_USING_DECLARATIONS
501 #endif
502 
505 
513  void assign(Scalar alpha)
514  { assignImpl(alpha); }
515 
517 
520 
525  RCP<const VectorBase<Scalar> > col(Ordinal j) const
526  { return colImpl(j); }
527 
532  RCP<VectorBase<Scalar> > col(Ordinal j)
533  { return nonconstColImpl(j); }
534 
536 
539 
544  RCP<const MultiVectorBase<Scalar> >
545  subView( const Range1D& colRng ) const
546  {
547  return contigSubViewImpl(colRng);
548  }
549 
554  RCP<MultiVectorBase<Scalar> >
555  subView( const Range1D& colRng )
556  { return nonconstContigSubViewImpl(colRng); }
557 
562  RCP<const MultiVectorBase<Scalar> >
563  subView( const ArrayView<const int> &cols ) const
564  { return nonContigSubViewImpl(cols); }
565 
570  RCP<MultiVectorBase<Scalar> >
571  subView( const ArrayView<const int> &cols )
572  { return nonconstNonContigSubViewImpl(cols); }
573 
575 
578 
583  void applyOp(
584  const RTOpPack::RTOpT<Scalar> &primary_op,
585  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
586  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
587  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
588  const Ordinal primary_global_offset
589  ) const
590  {
591  mvMultiReductApplyOpImpl(primary_op, multi_vecs, targ_multi_vecs,
592  reduct_objs, primary_global_offset);
593  }
594 
599  void applyOp(
600  const RTOpPack::RTOpT<Scalar> &primary_op,
601  const RTOpPack::RTOpT<Scalar> &secondary_op,
602  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
603  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
604  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
605  const Ordinal primary_global_offset
606  ) const
607  {
608  mvSingleReductApplyOpImpl(primary_op, secondary_op, multi_vecs, targ_multi_vecs,
609  reduct_obj, primary_global_offset);
610  }
611 
613 
616 
622  const Range1D &rowRng,
623  const Range1D &colRng,
625  ) const
626  { acquireDetachedMultiVectorViewImpl( rowRng, colRng, sub_mv ); }
627 
634  ) const
636 
642  const Range1D &rowRng,
643  const Range1D &colRng,
645  )
646  { acquireNonconstDetachedMultiVectorViewImpl(rowRng,colRng,sub_mv); }
647 
654  )
656 
658 
661 
670  virtual RCP<MultiVectorBase<Scalar> > clone_mv() const = 0;
671 
673 
676 
678  RCP<const LinearOpBase<Scalar> > clone() const;
679 
681 
682 protected:
683 
686 
690  virtual void assignImpl(Scalar alpha) = 0;
691 
713  virtual RCP<const VectorBase<Scalar> > colImpl(Ordinal j) const;
714 
735  virtual RCP<VectorBase<Scalar> > nonconstColImpl(Ordinal j) = 0;
736 
761  virtual RCP<const MultiVectorBase<Scalar> >
762  contigSubViewImpl( const Range1D& colRng ) const = 0;
763 
788  virtual RCP<MultiVectorBase<Scalar> >
789  nonconstContigSubViewImpl( const Range1D& colRng ) = 0;
790 
815  virtual RCP<const MultiVectorBase<Scalar> >
816  nonContigSubViewImpl( const ArrayView<const int> &cols ) const = 0;
817 
842  virtual RCP<MultiVectorBase<Scalar> >
843  nonconstNonContigSubViewImpl( const ArrayView<const int> &cols ) = 0;
844 
866  virtual void mvMultiReductApplyOpImpl(
867  const RTOpPack::RTOpT<Scalar> &primary_op,
868  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
869  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
870  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
871  const Ordinal primary_global_offset
872  ) const = 0;
873 
894  virtual void mvSingleReductApplyOpImpl(
895  const RTOpPack::RTOpT<Scalar> &primary_op,
896  const RTOpPack::RTOpT<Scalar> &secondary_op,
897  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
898  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
899  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
900  const Ordinal primary_global_offset
901  ) const = 0;
902 
967  const Range1D &rowRng,
968  const Range1D &colRng,
970  ) const = 0;
971 
999  ) const = 0;
1000 
1074  const Range1D &rowRng,
1075  const Range1D &colRng,
1077  ) = 0;
1078 
1108  ) = 0;
1109 
1111  virtual bool rowStatIsSupportedImpl(
1112  const RowStatLinearOpBaseUtils::ERowStat rowStat) const;
1113 
1115  virtual void getRowStatImpl(
1116  const RowStatLinearOpBaseUtils::ERowStat rowStat,
1117  const Ptr<VectorBase<Scalar> > &rowStatVec) const;
1118 
1120  virtual bool supportsScaleLeftImpl() const;
1121 
1123  virtual bool supportsScaleRightImpl() const;
1124 
1126  virtual void scaleLeftImpl(const VectorBase< Scalar > &row_scaling);
1127 
1129  virtual void scaleRightImpl(const VectorBase< Scalar > &col_scaling);
1130 
1132 
1140  void absRowSum(const Teuchos::Ptr<Thyra::VectorBase<Scalar> > & output) const;
1141 
1147  void absColSum(const Teuchos::Ptr<Thyra::VectorBase<Scalar> > & output) const;
1148 
1149 public:
1150 
1151 private:
1152 
1153  // Not defined and not to be called
1155  operator=(const MultiVectorBase<Scalar>&);
1156 
1157 };
1158 
1159 
1167 template<class Scalar>
1168 inline
1169 void applyOp(
1170  const RTOpPack::RTOpT<Scalar> &primary_op,
1171  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
1172  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
1173  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
1174  const Ordinal primary_global_offset = 0
1175  )
1176 {
1177  if(multi_vecs.size())
1178  multi_vecs[0]->applyOp(primary_op, multi_vecs, targ_multi_vecs,
1179  reduct_objs, primary_global_offset);
1180  else if(targ_multi_vecs.size())
1181  targ_multi_vecs[0]->applyOp(primary_op, multi_vecs, targ_multi_vecs,
1182  reduct_objs, primary_global_offset);
1183 }
1184 
1185 
1193 template<class Scalar>
1194 inline
1195 void applyOp(
1196  const RTOpPack::RTOpT<Scalar> &primary_op,
1197  const RTOpPack::RTOpT<Scalar> &secondary_op,
1198  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
1199  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
1200  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
1201  const Ordinal primary_global_offset = 0
1202  )
1203 {
1204  if(multi_vecs.size())
1205  multi_vecs[0]->applyOp(primary_op, secondary_op, multi_vecs, targ_multi_vecs,
1206  reduct_obj, primary_global_offset);
1207  else if(targ_multi_vecs.size())
1208  targ_multi_vecs[0]->applyOp(primary_op, secondary_op, multi_vecs, targ_multi_vecs,
1209  reduct_obj, primary_global_offset);
1210 }
1211 
1212 
1213 } // namespace Thyra
1214 
1215 
1216 #endif // THYRA_MULTI_VECTOR_BASE_DECL_HPP
void absColSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
RCP< MultiVectorBase< Scalar > > subView(const ArrayView< const int > &cols)
nonconstNonContigSubViewImpl().
void absRowSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
void commitDetachedView(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
Calls commitNonconstDetachedMultiVectorViewImpl().
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Ptr< VectorBase< Scalar > > &rowStatVec) const
virtual RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const =0
Return a non-changeable sub-view of a contiguous set of columns of the this multi-vector.
virtual RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)=0
Return a changeable sub-view of a contiguous set of columns of the this multi-vector.
void acquireDetachedView(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
Calls acquireNonconstDetachedMultiVectorViewImpl().
virtual void scaleLeftImpl(const VectorBase< Scalar > &row_scaling)
virtual void assignImpl(Scalar alpha)=0
Virtual implementation for NVI assign().
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
virtual bool supportsScaleRightImpl() const
RCP< const MultiVectorBase< Scalar > > subView(const Range1D &colRng) const
Calls contigSubViewImpl().
void acquireDetachedView(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Calls acquireDetachedMultiVectorViewImpl().
virtual void releaseDetachedMultiVectorViewImpl(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const =0
Free a non-changeable explicit view of a sub-multi-vector.
virtual RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)=0
Return a changeable view of a constituent column vector.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
RCP< VectorBase< Scalar > > col(Ordinal j)
Calls nonconstColImpl().
Abstract interface for finite-dimensional dense vectors.
virtual bool supportsScaleLeftImpl() const
Base class for all linear operators.
void applyOp(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
Calls mvMultiReductApplyOpImpl().
Applies left or right sclaing to the linear operator.
void assign(Scalar alpha)
V = alpha.
void applyOp(const RTOpPack::RTOpT< Scalar > &primary_op, const RTOpPack::RTOpT< Scalar > &secondary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal primary_global_offset=0)
Apply a reduction/transformation operator column by column and reduce the intermediate reduction obje...
void applyOp(const RTOpPack::RTOpT< Scalar > &primary_op, const RTOpPack::RTOpT< Scalar > &secondary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal primary_global_offset) const
mvSingleReductApplyOpImpl().
virtual void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)=0
Get a changeable explicit view of a sub-multi-vector.
virtual RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols) const =0
Return a non-changeable sub-view of a non-contiguous set of columns of this multi-vector.
virtual RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols)=0
Return a changeable sub-view of a non-contiguous set of columns of this multi-vector.
Interface for exxtracting row statistics as a VectorBase from a supporting LinearOpBase object...
virtual void mvSingleReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const RTOpPack::RTOpT< Scalar > &secondary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal primary_global_offset) const =0
Apply a reduction/transformation operator column by column and reduce the intermediate reduction obje...
virtual void scaleRightImpl(const VectorBase< Scalar > &col_scaling)
virtual void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const =0
Get a non-changeable explicit view of a sub-multi-vector.
virtual RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
Return a non-changeable view of a constituent column vector.
virtual void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)=0
Commit changes for a changeable explicit view of a sub-multi-vector.
virtual RCP< MultiVectorBase< Scalar > > clone_mv() const =0
Clone the multi-vector object (if supported).
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const =0
Apply a reduction/transformation operator column by column and return an array of the reduction objec...
RCP< const LinearOpBase< Scalar > > clone() const
This function is simply overridden to return this->clone_mv().
void releaseDetachedView(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Calls releaseDetachedMultiVectorViewImpl().
RCP< MultiVectorBase< Scalar > > subView(const Range1D &colRng)
Calls nonconstContigSubViewImpl().
void applyOp(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset=0)
Apply a reduction/transformation operator column by column and return an array of the reduction objec...
Teuchos::Range1D Range1D
RCP< const MultiVectorBase< Scalar > > subView(const ArrayView< const int > &cols) const
nonContigSubViewImpl().