11from collections .abc import Mapping , Sequence
2- from ctypes import (c_int , c_int32 , c_char_p , c_double , POINTER ,
2+ from ctypes import (c_int , c_int32 , c_char_p , c_double , POINTER , c_void_p ,
33 create_string_buffer , c_size_t )
44from math import sqrt
55import sys
4747_dll .openmc_mesh_bounding_box .restype = c_int
4848_dll .openmc_mesh_bounding_box .errcheck = _error_handler
4949_dll .openmc_mesh_material_volumes .argtypes = [
50- c_int32 , c_int , c_int , c_int , c_int , arr_2d_int32 , arr_2d_double ]
50+ c_int32 , c_int , c_int , c_int , c_int , arr_2d_int32 , arr_2d_double ,
51+ c_void_p ]
5152_dll .openmc_mesh_material_volumes .restype = c_int
5253_dll .openmc_mesh_material_volumes .errcheck = _error_handler
5354_dll .openmc_mesh_get_plot_bins .argtypes = [
@@ -188,6 +189,7 @@ def material_volumes(
188189 n_samples : int | tuple [int , int , int ] = 10_000 ,
189190 max_materials : int = 4 ,
190191 output : bool = True ,
192+ bounding_boxes : bool = False ,
191193 ) -> MeshMaterialVolumes :
192194 """Determine volume of materials in each mesh element.
193195
@@ -213,6 +215,11 @@ def material_volumes(
213215 Estimated maximum number of materials in any given mesh element.
214216 output : bool, optional
215217 Whether or not to show output.
218+ bounding_boxes : bool, optional
219+ Whether or not to compute an axis-aligned bounding box for each
220+ (mesh element, material) combination. When enabled, the bounding
221+ box encloses the ray-estimator prisms used for the volume
222+ estimation.
216223
217224 Returns
218225 -------
@@ -243,23 +250,36 @@ def material_volumes(
243250 table_size = slot_factor * max_materials
244251 materials = np .full ((n , table_size ), EMPTY_SLOT , dtype = np .int32 )
245252 volumes = np .zeros ((n , table_size ), dtype = np .float64 )
253+ bboxes = None
254+ if bounding_boxes :
255+ bboxes = np .empty ((n , table_size , 6 ), dtype = np .float64 )
256+ bboxes [..., 0 :3 ] = np .inf
257+ bboxes [..., 3 :6 ] = - np .inf
246258
247259 # Run material volume calculation
248260 while True :
249261 try :
262+ bboxes_ptr = None
263+ if bboxes is not None :
264+ bboxes_ptr = bboxes .ctypes .data_as (POINTER (c_double ))
250265 with quiet_dll (output ):
251266 _dll .openmc_mesh_material_volumes (
252- self ._index , nx , ny , nz , table_size , materials , volumes )
267+ self ._index , nx , ny , nz , table_size , materials ,
268+ volumes , bboxes_ptr )
253269 except AllocationError :
254270 # Increase size of result array and try again
255271 table_size *= 2
256272 materials = np .full ((n , table_size ), EMPTY_SLOT , dtype = np .int32 )
257273 volumes = np .zeros ((n , table_size ), dtype = np .float64 )
274+ if bounding_boxes :
275+ bboxes = np .empty ((n , table_size , 6 ), dtype = np .float64 )
276+ bboxes [..., 0 :3 ] = np .inf
277+ bboxes [..., 3 :6 ] = - np .inf
258278 else :
259279 # If no error, break out of loop
260280 break
261281
262- return MeshMaterialVolumes (materials , volumes )
282+ return MeshMaterialVolumes (materials , volumes , bboxes )
263283
264284 def get_plot_bins (
265285 self ,
0 commit comments