From 80dc21be2c62236fb7b654087fd7624f2fc41060 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 11 Aug 2022 11:10:49 -0500 Subject: [PATCH] Add test for TimeFilter when time intervals are effectively zero --- tests/unit_tests/test_time_filter.py | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/unit_tests/test_time_filter.py b/tests/unit_tests/test_time_filter.py index 5b09c6d5f7..45fabc5449 100644 --- a/tests/unit_tests/test_time_filter.py +++ b/tests/unit_tests/test_time_filter.py @@ -149,3 +149,39 @@ def test_time_filter_surface(model_surf, run_in_tmpdir): # After t0+ε, the current should be zero assert values[2] == 0.0 + + +def test_small_time_interval(run_in_tmpdir): + # Create a model with a photon source at 1.0e8 seconds. Based on the speed + # of the photon, the time intervals are on the order of 1e-9 seconds, which + # are effectively 0 when compared to the starting time of the photon. + mat = openmc.Material() + mat.add_element('N', 1.0) + mat.set_density('g/cm3', 0.001) + sph = openmc.Sphere(r=5.0, boundary_type='vacuum') + cell = openmc.Cell(fill=mat, region=-sph) + model = openmc.Model() + model.geometry = openmc.Geometry([cell]) + model.settings.particles = 100 + model.settings.batches = 10 + model.settings.run_mode = 'fixed source' + model.settings.source = openmc.Source( + time=openmc.stats.Discrete([1.0e8], [1.0]), + particle='photon' + ) + + # Add tallies with and without a time filter that should match all particles + time_filter = openmc.TimeFilter([0.0, 1.0e100]) + tally_with_filter = openmc.Tally() + tally_with_filter.filters = [time_filter] + tally_with_filter.scores = ['flux'] + tally_without_filter = openmc.Tally() + tally_without_filter.scores = ['flux'] + model.tallies.extend([tally_with_filter, tally_without_filter]) + + # Run the model and make sure the two tallies match + sp_filename = model.run() + with openmc.StatePoint(sp_filename) as sp: + flux_with = sp.tallies[tally_with_filter.id].mean.ravel()[0] + flux_without = sp.tallies[tally_without_filter.id].mean.ravel()[0] + assert flux_with == pytest.approx(flux_without)