Removed second region expression so search finding relys on region_

This commit is contained in:
myerspat 2022-08-15 10:18:45 -04:00
parent a3c15fb07f
commit 809863c15c
4 changed files with 27 additions and 33 deletions

View file

@ -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<ParentCell> find_parent_cells(
int32_t instance, Particle& p) const;
vector<ParentCell> 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<ParentCell> exhaustive_find_parent_cells(
int32_t instance) const;
vector<ParentCell> 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<std::int32_t> region_;
//! Revised infix notation with no complements
vector<std::int32_t> region_no_complements_;
vector<std::int32_t> rpn_;
bool simple_; //!< Does the region contain only intersections?
//! \brief Neighboring cells in the same universe.

View file

@ -108,7 +108,7 @@ vector<int32_t> 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<int32_t>& 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<double, int32_t> CSGCell::distance(
double min_dist {INFTY};
int32_t i_surf {std::numeric_limits<int32_t>::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<int32_t> 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;

View file

@ -154,7 +154,7 @@ void partition_universes()
// Collect the set of surfaces in this universe.
std::unordered_set<int32_t> 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);
}

View file

@ -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<const SurfaceZPlane*>(surf)) {