Skip to content

Commit 1074e77

Browse files
committed
remove id mapping feature and fix some things
1 parent 3329b41 commit 1074e77

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

include/openmc/mesh.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,7 @@ void read_meshes(pugi::xml_node root);
10821082
//! Read meshes from a HDF5 file
10831083
//
10841084
//! \param[in] group HDF5 group
1085-
//! \param[out] mesh_map mapping from mesh ids inside HDF5 group to global mesh
1086-
//! ids
1087-
void read_meshes(hid_t group, std::unordered_map<int32_t, int32_t>& mesh_map);
1085+
void read_meshes(hid_t group);
10881086

10891087
//! Write mesh data to an HDF5 group
10901088
//

include/openmc/weight_windows.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ class WeightWindows {
8787
WeightWindows(pugi::xml_node node);
8888
~WeightWindows();
8989
static WeightWindows* create(int32_t id = -1);
90-
static WeightWindows* from_hdf5(hid_t wws_group,
91-
const std::string& group_name,
92-
std::unordered_map<int32_t, int32_t>& id_map);
90+
static WeightWindows* from_hdf5(
91+
hid_t wws_group, const std::string& group_name);
9392

9493
//----------------------------------------------------------------------------
9594
// Methods

src/mesh.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,23 +3821,15 @@ void read_meshes(pugi::xml_node root)
38213821
}
38223822
}
38233823

3824-
void read_meshes(hid_t group, std::unordered_map<int32_t, int32_t>& mesh_map)
3824+
void read_meshes(hid_t group)
38253825
{
3826-
// Find the iterator to the element with the maximum key
3827-
auto max_key_it =
3828-
std::max_element(model::mesh_map.begin(), model::mesh_map.end(),
3829-
[](const auto& p1, const auto& p2) { return p1.first < p2.first; });
3830-
auto offset = max_key_it->first;
3831-
38323826
std::unordered_set<int> mesh_ids;
38333827

38343828
std::array<int, 1> ids;
38353829
read_attribute(group, "ids", ids);
38363830

38373831
for (auto id : ids) {
38383832

3839-
mesh_map[id] = id + offset;
3840-
38413833
// Check to make sure multiple meshes in the same file don't share IDs
38423834
if (contains(mesh_ids, id)) {
38433835
fatal_error(fmt::format("Two or more meshes use the same unique ID "
@@ -3846,19 +3838,26 @@ void read_meshes(hid_t group, std::unordered_map<int32_t, int32_t>& mesh_map)
38463838
}
38473839
mesh_ids.insert(id);
38483840

3841+
// If we've already read a mesh with the same ID in a *different* file,
3842+
// assume it is the same here
3843+
if (model::mesh_map.find(id) != model::mesh_map.end()) {
3844+
warning(fmt::format("Mesh with ID={} appears in multiple files.", id));
3845+
continue;
3846+
}
3847+
38493848
std::string name = fmt::format("mesh {}", id);
38503849
hid_t mesh_group = open_group(group, name.c_str());
38513850

38523851
std::string mesh_type;
3853-
if (attribute_exists(mesh_group, "type")) {
3852+
if (object_exists(mesh_group, "type")) {
38543853
read_dataset(mesh_group, "type", mesh_type);
38553854
} else {
38563855
mesh_type = "regular";
38573856
}
38583857

38593858
// determine the mesh library to use
38603859
std::string mesh_lib;
3861-
if (attribute_exists(mesh_group, "library")) {
3860+
if (object_exists(mesh_group, "library")) {
38623861
read_dataset(mesh_group, "library", mesh_lib);
38633862
}
38643863

@@ -3888,8 +3887,6 @@ void read_meshes(hid_t group, std::unordered_map<int32_t, int32_t>& mesh_map)
38883887
fatal_error("Invalid mesh type: " + mesh_type);
38893888
}
38903889

3891-
model::meshes.back()->id_ = mesh_map[model::meshes.back()->id_];
3892-
38933890
// Map ID to position in vector
38943891
model::mesh_map[model::meshes.back()->id_] = model::meshes.size() - 1;
38953892
}

src/weight_windows.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ WeightWindows* WeightWindows::create(int32_t id)
241241
return wws;
242242
}
243243

244-
WeightWindows* WeightWindows::from_hdf5(hid_t wws_group,
245-
const std::string& group_name, std::unordered_map<int32_t, int32_t>& id_map)
244+
WeightWindows* WeightWindows::from_hdf5(
245+
hid_t wws_group, const std::string& group_name)
246246
{
247247
// collect ID from the name of this group
248248
hid_t ww_group = open_group(wws_group, group_name);
@@ -258,8 +258,6 @@ WeightWindows* WeightWindows::from_hdf5(hid_t wws_group,
258258
int32_t mesh_id;
259259
read_dataset(ww_group, "mesh", mesh_id);
260260

261-
mesh_id = id_map[mesh_id];
262-
263261
if (model::mesh_map.count(mesh_id) == 0) {
264262
fatal_error(
265263
fmt::format("Mesh {} used in weight windows does not exist.", mesh_id));
@@ -1330,16 +1328,14 @@ extern "C" int openmc_weight_windows_import(const char* filename)
13301328

13311329
hid_t weight_windows_group = open_group(ww_file, "weight_windows");
13321330

1333-
std::unordered_map<int32_t, int32_t> mesh_map;
1334-
13351331
hid_t mesh_group = open_group(ww_file, "meshes");
13361332

1337-
read_meshes(mesh_group, mesh_map);
1333+
read_meshes(mesh_group);
13381334

13391335
std::vector<std::string> names = group_names(weight_windows_group);
13401336

13411337
for (const auto& name : names) {
1342-
WeightWindows::from_hdf5(weight_windows_group, name, mesh_map);
1338+
WeightWindows::from_hdf5(weight_windows_group, name);
13431339
}
13441340

13451341
close_group(weight_windows_group);

0 commit comments

Comments
 (0)