From 08239a98d276e897f0bdffec6826727531817841 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 21 Jun 2019 14:51:06 -0500 Subject: [PATCH] Adding a bounding box method to the universe class. --- include/openmc/cell.h | 2 ++ src/cell.cpp | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index b4848bb50..a6432a304 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -65,6 +65,8 @@ public: //! \param group_id An HDF5 group id. void to_hdf5(hid_t group_id) const; + BoundingBox bounding_box() const; + std::unique_ptr partitioner_; }; diff --git a/src/cell.cpp b/src/cell.cpp index ebf466bd6..107724c61 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -208,6 +208,19 @@ Universe::to_hdf5(hid_t universes_group) const close_group(group); } +BoundingBox Universe::bounding_box() const { + BoundingBox bbox; + if (cells_.size() == 0) { + bbox = {-INFTY, INFTY, -INFTY, -INFTY, INFTY}; + } else { + for (const auto& cell : cells_) { + auto& c = model::cells[cell]; + bbox.update(c->bounding_box()); + } + } + return bbox; +} + //============================================================================== // Cell implementation //============================================================================== @@ -569,9 +582,14 @@ CSGCell::to_hdf5(hid_t cell_group) const BoundingBox CSGCell::bounding_box() const { BoundingBox bbox; - for (int32_t token : rpn_) { - bbox.update(model::surfaces[abs(token)-1]->bounding_box(token > 0)); + if (rpn_.size() == 0) { + bbox = {-INFTY, INFTY, -INFTY, INFTY, -INFTY, INFTY}; + } else { + for (int32_t token : rpn_) { + bbox.update(model::surfaces[abs(token)-1]->bounding_box(token > 0)); + } } + return bbox; } //==============================================================================