PlayaEpetraVector.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 //
00003  /* @HEADER@ */
00004 
00005 #ifndef PLAYA_EPETRAVECTOR_HPP
00006 #define PLAYA_EPETRAVECTOR_HPP
00007 
00008 #include "PlayaDefs.hpp"
00009 #include "PlayaPrintable.hpp"
00010 #include "PlayaVectorDecl.hpp"
00011 #include "PlayaLoadableVector.hpp"
00012 #include "PlayaSingleChunkVector.hpp"
00013 #include "Epetra_FEVector.h"
00014 #include "Epetra_Vector.h"
00015 #include "PlayaEpetraVectorSpace.hpp"
00016 
00017 
00018 namespace Playa
00019 {
00020 using Teuchos::RCP;
00021 /**
00022  * Playa::VectorBase wrapper for Epetra_Vector
00023  */
00024 class EpetraVector : public SingleChunkVector<double>,
00025                      public LoadableVector<double>,
00026                      public Printable,
00027                      public Teuchos::Describable
00028 {
00029 public:
00030 
00031   /** Construct with an Epetra vector space. */
00032   EpetraVector(const VectorSpace<double>& vs);
00033 
00034   /** Construct with an Epetra vector space
00035       and an existing Epetra vector. */
00036   EpetraVector(const VectorSpace<double>& vs,
00037     const RCP<Epetra_Vector>& vec);
00038 
00039 
00040   /** \name VectorBase interface */
00041   //@{
00042   /** Return the space in which this vector lives */
00043   RCP< const VectorSpaceBase<double> > space() const {return vecSpace_.ptr();}
00044   //@}
00045 
00046   /** \name IndexableVector interface */
00047   //@{
00048   /** read the element at the given global index */
00049   virtual const double& operator[](int globalIndex) const 
00050     {return getElement(globalIndex);}
00051 
00052   /** writable access to the element at the given global index */
00053   virtual double& operator[](int globalIndex) ;
00054   //@}
00055 
00056   /** \name LoadableVector interface */
00057   //@{
00058   /** set a single element */
00059   void setElement(int globalIndex, const double& value);
00060 
00061   /** add to a single element */
00062   void addToElement(int globalIndex, const double& value);
00063 
00064   /** set a group of elements */
00065   void setElements(int numElems, const int* globalIndices, 
00066     const double* values);
00067 
00068 
00069   /** add to a group of elements */
00070   void addToElements(int numElems, const int* globalIndices, 
00071     const double* values);
00072 
00073   /** */
00074   void finalizeAssembly();
00075   //@}
00076 
00077   /** \name AccessibleVector interface */
00078   //@{
00079   /** */
00080   const double& getElement(int globalIndex) const ;
00081 
00082   /** */
00083   void getElements(const int* globalIndices, int numElems,
00084     Teuchos::Array<double>& elems) const ;
00085   //@}
00086 
00087   /** \name Printable interface */
00088   //@{
00089   /** Print to a stream */
00090   void print(std::ostream& os) const ;
00091   //@}
00092       
00093 
00094   /** */
00095   const RCP<Epetra_Vector>& epetraVec() const 
00096     {return epetraVec_;}
00097 
00098   /** */
00099   RCP<Epetra_Vector>& epetraVec() {return epetraVec_;}
00100 
00101   /** Get a read-only Epetra_Vector */
00102   static const Epetra_Vector& getConcrete(const Playa::Vector<double>& tsfVec);
00103   /** Get a read-write Epetra_Vector */
00104   static Epetra_Vector& getConcrete(Playa::Vector<double>& tsfVec);
00105   /** Get a read-write Epetra_Vector pointer */
00106   static Epetra_Vector* getConcretePtr(Playa::Vector<double>& tsfVec);
00107 
00108   
00109   /** */
00110   virtual void update(const double& alpha, const VectorBase<double>* other,
00111     const double& gamma);
00112     
00113 
00114   /** */
00115   virtual void update(
00116     const double& alpha, const VectorBase<double>* x,
00117     const double& beta, const VectorBase<double>* y,
00118     const double& gamma) ;
00119 
00120   /** */
00121   virtual double dot(const VectorBase<double>* other) const ;
00122 
00123   /** */
00124   virtual double norm2() const ;
00125 protected:    
00126 
00127   /** \name Single chunk data access interface */
00128   //@{
00129   /** */
00130   virtual const double* dataPtr() const {return &(epetraVec_->operator[](0));}
00131   /** */
00132   virtual double* dataPtr() {return &(epetraVec_->operator[](0));}
00133 
00134   /** Size of the (single) chunk of data values */
00135   virtual int chunkSize() const {return numLocalElements_;}
00136   //@}
00137 
00138 private:
00139 
00140   VectorSpace<double> vecSpace_;
00141 
00142   RCP<Epetra_Vector> epetraVec_;
00143 
00144   int numLocalElements_;
00145   
00146 };
00147   
00148 }
00149 
00150 
00151 #endif

Site Contact