Thyra Version of the Day
Thyra_VectorBase.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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_VECTOR_BASE_DECL_HPP
00043 #define THYRA_VECTOR_BASE_DECL_HPP
00044 
00045 
00046 #include "Thyra_OperatorVectorTypes.hpp"
00047 #include "Thyra_MultiVectorBase_decl.hpp"
00048 #include "RTOpPack_RTOpT.hpp"
00049 #include "RTOpPack_SparseSubVectorT.hpp"
00050 
00051 
00052 namespace Thyra {
00053 
00054 
00145 template<class Scalar>
00146 class VectorBase : virtual public MultiVectorBase<Scalar>
00147 {
00148 public:
00149 
00150 #ifdef THYRA_INJECT_USING_DECLARATIONS
00151   using MultiVectorBase<Scalar>::apply;
00152 #endif
00153 
00156 
00173   virtual RCP< const VectorSpaceBase<Scalar> > space() const = 0;
00174 
00176 
00179 
00184   void applyOp(
00185     const RTOpPack::RTOpT<Scalar> &op,
00186     const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00187     const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00188     const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00189     const Ordinal global_offset
00190     ) const
00191     {
00192       applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
00193     }
00194 
00196 
00199 
00214   virtual RCP<VectorBase<Scalar> > clone_v() const = 0;
00215 
00217 
00220 
00225   void acquireDetachedView(
00226     const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00227     ) const
00228     { acquireDetachedVectorViewImpl(rng,sub_vec); }
00229 
00234   void releaseDetachedView(
00235     RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00236     ) const
00237     { releaseDetachedVectorViewImpl(sub_vec); }
00238 
00243   void acquireDetachedView(
00244     const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00245     )
00246     { acquireNonconstDetachedVectorViewImpl(rng,sub_vec); }
00247 
00252   void commitDetachedView(
00253     RTOpPack::SubVectorView<Scalar>* sub_vec
00254     )
00255     { commitNonconstDetachedVectorViewImpl(sub_vec); }
00256 
00261   void setSubVector(
00262     const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00263     )
00264     { setSubVectorImpl(sub_vec); }
00265 
00267 
00268 protected:
00269 
00272 
00289   virtual void applyOpImpl(
00290     const RTOpPack::RTOpT<Scalar> &op,
00291     const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00292     const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00293     const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00294     const Ordinal global_offset
00295     ) const = 0;
00296   
00338   virtual void acquireDetachedVectorViewImpl(
00339     const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00340     ) const = 0;
00341 
00361   virtual void releaseDetachedVectorViewImpl(
00362     RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00363     ) const = 0;
00364 
00413   virtual void acquireNonconstDetachedVectorViewImpl(
00414     const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00415     ) = 0;
00416 
00439   virtual void commitNonconstDetachedVectorViewImpl(
00440     RTOpPack::SubVectorView<Scalar>* sub_vec
00441     ) = 0;
00442 
00466   virtual void setSubVectorImpl(
00467     const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00468     ) = 0;
00469 
00471 
00472 private:
00473   
00474   // Not defined and not to be called
00475   VectorBase<Scalar>&
00476   operator=(const VectorBase<Scalar>&);
00477 
00478 };
00479 
00480 
00551 template<class Scalar>
00552 inline
00553 void applyOp(
00554   const RTOpPack::RTOpT<Scalar> &op,
00555   const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00556   const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00557   const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00558   const Ordinal global_offset = 0
00559   )
00560 {
00561   if (vecs.size())
00562     vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
00563   else if (targ_vecs.size())
00564     targ_vecs[0]->applyOp(op, vecs, targ_vecs, reduct_obj, global_offset);
00565 }
00566 
00567 
00572 template<class Scalar>
00573 inline
00574 void applyOp(
00575   const RTOpPack::RTOpT<Scalar> &op,
00576   const int num_vecs,
00577   const VectorBase<Scalar>*const vecs_in[],
00578   const int num_targ_vecs,
00579   VectorBase<Scalar>*const targ_vecs_inout[],
00580   RTOpPack::ReductTarget *reduct_obj,
00581   const Ordinal global_offset = 0
00582   )
00583 {
00584   using Teuchos::ptr;
00585   Array<Ptr<const VectorBase<Scalar> > > vecs(num_vecs);
00586   for ( int k = 0; k < num_vecs; ++k )
00587     vecs[k] = ptr(vecs_in[k]);
00588   Array<Ptr<VectorBase<Scalar> > > targ_vecs(num_targ_vecs);
00589   for ( int k = 0; k < num_targ_vecs; ++k )
00590     targ_vecs[k] = ptr(targ_vecs_inout[k]);
00591   applyOp<Scalar>(op, vecs(), targ_vecs(), ptr(reduct_obj), global_offset);
00592 }
00593 
00594 
00595 } // end namespace Thyra
00596 
00597 
00598 #endif  // THYRA_VECTOR_BASE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines