Skip to content

Commit 80c8692

Browse files
committed
Removed one of the region vectors and changed HDF5 output for geometry
1 parent c74e6a8 commit 80c8692

4 files changed

Lines changed: 29 additions & 28 deletions

File tree

‎include/openmc/cell.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ class Cell {
200200

201201
//! Definition of spatial region as Boolean expression of half-spaces
202202
vector<int32_t> region_;
203-
//! Region in infix that may be modified depending on simplicity
204-
vector<int32_t> region_infix_;
205203
bool simple_; //!< Does the region contain only intersections?
206204

207205
//! \brief Neighboring cells in the same universe.

‎src/cell.cpp‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void add_precedence(std::vector<int32_t>& infix)
205205
//! This function uses the shunting-yard algorithm.
206206
//==============================================================================
207207

208-
vector<int32_t> generate_rpn(int32_t cell_id, vector<int32_t> infix)
208+
vector<int32_t> generate_postfix(int32_t cell_id, vector<int32_t> infix)
209209
{
210210
vector<int32_t> rpn;
211211
vector<int32_t> stack;
@@ -619,15 +619,14 @@ CSGCell::CSGCell(pugi::xml_node cell_node)
619619
}
620620
region_.shrink_to_fit();
621621

622-
region_infix_ = region_;
623622
// If this cell is simple, remove all the superfluous operator tokens.
624623
if (simple_) {
625-
for (auto it = region_infix_.begin(); it != region_infix_.end(); it++) {
624+
for (auto it = region_.begin(); it != region_.end(); it++) {
626625
if (*it == OP_INTERSECTION || *it > OP_COMPLEMENT) {
627-
region_infix_.erase(it);
626+
region_.erase(it);
628627
}
629628
}
630-
region_infix_.shrink_to_fit();
629+
region_.shrink_to_fit();
631630
}
632631

633632
// Read the translation vector.
@@ -672,7 +671,7 @@ std::pair<double, int32_t> CSGCell::distance(
672671
double min_dist {INFTY};
673672
int32_t i_surf {std::numeric_limits<int32_t>::max()};
674673

675-
for (int32_t token : region_infix_) {
674+
for (int32_t token : region_) {
676675
// Ignore this token if it corresponds to an operator rather than a region.
677676
if (token >= OP_UNION)
678677
continue;
@@ -705,19 +704,18 @@ void CSGCell::to_hdf5_inner(hid_t group_id) const
705704
if (!region_.empty()) {
706705
std::stringstream region_spec {};
707706
for (int32_t token : region_) {
708-
if (token == OP_LEFT_PAREN) {
709-
region_spec << " (";
710-
} else if (token == OP_RIGHT_PAREN) {
711-
region_spec << " )";
712-
} else if (token == OP_COMPLEMENT) {
713-
region_spec << " ~";
714-
} else if (token == OP_INTERSECTION) {
715-
} else if (token == OP_UNION) {
716-
region_spec << " |";
717-
} else {
707+
if (token < OP_UNION) {
718708
// Note the off-by-one indexing
719709
auto surf_id = model::surfaces[abs(token) - 1]->id_;
720710
region_spec << " " << ((token > 0) ? surf_id : -surf_id);
711+
} else if (token > OP_COMPLEMENT) {
712+
if (token == OP_LEFT_PAREN) {
713+
region_spec << " (";
714+
} else {
715+
region_spec << " )";
716+
}
717+
} else if (token == OP_UNION) {
718+
region_spec << " |";
721719
}
722720
}
723721
write_string(group_id, "region", region_spec.str(), false);
@@ -727,7 +725,7 @@ void CSGCell::to_hdf5_inner(hid_t group_id) const
727725
BoundingBox CSGCell::bounding_box_simple() const
728726
{
729727
BoundingBox bbox;
730-
for (int32_t token : region_infix_) {
728+
for (int32_t token : region_) {
731729
bbox &= model::surfaces[abs(token) - 1]->bounding_box(token > 0);
732730
}
733731
return bbox;
@@ -813,12 +811,12 @@ void CSGCell::remove_complement_ops(vector<int32_t>& infix)
813811
}
814812
}
815813

816-
BoundingBox CSGCell::bounding_box_complex(vector<int32_t> rpn)
814+
BoundingBox CSGCell::bounding_box_complex(vector<int32_t> postfix)
817815
{
818-
vector<BoundingBox> stack(rpn.size());
816+
vector<BoundingBox> stack(postfix.size());
819817
int i_stack = -1;
820818

821-
for (auto& token : rpn) {
819+
for (auto& token : postfix) {
822820
if (token == OP_UNION) {
823821
stack[i_stack - 1] = stack[i_stack - 1] | stack[i_stack];
824822
i_stack--;
@@ -837,14 +835,19 @@ BoundingBox CSGCell::bounding_box_complex(vector<int32_t> rpn)
837835

838836
BoundingBox CSGCell::bounding_box() const
839837
{
840-
return simple_ ? bounding_box_simple() : bounding_box_complex(region_infix_);
838+
if (simple_) {
839+
return bounding_box_simple();
840+
} else {
841+
auto postfix = generate_postfix(this->id_, this->region_);
842+
return bounding_box_complex(postfix);
843+
}
841844
}
842845

843846
//==============================================================================
844847

845848
bool CSGCell::contains_simple(Position r, Direction u, int32_t on_surface) const
846849
{
847-
for (int32_t token : region_infix_) {
850+
for (int32_t token : region_) {
848851
// Assume that no tokens are operators. Evaluate the sense of particle with
849852
// respect to the surface and see if the token matches the sense. If the
850853
// particle's surface attribute is set and matches the token, that
@@ -872,7 +875,7 @@ bool CSGCell::contains_complex(
872875
int total_depth = 0;
873876

874877
// For each token
875-
for (auto it = region_infix_.begin(); it != region_infix_.end(); it++) {
878+
for (auto it = region_.begin(); it != region_.end(); it++) {
876879
int32_t token = *it;
877880

878881
// If the token is a surface evaluate the sense

‎src/geometry_aux.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void partition_universes()
154154
// Collect the set of surfaces in this universe.
155155
std::unordered_set<int32_t> surf_inds;
156156
for (auto i_cell : univ->cells_) {
157-
for (auto token : model::cells[i_cell]->region_infix_) {
157+
for (auto token : model::cells[i_cell]->region_) {
158158
if (token < OP_UNION)
159159
surf_inds.insert(std::abs(token) - 1);
160160
}

‎src/universe.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ UniversePartitioner::UniversePartitioner(const Universe& univ)
9898
// Find all of the z-planes in this universe. A set is used here for the
9999
// O(log(n)) insertions that will ensure entries are not repeated.
100100
for (auto i_cell : univ.cells_) {
101-
for (auto token : model::cells[i_cell]->region_infix_) {
101+
for (auto token : model::cells[i_cell]->region_) {
102102
if (token < OP_UNION) {
103103
auto i_surf = std::abs(token) - 1;
104104
const auto* surf = model::surfaces[i_surf].get();
@@ -125,7 +125,7 @@ UniversePartitioner::UniversePartitioner(const Universe& univ)
125125
// Find the tokens for bounding z-planes.
126126
int32_t lower_token = 0, upper_token = 0;
127127
double min_z, max_z;
128-
for (auto token : model::cells[i_cell]->region_infix_) {
128+
for (auto token : model::cells[i_cell]->region_) {
129129
if (token < OP_UNION) {
130130
const auto* surf = model::surfaces[std::abs(token) - 1].get();
131131
if (const auto* zplane = dynamic_cast<const SurfaceZPlane*>(surf)) {

0 commit comments

Comments
 (0)