Ensure that implicit complement cells appear last in DAGMC universes (#2838)

This commit is contained in:
Paul Romano 2024-01-15 14:33:56 -06:00 committed by GitHub
parent d8e9d58c5e
commit 971c5f77a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 5 deletions

View file

@ -1020,19 +1020,41 @@ void read_cells(pugi::xml_node node)
void populate_universes()
{
// Used to map universe index to the index of an implicit complement cell for
// DAGMC universes
std::unordered_map<int, int> implicit_comp_cells;
// Populate the Universe vector and map.
for (int i = 0; i < model::cells.size(); i++) {
int32_t uid = model::cells[i]->universe_;
for (int index_cell = 0; index_cell < model::cells.size(); index_cell++) {
int32_t uid = model::cells[index_cell]->universe_;
auto it = model::universe_map.find(uid);
if (it == model::universe_map.end()) {
model::universes.push_back(make_unique<Universe>());
model::universes.back()->id_ = uid;
model::universes.back()->cells_.push_back(i);
model::universes.back()->cells_.push_back(index_cell);
model::universe_map[uid] = model::universes.size() - 1;
} else {
model::universes[it->second]->cells_.push_back(i);
#ifdef DAGMC
// Skip implicit complement cells for now
Universe* univ = model::universes[it->second].get();
DAGUniverse* dag_univ = dynamic_cast<DAGUniverse*>(univ);
if (dag_univ && (dag_univ->implicit_complement_idx() == index_cell)) {
implicit_comp_cells[it->second] = index_cell;
continue;
}
#endif
model::universes[it->second]->cells_.push_back(index_cell);
}
}
// Add DAGUniverse implicit complement cells last
for (const auto& it : implicit_comp_cells) {
int index_univ = it.first;
int index_cell = it.second;
model::universes[index_univ]->cells_.push_back(index_cell);
}
model::universes.shrink_to_fit();
}

View file

@ -33,7 +33,7 @@ int main(int argc, char* argv[])
// Initialize acceleration data structures
rval = dag_ptr->init_OBBTree();
if (rval != moab::MB_SUCCESS) {
fatal_error("Failed to initialise OBB tree");
fatal_error("Failed to initialize OBB tree");
}
// Get rid of existing geometry
@ -62,6 +62,20 @@ int main(int argc, char* argv[])
// Add cells to universes
openmc::populate_universes();
// Make sure implicit complement appears last
auto dag_univ = dynamic_cast<DAGUniverse*>(model::universes.back().get());
int n = dag_univ->cells_.size();
for (int i = 0; i < n - 1; ++i) {
if (dag_univ->cells_[i] == dag_univ->implicit_complement_idx()) {
fatal_error("Implicit complement cell should appear last in vector of "
"cells for DAGMC universe.");
}
}
if (dag_univ->cells_.back() != dag_univ->implicit_complement_idx()) {
fatal_error(
"Last cell in DAGMC universe is not an implicit complement cell.");
}
// Set root universe
openmc::model::root_universe = openmc::find_root_universe();
openmc::check_dagmc_root_univ();