From 7dfb35a39a553bcb7abe06447a2d8e0a2ff6dc46 Mon Sep 17 00:00:00 2001 From: myerspat Date: Wed, 27 Jul 2022 12:15:46 -0500 Subject: [PATCH] removed rpn_ and changed to only region_ --- include/openmc/cell.h | 2 -- src/cell.cpp | 32 ++++++++++++++------------------ src/geometry_aux.cpp | 2 +- src/universe.cpp | 4 ++-- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 01f037586..887901707 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -202,8 +202,6 @@ public: //! Definition of spatial region as Boolean expression of half-spaces vector region_; - //! Reverse Polish notation for region expression - 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 edd4da84d..943722f35 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -497,8 +497,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 Morgan's laws to remove complements. region_ = tokenize(region_spec); + remove_complement_ops(region_); region_.shrink_to_fit(); // Convert user IDs to surface indices. @@ -514,15 +516,9 @@ CSGCell::CSGCell(pugi::xml_node cell_node) } } - // Convert the infix region spec to infix with no complements - // using De Morgan's law. - // TODO: Convert rpn to something that makes sense - rpn_ = region_; - remove_complement_ops(rpn_); - // Check if this is a simple cell. simple_ = true; - for (int32_t token : rpn_) { + for (int32_t token : region_) { if (token == OP_UNION) { simple_ = false; break; @@ -531,13 +527,13 @@ CSGCell::CSGCell(pugi::xml_node cell_node) // If this cell is simple, remove all the superfluous operator tokens. if (simple_) { - for (auto it = rpn_.begin(); it != rpn_.end(); it++) { + for (auto it = region_.begin(); it != region_.end(); it++) { if (*it == OP_INTERSECTION || *it > OP_COMPLEMENT) { - rpn_.erase(it); + region_.erase(it); } } } - rpn_.shrink_to_fit(); + region_.shrink_to_fit(); // Read the translation vector. if (check_for_node(cell_node, "translation")) { @@ -581,7 +577,7 @@ std::pair CSGCell::distance( double min_dist {INFTY}; int32_t i_surf {std::numeric_limits::max()}; - for (int32_t token : rpn_) { + for (int32_t token : region_) { // Ignore this token if it corresponds to an operator rather than a region. if (token >= OP_UNION) continue; @@ -636,7 +632,7 @@ void CSGCell::to_hdf5_inner(hid_t group_id) const BoundingBox CSGCell::bounding_box_simple() const { BoundingBox bbox; - for (int32_t token : rpn_) { + for (int32_t token : region_) { bbox &= model::surfaces[abs(token) - 1]->bounding_box(token > 0); } return bbox; @@ -739,14 +735,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 : rpn_) { + 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 @@ -773,7 +769,7 @@ bool CSGCell::contains_complex( bool in_cell = true; // For each token - for (auto it = rpn_.begin(); it != rpn_.end(); it++) { + for (auto it = region_.begin(); it != region_.end(); it++) { int32_t token = *it; // If the token is a surface evaluate the sense @@ -801,11 +797,11 @@ bool CSGCell::contains_complex( // the next right parenthesis, if the token is a right // parenthesis leave short circuiting if (next_token == OP_LEFT_PAREN) { - it = std::find(it, rpn_.end() - 1, OP_RIGHT_PAREN); + it = std::find(it, region_.end() - 1, OP_RIGHT_PAREN); } else if (next_token == OP_RIGHT_PAREN) { break; } - } while (it < rpn_.end() - 1); + } while (it < region_.end() - 1); } } return in_cell; diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index ddce2469b..c3458d469 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]->rpn_) { + 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 f3f9cf8e8..873d03bb7 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]->rpn_) { + 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]->rpn_) { + 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)) {