Thyra_VectorBaseDecl.hpp

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_MultiVectorBaseDecl.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 Index first_ele_offset,
00177     const Index sub_dim,
00178     const Index global_offset
00179     ) const
00180     { applyOpImpl(op,vecs,targ_vecs,reduct_obj,
00181         first_ele_offset,sub_dim,global_offset); }
00182 
00184 
00187 
00202   virtual RCP<VectorBase<Scalar> > clone_v() const = 0;
00203 
00205 
00208 
00213   void acquireDetachedView(
00214     const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00215     ) const
00216     { acquireDetachedVectorViewImpl(rng,sub_vec); }
00217 
00222   void releaseDetachedView(
00223     RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00224     ) const
00225     { releaseDetachedVectorViewImpl(sub_vec); }
00226 
00231   void acquireDetachedView(
00232     const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00233     )
00234     { acquireNonconstDetachedVectorViewImpl(rng,sub_vec); }
00235 
00240   void commitDetachedView(
00241     RTOpPack::SubVectorView<Scalar>* sub_vec
00242     )
00243     { commitNonconstDetachedVectorViewImpl(sub_vec); }
00244 
00249   void setSubVector(
00250     const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00251     )
00252     { setSubVectorImpl(sub_vec); }
00253 
00255 
00256 protected:
00257 
00260 
00277   virtual void applyOpImpl(
00278     const RTOpPack::RTOpT<Scalar> &op,
00279     const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00280     const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00281     const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00282     const Index first_ele_offset,
00283     const Index sub_dim,
00284     const Index global_offset
00285     ) const = 0;
00286 /*
00287     {
00288       // 2008/02/19: rabartl: ToDo: Remove this default implemenation once the
00289       // refactoring is done.
00290       using Teuchos::as;
00291       Array<const VectorBase<Scalar>*> raw_vecs(vecs.size());
00292       for ( int k = 0; k < as<int>(vecs.size()); ++k )
00293         raw_vecs[k] = &*vecs[k];
00294       Array<VectorBase<Scalar>*> raw_targ_vecs(targ_vecs.size());
00295       for ( int k = 0; k < as<int>(targ_vecs.size()); ++k )
00296         raw_targ_vecs[k] = &*targ_vecs[k];
00297       this->applyOp(op, raw_vecs.size(), raw_vecs.getRawPtr(),
00298         raw_targ_vecs.size(), raw_targ_vecs.getRawPtr(),
00299         reduct_obj.get(), first_ele_offset, sub_dim, global_offset );
00300     }
00301 */
00302   
00344   virtual void acquireDetachedVectorViewImpl(
00345     const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00346     ) const = 0;
00347 
00367   virtual void releaseDetachedVectorViewImpl(
00368     RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00369     ) const = 0;
00370 
00419   virtual void acquireNonconstDetachedVectorViewImpl(
00420     const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00421     ) = 0;
00422 
00445   virtual void commitNonconstDetachedVectorViewImpl(
00446     RTOpPack::SubVectorView<Scalar>* sub_vec
00447     ) = 0;
00448 
00472   virtual void setSubVectorImpl(
00473     const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00474     ) = 0;
00475 
00477 
00478 public:
00479 
00480 /*
00481   virtual void applyOp(
00482     const RTOpPack::RTOpT<Scalar> &op,
00483     const int num_vecs,
00484     const VectorBase<Scalar>*const vecs[],
00485     const int num_targ_vecs,
00486     VectorBase<Scalar>*const targ_vecs[],
00487     RTOpPack::ReductTarget *reduct_obj,
00488     const Index first_ele_offset,
00489     const Index sub_dim,
00490     const Index global_offset
00491     ) const
00492     {
00493       TEST_FOR_EXCEPT(true);
00494       // ToDo: remove this function once the refactoring is finished!
00495     }
00496 */
00497 
00498 };
00499 
00500 
00585 template<class Scalar>
00586 inline
00587 void applyOp(
00588   const RTOpPack::RTOpT<Scalar> &op,
00589   const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00590   const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00591   const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00592   const Index first_ele_offset = 0,
00593   const Index sub_dim = -1,
00594   const Index global_offset = 0
00595   )
00596 {
00597   if (vecs.size())
00598     vecs[0]->applyOp(
00599       op, vecs, targ_vecs, reduct_obj, first_ele_offset, sub_dim, global_offset);
00600   else if (targ_vecs.size())
00601     targ_vecs[0]->applyOp(
00602       op, vecs, targ_vecs, reduct_obj, first_ele_offset, sub_dim, global_offset);
00603 }
00604 
00605 
00610 template<class Scalar>
00611 inline
00612 void applyOp(
00613   const RTOpPack::RTOpT<Scalar> &op,
00614   const int num_vecs,
00615   const VectorBase<Scalar>*const vecs_in[],
00616   const int num_targ_vecs,
00617   VectorBase<Scalar>*const targ_vecs_inout[],
00618   RTOpPack::ReductTarget *reduct_obj,
00619   const Index first_ele_offset = 0,
00620   const Index sub_dim = -1,
00621   const Index global_offset = 0
00622   )
00623 {
00624   using Teuchos::ptr;
00625   Array<Ptr<const VectorBase<Scalar> > > vecs(num_vecs);
00626   for ( int k = 0; k < num_vecs; ++k )
00627     vecs[k] = ptr(vecs_in[k]);
00628   Array<Ptr<VectorBase<Scalar> > > targ_vecs(num_targ_vecs);
00629   for ( int k = 0; k < num_targ_vecs; ++k )
00630     targ_vecs[k] = ptr(targ_vecs_inout[k]);
00631   applyOp<Scalar>(op, vecs(), targ_vecs(), ptr(reduct_obj),
00632     first_ele_offset, sub_dim, global_offset );
00633 }
00634 
00635 
00636 } // end namespace Thyra
00637 
00638 
00639 #endif  // THYRA_VECTOR_BASE_DECL_HPP

Generated on Wed May 12 21:42:09 2010 for Fundamental Thyra ANA Operator/Vector Interfaces by  doxygen 1.4.7