Skip to content

Commit 6592885

Browse files
committed
Add bounds calculation for geometric sets.
1 parent 418e576 commit 6592885

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/pydagmc/dagnav.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ def category(self, category: str):
407407
def groups(self) -> list[Group]:
408408
"""Get list of groups containing this DAGMC set."""
409409
return [group for group in self.model.groups if self in group]
410-
410+
411411
def _metadata_group(self, prefix: str) -> list[Group]:
412412
"""Get single group containing this DAGMC set, with matching prefix."""
413413
for group in self.model.groups:
414414
if self in group and prefix in group.name:
415-
return group
415+
return group
416416
return None
417-
417+
418418
def _metadata_group_name(self, prefix: str) -> Optional[str]:
419419
group = self._metadata_group(prefix)
420420
if group is not None:
@@ -479,6 +479,20 @@ def triangle_coords(self):
479479

480480
return self.model.mb.get_coords(conn.flatten()).reshape(-1, 3)
481481

482+
@property
483+
def bounds(self):
484+
"""Returns the axis-aligned bounding box for all triangles under this set.
485+
486+
Returns
487+
-------
488+
tuple(float, float, float, float, float, float)
489+
(xmin, xmax, ymin, ymax, zmin, zmax)
490+
"""
491+
coords = self.triangle_coords
492+
min_coord = np.min(coords, axis=0)
493+
max_coord = np.max(coords, axis=0)
494+
return min_coord, max_coord
495+
482496
def get_triangle_conn_and_coords(self, compress=False):
483497
"""Returns the triangle connectivity and coordinates for all triangles under this set.
484498
@@ -623,7 +637,7 @@ def boundary_group(self) -> Optional[Group]:
623637
def boundary(self) -> Optional[str]:
624638
"""Name of the boundary assigned to this surface."""
625639
return self._metadata_group_name(self._boundary_prefix)
626-
640+
627641
@boundary.setter
628642
def boundary(self, name: Optional[str]):
629643
self._set_metadata_group(self._boundary_prefix, name)

test/test_dagnav.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,24 @@ def test_area(fuel_pin_model):
858858
pytest.approx(model.surfaces[surf_id].area, exp_area)
859859

860860

861+
def test_bounds(fuel_pin_model):
862+
model = fuel_pin_model
863+
vol1_bounds = model.volumes_by_id[1].bounds
864+
expected_bounds = (-7.0, 7.0, -7.0, 7.0, -20.0, 20.0)
865+
for val, exp_val in zip(vol1_bounds, expected_bounds):
866+
pytest.approx(val, exp_val)
867+
868+
exp_surface_bounds = {1: (-7.0, 7.0, -7.0, 7.0, -20.0, 20.0),
869+
2: (-9.0, 9.0, -9.0, 9.0, -20.0, 20.0),
870+
3: (-10.0, 10.0, -10.0, 10.0, -20.0, 20.0),}
871+
872+
# test all surface bounds
873+
for surf_id, expected_bounds in exp_surface_bounds.items():
874+
surface_bounds = model.surfaces_by_id[surf_id].bounds
875+
for val, exp_val in zip(surface_bounds, expected_bounds):
876+
pytest.approx(val, exp_val)
877+
878+
861879
def test_add_groups(fuel_pin_model):
862880
model = fuel_pin_model
863881
volumes = model.volumes_by_id

0 commit comments

Comments
 (0)