From 775cc1ae19a80242aceed019e7af624a803ab3ad Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 2 Jun 2020 09:10:13 -0500 Subject: [PATCH] Incorporating @paulromano's comments --- include/openmc/cell.h | 5 ++--- include/openmc/lattice.h | 6 +++--- src/cell.cpp | 15 ++++++++------- src/lattice.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index ba905207ee..5efbdd99ef 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -5,7 +5,6 @@ #include // for hash #include #include // for unique_ptr -#include #include #include #include @@ -153,12 +152,12 @@ public: //! Get all cell instances contained by this cell //! \return Map with cell indexes as keys and instances as values std::unordered_map> - get_contained_cells(); + get_contained_cells() const; protected: void get_contained_cells_inner(std::unordered_map>& contained_cells, - std::vector& parent_cells); + std::vector& parent_cells) const; public: //---------------------------------------------------------------------------- diff --git a/include/openmc/lattice.h b/include/openmc/lattice.h index 4fc28b76b4..bf18d92e4b 100644 --- a/include/openmc/lattice.h +++ b/include/openmc/lattice.h @@ -134,7 +134,7 @@ public: //! \param indx The index for a lattice tile. //! \return Distribcell offset i.e. the largest instance number for the target //! cell found in the geometry tree for this lattice index. - virtual int32_t& offset(int map, int indx) = 0; + virtual int32_t offset(int map, int indx) const = 0; //! \brief Convert an array index to a useful human-readable string. //! \param indx The index for a lattice tile. @@ -227,7 +227,7 @@ public: int32_t& offset(int map, const int i_xyz[3]); - int32_t& offset(int map, int indx); + int32_t offset(int map, int indx) const; std::string index_to_string(int indx) const; @@ -271,7 +271,7 @@ public: int32_t& offset(int map, const int i_xyz[3]); - int32_t& offset(int map, int indx); + int32_t offset(int map, int indx) const; std::string index_to_string(int indx) const; diff --git a/src/cell.cpp b/src/cell.cpp index 431d40b322..2761baa44f 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -275,8 +276,8 @@ Cell::set_temperature(double T, int32_t instance, bool set_contained) auto& cell = model::cells[entry.first]; Expects(cell->type_ == Fill::MATERIAL); auto& instances = entry.second; - for (auto instance = instances.begin(); instance != instances.end(); ++instance) { - cell->set_temperature(T, *instance); + for (auto instance : instances) { + cell->set_temperature(T, instance); } } } @@ -1176,7 +1177,7 @@ openmc_cell_set_name(int32_t index, const char* name) { std::unordered_map> -Cell::get_contained_cells() { +Cell::get_contained_cells() const { std::unordered_map> contained_cells; std::vector parent_cells; @@ -1191,20 +1192,20 @@ 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) + std::vector& parent_cells) const { // filled by material, determine instance based on parent cells if (this->type_ == Fill::MATERIAL) { int instance = 0; if (this->distribcell_index_ >= 0) { - for (int i = 0; i < parent_cells.size(); i++) { - auto& cell = model::cells[parent_cells[i].cell_index]; + for (auto& parent_cell : parent_cells) { + auto& cell = openmc::model::cells[parent_cell.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].lattice_index); + instance += lattice->offset(this->distribcell_index_, parent_cell.lattice_index); } } } diff --git a/src/lattice.cpp b/src/lattice.cpp index a3287982a3..f0c3dc979f 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -342,8 +342,8 @@ RectLattice::offset(int map, const int i_xyz[3]) //============================================================================== -int32_t& -RectLattice::offset(int map, int indx) +int32_t +RectLattice::offset(int map, int indx) const { return offsets_[nx*ny*nz*map + indx]; } @@ -981,8 +981,8 @@ HexLattice::offset(int map, const int i_xyz[3]) return offsets_[nx*ny*nz*map + nx*ny*i_xyz[2] + nx*i_xyz[1] + i_xyz[0]]; } -int32_t& -HexLattice::offset(int map, int indx) +int32_t +HexLattice::offset(int map, int indx) const { int nx {2*n_rings_ - 1}; int ny {2*n_rings_ - 1};