Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/pydagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,14 @@ def category(self, category: str):
def groups(self) -> list[Group]:
"""Get list of groups containing this DAGMC set."""
return [group for group in self.model.groups if self in group]

def _metadata_group(self, prefix: str) -> list[Group]:
"""Get single group containing this DAGMC set, with matching prefix."""
for group in self.model.groups:
if self in group and prefix in group.name:
return group
return group
return None

def _metadata_group_name(self, prefix: str) -> Optional[str]:
group = self._metadata_group(prefix)
if group is not None:
Expand Down Expand Up @@ -479,6 +479,20 @@ def triangle_coords(self):

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

@property
def bounds(self):
"""Returns the axis-aligned bounding box for all triangles under this set.

Returns
-------
tuple(float, float, float, float, float, float)
(xmin, xmax, ymin, ymax, zmin, zmax)
"""
coords = self.triangle_coords
min_coord = np.min(coords, axis=0)
max_coord = np.max(coords, axis=0)
return min_coord, max_coord

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this (xmin, ymin, zmin), (xmax, ymax, zmax)? Is it really a tuple? or is it a pair of numpy arrays that can be iterated like a tuple like they are in the tests?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad here. I changed the data structure to something I liked better but didn't update the docs/expected test data structure -- the result of pytest.approx was a boolean array that it always considered to be true. No bueno. I brought in numpy.testing.assert_equal to remedy this. I also selected different surface bounds. Some which are the top and bottom of the cylinder and have the same min/max coordinate in one dimension for more varitey.


def get_triangle_conn_and_coords(self, compress=False):
"""Returns the triangle connectivity and coordinates for all triangles under this set.

Expand Down Expand Up @@ -623,7 +637,7 @@ def boundary_group(self) -> Optional[Group]:
def boundary(self) -> Optional[str]:
"""Name of the boundary assigned to this surface."""
return self._metadata_group_name(self._boundary_prefix)

@boundary.setter
def boundary(self, name: Optional[str]):
self._set_metadata_group(self._boundary_prefix, name)
Expand Down
18 changes: 18 additions & 0 deletions test/test_dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,24 @@ def test_area(fuel_pin_model):
pytest.approx(model.surfaces[surf_id].area, exp_area)


def test_bounds(fuel_pin_model):
model = fuel_pin_model
vol1_bounds = model.volumes_by_id[1].bounds
expected_bounds = (-7.0, 7.0, -7.0, 7.0, -20.0, 20.0)
for val, exp_val in zip(vol1_bounds, expected_bounds):
pytest.approx(val, exp_val)

exp_surface_bounds = {1: (-7.0, 7.0, -7.0, 7.0, -20.0, 20.0),
2: (-9.0, 9.0, -9.0, 9.0, -20.0, 20.0),
3: (-10.0, 10.0, -10.0, 10.0, -20.0, 20.0),}

# test all surface bounds
for surf_id, expected_bounds in exp_surface_bounds.items():
surface_bounds = model.surfaces_by_id[surf_id].bounds
for val, exp_val in zip(surface_bounds, expected_bounds):
pytest.approx(val, exp_val)


def test_add_groups(fuel_pin_model):
model = fuel_pin_model
volumes = model.volumes_by_id
Expand Down
Loading