From 329394824893e63170139b6785affa3d5f68a79e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Mar 2021 14:58:18 -0500 Subject: [PATCH] 65;6003;1cAdding a find_cell method to universes. --- include/openmc/cell.h | 2 ++ src/cell.cpp | 25 +++++++++++++++++++++++++ src/geometry.cpp | 27 +++------------------------ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index b7f18a116f..54e06f782e 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -70,6 +70,8 @@ public: //! \param group_id An HDF5 group id. void to_hdf5(hid_t group_id) const; + virtual bool find_cell(Particle &p) const; + BoundingBox bounding_box() const; GeometryType type_ = GeometryType::CSG; diff --git a/src/cell.cpp b/src/cell.cpp index 63edf644be..4dee4730f0 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -212,6 +212,31 @@ Universe::to_hdf5(hid_t universes_group) const close_group(group); } +bool +Universe::find_cell(Particle& p) const { + const auto& cells { + !partitioner_ + ? cells_ + : partitioner_->get_cells(p.r_local(), p.u_local()) + }; + + for (auto it = cells.begin(); it != cells.end(); it++) { + int32_t i_cell = *it; + int32_t i_univ = p.coord_[p.n_coord_-1].universe; + if (model::cells[i_cell]->universe_ != i_univ) continue; + + // Check if this cell contains the particle; + Position r {p.r_local()}; + Direction u {p.u_local()}; + auto surf = p.surface_; + if (model::cells[i_cell]->contains(r, u, surf)) { + p.coord_[p.n_coord_-1].cell = i_cell; + return true; + } + } + return false; +} + BoundingBox Universe::bounding_box() const { BoundingBox bbox = {INFTY, -INFTY, INFTY, -INFTY, INFTY, -INFTY}; if (cells_.size() == 0) { diff --git a/src/geometry.cpp b/src/geometry.cpp index 59607f637a..7e7b3b1729 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -112,34 +112,13 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) // that. if (i_cell == C_NONE) { int i_universe = p.coord(p.n_coord() - 1).universe; - const auto& univ {*model::universes[i_universe]}; - const auto& cells { - !univ.partitioner_ - ? model::universes[i_universe]->cells_ - : univ.partitioner_->get_cells(p.r_local(), p.u_local()) - }; - - for (auto it = cells.cbegin(); it != cells.cend(); it++) { - i_cell = *it; - - // Make sure the search cell is in the same universe. - int i_universe = p.coord(p.n_coord() - 1).universe; - if (model::cells[i_cell]->universe_ != i_universe) continue; - - // Check if this cell contains the particle. - Position r {p.r_local()}; - Direction u {p.u_local()}; - auto surf = p.surface(); - if (model::cells[i_cell]->contains(r, u, surf)) { - p.coord(p.n_coord() - 1).cell = i_cell; - found = true; - break; - } - } + const auto& univ {model::universes[i_universe]}; + found = univ->find_cell(p); } if (!found) { return found; } + i_cell = p.coord_[p.n_coord_ - 1].cell; // Announce the cell that the particle is entering. if (found && (settings::verbosity >= 10 || p.trace())) {