[WIP] started region refactor

This commit is contained in:
Paul Romano 2022-09-08 11:24:08 -05:00
parent aea5628819
commit 9127ff4f5e
2 changed files with 43 additions and 4 deletions

View file

@ -52,8 +52,41 @@ extern vector<unique_ptr<Cell>> 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<int32_t>::iterator start, vector<int32_t>::iterator stop);
//! Definition of spatial region as Boolean expression of half-spaces
// TODO: Should this be a vector of some other type
vector<int32_t> 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<double> sqrtkT_;
// TODO: Probably move this guy to CSGCell
//! Definition of spatial region as Boolean expression of half-spaces
vector<int32_t> 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<int32_t>::iterator find_left_parenthesis(
vector<int32_t>::iterator start, const vector<int32_t>& rpn);
private:
Region region_;
};
//==============================================================================

View file

@ -43,6 +43,7 @@ vector<unique_ptr<Cell>> cells;
//! operators.
//==============================================================================
// TODO: Move this to be Region::Region(...)
vector<int32_t> tokenize(const std::string region_spec)
{
// Check for an empty region_spec first.
@ -183,7 +184,8 @@ void add_precedence(std::vector<int32_t>& 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 {};