|
| 1 | +import os |
| 2 | + |
| 3 | +import openmc |
| 4 | +from openmc.utility_funcs import change_directory |
| 5 | +from openmc.examples import random_ray_three_region_cube |
| 6 | +import pytest |
| 7 | + |
| 8 | +from tests.testing_harness import TolerantPyAPITestHarness |
| 9 | + |
| 10 | + |
| 11 | +class MGXSTestHarness(TolerantPyAPITestHarness): |
| 12 | + def _cleanup(self): |
| 13 | + super()._cleanup() |
| 14 | + f = 'mgxs.h5' |
| 15 | + if os.path.exists(f): |
| 16 | + os.remove(f) |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.parametrize("domain_type", ["cell", "material", "universe"]) |
| 20 | +def test_random_ray_fixed_source(domain_type): |
| 21 | + with change_directory(domain_type): |
| 22 | + openmc.reset_auto_ids() |
| 23 | + model = random_ray_three_region_cube() |
| 24 | + |
| 25 | + # Based on the parameter, we need to adjust |
| 26 | + # the particle source constraints |
| 27 | + source = model.settings.source[0] |
| 28 | + constraints = source.constraints |
| 29 | + |
| 30 | + if domain_type == 'cell': |
| 31 | + cells = model.geometry.get_all_cells() |
| 32 | + for key, cell in cells.items(): |
| 33 | + print(cell.name) |
| 34 | + if cell.name == 'infinite source region': |
| 35 | + constraints['domain_type'] = 'cell' |
| 36 | + constraints['domain_ids'] = [cell.id] |
| 37 | + elif domain_type == 'material': |
| 38 | + materials = model.materials |
| 39 | + for material in materials: |
| 40 | + if material.name == 'source': |
| 41 | + constraints['domain_type'] = 'material' |
| 42 | + constraints['domain_ids'] = [material.id] |
| 43 | + elif domain_type == 'universe': |
| 44 | + universes = model.geometry.get_all_universes() |
| 45 | + for key, universe in universes.items(): |
| 46 | + if universe.name == 'source universe': |
| 47 | + constraints['domain_type'] = 'universe' |
| 48 | + constraints['domain_ids'] = [universe.id] |
| 49 | + |
| 50 | + harness = MGXSTestHarness('statepoint.10.h5', model) |
| 51 | + harness.main() |
0 commit comments