TSFEpetraVector.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 TSFEPETRAVECTOR_HPP
00028 #define TSFEPETRAVECTOR_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 "Epetra_FEVector.h"
00037 #include "Epetra_Vector.h"
00038 #include "TSFEpetraVectorSpace.hpp"
00039 
00040 
00041 namespace TSFExtended
00042 {
00043 using Teuchos::Range1D;
00044 using namespace Thyra;
00045 using namespace Teuchos;
00046 /**
00047  * TSF extension of Thyra::EpetraVector, implementing the LoadableVector
00048  * interface allowing an application to access elements. This class derives
00049  * from Thyra::VectorDefaultBase, so it can be used seamlessly in any 
00050  * Thyra-based code.
00051  */
00052 class EpetraVector : public Thyra::VectorDefaultBase<double>,
00053                      public IndexableVector<double>,
00054                      public RawDataAccessibleVector<double>,
00055                      public Sundance::Printable
00056 {
00057 public:
00058 
00059   /** Construct with a smart pointer to an Epetra vector space. */
00060   EpetraVector(const RCP<const VectorSpaceBase<double> >& vs);
00061 
00062   /** Construct with smart pointers to an Epetra vector space
00063       and an existing Epetra vector. */
00064   EpetraVector(const RCP<const VectorSpaceBase<double> >& vs,
00065     const RCP<Epetra_Vector>& vec);
00066 
00067 
00068   /** \name VectorBase interface */
00069   //@{
00070   /** */
00071    RCP< const VectorSpaceBase<double> > 
00072    space() const {return vecSpace_;}
00073 
00074 #ifndef TRILINOS_8
00075   /** */
00076   void applyOpImpl(const RTOpPack::RTOpT< double >& op,
00077     const ArrayView< const Ptr< const VectorBase< double > > > &    vecs,
00078     const ArrayView< const Ptr< VectorBase< double > > > &    targ_vecs,
00079     const Ptr< RTOpPack::ReductTarget > &   reduct_obj,
00080     const OrdType   global_offset  
00081     ) const ;
00082 #else
00083   virtual void applyOp(
00084     const RTOpPack::RTOpT<double> &op,
00085     const int num_vecs,
00086     const VectorBase<double>*const vecs[],
00087     const int num_targ_vecs,
00088     VectorBase<double>*const targ_vecs[],
00089     RTOpPack::ReductTarget *reduct_obj,
00090     const OrdType first_ele_offset,
00091     const OrdType sub_dim,
00092     const OrdType global_offset
00093     ) const ;
00094 #endif
00095 
00096   /** */
00097   void acquireDetachedVectorViewImpl(const Range1D& rng,
00098     RTOpPack::ConstSubVectorView<double>* sub_vec) const ;
00099 
00100   /** */
00101   void releaseDetachedVectorViewImpl(
00102     RTOpPack::ConstSubVectorView<double>* sub_vec) const ;
00103 
00104   /** */
00105   void acquireNonconstDetachedVectorViewImpl(const Range1D& rng,
00106     RTOpPack::SubVectorView<double> * sub_vec);  
00107 
00108 
00109   /** */
00110   void commitNonconstDetachedVectorViewImpl(
00111     RTOpPack::SubVectorView<double>* sub_vec);
00112   
00113   //@}
00114 
00115   /** \name IndexableVector interface */
00116   //@{
00117   /** read the element at the given global index */
00118   virtual const double& operator[](OrdType globalIndex) const 
00119     {return getElement(globalIndex);}
00120 
00121   /** writable access to the element at the given global index */
00122   virtual double& operator[](OrdType globalIndex) ;
00123   //@}
00124 
00125   /** \name Raw data access interface */
00126   //@{
00127   /** */
00128   virtual const double* dataPtr() const {return &(epetraVec_->operator[](0));}
00129   /** */
00130   virtual double* dataPtr() {return &(epetraVec_->operator[](0));}
00131   //@}
00132 
00133   /** \name LoadableVector interface */
00134   //@{
00135   /** set a single element */
00136   void setElement(OrdType globalIndex, const double& value);
00137 
00138   /** add to a single element */
00139   void addToElement(OrdType globalIndex, const double& value);
00140 
00141   /** set a group of elements */
00142   void setElements(int numElems, const int* globalIndices, 
00143     const double* values);
00144 
00145 
00146   /** add to a group of elements */
00147   void addToElements(int numElems, const int* globalIndices, 
00148     const double* values);
00149 
00150   /** */
00151   void finalizeAssembly();
00152   //@}
00153 
00154   /** \name AccessibleVector interface */
00155   //@{
00156   /** */
00157   const double& getElement(OrdType globalIndex) const ;
00158 
00159   /** */
00160   void getElements(const OrdType* globalIndices, int numElems,
00161     Teuchos::Array<double>& elems) const ;
00162   //@}
00163 
00164   /** \name Printable interface */
00165   //@{
00166   /** Print to a stream */
00167   void print(std::ostream& os) const ;
00168   //@}
00169       
00170 
00171   /** */
00172   const RCP<Epetra_Vector>& epetraVec() const 
00173     {return epetraVec_;}
00174 
00175   /** */
00176   RCP<Epetra_Vector>& epetraVec() {return epetraVec_;}
00177 
00178   /** Get a read-only Epetra_Vector */
00179   static const Epetra_Vector& getConcrete(const TSFExtended::Vector<double>& tsfVec);
00180   /** Get a read-write Epetra_Vector */
00181   static Epetra_Vector& getConcrete(TSFExtended::Vector<double>& tsfVec);
00182   /** Get a read-write Epetra_Vector pointer */
00183   static Epetra_Vector* getConcretePtr(TSFExtended::Vector<double>& tsfVec);
00184 
00185   
00186 
00187     
00188 
00189 protected:    
00190   /** */
00191   const RCP<const Epetra_Map>& epetraMap() const {return epetraMap_;}
00192 
00193   /** */
00194   Range1D validateRange(const Range1D& rng) const ;
00195 
00196 private:
00197 
00198   RCP<Epetra_Vector> epetraVec_;
00199 
00200   RCP<const Thyra::VectorSpaceBase<double> > vecSpace_;
00201 
00202   RCP<const EpetraVectorSpace> epetraVecSpace_;
00203 
00204   RCP<const Epetra_Map> epetraMap_;
00205 
00206   int localOffset_;
00207 
00208   int localSubDim_;
00209 
00210   int globalDim_;
00211 
00212   mutable bool in_applyOpImpl_;
00213 };
00214   
00215 }
00216 
00217 
00218 #endif

Site Contact