From 9127ff4f5ecacd46692784f1a75e490490d1b3f2 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 8 Sep 2022 11:24:08 -0500 Subject: [PATCH] [WIP] started region refactor --- include/openmc/cell.h | 40 ++++++++++++++++++++++++++++++++++++++-- src/cell.cpp | 7 +++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 8171967273..fcce520fed 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -52,8 +52,41 @@ extern vector> cells; } // namespace model //============================================================================== + +// TODO: Maybe not, just move this inline to Region::bounding_box() for complex +// case +class RegionPostfix { +public: + BoundingBox bounding_box() const; +}; + +class Region { +public: + Region() {} + explicit Region(std::string region_expression); + + void add_precedence(); + std::string str() const; + BoundingBox bounding_box() const; + bool contains(Position r, Direction u, int32_t on_surface) const; + + RegionPostfix to_postfix() const; + +private: + void add_parentheses(); + void apply_demorgan( + vector::iterator start, vector::iterator stop); + + //! Definition of spatial region as Boolean expression of half-spaces + // TODO: Should this be a vector of some other type + vector tokens_; + bool simple_; //!< Does the region contain only intersections? +}; + //============================================================================== +// TODO: Think about what data members really need to live in this class versus +// putting them in the Region class class Cell { public: //---------------------------------------------------------------------------- @@ -198,9 +231,9 @@ public: //! T. The units are sqrt(eV). vector sqrtkT_; + // TODO: Probably move this guy to CSGCell //! Definition of spatial region as Boolean expression of half-spaces - vector region_; - bool simple_; //!< Does the region contain only intersections? + Region region_; //! \brief Neighboring cells in the same universe. NeighborList neighbors_; @@ -263,6 +296,9 @@ protected: //! \param rpn The rpn being searched static vector::iterator find_left_parenthesis( vector::iterator start, const vector& rpn); + +private: + Region region_; }; //============================================================================== diff --git a/src/cell.cpp b/src/cell.cpp index 4ff35498c6..4eb0fa0b95 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -43,6 +43,7 @@ vector> cells; //! operators. //============================================================================== +// TODO: Move this to be Region::Region(...) vector tokenize(const std::string region_spec) { // Check for an empty region_spec first. @@ -183,7 +184,8 @@ void add_precedence(std::vector& infix) // Set the current operator if is hasn't been set current_op = token; } else if (token != current_op) { - // If the current operator doesn't match the token, add parenthesis to assert precedence + // If the current operator doesn't match the token, add parenthesis to + // assert precedence it = add_parentheses(it, infix); current_op = 0; } @@ -586,7 +588,7 @@ CSGCell::CSGCell(pugi::xml_node cell_node) // Get a tokenized representation of the region specification and apply De // Morgans law - region_ = tokenize(region_spec); + region_ = Region(region_spec); remove_complement_ops(region_); // Convert user IDs to surface indices. @@ -696,6 +698,7 @@ void CSGCell::to_hdf5_inner(hid_t group_id) const write_string(group_id, "geom_type", "csg", false); + // TODO: Move to Region::str() // Write the region specification. if (!region_.empty()) { std::stringstream region_spec {};