3333_SPATIAL_FILTERS = (openmc .UniverseFilter ,
3434 openmc .MaterialFilter ,
3535 openmc .CellFilter ,
36+ openmc .DistribcellFilter ,
3637 openmc .MeshFilter )
3738
3839_PRODUCTIONS = ('delayed-nu-fission' , 'prompt-nu-fission' , 'nu-fission' ,
@@ -280,6 +281,19 @@ def storeCurrent(self):
280281 self .previousViews .append (copy .deepcopy (self .currentView ))
281282
282283 def create_tally_image (self , view = None ):
284+ """
285+ Parameters
286+ ----------
287+ view :
288+ View used to set bounds of the tally data
289+
290+ Returns
291+ -------
292+ tuple
293+ image data (numpy.ndarray), data extents (optional),
294+ data_min_value (float), data_max_value (float),
295+ data label (str)
296+ """
283297 if view is None :
284298 view = self .currentView
285299
@@ -346,20 +360,41 @@ def create_tally_image(self, view=None):
346360 nuclides ,
347361 view )
348362 return image + (units_out ,)
363+ elif tally .contains_filter (openmc .DistribcellFilter ):
364+ if tally_value == 'rel_err' :
365+ mean_data = self ._create_distribcell_image (tally ,
366+ 'mean' ,
367+ scores ,
368+ nuclides )
369+ std_dev_data = self ._create_distribcell_image (tally ,
370+ 'std_dev' ,
371+ scores ,
372+ nuclides )
373+ image_data = 100 * np .divide (std_dev_data [0 ],
374+ mean_data [0 ],
375+ out = np .zeros_like (mean_data [0 ]),
376+ where = mean_data != 0 )
377+ data_min = np .min (image_data )
378+ data_max = np .max (image_data )
379+ return image_data , None , data_min , data_max , '% error'
380+ else :
381+ image = self ._create_distribcell_image (tally ,
382+ tally_value ,
383+ scores ,
384+ nuclides )
385+ return image + (units_out ,)
349386 else :
350387 # same as above, get the std. dev. data
351388 # and mean date to produce the relative error data
352389 if tally_value == 'rel_err' :
353390 mean_data = self ._create_tally_domain_image (tally ,
354391 'mean' ,
355392 scores ,
356- nuclides ,
357- view )
393+ nuclides )
358394 std_dev_data = self ._create_tally_domain_image (tally ,
359395 'std_dev' ,
360396 scores ,
361- nuclides ,
362- view )
397+ nuclides )
363398 image_data = 100 * np .divide (std_dev_data [0 ],
364399 mean_data [0 ],
365400 out = np .zeros_like (mean_data [0 ]),
@@ -377,8 +412,7 @@ def create_tally_image(self, view=None):
377412 image = self ._create_tally_domain_image (tally ,
378413 tally_value ,
379414 scores ,
380- nuclides ,
381- view )
415+ nuclides )
382416 return image + (units_out ,)
383417
384418 def _create_tally_domain_image (self , tally , tally_value , scores , nuclides , view = None ):
@@ -467,10 +501,31 @@ def _do_op(array, tally_value, ax=0):
467501
468502 return image_data , None , data_min , data_max
469503
504+ def _create_distribcell_image (self , tally , tally_value , scores , nuclides ):
505+ dfilter = tally .find_filter (openmc .DistribcellFilter )
506+
507+ data = tally .get_values (scores = scores , nuclides = nuclides , value = tally_value )
508+ data = data .flatten ()
509+
510+ cell_id = dfilter .bins [0 ]
511+ # create a mask for ids that match the cell
512+ image_data = np .full_like (self .ids , np .nan , dtype = float )
513+
514+ cell_id_mask = self .cell_ids == cell_id
515+ for i , v in enumerate (data ):
516+ instance_mask = self .instances == i
517+ image_data [cell_id_mask & instance_mask ] = v
518+
519+ data_min = np .min (data )
520+ data_max = np .max (data )
521+ image_data = np .ma .masked_where (image_data < 0.0 , image_data )
522+
523+ return image_data , None , data_min , data_max
524+
470525 def _create_tally_mesh_image (self , tally , tally_value , scores , nuclides , view = None ):
471526 # some variables used throughout
472527 if view is None :
473- cv = self .currentView
528+ view = self .currentView
474529
475530 sp = self .statepoint
476531 mesh_filter = tally .find_filter (openmc .MeshFilter )
0 commit comments