17 #define fei_file "snl_fei_RecordCollection.cpp"
26 localProc_(localProc),
35 : m_records(src.m_records),
36 m_global_to_local(src.m_global_to_local),
39 localProc_(src.localProc_),
40 debugOutput_(src.debugOutput_),
51 const int* localIDs_begin,
const int* localIDs_end,
52 const int* globalIDs_begin,
const int* globalIDs_end)
54 int numLocal = localIDs_end - localIDs_begin;
55 int numGlobal = globalIDs_end - globalIDs_begin;
56 if (numLocal != numGlobal) {
57 throw std::runtime_error(
"RecordCollection::setIDMap ERROR, num local IDs must match num global IDs.");
59 m_global_to_local.clear();
60 m_records.resize(numLocal);
61 const int* localID_iter = localIDs_begin;
62 const int* globalID_iter = globalIDs_begin;
63 for(
int i=0; i<numLocal; ++i) {
64 int lid = *localID_iter++;
65 int gid = *globalID_iter++;
66 m_records[lid].setID(gid);
67 m_records[lid].setOwnerProc(localProc_);
68 m_global_to_local.insert(std::make_pair(gid, lid));
74 std::vector<fei::FieldMask*>& fieldMasks,
79 for(
unsigned m=0; m<fieldMasks.size(); ++m) {
80 if (maskID == fieldMasks[m]->getMaskID()) {
81 mask = fieldMasks[m];
break;
88 fieldMasks.push_back(mask);
91 for(
int i=0; i<numIDs; ++i) {
92 if (m_minID > IDs[i]) m_minID = IDs[i];
93 if (m_maxID < IDs[i]) m_maxID = IDs[i];
96 std::map<int,int>::iterator iter = m_global_to_local.lower_bound(IDs[i]);
97 if (iter == m_global_to_local.end() || iter->first != IDs[i]) {
99 local_id = m_records.size();
100 m_global_to_local.insert(iter, std::make_pair(IDs[i], local_id));
102 record.
setID(IDs[i]);
105 m_records.push_back(record);
108 local_id = iter->second;
111 if (recordLocalIDs != NULL) recordLocalIDs[i] = local_id;
117 int numIDs,
const int* IDs,
118 std::vector<fei::FieldMask*>& fieldMasks,
123 for(
unsigned m=0; m<fieldMasks.size(); ++m) {
124 if (maskID == fieldMasks[m]->getMaskID()) {
125 mask = fieldMasks[m];
break;
132 fieldMasks.push_back(mask);
135 int lastMaskID = maskID;
138 for(
int i=0; i<numIDs; ++i) {
139 if (m_minID > IDs[i]) m_minID = IDs[i];
140 if (m_maxID < IDs[i]) m_maxID = IDs[i];
142 std::map<int,int>::iterator iter = m_global_to_local.lower_bound(IDs[i]);
143 if (iter == m_global_to_local.end() || iter->first != IDs[i]) {
145 local_id = m_records.size();
146 m_global_to_local.insert(iter, std::make_pair(IDs[i], local_id));
148 record.
setID(IDs[i]);
151 m_records.push_back(record);
153 if (recordLocalIDs != NULL) {
154 recordLocalIDs[i] = local_id;
158 local_id = iter->second;
161 if (recordLocalIDs != NULL) {
162 recordLocalIDs[i] = local_id;
166 if (thisMask == NULL) {
172 if (maskID == thisMaskID || thisMask->
hasFieldID(fieldID)) {
176 if (lastMaskID == thisMaskID) {
182 if (lastMaskID == newMaskID) {
187 bool newMaskAlreadyExists =
false;
188 for(
unsigned m=0; m<fieldMasks.size(); ++m) {
189 if (newMaskID == fieldMasks[m]->getMaskID()) {
190 lastMask = fieldMasks[m];
193 newMaskAlreadyExists =
true;
198 if (!newMaskAlreadyExists) {
200 newmask->
addField(fieldID, fieldSize);
202 fieldMasks.push_back(newmask);
213 for(
size_t i=0; i<m_records.size(); ++i) {
230 for(i=0, s_it = s_beg; s_it != s_end; ++i, ++s_it) {
231 int sh_id = s_it->first;
233 if (record == NULL)
continue;
241 if (rec_owner != -1) owningProcs[i] = rec_owner;
243 rec_owner = owningProcs[i];
248 *dbgOut_ <<
"# setting ID " << (int)(record->
getID())
249 <<
"'s owner to proc " << rec_owner <<
FEI_ENDL;
256 std::map<int,int>::iterator iter = m_global_to_local.find(ID);
258 if (iter == m_global_to_local.end()) {
262 return(&m_records[iter->second]);
267 std::map<int,int>::const_iterator iter = m_global_to_local.find(ID);
269 if (iter == m_global_to_local.end()) {
273 return(&m_records[iter->second]);
279 if (record == NULL) {
293 int whichComponentOfField,
294 const int* eqnNumbers)
297 if (record == NULL) {
309 if (eqnNums == NULL) {
311 osstr <<
"snl_fei::RecordCollection::getGlobalIndex ERROR: null pointer,"
312 <<
" possibly because initComplete() hasn't been called yet?";
313 throw std::runtime_error(osstr.str());
316 int globalIndex = -1;
317 if (fieldOffset > 0) {
318 globalIndex = eqnNums[offset + fieldOffset*fieldSize + whichComponentOfField];
321 globalIndex = eqnNums[offset + whichComponentOfField];
332 int whichComponentOfField,
333 const int* eqnNumbers)
336 if (record == NULL) {
338 osstr <<
"snl_fei::RecordCollection::getGlobalIndexLocalID ERROR, no record with "
339 <<
"localID=" << localID;
340 throw std::runtime_error(osstr.str());
351 if (eqnNums == NULL) {
353 osstr <<
"snl_fei::RecordCollection::getGlobalIndex ERROR: null pointer,"
354 <<
" possibly because initComplete() hasn't been called yet?";
355 throw std::runtime_error(osstr.str());
358 int globalIndex = -1;
359 if (fieldOffset > 0) {
360 globalIndex = eqnNums[offset + fieldOffset*fieldSize + whichComponentOfField];
363 globalIndex = eqnNums[offset + whichComponentOfField];
GlobalIDType getNumber() const
std::vector< int > & getOwningProcs()
map_type & getSharedIDs()
void setOwners_lowestSharing(fei::SharedIDs< int > &sharedIDs)
std::vector< fei::Record< int > > m_records
void setFieldMask(fei::FieldMask *fm)
int getGlobalIndex(int ID, int fieldID, int fieldSize, int fieldOffset, int whichComponentOfField, const int *eqnNumbers)
RecordCollection(int localProc)
bool hasFieldID(int fieldID) const
virtual ~RecordCollection()
void setOwnerProc(int owner)
void setID(const GlobalIDType &ID)
void addField(int fieldID, int fieldSize)
int localProc(MPI_Comm comm)
void setIDMap(const int *localIDs_begin, const int *localIDs_end, const int *globalIDs_begin, const int *globalIDs_end)
int getFieldEqnOffset(int fieldID, int &offset) const
GlobalIDType getID() const
void initRecords(int numIDs, const int *IDs, std::vector< fei::FieldMask * > &fieldMasks, int *recordLocalIDs=NULL)
int getOffsetIntoEqnNumbers() const
int getGlobalBlkIndex(int ID, int &globalBlkIndex)
fei::FieldMask * getFieldMask()
fei::Record< int > * getRecordWithID(int ID)
#define FEI_OSTRINGSTREAM
int getGlobalIndexLocalID(int localID, int fieldID, int fieldSize, int fieldOffset, int whichComponentOfField, const int *eqnNumbers)