|
34 | 34 | openmc.MaterialFilter, |
35 | 35 | openmc.CellFilter, |
36 | 36 | openmc.DistribcellFilter, |
| 37 | + openmc.CellInstanceFilter, |
37 | 38 | openmc.MeshFilter) |
38 | 39 |
|
39 | 40 | _PRODUCTIONS = ('delayed-nu-fission', 'prompt-nu-fission', 'nu-fission', |
@@ -330,6 +331,9 @@ def create_tally_image(self, view=None): |
330 | 331 |
|
331 | 332 | units_out = list(units)[0] |
332 | 333 |
|
| 334 | + contains_distribcell = tally.contains_filter(openmc.DistribcellFilter) |
| 335 | + contains_cellinstance = tally.contains_filter(openmc.CellInstanceFilter) |
| 336 | + |
333 | 337 | if tally.contains_filter(openmc.MeshFilter): |
334 | 338 | if tally_value == 'rel_err': |
335 | 339 | # get both the std. dev. data and mean data |
@@ -360,28 +364,26 @@ def create_tally_image(self, view=None): |
360 | 364 | nuclides, |
361 | 365 | view) |
362 | 366 | return image + (units_out,) |
363 | | - elif tally.contains_filter(openmc.DistribcellFilter): |
| 367 | + elif contains_distribcell or contains_cellinstance: |
| 368 | + # Select appropriate function |
| 369 | + if contains_distribcell: |
| 370 | + create_image = self._create_distribcell_image |
| 371 | + else: |
| 372 | + create_image = self._create_cellinstance_image |
| 373 | + |
364 | 374 | 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) |
| 375 | + mean_data = create_image(tally, 'mean', scores, nuclides) |
| 376 | + std_dev_data = create_image(tally, 'std_dev', scores, nuclides) |
| 377 | + image_data = 100 * np.divide( |
| 378 | + std_dev_data[0], mean_data[0], |
| 379 | + out=np.zeros_like(mean_data[0]), |
| 380 | + where=mean_data != 0 |
| 381 | + ) |
377 | 382 | data_min = np.min(image_data) |
378 | 383 | data_max = np.max(image_data) |
379 | 384 | return image_data, None, data_min, data_max, '% error' |
380 | 385 | else: |
381 | | - image = self._create_distribcell_image(tally, |
382 | | - tally_value, |
383 | | - scores, |
384 | | - nuclides) |
| 386 | + image = create_image(tally, tally_value, scores, nuclides) |
385 | 387 | return image + (units_out,) |
386 | 388 | else: |
387 | 389 | # same as above, get the std. dev. data |
@@ -522,6 +524,26 @@ def _create_distribcell_image(self, tally, tally_value, scores, nuclides): |
522 | 524 |
|
523 | 525 | return image_data, None, data_min, data_max |
524 | 526 |
|
| 527 | + def _create_cellinstance_image(self, tally, tally_value, scores, nuclides): |
| 528 | + cellinst_filter = tally.find_filter(openmc.CellInstanceFilter) |
| 529 | + |
| 530 | + data = tally.get_values(scores=scores, nuclides=nuclides, value=tally_value) |
| 531 | + data = data.flatten() |
| 532 | + |
| 533 | + # create a mask for ids that match the cell |
| 534 | + image_data = np.full_like(self.ids, np.nan, dtype=float) |
| 535 | + |
| 536 | + for v, (cell_id, instance) in zip(data, cellinst_filter.bins): |
| 537 | + cell_id_mask = self.cell_ids == cell_id |
| 538 | + instance_mask = self.instances == instance |
| 539 | + image_data[cell_id_mask & instance_mask] = v |
| 540 | + |
| 541 | + data_min = np.min(data) |
| 542 | + data_max = np.max(data) |
| 543 | + image_data = np.ma.masked_where(image_data < 0.0, image_data) |
| 544 | + |
| 545 | + return image_data, None, data_min, data_max |
| 546 | + |
525 | 547 | def _create_tally_mesh_image(self, tally, tally_value, scores, nuclides, view=None): |
526 | 548 | # some variables used throughout |
527 | 549 | if view is None: |
|
0 commit comments