FEI Version of the Day
fei_Vector_core.hpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
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 Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #ifndef _fei_Vector_core_hpp_
00045 #define _fei_Vector_core_hpp_
00046 
00047 #include <fei_iosfwd.hpp>
00048 #include <fei_CSVec.hpp>
00049 #include <fei_VectorSpace.hpp>
00050 #include <fei_Reducer.hpp>
00051 #include <fei_Logger.hpp>
00052 #include <fei_SharedPtr.hpp>
00053 #include <fei_EqnComm.hpp>
00054 
00055 namespace fei {
00056 
00058 class Vector_core : protected fei::Logger {
00059  public:
00061   Vector_core(fei::SharedPtr<fei::VectorSpace> vecSpace, int numLocalEqns);
00062 
00064   virtual ~Vector_core();
00065 
00071   int copyOut(int numValues,
00072         const int* indices,
00073         double* values,
00074         int vectorIndex=0) const;
00075 
00077   virtual int sumIntoFEVector(int blockID,
00078             int connOffset,
00079             int numNodes,
00080             const int* nodeNumbers,
00081             const int* numIndicesPerNode,
00082             const int* dof_ids,
00083             const double* values) = 0;
00084 
00086   virtual int copyOut_FE(int nodeNumber, int dofOffset, double& value) = 0;
00087 
00089   int giveToVector(int numValues,
00090        const int* indices,
00091        const double* values,
00092        bool sumInto=true,
00093        int vectorIndex=0);
00094 
00096   virtual int scatterToOverlap();
00097 
00101   void setOverlap(int numRemoteEqns=0, const int* remoteEqns=NULL);
00102 
00103  protected:
00105   int assembleFieldData(int fieldID,
00106       int idType,
00107       int numIDs,
00108       const int* IDs,
00109       const double* data,
00110       bool sumInto=true,
00111       int vectorIndex=0);
00112 
00113   int assembleFieldDataLocalIDs(int fieldID,
00114       int idType,
00115       int numIDs,
00116       const int* localIDs,
00117       const double* data,
00118       bool sumInto=true,
00119       int vectorIndex=0);
00120 
00121   void setCommSizes();
00123   virtual int gatherFromOverlap(bool accumulate = true);
00124 
00126   virtual int copyOutFieldData(int fieldID,
00127              int idType,
00128              int numIDs,
00129              const int* IDs,
00130              double* data,
00131              int vectorIndex=0);
00132 
00134   virtual int giveToUnderlyingVector(int numValues,
00135              const int* indices,
00136              const double* values,
00137              bool sumInto=true,
00138              int vectorIndex=0) = 0;
00139 
00141   virtual int copyOutOfUnderlyingVector(int numValues,
00142           const int* indices,
00143           double* values,
00144           int vectorIndex=0) const = 0;
00145 
00148   virtual int writeToFile(const char* filename,
00149         bool matrixMarketFormat=true);
00150 
00152   virtual int writeToStream(FEI_OSTREAM& ostrm,
00153           bool matrixMarketFormat=true);
00154 
00156   fei::SharedPtr<fei::VectorSpace> get_vector_space() const
00157     {
00158       return( vecSpace_ );
00159     }
00160 
00162   void set_vector_space(fei::SharedPtr<fei::VectorSpace> vspace)
00163     {
00164       vecSpace_ = vspace;
00165     }
00166 
00168   int firstLocalOffset() const { return( firstLocalOffset_ ); }
00169 
00171   int lastLocalOffset() const { return( lastLocalOffset_ ); }
00172 
00174   std::vector<int>& work_indices() { return( work_indices_ ); }
00176   std::vector<int>& work_indices2(){ return( work_indices2_); }
00177 
00179   bool haveFEVector() { return( haveFEVector_ ); }
00181   void setFEVector(bool flag) {haveFEVector_ = flag; }
00182 
00184   std::vector<CSVec*>& remotelyOwned() { return( remotelyOwned_ ); }
00185   const std::vector<CSVec*>& remotelyOwned() const { return( remotelyOwned_ ); }
00186   std::vector<int>& remotelyOwnedProcs() { return( remotelyOwnedProcs_ ); }
00187   const std::vector<int>& remotelyOwnedProcs() const { return( remotelyOwnedProcs_ ); }
00188 
00189   fei::CSVec* getRemotelyOwned(int proc) {
00190     std::vector<int>::iterator iter = std::lower_bound(remotelyOwnedProcs_.begin(), remotelyOwnedProcs_.end(), proc);
00191     fei::CSVec* return_vec = NULL;
00192     size_t offset = iter - remotelyOwnedProcs_.begin();
00193     if (iter == remotelyOwnedProcs_.end() || *iter != proc) {
00194       remotelyOwnedProcs_.insert(iter, proc);
00195       return_vec = new fei::CSVec;
00196       remotelyOwned_.insert(remotelyOwned_.begin()+offset, return_vec);
00197     }
00198     else {
00199       return_vec = remotelyOwned_[offset];
00200     }
00201  
00202     return return_vec;
00203   }
00204 
00205   const fei::CSVec* getRemotelyOwned(int proc) const {
00206     std::vector<int>::const_iterator iter = std::lower_bound(remotelyOwnedProcs_.begin(), remotelyOwnedProcs_.end(), proc);
00207     if (iter == remotelyOwnedProcs_.end() || *iter != proc) {
00208       throw std::runtime_error("failed to find remote-vec for specified processor.");
00209     }
00210 
00211     size_t offset = iter - remotelyOwnedProcs_.begin();
00212     return remotelyOwned_[offset];
00213   }
00214 
00215  protected:
00216   fei::SharedPtr<fei::EqnComm> eqnComm_;
00217 
00218  private:
00219   void pack_send_buffers(const std::vector<int>& sendProcs,
00220                        const std::vector<fei::CSVec*>& remotelyOwned,
00221                        std::vector<std::vector<char> >& send_chars,
00222                        bool resize_buffer,
00223                        bool zeroRemotelyOwnedAfterPacking);
00224 
00225   fei::SharedPtr<fei::VectorSpace> vecSpace_;
00226 
00227   MPI_Comm comm_;
00228 
00229   int firstLocalOffset_, lastLocalOffset_, numLocal_;
00230 
00231   std::vector<int> work_indices_;
00232   std::vector<int> work_indices2_;
00233 
00234   bool haveFEVector_;
00235 
00236   std::vector<int> remotelyOwnedProcs_;
00237   std::vector<CSVec*> remotelyOwned_;
00238   std::vector<int> sendProcs_;
00239   std::vector<int> recvProcs_;
00240   std::vector<int> recv_sizes_;
00241   std::vector<std::vector<char> > recv_chars_;
00242   std::vector<std::vector<char> > send_chars_;
00243   bool sendRecvProcsNeedUpdated_;
00244 
00245   bool overlapAlreadySet_;
00246   std::string dbgprefix_;
00247 };//class Vector_core
00248 
00249 }//namespace fei
00250 
00251 #endif
00252 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends