From 1d02c874660dea68c0ef248881f684ea8b239451 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 15 Jul 2019 15:02:07 -0500 Subject: [PATCH] Some self-review. --- include/openmc/surface.h | 13 +++++++++++-- openmc/capi/core.py | 3 ++- src/cell.cpp | 21 +++++++++++---------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 2b6c5cd0c9..6a688c2403 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -31,6 +31,7 @@ extern "C" const int BC_PERIODIC; //============================================================================== class Surface; + struct BoundingBox; namespace model { @@ -51,7 +52,7 @@ struct BoundingBox double zmin = -INFTY; double zmax = INFTY; - // in-place update + // in-place update to include another bounding box inline void update(const BoundingBox& other) { xmin = std::min(xmin, other.xmin); xmax = std::max(xmax, other.xmax); @@ -61,7 +62,7 @@ struct BoundingBox zmax = std::max(zmax, other.zmax); }; - // in-place intersection + // in-place intersection with another bounding box inline void intersect(const BoundingBox& other) { xmin = std::max(xmin, other.xmin); xmax = std::min(xmax, other.xmax); @@ -298,6 +299,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double y0_, z0_, radius_; }; @@ -317,6 +319,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double x0_, z0_, radius_; }; @@ -336,6 +339,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double x0_, y0_, radius_; }; @@ -355,6 +359,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double x0_, y0_, z0_, radius_; }; @@ -374,6 +379,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double x0_, y0_, z0_, radius_sq_; }; @@ -393,6 +399,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double x0_, y0_, z0_, radius_sq_; }; @@ -412,6 +419,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + double x0_, y0_, z0_, radius_sq_; }; @@ -430,6 +438,7 @@ public: Direction normal(Position r) const; void to_hdf5_inner(hid_t group_id) const; BoundingBox bounding_box(bool pos_side) const; + // Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0 double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_; }; diff --git a/openmc/capi/core.py b/openmc/capi/core.py index a3ae6a2199..d37e0de757 100644 --- a/openmc/capi/core.py +++ b/openmc/capi/core.py @@ -73,7 +73,8 @@ _dll.openmc_simulation_finalize.errcheck = _error_handler _dll.openmc_statepoint_write.argtypes = [c_char_p, POINTER(c_bool)] _dll.openmc_statepoint_write.restype = c_int _dll.openmc_statepoint_write.errcheck = _error_handler -_dll.openmc_bounding_box.argtypes = [c_char_p, c_int, POINTER(c_double), +_dll.openmc_bounding_box.argtypes = [c_char_p, c_int, + POINTER(c_double), POINTER(c_double)] _dll.openmc_bounding_box.restype = c_int _dll.openmc_bounding_box.errcheck = _error_handler diff --git a/src/cell.cpp b/src/cell.cpp index 586ccf2204..a9c40ac24b 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -594,9 +594,11 @@ BoundingBox CSGCell::bounding_box_complex(std::vector rpn) const { rpn.pop_back(); while (rpn.size()) { + // move through the rpn in twos int32_t one = rpn.back(); rpn.pop_back(); int32_t two = rpn.back(); rpn.pop_back(); + // the first token should always be a surface assert(one < OP_UNION); if (two >= OP_UNION) { @@ -605,19 +607,20 @@ BoundingBox CSGCell::bounding_box_complex(std::vector rpn) const { } else if (two == OP_INTERSECTION) { current.intersect(model::surfaces[abs(one)-1]->bounding_box(one > 0)); } - } else { // two surfaces in a row, create sub-rpn for parenthesis + } else { + // two surfaces in a row, create sub-rpn for region in parenthesis std::vector subrpn; subrpn.push_back(one); subrpn.push_back(two); int32_t sone = one; int32_t stwo = two; - // add until last two tokens are operators + // add until last two tokens in the sub-rpn are operators while ((subrpn.back() < OP_UNION) || (*(subrpn.rbegin() + 1) < OP_UNION)) { subrpn.push_back(rpn.back()); rpn.pop_back(); } - // handle complement case + // handle complement case using De Morgan's laws if (subrpn.back() == OP_COMPLEMENT) { subrpn.pop_back(); for (auto& token : subrpn) { @@ -628,10 +631,12 @@ BoundingBox CSGCell::bounding_box_complex(std::vector rpn) const { subrpn.push_back(rpn.back()); rpn.pop_back(); } - // get bbox for the subrpn - int32_t op = subrpn.back(); - subrpn.pop_back(); + // save the last operator, tells us how to combine this region + // with our current bounding box + int32_t op = subrpn.back(); subrpn.pop_back(); + // get bounding box for the subrpn BoundingBox sub_box = bounding_box_complex(subrpn); + // combine the sub-rpn bounding box with our current cell box if (op == OP_UNION) { current.update(sub_box); } else if (op == OP_INTERSECTION) { @@ -644,16 +649,12 @@ BoundingBox CSGCell::bounding_box_complex(std::vector rpn) const { } BoundingBox CSGCell::bounding_box() const { - if (rpn_.size() == 0) { - return {-INFTY, INFTY, -INFTY, INFTY, -INFTY, INFTY}; - } else { if (simple_) { return bounding_box_simple(); } else { return bounding_box_complex(rpn_); } - } } //==============================================================================