FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fei_VectorReducer.cpp
Go to the documentation of this file.
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 #include <fei_VectorReducer.hpp>
10 #include <fei_VectorSpace.hpp>
11 #include <fei_Vector_core.hpp>
12 #include <fei_Vector.hpp>
13 #include <fei_CommUtils.hpp>
14 
15 #undef fei_file
16 #define fei_file "fei_VectorReducer.cpp"
17 
18 #include <fei_ErrMacros.hpp>
19 
20 namespace fei {
21 
22 //----------------------------------------------------------------------------
25  bool isSolutionVector)
26  : reducer_(reducer),
27  target_(target),
28  isSolution_(isSolutionVector)
29 {
32 
33  fei::Vector_core* target_core = dynamic_cast<fei::Vector_core*>(target.get());
34  if (target_core == NULL) {
35  throw std::runtime_error("fei::VectorReducer ERROR, target vector not dynamic_cast-able to fei::Vector_core.");
36  }
37 
39  int numEqns = vecspace->getNumIndices_SharedAndOwned();
40  std::vector<int> eqns;
41  vecspace->getIndices_SharedAndOwned(eqns);
42 
43  std::vector<int> overlap;
44  for(int i=0; i<numEqns; ++i) {
45  if (!reducer->isSlaveEqn(eqns[i])) {
46  overlap.push_back(reducer->translateToReducedEqn(eqns[i]));
47  }
48  else {
49  std::vector<int> masters;
50  reducer->getSlaveMasterEqns(eqns[i], masters);
51  for(unsigned j=0; j<masters.size(); ++j) {
52  overlap.push_back(reducer->translateToReducedEqn(masters[j]));
53  }
54  }
55  }
56 
57  int* overlap_ptr = overlap.empty() ? NULL : &overlap[0];
58  target_core->setOverlap(overlap.size(), overlap_ptr);
59 }
60 
61 //----------------------------------------------------------------------------
63 {
64 }
65 
66 //----------------------------------------------------------------------------
67 int VectorReducer::putScalar(double scalar)
68 {
69  return(target_->putScalar(scalar));
70 }
71 
72 //----------------------------------------------------------------------------
73 int VectorReducer::update(double a, const fei::Vector* x, double b)
74 {
75  return(target_->update(a, x, b));
76 }
77 
78 //----------------------------------------------------------------------------
80 {
81  return(target_->scatterToOverlap());
82 }
83 
84 //----------------------------------------------------------------------------
86 {
89  return(target_->gatherFromOverlap(accumulate));
90 }
91 
92 //----------------------------------------------------------------------------
93 int VectorReducer::sumIn(int numValues,
94  const int* indices, const double* values,
95  int vectorIndex)
96 {
97  return(reducer_->addVectorValues(numValues, indices, values, true,
98  isSolution_, vectorIndex, *target_));
99 }
100 
101 //----------------------------------------------------------------------------
102 int VectorReducer::copyIn(int numValues,
103  const int* indices, const double* values,
104  int vectorIndex)
105 {
106  return(reducer_->addVectorValues(numValues, indices, values, false,
107  isSolution_, vectorIndex, *target_));
108 }
109 
110 //----------------------------------------------------------------------------
112  const int* indices,
113  const double* values,
114  bool sumInto,
115  int vectorIndex)
116 {
117  int err = reducer_->addVectorValues(numValues, indices, values, sumInto,
118  isSolution_, vectorIndex, *target_);
119  return(err);
120 }
121 
122 //----------------------------------------------------------------------------
124  int idType,
125  int numIDs,
126  const int* IDs,
127  const double* data,
128  int vectorIndex)
129 {
131  int fieldSize = vspace->getFieldSize(fieldID);
132  int numIndices = numIDs*fieldSize;
133  std::vector<int> indices(numIndices);
134  int err = vspace->getGlobalIndices(numIDs, IDs, idType, fieldID, &indices[0]);
135  if (err != 0) {
136  throw std::runtime_error("fei::VectorReducer::sumInFieldData ERROR in vspace->getGlobalIndices.");
137  }
138 
139  return(sumIn(numIndices, &indices[0], data, vectorIndex));
140 }
141 
142 //----------------------------------------------------------------------------
144  int idType,
145  int numIDs,
146  const int* IDs,
147  const double* data,
148  int vectorIndex)
149 {
151  int fieldSize = vspace->getFieldSize(fieldID);
152  int numIndices = numIDs*fieldSize;
153  std::vector<int> indices(numIndices);
154  int err = vspace->getGlobalIndices(numIDs, IDs, idType, fieldID, &indices[0]);
155  if (err != 0) {
156  throw std::runtime_error("fei::VectorReducer::copyInFieldData ERROR in vspace->getGlobalIndices.");
157  }
158 
159  return(copyIn(numIndices, &indices[0], data, vectorIndex));
160 }
161 
162 //----------------------------------------------------------------------------
164  int idType,
165  int numIDs,
166  const int* localIDs,
167  const double* data,
168  int vectorIndex)
169 {
171  int fieldSize = vspace->getFieldSize(fieldID);
172  int numIndices = numIDs*fieldSize;
173  std::vector<int> indices(numIndices);
174  int err = vspace->getGlobalIndicesLocalIDs(numIDs, localIDs, idType, fieldID, &indices[0]);
175  if (err != 0) {
176  throw std::runtime_error("fei::VectorReducer::copyInFieldData ERROR in vspace->getGlobalIndices.");
177  }
178 
179  return(copyIn(numIndices, &indices[0], data, vectorIndex));
180 }
181 
182 //----------------------------------------------------------------------------
183 int VectorReducer::copyOut_FE(int nodeNumber, int dofOffset,
184  double& value)
185 {
186  return(-1);
187 }
188 
189 //----------------------------------------------------------------------------
191  int idType,
192  int numIDs,
193  const int* IDs,
194  double* data,
195  int vectorIndex)
196 {
198  int fieldSize = vspace->getFieldSize(fieldID);
199  int numIndices = numIDs*fieldSize;
200  std::vector<int> indices(numIndices);
201  int err = vspace->getGlobalIndices(numIDs, IDs, idType, fieldID, &indices[0]);
202  if (err != 0) {
203  throw std::runtime_error("fei::VectorReducer::copyOutFieldData ERROR in vspace->getGlobalIndices.");
204  }
205 
206  return(copyOut(numIndices, &indices[0], data, vectorIndex));
207 }
208 
209 //----------------------------------------------------------------------------
210 int VectorReducer::writeToFile(const char* filename,
211  bool matrixMarketFormat)
212 {
213  return( target_->writeToFile(filename, matrixMarketFormat) );
214 }
215 
216 //----------------------------------------------------------------------------
218  bool matrixMarketFormat)
219 {
220  return( target_->writeToStream(ostrm, matrixMarketFormat) );
221 }
222 
223 //----------------------------------------------------------------------------
224 int VectorReducer::copyOut(int numValues,
225  const int* indices,
226  double* values,
227  int vectorIndex) const
228 {
229  int err = reducer_->copyOutVectorValues(numValues, indices, values,
230  isSolution_, vectorIndex,
231  *target_);
232  return(err);
233 }
234 
235 //----------------------------------------------------------------------------
237  int connOffset,
238  int numNodes,
239  const int* nodeNumbers,
240  const int* numIndicesPerNode,
241  const double* values)
242 {
243  return(-1);
244 }
245 
246 }//namespace fei
247 
MPI_Comm getCommunicator() const
int getGlobalIndicesLocalIDs(int numIDs, const int *localIDs, int idType, int fieldID, int *globalIndices)
int copyOut(int numValues, const int *indices, double *values, int vectorIndex=0) const
virtual int writeToFile(const char *filename, bool matrixMarketFormat=true)=0
int getIndices_SharedAndOwned(std::vector< int > &globalIndices) const
virtual fei::SharedPtr< fei::VectorSpace > getVectorSpace() const =0
int copyInFieldData(int fieldID, int idType, int numIDs, const int *IDs, const double *data, int vectorIndex=0)
int update(double a, const fei::Vector *x, double b)
fei::SharedPtr< fei::Reducer > reducer_
void assembleReducedVector(bool soln_vector, fei::Vector &feivec)
virtual int gatherFromOverlap(bool accumulate=true)=0
int copyOutFieldData(int fieldID, int idType, int numIDs, const int *IDs, double *data, int vectorIndex=0)
VectorReducer(fei::SharedPtr< fei::Reducer > reducer, fei::SharedPtr< fei::Vector > target, bool isSolutionVector=false)
int translateToReducedEqn(int unreducedEqn) const
int sumIn(int numValues, const int *indices, const double *values, int vectorIndex=0)
void getSlaveMasterEqns(int slaveEqn, std::vector< int > &masterEqns)
int writeToFile(const char *filename, bool matrixMarketFormat=true)
virtual int scatterToOverlap()=0
virtual int putScalar(double scalar)=0
int copyOutVectorValues(int numValues, const int *globalIndices, double *values, bool soln_vector, int vectorIndex, fei::Vector &feivec)
virtual int update(double a, const fei::Vector *x, double b)=0
int putScalar(double scalar)
int getGlobalIndices(int numIDs, const int *IDs, int idType, int fieldID, int *globalIndices)
#define FEI_OSTREAM
Definition: fei_iosfwd.hpp:24
fei::SharedPtr< fei::Vector > target_
T * get() const
int copyInFieldDataLocalIDs(int fieldID, int idType, int numIDs, const int *localIDs, const double *data, int vectorIndex=0)
int gatherFromOverlap(bool accumulate=true)
int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)
int copyIn(int numValues, const int *indices, const double *values, int vectorIndex=0)
int addVectorValues(int numValues, const int *globalIndices, const double *values, bool sum_into, bool soln_vector, int vectorIndex, fei::Vector &feivec)
int localProc(MPI_Comm comm)
int giveToUnderlyingVector(int numValues, const int *indices, const double *values, bool sumInto=true, int vectorIndex=0)
int getNumIndices_SharedAndOwned() const
unsigned getFieldSize(int fieldID)
bool isSlaveEqn(int unreducedEqn) const
virtual void setCommSizes()=0
int sumIntoFEVector(int blockID, int connOffset, int numNodes, const int *nodeNumbers, const int *numIndicesPerNode, const double *values)
virtual int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)=0
int sumInFieldData(int fieldID, int idType, int numIDs, const int *IDs, const double *data, int vectorIndex=0)
int numProcs(MPI_Comm comm)
int copyOut_FE(int nodeNumber, int dofOffset, double &value)