FEI Version of the Day
fei_Vector_core.hpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_Vector_core_hpp_
00010 #define _fei_Vector_core_hpp_
00011 
00012 #include <fei_iosfwd.hpp>
00013 #include <fei_CSVec.hpp>
00014 #include <fei_VectorSpace.hpp>
00015 #include <fei_Reducer.hpp>
00016 #include <fei_Logger.hpp>
00017 #include <fei_SharedPtr.hpp>
00018 #include <fei_EqnComm.hpp>
00019 
00020 namespace fei {
00021 
00023 class Vector_core : protected fei::Logger {
00024  public:
00026   Vector_core(fei::SharedPtr<fei::VectorSpace> vecSpace, int numLocalEqns);
00027 
00029   virtual ~Vector_core();
00030 
00036   int copyOut(int numValues,
00037         const int* indices,
00038         double* values,
00039         int vectorIndex=0) const;
00040 
00042   virtual int sumIntoFEVector(int blockID,
00043             int connOffset,
00044             int numNodes,
00045             const int* nodeNumbers,
00046             const int* numIndicesPerNode,
00047             const int* dof_ids,
00048             const double* values) = 0;
00049 
00051   virtual int copyOut_FE(int nodeNumber, int dofOffset, double& value) = 0;
00052 
00054   int giveToVector(int numValues,
00055        const int* indices,
00056        const double* values,
00057        bool sumInto=true,
00058        int vectorIndex=0);
00059 
00061   virtual int scatterToOverlap();
00062 
00066   void setOverlap(int numRemoteEqns=0, const int* remoteEqns=NULL);
00067 
00068  protected:
00070   int assembleFieldData(int fieldID,
00071       int idType,
00072       int numIDs,
00073       const int* IDs,
00074       const double* data,
00075       bool sumInto=true,
00076       int vectorIndex=0);
00077 
00078   int assembleFieldDataLocalIDs(int fieldID,
00079       int idType,
00080       int numIDs,
00081       const int* localIDs,
00082       const double* data,
00083       bool sumInto=true,
00084       int vectorIndex=0);
00085 
00086   void setCommSizes();
00088   virtual int gatherFromOverlap(bool accumulate = true);
00089 
00091   virtual int copyOutFieldData(int fieldID,
00092              int idType,
00093              int numIDs,
00094              const int* IDs,
00095              double* data,
00096              int vectorIndex=0);
00097 
00099   virtual int giveToUnderlyingVector(int numValues,
00100              const int* indices,
00101              const double* values,
00102              bool sumInto=true,
00103              int vectorIndex=0) = 0;
00104 
00106   virtual int copyOutOfUnderlyingVector(int numValues,
00107           const int* indices,
00108           double* values,
00109           int vectorIndex=0) const = 0;
00110 
00113   virtual int writeToFile(const char* filename,
00114         bool matrixMarketFormat=true);
00115 
00117   virtual int writeToStream(FEI_OSTREAM& ostrm,
00118           bool matrixMarketFormat=true);
00119 
00121   fei::SharedPtr<fei::VectorSpace> get_vector_space() const
00122     {
00123       return( vecSpace_ );
00124     }
00125 
00127   void set_vector_space(fei::SharedPtr<fei::VectorSpace> vspace)
00128     {
00129       vecSpace_ = vspace;
00130     }
00131 
00133   int firstLocalOffset() const { return( firstLocalOffset_ ); }
00134 
00136   int lastLocalOffset() const { return( lastLocalOffset_ ); }
00137 
00139   std::vector<int>& work_indices() { return( work_indices_ ); }
00141   std::vector<int>& work_indices2(){ return( work_indices2_); }
00142 
00144   bool haveFEVector() { return( haveFEVector_ ); }
00146   void setFEVector(bool flag) {haveFEVector_ = flag; }
00147 
00149   std::vector<CSVec*>& remotelyOwned() { return( remotelyOwned_ ); }
00150   const std::vector<CSVec*>& remotelyOwned() const { return( remotelyOwned_ ); }
00151   std::vector<int>& remotelyOwnedProcs() { return( remotelyOwnedProcs_ ); }
00152   const std::vector<int>& remotelyOwnedProcs() const { return( remotelyOwnedProcs_ ); }
00153 
00154   fei::CSVec* getRemotelyOwned(int proc) {
00155     std::vector<int>::iterator iter = std::lower_bound(remotelyOwnedProcs_.begin(), remotelyOwnedProcs_.end(), proc);
00156     fei::CSVec* return_vec = NULL;
00157     size_t offset = iter - remotelyOwnedProcs_.begin();
00158     if (iter == remotelyOwnedProcs_.end() || *iter != proc) {
00159       remotelyOwnedProcs_.insert(iter, proc);
00160       return_vec = new fei::CSVec;
00161       remotelyOwned_.insert(remotelyOwned_.begin()+offset, return_vec);
00162     }
00163     else {
00164       return_vec = remotelyOwned_[offset];
00165     }
00166  
00167     return return_vec;
00168   }
00169 
00170   const fei::CSVec* getRemotelyOwned(int proc) const {
00171     std::vector<int>::const_iterator iter = std::lower_bound(remotelyOwnedProcs_.begin(), remotelyOwnedProcs_.end(), proc);
00172     if (iter == remotelyOwnedProcs_.end() || *iter != proc) {
00173       throw std::runtime_error("failed to find remote-vec for specified processor.");
00174     }
00175 
00176     size_t offset = iter - remotelyOwnedProcs_.begin();
00177     return remotelyOwned_[offset];
00178   }
00179 
00180  protected:
00181   fei::SharedPtr<fei::EqnComm> eqnComm_;
00182 
00183  private:
00184   void pack_send_buffers(const std::vector<int>& sendProcs,
00185                        const std::vector<fei::CSVec*>& remotelyOwned,
00186                        std::vector<std::vector<char> >& send_chars,
00187                        bool resize_buffer,
00188                        bool zeroRemotelyOwnedAfterPacking);
00189 
00190   fei::SharedPtr<fei::VectorSpace> vecSpace_;
00191 
00192   MPI_Comm comm_;
00193 
00194   int firstLocalOffset_, lastLocalOffset_, numLocal_;
00195 
00196   std::vector<int> work_indices_;
00197   std::vector<int> work_indices2_;
00198 
00199   bool haveFEVector_;
00200 
00201   std::vector<int> remotelyOwnedProcs_;
00202   std::vector<CSVec*> remotelyOwned_;
00203   std::vector<int> sendProcs_;
00204   std::vector<int> recvProcs_;
00205   std::vector<int> recv_sizes_;
00206   std::vector<std::vector<char> > recv_chars_;
00207   std::vector<std::vector<char> > send_chars_;
00208   bool sendRecvProcsNeedUpdated_;
00209 
00210   bool overlapAlreadySet_;
00211   std::string dbgprefix_;
00212 };//class Vector_core
00213 
00214 }//namespace fei
00215 
00216 #endif
00217 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends