|
| 1 | +"""Test the settings.no_reduce feature to ensure tallies are correctly |
| 2 | +reduced across MPI processes.""" |
| 3 | + |
| 4 | +import openmc |
| 5 | +import pytest |
| 6 | + |
| 7 | +from tests.testing_harness import config |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize('no_reduce', [True, False]) |
| 11 | +def test_no_reduce(no_reduce, run_in_tmpdir): |
| 12 | + """Test that tally results are correct with and without no_reduce.""" |
| 13 | + |
| 14 | + # Create simple sphere model with vacuum |
| 15 | + model = openmc.Model() |
| 16 | + sphere = openmc.Sphere(r=1.0, boundary_type='vacuum') |
| 17 | + cell = openmc.Cell(region=-sphere) |
| 18 | + model.geometry = openmc.Geometry([cell]) |
| 19 | + model.settings.run_mode = 'fixed source' |
| 20 | + model.settings.batches = 10 |
| 21 | + model.settings.particles = 100 |
| 22 | + model.settings.source = openmc.IndependentSource(space=openmc.stats.Point()) |
| 23 | + model.settings.no_reduce = no_reduce |
| 24 | + |
| 25 | + # Tally: surface current on vacuum boundary |
| 26 | + surf_filter = openmc.SurfaceFilter(sphere) |
| 27 | + tally = openmc.Tally() |
| 28 | + tally.filters = [surf_filter] |
| 29 | + tally.scores = ['current'] |
| 30 | + model.tallies = [tally] |
| 31 | + |
| 32 | + # Run OpenMC with proper MPI arguments if needed |
| 33 | + kwargs = {'apply_tally_results': True, 'openmc_exec': config['exe']} |
| 34 | + if config['mpi']: |
| 35 | + kwargs['mpi_args'] = [config['mpiexec'], '-n', config['mpi_np']] |
| 36 | + model.run(**kwargs) |
| 37 | + |
| 38 | + # The tally should be ~1.0 (every particle crosses the surface once) |
| 39 | + tally_mean = tally.mean.flatten()[0] |
| 40 | + assert tally_mean == pytest.approx(1.0) |
0 commit comments