diff --git a/include/openmc/cell.h b/include/openmc/cell.h index e812fc88f0..4d07b26199 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -204,6 +204,7 @@ public: vector region_; //! Revised infix notation with no complements vector region_no_complements_; + vector rpn_; bool simple_; //!< Does the region contain only intersections? //! \brief Neighboring cells in the same universe. diff --git a/src/cell.cpp b/src/cell.cpp index fc19c1c496..c89e437acd 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -138,7 +138,17 @@ std::vector::iterator add_parenthesis( } else if (*start == OP_LEFT_PAREN) { return_iterator = start; - start = std::find(start, infix.end(), OP_RIGHT_PAREN); + int depth = 1; + do { + start++; + if (*start > OP_COMPLEMENT) { + if (*start == OP_RIGHT_PAREN) { + depth--; + } else { + depth++; + } + } + } while (depth > 0); } } @@ -598,6 +608,7 @@ CSGCell::CSGCell(pugi::xml_node cell_node) } else { // Ensure intersections have precedence over unions add_precedence(region_no_complements_); + rpn_ = generate_rpn(id_, region_no_complements_); } region_no_complements_.shrink_to_fit(); @@ -776,9 +787,6 @@ void CSGCell::remove_complement_ops(vector& infix) BoundingBox CSGCell::bounding_box_complex(vector rpn) { - // remove complements by adjusting surface signs and operators - remove_complement_ops(rpn); - vector stack(rpn.size()); int i_stack = -1; @@ -802,7 +810,7 @@ BoundingBox CSGCell::bounding_box_complex(vector rpn) BoundingBox CSGCell::bounding_box() const { return simple_ ? bounding_box_simple() - : bounding_box_complex(region_no_complements_); + : bounding_box_complex(rpn_); } //============================================================================== @@ -867,7 +875,7 @@ bool CSGCell::contains_complex( if (next_token >= OP_UNION && token != next_token) { if (next_token == OP_LEFT_PAREN) { int depth = 1; - while (depth > 0) { + do { it++; if (*it > OP_COMPLEMENT) { if (*it == OP_RIGHT_PAREN) { @@ -876,7 +884,7 @@ bool CSGCell::contains_complex( depth++; } } - } + } while (depth > 0); } else { break; }