From 64e93c930c1fe45f6784f7a09edf5fc0eb499ace Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 18 Aug 2021 08:52:10 -0500 Subject: [PATCH] Moving the compute_instance method to the ParentCellStack and adding some documentation there. --- include/openmc/cell.h | 26 +++++++++++++++++--------- src/cell.cpp | 12 +++++++----- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 0e3e4b5df..6cce58f7a 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -321,27 +321,42 @@ struct ParentCell { gsl::index lattice_index; }; +struct ParentCellHash { + std::size_t operator()(const ParentCell& p) const + { + return 4096*p.cell_index + p.lattice_index; + } +}; + struct ParentCellStack { + //! push method that adds to the parent_cells visited cells for this search universe void push(int32_t search_universe, const ParentCell& pc) { parent_cells_.push_back(pc); // add parent cell to the set of cells we've visited for this search universe visited_cells_[search_universe].insert(pc); } + //! removes the last parent_cell and clears the visited cells for the popped cell's universe void pop() { visited_cells_[this->current_univ()].clear(); parent_cells_.pop_back(); } - bool visited(int32_t univ_idx, const ParentCell& parent_cell) { - return visited_cells_[univ_idx].count(parent_cell) != 0; + //! checks whether or not the parent cell has been visited already for this search universe + bool visited(int32_t search_universe, const ParentCell& parent_cell) { + return visited_cells_[search_universe].count(parent_cell) != 0; } + //! return the next universe to search for a parent cell int32_t current_univ() const { return model::cells[parent_cells_.back().cell_index]->universe_; } + //! indicates whether nor not parent cells are present on the stack bool empty() const { return parent_cells_.empty(); } + //! compute an instance for the provided distribcell index + 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_; } @@ -351,13 +366,6 @@ struct ParentCellStack { std::unordered_map> visited_cells_; }; -struct ParentCellHash { - std::size_t operator()(const ParentCell& p) const - { - return 4096*p.cell_index + p.lattice_index; - } -}; - //============================================================================== //! Define an instance of a particular cell //============================================================================== diff --git a/src/cell.cpp b/src/cell.cpp index 60e7f89f3..9bfe2be31 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -1266,7 +1266,7 @@ Cell::find_parent_cells(vector& parent_cells, int32_t instance) cons } // if we're at the top of the geometry and the instance matches, we're done - if (univ_idx == model::root_universe && this->compute_instance(stack.parent_cells()) == instance) break; + 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 (univ_idx == this->universe_) { @@ -1286,15 +1286,17 @@ Cell::find_parent_cells(vector& parent_cells, int32_t instance) cons return stack.parent_cells(); } -int32_t Cell::compute_instance(const vector& parent_cells) const { +int32_t +ParentCellStack::compute_instance(int32_t distribcell_index) const +{ int32_t instance = 0; - for (const auto& parent_cell : parent_cells) { + for (const auto& parent_cell : this->parent_cells_) { auto& cell = model::cells[parent_cell.cell_index]; if (cell->type_ == Fill::UNIVERSE) { - instance += cell->offset_[this->distribcell_index_]; + instance += cell->offset_[distribcell_index]; } else if (cell->type_ == Fill::LATTICE) { auto& lattice = model::lattices[cell->fill_]; - instance += lattice->offset(this->distribcell_index_, parent_cell.lattice_index); + instance += lattice->offset(distribcell_index, parent_cell.lattice_index); } } return instance;