File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -700,6 +700,16 @@ def surfaces(self) -> list[Surface]:
700700 def surfaces_by_id (self ) -> dict [int , Surface ]:
701701 return {s .id : s for s in self .surfaces }
702702
703+ @property
704+ def adjacent_volumes (self ) -> list [Volume ]:
705+ """Returns a list of volumes adjacent to this volume."""
706+ adjacent_vols = set ()
707+ for surface in self .surfaces :
708+ for vol in surface .volumes :
709+ if vol != self :
710+ adjacent_vols .add (vol )
711+ return sorted (list (adjacent_vols ), key = lambda v : v .id )
712+
703713 @property
704714 def num_triangles (self ) -> int :
705715 """Returns the number of triangles in this volume"""
Original file line number Diff line number Diff line change @@ -1033,3 +1033,30 @@ def test_geometryset_check_tags_errors(request):
10331033 with pytest .raises (ValueError , match = "has no category or geom_dimension" ):
10341034 _ = pydagmc .Surface (model , raw_handle_surf_missing_all )
10351035
1036+
1037+ def test_adjacent_volumes (fuel_pin_model ):
1038+
1039+ # innermost volume
1040+ model = fuel_pin_model
1041+ vol1 = model .volumes_by_id [1 ]
1042+ adj_vols = vol1 .adjacent_volumes
1043+ assert len (adj_vols ) == 1
1044+ assert model .volumes_by_id [2 ] in adj_vols
1045+
1046+ # middle volume
1047+ vol2 = model .volumes_by_id [2 ]
1048+ adj_vols = vol2 .adjacent_volumes
1049+ assert len (adj_vols ) == 2
1050+ assert model .volumes_by_id [1 ] in adj_vols
1051+ assert model .volumes_by_id [3 ] in adj_vols
1052+
1053+ # outermost pin volume
1054+ vol3 = model .volumes_by_id [3 ]
1055+ adj_vols = vol3 .adjacent_volumes
1056+ assert len (adj_vols ) == 1
1057+ assert model .volumes_by_id [2 ] in adj_vols
1058+
1059+ # graveyard volume -- doesn't touch any other explicit volumes
1060+ vol6 = model .volumes_by_id [6 ]
1061+ adj_vols = vol6 .adjacent_volumes
1062+ assert len (adj_vols ) == 0
You can’t perform that action at this time.
0 commit comments