Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
524  { assignMultiVecImpl(mv); }
525 
532  void scale(Scalar alpha)
533  { scaleImpl(alpha); }
534 
543  void update(
544  Scalar alpha,
545  const MultiVectorBase<Scalar>& mv
546  )
547  { updateImpl(alpha, mv); }
548 
575  const ArrayView<const Scalar>& alpha,
576  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > >& mv,
577  const Scalar& beta
578  )
579  { linearCombinationImpl(alpha, mv, beta); }
580 
590  void dots(
591  const MultiVectorBase<Scalar>& mv,
592  const ArrayView<Scalar>& prods
593  ) const
594  { dotsImpl(mv, prods); }
595 
603  void norms_1(
605  ) const
606  { norms1Impl(norms); }
607 
615  void norms_2(
617  ) const
618  { norms2Impl(norms); }
619 
627  void norms_inf(
629  ) const
630  { normsInfImpl(norms); }
631 
633 
636 
642  { return colImpl(j); }
643 
649  { return nonconstColImpl(j); }
650 
652 
655 
661  subView( const Range1D& colRng ) const
662  {
663  return contigSubViewImpl(colRng);
664  }
665 
671  subView( const Range1D& colRng )
672  { return nonconstContigSubViewImpl(colRng); }
673 
679  subView( const ArrayView<const int> &cols ) const
680  { return nonContigSubViewImpl(cols); }
681 
688  { return nonconstNonContigSubViewImpl(cols); }
689 
691 
694 
699  void applyOp(
700  const RTOpPack::RTOpT<Scalar> &primary_op,
701  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
702  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
703  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
704  const Ordinal primary_global_offset
705  ) const
706  {
707  mvMultiReductApplyOpImpl(primary_op, multi_vecs, targ_multi_vecs,
708  reduct_objs, primary_global_offset);
709  }
710 
715  void applyOp(
716  const RTOpPack::RTOpT<Scalar> &primary_op,
717  const RTOpPack::RTOpT<Scalar> &secondary_op,
718  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
719  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
720  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
721  const Ordinal primary_global_offset
722  ) const
723  {
724  mvSingleReductApplyOpImpl(primary_op, secondary_op, multi_vecs, targ_multi_vecs,
725  reduct_obj, primary_global_offset);
726  }
727 
729 
732 
738  const Range1D &rowRng,
739  const Range1D &colRng,
741  ) const
742  { acquireDetachedMultiVectorViewImpl( rowRng, colRng, sub_mv ); }
743 
750  ) const
752 
758  const Range1D &rowRng,
759  const Range1D &colRng,
761  )
762  { acquireNonconstDetachedMultiVectorViewImpl(rowRng,colRng,sub_mv); }
763 
770  )
772 
774 
777 
786  virtual RCP<MultiVectorBase<Scalar> > clone_mv() const = 0;
787 
789 
792 
795 
797 
798 protected:
799 
802 
806  virtual void assignImpl(Scalar alpha) = 0;
807 
811  virtual void assignMultiVecImpl(const MultiVectorBase<Scalar>& mv) = 0;
812 
816  virtual void scaleImpl(Scalar alpha) = 0;
817 
821  virtual void updateImpl(
822  Scalar alpha,
823  const MultiVectorBase<Scalar>& mv
824  ) = 0;
825 
829  virtual void linearCombinationImpl(
830  const ArrayView<const Scalar>& alpha,
831  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > >& mv,
832  const Scalar& beta
833  ) = 0;
834 
838  virtual void dotsImpl(
839  const MultiVectorBase<Scalar>& mv,
840  const ArrayView<Scalar>& prods
841  ) const = 0;
842 
846  virtual void norms1Impl(
848  ) const = 0;
849 
853  virtual void norms2Impl(
855  ) const = 0;
856 
860  virtual void normsInfImpl(
862  ) const = 0;
863 
885  virtual RCP<const VectorBase<Scalar> > colImpl(Ordinal j) const;
886 
908 
934  contigSubViewImpl( const Range1D& colRng ) const = 0;
935 
961  nonconstContigSubViewImpl( const Range1D& colRng ) = 0;
962 
988  nonContigSubViewImpl( const ArrayView<const int> &cols ) const = 0;
989 
1014  virtual RCP<MultiVectorBase<Scalar> >
1016 
1038  virtual void mvMultiReductApplyOpImpl(
1039  const RTOpPack::RTOpT<Scalar> &primary_op,
1040  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
1041  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
1042  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
1043  const Ordinal primary_global_offset
1044  ) const = 0;
1045 
1066  virtual void mvSingleReductApplyOpImpl(
1067  const RTOpPack::RTOpT<Scalar> &primary_op,
1068  const RTOpPack::RTOpT<Scalar> &secondary_op,
1069  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
1070  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
1071  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
1072  const Ordinal primary_global_offset
1073  ) const = 0;
1074 
1139  const Range1D &rowRng,
1140  const Range1D &colRng,
1142  ) const = 0;
1143 
1171  ) const = 0;
1172 
1246  const Range1D &rowRng,
1247  const Range1D &colRng,
1249  ) = 0;
1250 
1280  ) = 0;
1281 
1283  virtual bool rowStatIsSupportedImpl(
1284  const RowStatLinearOpBaseUtils::ERowStat rowStat) const;
1285 
1287  virtual void getRowStatImpl(
1288  const RowStatLinearOpBaseUtils::ERowStat rowStat,
1289  const Ptr<VectorBase<Scalar> > &rowStatVec) const;
1290 
1292  virtual bool supportsScaleLeftImpl() const;
1293 
1295  virtual bool supportsScaleRightImpl() const;
1296 
1298  virtual void scaleLeftImpl(const VectorBase< Scalar > &row_scaling);
1299 
1301  virtual void scaleRightImpl(const VectorBase< Scalar > &col_scaling);
1302 
1304 
1312  void absRowSum(const Teuchos::Ptr<Thyra::VectorBase<Scalar> > & output) const;
1313 
1319  void absColSum(const Teuchos::Ptr<Thyra::VectorBase<Scalar> > & output) const;
1320 
1321 public:
1322 
1323 private:
1324 
1325  // Not defined and not to be called
1327  operator=(const MultiVectorBase<Scalar>&);
1328 
1329 };
1330 
1331 
1339 template<class Scalar>
1340 inline
1341 void applyOp(
1342  const RTOpPack::RTOpT<Scalar> &primary_op,
1343  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
1344  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
1345  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
1346  const Ordinal primary_global_offset = 0
1347  )
1348 {
1349  if(multi_vecs.size())
1350  multi_vecs[0]->applyOp(primary_op, multi_vecs, targ_multi_vecs,
1351  reduct_objs, primary_global_offset);
1352  else if(targ_multi_vecs.size())
1353  targ_multi_vecs[0]->applyOp(primary_op, multi_vecs, targ_multi_vecs,
1354  reduct_objs, primary_global_offset);
1355 }
1356 
1357 
1365 template<class Scalar>
1366 inline
1367 void applyOp(
1368  const RTOpPack::RTOpT<Scalar> &primary_op,
1369  const RTOpPack::RTOpT<Scalar> &secondary_op,
1370  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
1371  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
1372  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
1373  const Ordinal primary_global_offset = 0
1374  )
1375 {
1376  if(multi_vecs.size())
1377  multi_vecs[0]->applyOp(primary_op, secondary_op, multi_vecs, targ_multi_vecs,
1378  reduct_obj, primary_global_offset);
1379  else if(targ_multi_vecs.size())
1380  targ_multi_vecs[0]->applyOp(primary_op, secondary_op, multi_vecs, targ_multi_vecs,
1381  reduct_obj, primary_global_offset);
1382 }
1383 
1384 
1385 } // namespace Thyra
1386 
1387 
1388 #endif // THYRA_MULTI_VECTOR_BASE_DECL_HPP
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Virtual implementation for NVI norms_inf().
void dots(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Column-wise Euclidean dot product.
virtual RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
Return a non-changeable view of a constituent column vector.
RCP< MultiVectorBase< Scalar > > subView(const ArrayView< const int > &cols)
nonconstNonContigSubViewImpl().
void commitDetachedView(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
Calls commitNonconstDetachedMultiVectorViewImpl().
virtual bool supportsScaleLeftImpl() const
RCP< const MultiVectorBase< Scalar > > subView(const ArrayView< const int > &cols) const
nonContigSubViewImpl().
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.
void norms_2(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Column-wise 2-norms.
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.
virtual bool supportsScaleRightImpl() const
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
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(Scalar).
virtual void scaleImpl(Scalar alpha)=0
Virtual implementation for NVI scale().
void releaseDetachedView(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Calls releaseDetachedMultiVectorViewImpl().
virtual void releaseDetachedMultiVectorViewImpl(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const =0
Free a non-changeable explicit view of a sub-multi-vector.
RCP< const MultiVectorBase< Scalar > > subView(const Range1D &colRng) const
Calls contigSubViewImpl().
virtual RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)=0
Return a changeable view of a constituent column vector.
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Ptr< VectorBase< Scalar > > &rowStatVec) const
void assign(const MultiVectorBase< Scalar > &mv)
V = mv.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)=0
Virtual implementation for NVI update().
Interface for a collection of column vectors called a multi-vector.
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().
RCP< const LinearOpBase< Scalar > > clone() const
This function is simply overridden to return this-&gt;clone_mv().
RCP< VectorBase< Scalar > > col(Ordinal j)
Calls nonconstColImpl().
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
void update(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Abstract interface for finite-dimensional dense vectors.
void norms(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector natural norm.
void linear_combination(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Y.col(j)(i) = beta*Y.col(j)(i) + sum( alpha[k]*X[k].col(j)(i),
Base class for all linear operators.
void acquireDetachedView(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Calls acquireDetachedMultiVectorViewImpl().
void absRowSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
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...
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 void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)=0
Virtual implementation for NVI linear_combination().
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)=0
Virtual implementation for NVI assign(MV).
void norms_1(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Column-wise 1-norms.
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 void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Virtual implementation for NVI norms_1().
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.
void norms_inf(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Column-wise infinity-norms.
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...
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().
void absColSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
RCP< MultiVectorBase< Scalar > > subView(const Range1D &colRng)
Calls nonconstContigSubViewImpl().
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Virtual implementation for NVI norms_2().
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const =0
Virtual implementation for NVI dots().
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...