From 809863c15ca760a708b62b5e844ebcb4aad2d3b7 Mon Sep 17 00:00:00 2001 From: myerspat Date: Mon, 15 Aug 2022 10:18:45 -0400 Subject: [PATCH] Removed second region expression so search finding relys on region_ --- include/openmc/cell.h | 9 ++------- src/cell.cpp | 45 +++++++++++++++++++++---------------------- src/geometry_aux.cpp | 2 +- src/universe.cpp | 4 ++-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 4d07b26199..0004a86c6f 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -160,14 +160,12 @@ protected: //! \param[in] instance of the cell to find parent cells for //! \param[in] p particle used to do a fast search for parent cells //! \return parent cells - vector find_parent_cells( - int32_t instance, Particle& p) const; + vector find_parent_cells(int32_t instance, Particle& p) const; //! Determine the path to this cell instance in the geometry hierarchy //! \param[in] instance of the cell to find parent cells for //! \return parent cells - vector exhaustive_find_parent_cells( - int32_t instance) const; + vector exhaustive_find_parent_cells(int32_t instance) const; //! Inner function for retrieving contained cells void get_contained_cells_inner( @@ -202,9 +200,6 @@ public: //! Definition of spatial region as Boolean expression of half-spaces 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 12fb9f6740..8224ba2665 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -108,7 +108,7 @@ vector tokenize(const std::string region_spec) } //============================================================================== -//! Add precedence for infix cell finding so intersections have higher +//! Add precedence for infix regions so intersections have higher //! precedence than unions using parenthesis. //============================================================================== @@ -165,11 +165,17 @@ void add_precedence(std::vector& infix) for (auto it = infix.begin(); it != infix.end(); it++) { int32_t token = *it; + // If the token is a union another operator has not been found set the + // current operator to union + // If the current operator is a union and the token is an intersection + // assert precedence + // If the token is a parenthesis reset the current operator if (token == OP_UNION && current_op == 0) { current_op = OP_UNION; } else if (current_op == OP_UNION && token == OP_INTERSECTION) { it = add_parenthesis(it - 1, infix); + current_op = 0; } else if (token > OP_COMPLEMENT) { current_op = 0; @@ -567,8 +573,10 @@ CSGCell::CSGCell(pugi::xml_node cell_node) region_spec = get_node_value(cell_node, "region"); } - // Get a tokenized representation of the region specification + // Get a tokenized representation of the region specification and apply De + // Morgans law region_ = tokenize(region_spec); + remove_complement_ops(region_); region_.shrink_to_fit(); // Convert user IDs to surface indices. @@ -584,33 +592,26 @@ CSGCell::CSGCell(pugi::xml_node cell_node) } } - // Remove complement operators using De Morgan's law - region_no_complements_ = region_; - remove_complement_ops(region_no_complements_); - // Check if this is a simple cell. simple_ = true; - for (int32_t token : region_no_complements_) { + for (int32_t token : region_) { if (token == OP_UNION) { simple_ = false; + // Ensure intersections have precedence over unions + add_precedence(region_); break; } } // If this cell is simple, remove all the superfluous operator tokens. if (simple_) { - for (auto it = region_no_complements_.begin(); - it != region_no_complements_.end(); it++) { + for (auto it = region_.begin(); it != region_.end(); it++) { if (*it == OP_INTERSECTION || *it > OP_COMPLEMENT) { - region_no_complements_.erase(it); + region_.erase(it); } } - } 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(); + region_.shrink_to_fit(); // Read the translation vector. if (check_for_node(cell_node, "translation")) { @@ -654,7 +655,7 @@ std::pair CSGCell::distance( double min_dist {INFTY}; int32_t i_surf {std::numeric_limits::max()}; - for (int32_t token : region_no_complements_) { + for (int32_t token : region_) { // Ignore this token if it corresponds to an operator rather than a region. if (token >= OP_UNION) continue; @@ -709,7 +710,7 @@ void CSGCell::to_hdf5_inner(hid_t group_id) const BoundingBox CSGCell::bounding_box_simple() const { BoundingBox bbox; - for (int32_t token : region_no_complements_) { + for (int32_t token : region_) { bbox &= model::surfaces[abs(token) - 1]->bounding_box(token > 0); } return bbox; @@ -819,15 +820,14 @@ BoundingBox CSGCell::bounding_box_complex(vector rpn) BoundingBox CSGCell::bounding_box() const { - return simple_ ? bounding_box_simple() - : bounding_box_complex(rpn_); + return simple_ ? bounding_box_simple() : bounding_box_complex(region_); } //============================================================================== bool CSGCell::contains_simple(Position r, Direction u, int32_t on_surface) const { - for (int32_t token : region_no_complements_) { + for (int32_t token : region_) { // Assume that no tokens are operators. Evaluate the sense of particle with // respect to the surface and see if the token matches the sense. If the // particle's surface attribute is set and matches the token, that @@ -854,8 +854,7 @@ bool CSGCell::contains_complex( bool in_cell = true; // For each token - for (auto it = region_no_complements_.begin(); - it != region_no_complements_.end(); it++) { + for (auto it = region_.begin(); it != region_.end(); it++) { int32_t token = *it; // If the token is a surface evaluate the sense @@ -899,7 +898,7 @@ bool CSGCell::contains_complex( break; } } - } while (it < region_no_complements_.end() - 1); + } while (it < region_.end() - 1); } } return in_cell; diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index 881af15b76..c3458d4697 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -154,7 +154,7 @@ void partition_universes() // Collect the set of surfaces in this universe. std::unordered_set surf_inds; for (auto i_cell : univ->cells_) { - for (auto token : model::cells[i_cell]->region_no_complements_) { + for (auto token : model::cells[i_cell]->region_) { if (token < OP_UNION) surf_inds.insert(std::abs(token) - 1); } diff --git a/src/universe.cpp b/src/universe.cpp index dc6f751c23..873d03bb74 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -98,7 +98,7 @@ UniversePartitioner::UniversePartitioner(const Universe& univ) // Find all of the z-planes in this universe. A set is used here for the // O(log(n)) insertions that will ensure entries are not repeated. for (auto i_cell : univ.cells_) { - for (auto token : model::cells[i_cell]->region_no_complements_) { + for (auto token : model::cells[i_cell]->region_) { if (token < OP_UNION) { auto i_surf = std::abs(token) - 1; const auto* surf = model::surfaces[i_surf].get(); @@ -125,7 +125,7 @@ UniversePartitioner::UniversePartitioner(const Universe& univ) // Find the tokens for bounding z-planes. int32_t lower_token = 0, upper_token = 0; double min_z, max_z; - for (auto token : model::cells[i_cell]->region_no_complements_) { + for (auto token : model::cells[i_cell]->region_) { if (token < OP_UNION) { const auto* surf = model::surfaces[std::abs(token) - 1].get(); if (const auto* zplane = dynamic_cast(surf)) {