コード例 #1
0
void Ioss::Map::build_reverse_map(int64_t num_to_get, int64_t offset)
{
  // Stored as a sorted vector of <global_id, local_id> pairs...
  // To build incrementally:
  // 0. PRE: reverseElementMap is sorted, size >= 0.
  // 1. Build vector of current ids. -- new_ids
  // 2. Sort that vector.
  // 3. Copy reverseElementMap to old_ids, empty reverseElementMap.
  // 4. Merge old_ids and new_ids to reverseElementMap.
  // 5. Check for duplicate global_ids...

  // Build a vector containing the current ids...
  ReverseMapContainer new_ids(num_to_get);
  for (int64_t i=0; i < num_to_get; i++) {
    int64_t local_id = offset + i + 1;
    new_ids[i] = std::make_pair(map[local_id], local_id);

    if (map[local_id] <= 0) {
      std::ostringstream errmsg;
      errmsg << "\nERROR: " << entityType << " map detected non-positive global id " << map[local_id]
	     << " for " << entityType << " with local id " << local_id
	     << " on processor " << myProcessor << ".\n";
      IOSS_ERROR(errmsg);
    }
  }

  // Sort that vector...
  std::sort(new_ids.begin(), new_ids.end(), IdPairCompare());

  int64_t new_id_min = new_ids.empty() ? 0 : new_ids.front().first;
  int64_t old_id_max = reverse.empty() ? 0 : reverse.back().first;
  if (new_id_min > old_id_max) {
    reverse.insert(reverse.end(), new_ids.begin(), new_ids.end());
  } else {
    // Copy reverseElementMap to old_ids, empty reverseElementMap.
    ReverseMapContainer old_ids;
    old_ids.swap(reverse);
    assert(reverse.empty());
    
    // Merge old_ids and new_ids to reverseElementMap.
    reverse.reserve(old_ids.size() + new_ids.size());
    std::merge(old_ids.begin(), old_ids.end(),
	       new_ids.begin(), new_ids.end(),
	       std::inserter(reverse, reverse.begin()), IdPairCompare());
    
  }
  // Check for duplicate ids...
#ifndef NDEBUG
  verify_no_duplicate_ids(reverse);
#endif
}
コード例 #2
0
ファイル: Ioss_Map.C プロジェクト: crtrott/Trilinos
int64_t Ioss::Map::global_to_local(int64_t global, bool must_exist) const
{
  int64_t local = global;
  if (map[0] == 1) {
    RMapI iter = std::lower_bound(reverse.begin(), reverse.end(), global, IdPairCompare());
    if (iter != reverse.end() && iter->first == global)
      local = iter->second;
    else
      local = 0;
  } else if (!must_exist && global > (int64_t)map.size()-1) {
    local = 0;
  }
  if (local > (int64_t)map.size()-1 || (local <= 0  && must_exist)) {
    std::ostringstream errmsg;
    errmsg << "ERROR: Ioss Mapping routines detected " << entityType << " with global id equal to " << global
	   << " returns a local id of " << local
	   << " which is invalid. This should not happen, please report.\n";
    IOSS_ERROR(errmsg);
      }
  return local;
}