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>
16 #define fei_file "fei_VectorReducer.cpp"
18 #include <fei_ErrMacros.hpp>
25 bool isSolutionVector)
28 isSolution_(isSolutionVector)
34 if (target_core == NULL) {
35 throw std::runtime_error(
"fei::VectorReducer ERROR, target vector not dynamic_cast-able to fei::Vector_core.");
40 std::vector<int> eqns;
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]));
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]));
57 int* overlap_ptr = overlap.empty() ? NULL : &overlap[0];
58 target_core->setOverlap(overlap.size(), overlap_ptr);
62 VectorReducer::~VectorReducer()
67 int VectorReducer::putScalar(
double scalar)
69 return(target_->putScalar(scalar));
73 int VectorReducer::update(
double a,
const fei::Vector* x,
double b)
75 return(target_->update(a, x, b));
79 int VectorReducer::scatterToOverlap()
81 return(target_->scatterToOverlap());
85 int VectorReducer::gatherFromOverlap(
bool accumulate)
87 reducer_->assembleReducedVector(isSolution_, *target_);
88 target_->setCommSizes();
89 return(target_->gatherFromOverlap(accumulate));
93 int VectorReducer::sumIn(
int numValues,
94 const int* indices,
const double* values,
97 return(reducer_->addVectorValues(numValues, indices, values,
true,
98 isSolution_, vectorIndex, *target_));
102 int VectorReducer::copyIn(
int numValues,
103 const int* indices,
const double* values,
106 return(reducer_->addVectorValues(numValues, indices, values,
false,
107 isSolution_, vectorIndex, *target_));
111 int VectorReducer::giveToUnderlyingVector(
int numValues,
113 const double* values,
117 int err = reducer_->addVectorValues(numValues, indices, values, sumInto,
118 isSolution_, vectorIndex, *target_);
123 int VectorReducer::sumInFieldData(
int fieldID,
132 int numIndices = numIDs*fieldSize;
133 std::vector<int> indices(numIndices);
134 int err = vspace->
getGlobalIndices(numIDs, IDs, idType, fieldID, &indices[0]);
136 throw std::runtime_error(
"fei::VectorReducer::sumInFieldData ERROR in vspace->getGlobalIndices.");
139 return(sumIn(numIndices, &indices[0], data, vectorIndex));
143 int VectorReducer::copyInFieldData(
int fieldID,
152 int numIndices = numIDs*fieldSize;
153 std::vector<int> indices(numIndices);
154 int err = vspace->
getGlobalIndices(numIDs, IDs, idType, fieldID, &indices[0]);
156 throw std::runtime_error(
"fei::VectorReducer::copyInFieldData ERROR in vspace->getGlobalIndices.");
159 return(copyIn(numIndices, &indices[0], data, vectorIndex));
163 int VectorReducer::copyInFieldDataLocalIDs(
int fieldID,
172 int numIndices = numIDs*fieldSize;
173 std::vector<int> indices(numIndices);
176 throw std::runtime_error(
"fei::VectorReducer::copyInFieldData ERROR in vspace->getGlobalIndices.");
179 return(copyIn(numIndices, &indices[0], data, vectorIndex));
183 int VectorReducer::copyOut_FE(
int nodeNumber,
int dofOffset,
190 int VectorReducer::copyOutFieldData(
int fieldID,
199 int numIndices = numIDs*fieldSize;
200 std::vector<int> indices(numIndices);
201 int err = vspace->
getGlobalIndices(numIDs, IDs, idType, fieldID, &indices[0]);
203 throw std::runtime_error(
"fei::VectorReducer::copyOutFieldData ERROR in vspace->getGlobalIndices.");
206 return(copyOut(numIndices, &indices[0], data, vectorIndex));
210 int VectorReducer::writeToFile(
const char* filename,
211 bool matrixMarketFormat)
213 return( target_->writeToFile(filename, matrixMarketFormat) );
217 int VectorReducer::writeToStream(FEI_OSTREAM& ostrm,
218 bool matrixMarketFormat)
220 return( target_->writeToStream(ostrm, matrixMarketFormat) );
224 int VectorReducer::copyOut(
int numValues,
227 int vectorIndex)
const
229 int err = reducer_->copyOutVectorValues(numValues, indices, values,
230 isSolution_, vectorIndex,
236 int VectorReducer::sumIntoFEVector(
int blockID,
239 const int* nodeNumbers,
240 const int* numIndicesPerNode,
241 const double* values)
MPI_Comm getCommunicator() const
int getGlobalIndicesLocalIDs(int numIDs, const int *localIDs, int idType, int fieldID, int *globalIndices)
int getIndices_SharedAndOwned(std::vector< int > &globalIndices) const
virtual fei::SharedPtr< fei::VectorSpace > getVectorSpace() const =0
int getGlobalIndices(int numIDs, const int *IDs, int idType, int fieldID, int *globalIndices)
int localProc(MPI_Comm comm)
int getNumIndices_SharedAndOwned() const
unsigned getFieldSize(int fieldID)
int numProcs(MPI_Comm comm)