9 #include "fei_Vector_Local.hpp"
10 #include "fei_sstream.hpp"
11 #include "fei_fstream.hpp"
12 #include <fei_ErrMacros.hpp>
17 #define fei_file "fei_Vector_Local.cpp"
22 : vecSpace_(vecSpace),
27 int numCoefs = vecSpace_->getNumIndices_SharedAndOwned();
28 coefs_.resize(numCoefs);
30 std::vector<int> indices;
31 vecSpace_->getIndices_SharedAndOwned(indices);
33 std::sort(indices.begin(), indices.end());
35 for(
int i=0; i<numCoefs; ++i) {
36 global_to_local_.insert(std::make_pair(indices[i], i));
40 Vector_Local::~Vector_Local()
45 Vector_Local::update(
double a,
54 Vector_Local::scatterToOverlap()
58 Vector_Local::setCommSizes()
63 Vector_Local::gatherFromOverlap(
bool accumulate)
64 { (void)accumulate;
return(0); }
67 Vector_Local::putScalar(
double scalar)
69 for(
size_t i=0; i<coefs_.size(); ++i) coefs_[i] = scalar;
74 Vector_Local::giveToVector(
int numValues,
const int* indices,
76 bool sumInto,
int vectorIndex)
78 if (vectorIndex != 0) {
79 fei::console_out() <<
"fei::Vector_Local ERROR, vectorIndex!=0. Report to Alan Williams."<<FEI_ENDL;
83 for(
int i=0; i<numValues; ++i) {
84 std::map<int,int>::iterator
85 iter = global_to_local_.find(indices[i]);
86 if (iter == global_to_local_.end()) {
87 fei::console_out() <<
"fei::Vector_Local ERROR, eqn "<<indices[i]<<
" not found "
88 <<
"locally."<<FEI_ENDL;
93 coefs_[iter->second] += values[i];
96 coefs_[iter->second] = values[i];
104 Vector_Local::sumIn(
int numValues,
const int* indices,
const double* values,
107 return( giveToVector(numValues, indices, values,
true, vectorIndex) );
111 Vector_Local::copyIn(
int numValues,
const int* indices,
const double* values,
114 return( giveToVector(numValues, indices, values,
false, vectorIndex) );
118 Vector_Local::getVectorSpace()
const
119 {
return( vecSpace_ ); }
123 { vecSpace_ = vecSpace; }
126 Vector_Local::assembleFieldData(
int fieldID,
136 work_indices_.resize(numIDs*fieldSize);
137 int* indicesPtr = &work_indices_[0];
139 CHK_ERR( vecSpace_->getGlobalIndices(numIDs, IDs, idType, fieldID,
142 CHK_ERR( giveToVector(numIDs*fieldSize, indicesPtr, data, sumInto, vectorIndex) );
148 Vector_Local::assembleFieldDataLocalIDs(
int fieldID,
156 int fieldSize = vecSpace_->getFieldSize(fieldID);
158 work_indices_.resize(numIDs*fieldSize);
159 int* indicesPtr = &work_indices_[0];
161 CHK_ERR( vecSpace_->getGlobalIndicesLocalIDs(numIDs, localIDs, idType, fieldID,
164 CHK_ERR( giveToVector(numIDs*fieldSize, indicesPtr, data, sumInto, vectorIndex) );
170 Vector_Local::sumInFieldData(
int fieldID,
177 return(assembleFieldData(fieldID, idType, numIDs, IDs,
178 data,
true, vectorIndex));
182 Vector_Local::copyInFieldData(
int fieldID,
189 return(assembleFieldData(fieldID, idType, numIDs, IDs,
190 data,
false, vectorIndex));
194 Vector_Local::copyInFieldDataLocalIDs(
int fieldID,
201 return(assembleFieldDataLocalIDs(fieldID, idType, numIDs, localIDs,
202 data,
false, vectorIndex));
206 Vector_Local::copyOutFieldData(
int fieldID,
213 int fieldSize = vecSpace_->getFieldSize(fieldID);
215 work_indices_.resize(numIDs*fieldSize);
216 int* indicesPtr = &work_indices_[0];
218 CHK_ERR( vecSpace_->getGlobalIndices(numIDs, IDs, idType, fieldID,
221 for(
int i=0; i<(int)work_indices_.size(); ++i) {
222 std::map<int,int>::iterator
223 iter = global_to_local_.find(work_indices_[i]);
224 if (iter == global_to_local_.end()) {
225 fei::console_out() <<
"fei::Vector_Local::copyOut ERROR, eqn "<<work_indices_[i]<<
" not found "
226 <<
"locally."<<FEI_ENDL;
230 data[i] = coefs_[iter->second];
237 Vector_Local::copyOut(
int numValues,
const int* indices,
238 double* values,
int vectorIndex)
const
240 if (vectorIndex != 0) {
241 fei::console_out() <<
"fei::Vector_Local ERROR, vectorIndex!=0. Report to Alan Williams."<<FEI_ENDL;
245 for(
int i=0; i<numValues; ++i) {
246 std::map<int,int>::const_iterator
247 iter = global_to_local_.find(indices[i]);
248 if (iter == global_to_local_.end()) {
249 fei::console_out() <<
"fei::Vector_Local::copyOut ERROR, eqn "<<indices[i]<<
" not found "
250 <<
"locally."<<FEI_ENDL;
254 values[i] = coefs_[iter->second];
261 Vector_Local::getCoefs()
267 Vector_Local::writeToFile(
const char* filename,
268 bool matrixMarketFormat)
271 FEI_OSTRINGSTREAM osstr;
272 osstr << filename <<
"." << local_proc;
273 std::string fullname = osstr.str();
274 FEI_OFSTREAM ofstr(fullname.c_str(), IOS_OUT);
280 Vector_Local::writeToStream(FEI_OSTREAM& ostrm,
281 bool matrixMarketFormat)
283 static char mmbanner[] =
"%%MatrixMarket matrix array real general";
285 if (matrixMarketFormat) {
286 ostrm << mmbanner << FEI_ENDL;
287 ostrm << coefs_.size() <<
" 1" << FEI_ENDL;
290 ostrm << coefs_.size() << FEI_ENDL;
293 ostrm.setf(IOS_SCIENTIFIC, IOS_FLOATFIELD);
296 std::map<int,int>::iterator
297 iter = global_to_local_.begin();
299 for(
unsigned i=0; i<coefs_.size(); ++i) {
300 if (matrixMarketFormat) {
301 ostrm << coefs_[i] << FEI_ENDL;
304 ostrm << iter->first <<
" " << coefs_[i] << FEI_ENDL;
void writeToStream(snl_fei::RaggedTable< MAP_TYPE, SET_TYPE > &table, FEI_OSTREAM &os, const char *lineprefix=NULL)
std::ostream & console_out()
int localProc(MPI_Comm comm)
unsigned getFieldSize(int fieldID)