FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_Vector_core.hpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef _fei_Vector_core_hpp_
10 #define _fei_Vector_core_hpp_
11 
12 #include <fei_iosfwd.hpp>
13 #include <fei_CSVec.hpp>
14 #include <fei_VectorSpace.hpp>
15 #include <fei_Reducer.hpp>
16 #include <fei_Logger.hpp>
17 #include <fei_SharedPtr.hpp>
18 #include <fei_EqnComm.hpp>
19 
20 namespace fei {
21 
23 class Vector_core : protected fei::Logger {
24  public:
26  Vector_core(fei::SharedPtr<fei::VectorSpace> vecSpace, int numLocalEqns);
27 
29  virtual ~Vector_core();
30 
36  int copyOut(int numValues,
37  const int* indices,
38  double* values,
39  int vectorIndex=0) const;
40 
42  virtual int sumIntoFEVector(int blockID,
43  int connOffset,
44  int numNodes,
45  const int* nodeNumbers,
46  const int* numIndicesPerNode,
47  const int* dof_ids,
48  const double* values) = 0;
49 
51  virtual int copyOut_FE(int nodeNumber, int dofOffset, double& value) = 0;
52 
54  int giveToVector(int numValues,
55  const int* indices,
56  const double* values,
57  bool sumInto=true,
58  int vectorIndex=0);
59 
61  virtual int scatterToOverlap();
62 
66  void setOverlap(int numRemoteEqns=0, const int* remoteEqns=NULL);
67 
68  protected:
70  int assembleFieldData(int fieldID,
71  int idType,
72  int numIDs,
73  const int* IDs,
74  const double* data,
75  bool sumInto=true,
76  int vectorIndex=0);
77 
78  int assembleFieldDataLocalIDs(int fieldID,
79  int idType,
80  int numIDs,
81  const int* localIDs,
82  const double* data,
83  bool sumInto=true,
84  int vectorIndex=0);
85 
86  void setCommSizes();
88  virtual int gatherFromOverlap(bool accumulate = true);
89 
91  virtual int copyOutFieldData(int fieldID,
92  int idType,
93  int numIDs,
94  const int* IDs,
95  double* data,
96  int vectorIndex=0);
97 
99  virtual int giveToUnderlyingVector(int numValues,
100  const int* indices,
101  const double* values,
102  bool sumInto=true,
103  int vectorIndex=0) = 0;
104 
106  virtual int copyOutOfUnderlyingVector(int numValues,
107  const int* indices,
108  double* values,
109  int vectorIndex=0) const = 0;
110 
113  virtual int writeToFile(const char* filename,
114  bool matrixMarketFormat=true);
115 
117  virtual int writeToStream(FEI_OSTREAM& ostrm,
118  bool matrixMarketFormat=true);
119 
122  {
123  return( vecSpace_ );
124  }
125 
128  {
129  vecSpace_ = vspace;
130  }
131 
133  int firstLocalOffset() const { return( firstLocalOffset_ ); }
134 
136  int lastLocalOffset() const { return( lastLocalOffset_ ); }
137 
139  std::vector<int>& work_indices() { return( work_indices_ ); }
141  std::vector<int>& work_indices2(){ return( work_indices2_); }
142 
144  bool haveFEVector() { return( haveFEVector_ ); }
146  void setFEVector(bool flag) {haveFEVector_ = flag; }
147 
149  std::vector<CSVec*>& remotelyOwned() { return( remotelyOwned_ ); }
150  const std::vector<CSVec*>& remotelyOwned() const { return( remotelyOwned_ ); }
151  std::vector<int>& remotelyOwnedProcs() { return( remotelyOwnedProcs_ ); }
152  const std::vector<int>& remotelyOwnedProcs() const { return( remotelyOwnedProcs_ ); }
153 
154  fei::CSVec* getRemotelyOwned(int proc) {
155  std::vector<int>::iterator iter = std::lower_bound(remotelyOwnedProcs_.begin(), remotelyOwnedProcs_.end(), proc);
156  fei::CSVec* return_vec = NULL;
157  size_t offset = iter - remotelyOwnedProcs_.begin();
158  if (iter == remotelyOwnedProcs_.end() || *iter != proc) {
159  remotelyOwnedProcs_.insert(iter, proc);
160  return_vec = new fei::CSVec;
161  remotelyOwned_.insert(remotelyOwned_.begin()+offset, return_vec);
162  }
163  else {
164  return_vec = remotelyOwned_[offset];
165  }
166 
167  return return_vec;
168  }
169 
170  const fei::CSVec* getRemotelyOwned(int proc) const {
171  std::vector<int>::const_iterator iter = std::lower_bound(remotelyOwnedProcs_.begin(), remotelyOwnedProcs_.end(), proc);
172  if (iter == remotelyOwnedProcs_.end() || *iter != proc) {
173  throw std::runtime_error("failed to find remote-vec for specified processor.");
174  }
175 
176  size_t offset = iter - remotelyOwnedProcs_.begin();
177  return remotelyOwned_[offset];
178  }
179 
180  protected:
182 
183  private:
184  void pack_send_buffers(const std::vector<int>& sendProcs,
185  const std::vector<fei::CSVec*>& remotelyOwned,
186  std::vector<std::vector<char> >& send_chars,
187  bool resize_buffer,
188  bool zeroRemotelyOwnedAfterPacking);
189 
191 
192  MPI_Comm comm_;
193 
194  int firstLocalOffset_, lastLocalOffset_, numLocal_;
195 
196  std::vector<int> work_indices_;
197  std::vector<int> work_indices2_;
198 
199  bool haveFEVector_;
200 
201  std::vector<int> remotelyOwnedProcs_;
202  std::vector<CSVec*> remotelyOwned_;
203  std::vector<int> sendProcs_;
204  std::vector<int> recvProcs_;
205  std::vector<int> recv_sizes_;
206  std::vector<std::vector<char> > recv_chars_;
207  std::vector<std::vector<char> > send_chars_;
208  bool sendRecvProcsNeedUpdated_;
209 
210  bool overlapAlreadySet_;
211  std::string dbgprefix_;
212 };//class Vector_core
213 
214 }//namespace fei
215 
216 #endif
217 
std::vector< int > & work_indices()
void setOverlap(int numRemoteEqns=0, const int *remoteEqns=NULL)
virtual int giveToUnderlyingVector(int numValues, const int *indices, const double *values, bool sumInto=true, int vectorIndex=0)=0
int giveToVector(int numValues, const int *indices, const double *values, bool sumInto=true, int vectorIndex=0)
std::vector< int > & work_indices2()
virtual int copyOut_FE(int nodeNumber, int dofOffset, double &value)=0
virtual int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)
int copyOut(int numValues, const int *indices, double *values, int vectorIndex=0) const
void set_vector_space(fei::SharedPtr< fei::VectorSpace > vspace)
std::vector< CSVec * > & remotelyOwned()
void setFEVector(bool flag)
virtual int copyOutFieldData(int fieldID, int idType, int numIDs, const int *IDs, double *data, int vectorIndex=0)
virtual int sumIntoFEVector(int blockID, int connOffset, int numNodes, const int *nodeNumbers, const int *numIndicesPerNode, const int *dof_ids, const double *values)=0
int lastLocalOffset() const
fei::SharedPtr< fei::VectorSpace > get_vector_space() const
Vector_core(fei::SharedPtr< fei::VectorSpace > vecSpace, int numLocalEqns)
virtual int writeToFile(const char *filename, bool matrixMarketFormat=true)
virtual int scatterToOverlap()
virtual int copyOutOfUnderlyingVector(int numValues, const int *indices, double *values, int vectorIndex=0) const =0
int firstLocalOffset() const
virtual int gatherFromOverlap(bool accumulate=true)
int assembleFieldData(int fieldID, int idType, int numIDs, const int *IDs, const double *data, bool sumInto=true, int vectorIndex=0)