TSFSerialVector.hpp
Go to the documentation of this file.
00001 /* ***********************************************************************
00002 // 
00003 //           TSFExtended: Trilinos Solver Framework Extended
00004 //                 Copyright (2004) Sandia Corporation
00005 // 
00006 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00007 // license for use of this work by or on behalf of the U.S. Government.
00008 // 
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Lesser General Public License as
00011 // published by the Free Software Foundation; either version 2.1 of the
00012 // License, or (at your option) any later version.
00013 //  
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //  
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022 // USA
00023 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00024 // 
00025 // **********************************************************************/
00026 
00027 #ifndef TSF_SERIAL_VECTOR_HPP
00028 #define TSF_SERIAL_VECTOR_HPP
00029 
00030 #include "SundanceDefs.hpp"
00031 #include "SundancePrintable.hpp"
00032 #include "TSFIndexableVector.hpp"
00033 #include "TSFVectorDecl.hpp"
00034 #include "TSFRawDataAccessibleVector.hpp"
00035 #include "Thyra_VectorDefaultBase.hpp"
00036 #include "TSFSerialVectorSpace.hpp"
00037 
00038 
00039 namespace TSFExtended
00040 {
00041 using Teuchos::Range1D;
00042 using namespace Thyra;
00043 using namespace Teuchos;
00044 /**
00045  * TSF implementation of a serial vector, implementing the LoadableVector
00046  * interface allowing an application to access elements. This class derives
00047  * from Thyra::VectorDefaultBase, so it can be used seamlessly in any 
00048  * Thyra-based code. If created in SPMD, this will be replicated on
00049  * all processors.
00050  */
00051 class SerialVector : public Thyra::VectorDefaultBase<double>,
00052                      public IndexableVector<double>,
00053                      public RawDataAccessibleVector<double>,
00054                      public Sundance::Printable
00055 {
00056 public:
00057 
00058   /** Construct with a smart pointer to a vector space. */
00059   SerialVector(const RCP<const VectorSpaceBase<double> >& vs);
00060 
00061   /** \name VectorBase interface */
00062   //@{
00063   /** */
00064    RCP< const VectorSpaceBase<double> > 
00065    space() const {return vecSpace_;}
00066 
00067   /** */
00068   void applyOpImpl(const RTOpPack::RTOpT< double >& op,
00069     const ArrayView< const Ptr< const VectorBase< double > > > &    vecs,
00070     const ArrayView< const Ptr< VectorBase< double > > > &    targ_vecs,
00071     const Ptr< RTOpPack::ReductTarget > &   reduct_obj,
00072     const OrdType   global_offset  
00073     ) const ;
00074 
00075   /** */
00076   void acquireDetachedVectorViewImpl(const Range1D& rng,
00077     RTOpPack::ConstSubVectorView<double>* sub_vec) const ;
00078 
00079   /** */
00080   void releaseDetachedVectorViewImpl(
00081     RTOpPack::ConstSubVectorView<double>* sub_vec) const ;
00082 
00083   /** */
00084   void acquireNonconstDetachedVectorViewImpl(const Range1D& rng,
00085     RTOpPack::SubVectorView<double> * sub_vec);  
00086 
00087 
00088   /** */
00089   void commitNonconstDetachedVectorViewImpl(
00090     RTOpPack::SubVectorView<double>* sub_vec);
00091   
00092   //@}
00093 
00094   /** \name IndexableVector interface */
00095   //@{
00096   /** read the element at the given global index */
00097   virtual const double& operator[](OrdType globalIndex) const 
00098     {return getElement(globalIndex);}
00099 
00100   /** writable access to the element at the given global index */
00101   virtual double& operator[](OrdType globalIndex) ;
00102   //@}
00103 
00104   /** \name Raw data access interface */
00105   //@{
00106   /** */
00107   virtual const double* dataPtr() const {return &(data_[0]);}
00108   /** */
00109   virtual double* dataPtr() {return &(data_[0]);}
00110   //@}
00111 
00112   /** \name LoadableVector interface */
00113   //@{
00114   /** set a single element */
00115   void setElement(OrdType globalIndex, const double& value);
00116 
00117   /** add to a single element */
00118   void addToElement(OrdType globalIndex, const double& value);
00119 
00120   /** set a group of elements */
00121   void setElements(int numElems, const int* globalIndices, 
00122     const double* values);
00123 
00124 
00125   /** add to a group of elements */
00126   void addToElements(int numElems, const int* globalIndices, 
00127     const double* values);
00128 
00129   /** */
00130   void finalizeAssembly();
00131   //@}
00132 
00133   /** \name AccessibleVector interface */
00134   //@{
00135   /** */
00136   const double& getElement(OrdType globalIndex) const ;
00137 
00138   /** */
00139   void getElements(const OrdType* globalIndices, int numElems,
00140     Teuchos::Array<double>& elems) const ;
00141   //@}
00142 
00143   /** \name Printable interface */
00144   //@{
00145   /** Print to a stream */
00146   void print(std::ostream& os) const ;
00147   //@}
00148 
00149   /** */
00150   static const SerialVector* getConcrete(const Vector<double>& x);
00151   /** */
00152   static SerialVector* getConcrete(Vector<double>& x);
00153       
00154 
00155 protected:    
00156   /** */
00157   Range1D validateRange(const Range1D& rng) const ;
00158 
00159 private:
00160 
00161   RCP<const Thyra::VectorSpaceBase<double> > vecSpace_;
00162 
00163   Array<double> data_;
00164 
00165   int globalDim_;
00166 
00167   mutable bool in_applyOpImpl_;
00168 };
00169   
00170 }
00171 
00172 
00173 #endif

Site Contact