Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/pydagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ def surfaces(self) -> list[Surface]:
def surfaces_by_id(self) -> dict[int, Surface]:
return {s.id: s for s in self.surfaces}

@property
def adjacent_volumes(self) -> list[Volume]:
"""Returns a list of volumes adjacent to this volume."""
adjacent_vols = set()
for surface in self.surfaces:
for vol in surface.volumes:
adjacent_vols.add(vol)
adjacent_vols.discard(self)
return sorted(list(adjacent_vols), key=lambda v: v.id)

@property
def num_triangles(self) -> int:
"""Returns the number of triangles in this volume"""
Expand Down
27 changes: 27 additions & 0 deletions test/test_dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,30 @@ def test_geometryset_check_tags_errors(request):
with pytest.raises(ValueError, match="has no category or geom_dimension"):
_ = pydagmc.Surface(model, raw_handle_surf_missing_all)


def test_adjacent_volumes(fuel_pin_model):

# innermost volume
model = fuel_pin_model
vol1 = model.volumes_by_id[1]
adj_vols = vol1.adjacent_volumes
assert len(adj_vols) == 1
assert model.volumes_by_id[2] in adj_vols

# middle volume
vol2 = model.volumes_by_id[2]
adj_vols = vol2.adjacent_volumes
assert len(adj_vols) == 2
assert model.volumes_by_id[1] in adj_vols
assert model.volumes_by_id[3] in adj_vols

# outermost pin volume
vol3 = model.volumes_by_id[3]
adj_vols = vol3.adjacent_volumes
assert len(adj_vols) == 1
assert model.volumes_by_id[2] in adj_vols

# graveyard volume -- doesn't touch any other explicit volumes
vol6 = model.volumes_by_id[6]
adj_vols = vol6.adjacent_volumes
assert len(adj_vols) == 0
Loading