From ad2aa90879affd54df2a493162dc2f07d6527169 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 15 May 2020 20:55:01 -0500 Subject: [PATCH] Making an inner function for the recursion to clean up the exerior API. --- include/openmc/cell.h | 10 +++++++--- src/cell.cpp | 25 +++++++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 5c8a30f34..352750cd0 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -76,7 +76,6 @@ public: }; //============================================================================== -//! A geometry primitive that links surfaces, universes, and materials //============================================================================== class Cell { @@ -148,8 +147,13 @@ public: void set_name(const std::string& name) { name_ = name; }; //! Get all cell instances contained by this cell - void get_contained_cells(std::unordered_map>& contained_cells, - std::vector& parent_cells); + //! \return Map with cell indexes as keys and instances as values + std::unordered_map> + get_contained_cells(); + + void + get_contained_cells_inner(std::unordered_map>& contained_cells, + std::vector& parent_cells); //---------------------------------------------------------------------------- // Data members diff --git a/src/cell.cpp b/src/cell.cpp index 10f90fdbe..6364a375b 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -269,15 +269,13 @@ Cell::set_temperature(double T, int32_t instance, bool set_contained_cells) throw std::runtime_error{fmt::format("Attempted to set the temperature of cell {} " "which is not filled by a material.", id_)}; } - std::unordered_map> contained_cells; - std::vector parent_cells; - this->get_contained_cells(contained_cells, parent_cells); + auto contained_cells = this->get_contained_cells(); for (const auto& entry : contained_cells) { auto& cell = model::cells[entry.first]; + Expects(cell->type_ == Fill::MATERIAL); auto& instances = entry.second; for (auto instance = instances.begin(); instance != instances.end(); ++instance) { - Expects(cell->type_ == Fill::MATERIAL); cell->set_temperature(T, *instance); } } @@ -1176,10 +1174,21 @@ openmc_cell_set_name(int32_t index, const char* name) { return 0; } + +std::unordered_map> +Cell::get_contained_cells() { + std::unordered_map> contained_cells; + std::vector parent_cells; + + this->get_contained_cells_inner(contained_cells, parent_cells); + + return contained_cells; +} + //! Get all cells within this cell void -Cell::get_contained_cells(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 @@ -1204,7 +1213,7 @@ Cell::get_contained_cells(std::unordered_map>& contai auto& univ = model::universes[fill_]; for(auto cell_index : univ->cells_) { auto& cell = model::cells[cell_index]; - cell->get_contained_cells(contained_cells, parent_cells); + cell->get_contained_cells_inner(contained_cells, parent_cells); } parent_cells.pop_back(); // filled with a lattice, visit each universe in the lattice @@ -1216,7 +1225,7 @@ Cell::get_contained_cells(std::unordered_map>& contai parent_cells.push_back({model::cell_map[this->id_], i.indx_}); for (auto cell_index : univ->cells_) { auto& cell = model::cells[cell_index]; - cell->get_contained_cells(contained_cells, parent_cells); + cell->get_contained_cells_inner(contained_cells, parent_cells); } parent_cells.pop_back(); }