From e5e1c6eccc389538a9be25b89b87b3255e2cf265 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 18 Aug 2021 09:20:29 -0500 Subject: [PATCH] Adding a few more comments. Changing to use of openmc::vector. --- include/openmc/cell.h | 15 ++++++++------- src/cell.cpp | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 6cce58f7a8..ac0c324300 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -166,10 +166,6 @@ public: //! \param[in] name Cell name void set_name(const std::string& name) { name_ = name; }; - //! Determine the path to this cell instance in the geometry hierarchy - vector - find_parent_cells(vector& parent_cells, int32_t instance) const; - //! Compute the cell's instance given a set of parent cells int32_t compute_instance(const vector& parent_cells) const; @@ -178,6 +174,11 @@ public: std::unordered_map> get_contained_cells(int32_t instance=0) const; protected: + //! Determine the path to this cell instance in the geometry hierarchy + vector + find_parent_cells(vector& parent_cells, int32_t instance) const; + + //! Inner function for retrieving contained cells void get_contained_cells_inner( std::unordered_map>& contained_cells, vector& parent_cells) const; @@ -358,11 +359,11 @@ struct ParentCellStack { int32_t compute_instance(int32_t distribcell_index) const; // Accessors - std::vector& parent_cells() { return parent_cells_; } - const std::vector& parent_cells() const { return parent_cells_; } + vector& parent_cells() { return parent_cells_; } + const vector& parent_cells() const { return parent_cells_; } // Data Members - std::vector parent_cells_; + vector parent_cells_; std::unordered_map> visited_cells_; }; diff --git a/src/cell.cpp b/src/cell.cpp index 9bfe2be31f..0e7adcdf64 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -1224,26 +1224,33 @@ Cell::find_parent_cells(vector& parent_cells, int32_t instance) cons { ParentCellStack stack; // start with this cell's universe - int32_t prev_univ_idx = C_NONE; + int32_t prev_univ_idx; int32_t univ_idx = this->universe_; while (true) { const auto& univ = model::universes[univ_idx]; prev_univ_idx = univ_idx; + + // search for a cell that is filled w/ this universe for (const auto& cell : model::cells) { - // if this is in our current set of visited cells, move on - if (stack.visited(univ_idx, {model::cell_map[cell->id_], C_NONE})) continue; // if this is a material-filled cell, move on if (cell->type_ == Fill::MATERIAL) continue; if (cell->type_ == Fill::UNIVERSE) { + // if this is in the set of cells previously visited for this universe, move on + if (stack.visited(univ_idx, {model::cell_map[cell->id_], C_NONE})) continue; + + // if this cell contains the universe we're searching for, add it to the stack if(cell->fill_ == univ_idx) { stack.push(univ_idx, {model::cell_map[cell->id_], C_NONE}); univ_idx = cell->universe_; } } else if (cell->type_ == Fill::LATTICE) { + // retrieve the lattice and lattice universes const auto& lattice = model::lattices[cell->fill_]; const auto& lattice_univs = lattice->universes_; + + // start search for universe auto lat_it = lattice_univs.begin(); while (true) { // find the next lattice cell with this universe @@ -1252,10 +1259,11 @@ Cell::find_parent_cells(vector& parent_cells, int32_t instance) cons int lattice_idx = lat_it - lattice_univs.begin(); + // move iterator forward one to avoid finding the same entry lat_it++; - if (stack.visited(univ_idx, {model::cell_map[cell->id_], lattice_idx})) continue; + // add this cell and lattice index to the stack and exit loop stack.push(univ_idx, {model::cell_map[cell->id_], lattice_idx}); univ_idx = cell->universe_; break; @@ -1263,12 +1271,12 @@ Cell::find_parent_cells(vector& parent_cells, int32_t instance) cons } // if we've updated the universe, break if (prev_univ_idx != univ_idx) break; - } + } // end cell loop search for universe // if we're at the top of the geometry and the instance matches, we're done if (univ_idx == model::root_universe && stack.compute_instance(this->distribcell_index_) == instance) break; - // if there was no match on the current cell's universe, report an error + // if there is no match on the original cell's universe, report an error if (univ_idx == this->universe_) { fatal_error(fmt::format("Could not find the parent cells for cell {}, instance {}.", this->id_, instance)); }