Skip to content

Commit

Permalink
Ensure that implicit complement cells appear last in DAGMC universes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano authored Jan 15, 2024
1 parent d8e9d58 commit 971c5f7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
16 changes: 15 additions & 1 deletion tests/regression_tests/dagmc/external/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 971c5f7

Please sign in to comment.