mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Some self-review.
This commit is contained in:
parent
9fab83c70c
commit
1d02c87466
3 changed files with 24 additions and 13 deletions
|
|
@ -31,6 +31,7 @@ extern "C" const int BC_PERIODIC;
|
|||
//==============================================================================
|
||||
|
||||
class Surface;
|
||||
|
||||
struct BoundingBox;
|
||||
|
||||
namespace model {
|
||||
|
|
@ -51,7 +52,7 @@ struct BoundingBox
|
|||
double zmin = -INFTY;
|
||||
double zmax = INFTY;
|
||||
|
||||
// in-place update
|
||||
// in-place update to include another bounding box
|
||||
inline void update(const BoundingBox& other) {
|
||||
xmin = std::min(xmin, other.xmin);
|
||||
xmax = std::max(xmax, other.xmax);
|
||||
|
|
@ -61,7 +62,7 @@ struct BoundingBox
|
|||
zmax = std::max(zmax, other.zmax);
|
||||
};
|
||||
|
||||
// in-place intersection
|
||||
// in-place intersection with another bounding box
|
||||
inline void intersect(const BoundingBox& other) {
|
||||
xmin = std::max(xmin, other.xmin);
|
||||
xmax = std::min(xmax, other.xmax);
|
||||
|
|
@ -298,6 +299,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double y0_, z0_, radius_;
|
||||
};
|
||||
|
||||
|
|
@ -317,6 +319,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double x0_, z0_, radius_;
|
||||
};
|
||||
|
||||
|
|
@ -336,6 +339,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double x0_, y0_, radius_;
|
||||
};
|
||||
|
||||
|
|
@ -355,6 +359,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double x0_, y0_, z0_, radius_;
|
||||
};
|
||||
|
||||
|
|
@ -374,6 +379,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double x0_, y0_, z0_, radius_sq_;
|
||||
};
|
||||
|
||||
|
|
@ -393,6 +399,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double x0_, y0_, z0_, radius_sq_;
|
||||
};
|
||||
|
||||
|
|
@ -412,6 +419,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
double x0_, y0_, z0_, radius_sq_;
|
||||
};
|
||||
|
||||
|
|
@ -430,6 +438,7 @@ public:
|
|||
Direction normal(Position r) const;
|
||||
void to_hdf5_inner(hid_t group_id) const;
|
||||
BoundingBox bounding_box(bool pos_side) const;
|
||||
|
||||
// Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
|
||||
double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ _dll.openmc_simulation_finalize.errcheck = _error_handler
|
|||
_dll.openmc_statepoint_write.argtypes = [c_char_p, POINTER(c_bool)]
|
||||
_dll.openmc_statepoint_write.restype = c_int
|
||||
_dll.openmc_statepoint_write.errcheck = _error_handler
|
||||
_dll.openmc_bounding_box.argtypes = [c_char_p, c_int, POINTER(c_double),
|
||||
_dll.openmc_bounding_box.argtypes = [c_char_p, c_int,
|
||||
POINTER(c_double),
|
||||
POINTER(c_double)]
|
||||
_dll.openmc_bounding_box.restype = c_int
|
||||
_dll.openmc_bounding_box.errcheck = _error_handler
|
||||
|
|
|
|||
21
src/cell.cpp
21
src/cell.cpp
|
|
@ -594,9 +594,11 @@ BoundingBox CSGCell::bounding_box_complex(std::vector<int32_t> rpn) const {
|
|||
rpn.pop_back();
|
||||
|
||||
while (rpn.size()) {
|
||||
// move through the rpn in twos
|
||||
int32_t one = rpn.back(); rpn.pop_back();
|
||||
int32_t two = rpn.back(); rpn.pop_back();
|
||||
|
||||
// the first token should always be a surface
|
||||
assert(one < OP_UNION);
|
||||
|
||||
if (two >= OP_UNION) {
|
||||
|
|
@ -605,19 +607,20 @@ BoundingBox CSGCell::bounding_box_complex(std::vector<int32_t> rpn) const {
|
|||
} else if (two == OP_INTERSECTION) {
|
||||
current.intersect(model::surfaces[abs(one)-1]->bounding_box(one > 0));
|
||||
}
|
||||
} else { // two surfaces in a row, create sub-rpn for parenthesis
|
||||
} else {
|
||||
// two surfaces in a row, create sub-rpn for region in parenthesis
|
||||
std::vector<int32_t> subrpn;
|
||||
subrpn.push_back(one);
|
||||
subrpn.push_back(two);
|
||||
int32_t sone = one;
|
||||
int32_t stwo = two;
|
||||
// add until last two tokens are operators
|
||||
// add until last two tokens in the sub-rpn are operators
|
||||
while ((subrpn.back() < OP_UNION) || (*(subrpn.rbegin() + 1) < OP_UNION)) {
|
||||
subrpn.push_back(rpn.back());
|
||||
rpn.pop_back();
|
||||
}
|
||||
|
||||
// handle complement case
|
||||
// handle complement case using De Morgan's laws
|
||||
if (subrpn.back() == OP_COMPLEMENT) {
|
||||
subrpn.pop_back();
|
||||
for (auto& token : subrpn) {
|
||||
|
|
@ -628,10 +631,12 @@ BoundingBox CSGCell::bounding_box_complex(std::vector<int32_t> rpn) const {
|
|||
subrpn.push_back(rpn.back());
|
||||
rpn.pop_back();
|
||||
}
|
||||
// get bbox for the subrpn
|
||||
int32_t op = subrpn.back();
|
||||
subrpn.pop_back();
|
||||
// save the last operator, tells us how to combine this region
|
||||
// with our current bounding box
|
||||
int32_t op = subrpn.back(); subrpn.pop_back();
|
||||
// get bounding box for the subrpn
|
||||
BoundingBox sub_box = bounding_box_complex(subrpn);
|
||||
// combine the sub-rpn bounding box with our current cell box
|
||||
if (op == OP_UNION) {
|
||||
current.update(sub_box);
|
||||
} else if (op == OP_INTERSECTION) {
|
||||
|
|
@ -644,16 +649,12 @@ BoundingBox CSGCell::bounding_box_complex(std::vector<int32_t> rpn) const {
|
|||
}
|
||||
|
||||
BoundingBox CSGCell::bounding_box() const {
|
||||
if (rpn_.size() == 0) {
|
||||
return {-INFTY, INFTY, -INFTY, INFTY, -INFTY, INFTY};
|
||||
} else {
|
||||
if (simple_) {
|
||||
return bounding_box_simple();
|
||||
}
|
||||
else {
|
||||
return bounding_box_complex(rpn_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue