@@ -994,3 +994,37 @@ def test_regular_mesh_get_indices_at_coords():
994994 assert isinstance (result_1d , tuple )
995995 assert len (result_1d ) == 1
996996 assert result_1d == (5 ,)
997+
998+
999+ def test_rectilinear_mesh_get_indices_at_coords ():
1000+ """Test get_indices_at_coords method for RectilinearMesh"""
1001+ # Create a 3x2x2 rectilinear mesh with non-uniform spacing
1002+ mesh = openmc .RectilinearMesh ()
1003+ mesh .x_grid = [0. , 1. , 5. , 10. ]
1004+ mesh .y_grid = [- 10. , - 5. , 0. ]
1005+ mesh .z_grid = [- 100. , 0. , 100. ]
1006+
1007+ # Test lower-left corner maps to first voxel (0, 0, 0)
1008+ assert mesh .get_indices_at_coords ([0.0 , - 10. , - 100. ]) == (0 , 0 , 0 )
1009+
1010+ # Test centroid of first voxel
1011+ assert mesh .get_indices_at_coords ([0.5 , - 7.5 , - 50. ]) == (0 , 0 , 0 )
1012+
1013+ # Test centroid of last voxel maps correctly
1014+ assert mesh .get_indices_at_coords ([7.5 , - 2.5 , 50. ]) == (2 , 1 , 1 )
1015+
1016+ # Test upper_right corner maps to last voxel
1017+ assert mesh .get_indices_at_coords ([10. , 0. , 100. ]) == (2 , 1 , 1 )
1018+
1019+ # Test a middle voxel
1020+ assert mesh .get_indices_at_coords ([2. , - 5. , 0. ]) == (1 , 1 , 1 )
1021+
1022+ # Test coordinates outside mesh bounds raise ValueError
1023+ with pytest .raises (ValueError ):
1024+ mesh .get_indices_at_coords ([- 0.5 , 0.5 , 0.5 ])
1025+ with pytest .raises (ValueError ):
1026+ mesh .get_indices_at_coords ([1.5 , 0.5 , 0.5 ])
1027+ with pytest .raises (ValueError ):
1028+ mesh .get_indices_at_coords ([0.5 , - 0.5 , 110. ])
1029+ with pytest .raises (ValueError ):
1030+ mesh .get_indices_at_coords ([0.5 , - 20. , 110. ])
0 commit comments