diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 201c1e5bc..ef454c6e8 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -44,6 +44,7 @@ constexpr int32_t OP_UNION {std::numeric_limits::max() - 4}; //============================================================================== class Cell; +class ParentCell; class CellInstance; class Universe; class UniversePartitioner; @@ -151,13 +152,15 @@ public: //! Get all cell instances contained by this cell //! \return Map with cell indexes as keys and instances as values - std::unordered_map> + std::unordered_map> get_contained_cells(); +protected: void - get_contained_cells_inner(std::unordered_map>& contained_cells, - std::vector& parent_cells); + get_contained_cells_inner(std::unordered_map>& contained_cells, + std::vector& parent_cells); +public: //---------------------------------------------------------------------------- // Data members @@ -307,6 +310,16 @@ private: std::vector> partitions_; }; + +//============================================================================== +//! Define a containing (parent) cell +//============================================================================== + +struct ParentCell { + gsl::index cell_index; + gsl::index lattice_index; +}; + //============================================================================== //! Define an instance of a particular cell //============================================================================== diff --git a/src/cell.cpp b/src/cell.cpp index 3217f2031..08476d31f 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -1175,10 +1175,10 @@ openmc_cell_set_name(int32_t index, const char* name) { } -std::unordered_map> +std::unordered_map> Cell::get_contained_cells() { - std::unordered_map> contained_cells; - std::vector parent_cells; + std::unordered_map> contained_cells; + std::vector parent_cells; this->get_contained_cells_inner(contained_cells, parent_cells); @@ -1187,8 +1187,8 @@ Cell::get_contained_cells() { //! Get all cells within this cell void -Cell::get_contained_cells_inner(std::unordered_map>& contained_cells, - std::vector& parent_cells) +Cell::get_contained_cells_inner(std::unordered_map>& contained_cells, + std::vector& parent_cells) { // filled by material, determine instance based on parent cells @@ -1196,18 +1196,19 @@ Cell::get_contained_cells_inner(std::unordered_map>& int instance = 0; if (this->distribcell_index_ >= 0) { for (int i = 0; i < parent_cells.size(); i++) { - auto& cell = model::cells[parent_cells[i].index_cell]; + auto& cell = model::cells[parent_cells[i].cell_index]; if (cell->type_ == Fill::UNIVERSE) { instance += cell->offset_[this->distribcell_index_]; } else if (cell->type_ == Fill::LATTICE) { auto& lattice = model::lattices[cell->fill_]; - instance += lattice->offset(this->distribcell_index_, parent_cells[i].instance); + instance += lattice->offset(this->distribcell_index_, parent_cells[i].lattice_index); } } } // add entry to contained cells - contained_cells[model::cell_map[this->id_]].insert(instance); - // filled with universe, add the containing cell and recurse + contained_cells[model::cell_map[this->id_]].push_back(instance); + // filled with universe, add the containing cell to the parent cells + // and recurse } else if (this->type_ == Fill::UNIVERSE) { parent_cells.push_back({model::cell_map[this->id_], -1}); auto& univ = model::universes[fill_]; @@ -1217,7 +1218,7 @@ Cell::get_contained_cells_inner(std::unordered_map>& } parent_cells.pop_back(); // filled with a lattice, visit each universe in the lattice - // with a recursive call + // with a recursive call to collect the cell instances } else if (this->type_ == Fill::LATTICE) { auto& lattice = model::lattices[this->fill_]; for (auto i = lattice->begin(); i != lattice->end(); ++i) {