Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_VectorBase.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_VECTOR_BASE_DECL_HPP
00030 #define THYRA_VECTOR_BASE_DECL_HPP
00031 
00032 
00033 #include "Thyra_OperatorVectorTypes.hpp"
00034 #include "Thyra_MultiVectorBase_decl.hpp"
00035 #include "RTOpPack_RTOpT.hpp"
00036 #include "RTOpPack_SparseSubVectorT.hpp"
00037 
00038 
00039 namespace Thyra {
00040 
00041 
00132 template<class Scalar>
00133 class VectorBase : virtual public MultiVectorBase<Scalar>
00134 {
00135 public:
00136 
00137 #ifdef THYRA_INJECT_USING_DECLARATIONS
00138   using MultiVectorBase<Scalar>::apply;
00139 #endif
00140 
00143 
00160   virtual RCP< const VectorSpaceBase<Scalar> > space() const = 0;
00161 
00163 
00166 
00171   void applyOp(
00172     const RTOpPack::RTOpT<Scalar> &op,
00173     const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00174     const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00175     const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00176     const Ordinal global_offset
00177     ) const
00178     {
00179       applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
00180     }
00181 
00183 
00186 
00201   virtual RCP<VectorBase<Scalar> > clone_v() const = 0;
00202 
00204 
00207 
00212   void acquireDetachedView(
00213     const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00214     ) const
00215     { acquireDetachedVectorViewImpl(rng,sub_vec); }
00216 
00221   void releaseDetachedView(
00222     RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00223     ) const
00224     { releaseDetachedVectorViewImpl(sub_vec); }
00225 
00230   void acquireDetachedView(
00231     const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00232     )
00233     { acquireNonconstDetachedVectorViewImpl(rng,sub_vec); }
00234 
00239   void commitDetachedView(
00240     RTOpPack::SubVectorView<Scalar>* sub_vec
00241     )
00242     { commitNonconstDetachedVectorViewImpl(sub_vec); }
00243 
00248   void setSubVector(
00249     const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00250     )
00251     { setSubVectorImpl(sub_vec); }
00252 
00254 
00255 protected:
00256 
00259 
00276   virtual void applyOpImpl(
00277     const RTOpPack::RTOpT<Scalar> &op,
00278     const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00279     const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00280     const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00281     const Ordinal global_offset
00282     ) const = 0;
00283   
00325   virtual void acquireDetachedVectorViewImpl(
00326     const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00327     ) const = 0;
00328 
00348   virtual void releaseDetachedVectorViewImpl(
00349     RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00350     ) const = 0;
00351 
00400   virtual void acquireNonconstDetachedVectorViewImpl(
00401     const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00402     ) = 0;
00403 
00426   virtual void commitNonconstDetachedVectorViewImpl(
00427     RTOpPack::SubVectorView<Scalar>* sub_vec
00428     ) = 0;
00429 
00453   virtual void setSubVectorImpl(
00454     const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00455     ) = 0;
00456 
00458 
00459 private:
00460   
00461   // Not defined and not to be called
00462   VectorBase<Scalar>&
00463   operator=(const VectorBase<Scalar>&);
00464 
00465 };
00466 
00467 
00538 template<class Scalar>
00539 inline
00540 void applyOp(
00541   const RTOpPack::RTOpT<Scalar> &op,
00542   const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00543   const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00544   const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00545   const Ordinal global_offset = 0
00546   )
00547 {
00548   if (vecs.size())
00549     vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
00550   else if (targ_vecs.size())
00551     targ_vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
00552 }
00553 
00554 
00559 template<class Scalar>
00560 inline
00561 void applyOp(
00562   const RTOpPack::RTOpT<Scalar> &op,
00563   const int num_vecs,
00564   const VectorBase<Scalar>*const vecs_in[],
00565   const int num_targ_vecs,
00566   VectorBase<Scalar>*const targ_vecs_inout[],
00567   RTOpPack::ReductTarget *reduct_obj,
00568   const Ordinal global_offset = 0
00569   )
00570 {
00571   using Teuchos::ptr;
00572   Array<Ptr<const VectorBase<Scalar> > > vecs(num_vecs);
00573   for ( int k = 0; k < num_vecs; ++k )
00574     vecs[k] = ptr(vecs_in[k]);
00575   Array<Ptr<VectorBase<Scalar> > > targ_vecs(num_targ_vecs);
00576   for ( int k = 0; k < num_targ_vecs; ++k )
00577     targ_vecs[k] = ptr(targ_vecs_inout[k]);
00578   applyOp<Scalar>(op, vecs(), targ_vecs(), ptr(reduct_obj), global_offset);
00579 }
00580 
00581 
00582 } // end namespace Thyra
00583 
00584 
00585 #endif  // THYRA_VECTOR_BASE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines