From 822879cc4838e52bf87202d11429756dbe234474 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sun, 12 Dec 2021 16:27:12 -0600 Subject: [PATCH 1/2] Ensure secondary particles below energy cutoff are not created --- src/particle.cpp | 6 +++ tests/unit_tests/test_energy_cutoff.py | 63 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/unit_tests/test_energy_cutoff.py diff --git a/src/particle.cpp b/src/particle.cpp index 7579f5f5a8d..fa35f634af2 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -39,6 +39,12 @@ namespace openmc { void Particle::create_secondary( double wgt, Direction u, double E, ParticleType type) { + // If energy is below cutoff for this particle, don't create secondary + // particle + if (E < settings::energy_cutoff[static_cast(type)]) { + return; + } + secondary_bank().emplace_back(); auto& bank {secondary_bank().back()}; diff --git a/tests/unit_tests/test_energy_cutoff.py b/tests/unit_tests/test_energy_cutoff.py new file mode 100644 index 00000000000..fb82c579a15 --- /dev/null +++ b/tests/unit_tests/test_energy_cutoff.py @@ -0,0 +1,63 @@ +from random import uniform + +import pytest +import openmc + + +def inf_medium_model(cutoff_energy, source_energy): + """Infinite medium problem with a monoenergetic photon source""" + model = openmc.Model() + + m = openmc.Material() + m.add_nuclide('Zr90', 1.0) + m.set_density('g/cm3', 1.0) + + sph = openmc.Sphere(r=100.0, boundary_type='reflective') + cell = openmc.Cell(fill=m, region=-sph) + model.geometry = openmc.Geometry([cell]) + + model.settings.run_mode = 'fixed source' + model.settings.source = openmc.Source( + particle='photon', + energy=openmc.stats.Discrete([source_energy], [1.0]), + ) + model.settings.particles = 100 + model.settings.batches = 10 + model.settings.cutoff = {'energy_photon': cutoff_energy} + + tally_flux = openmc.Tally(name='flux') + tally_flux.filters = [ + openmc.EnergyFilter([0.0, cutoff_energy, source_energy]), + openmc.ParticleFilter(['photon']) + ] + tally_flux.scores = ['flux'] + tally_heating = openmc.Tally(name='heating') + tally_heating.scores = ['heating'] + model.tallies = openmc.Tallies([tally_flux, tally_heating]) + + return model + + +def test_energy_cutoff(run_in_tmpdir): + # Pick a random cutoff energy between 1 and 5 keV + cutoff_energy = uniform(1e3, 5e3) + + # Pick a random source energy some factor higher than cutoff energy + source_energy = uniform(10, 20) * cutoff_energy + + # Create model and run simulation + model = inf_medium_model(cutoff_energy, source_energy) + statepoint_path = model.run() + + # Get resulting flux and heating values + with openmc.StatePoint(statepoint_path) as sp: + flux = sp.get_tally(name='flux').mean.ravel() + heating = sp.get_tally(name='heating').mean.ravel() + + # There should be no flux below the cutoff energy (first bin in the tally) + assert flux[0] == 0.0 + assert flux[1] > 0.0 + + # Despite killing particles below the cutoff, the total heating should be + # equal to the source energy + assert heating[0] == pytest.approx(source_energy) From baa38a116886dd1121922287c344de01f7a6c949 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sun, 12 Dec 2021 17:26:24 -0600 Subject: [PATCH 2/2] Update photon-related regression test results --- .../photon_production/results_true.dat | 68 +++++++++---------- .../results_true.dat | 58 ++++++++-------- .../photon_source/results_true.dat | 4 +- 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/tests/regression_tests/photon_production/results_true.dat b/tests/regression_tests/photon_production/results_true.dat index 0502dce740b..03fb80b81e6 100644 --- a/tests/regression_tests/photon_production/results_true.dat +++ b/tests/regression_tests/photon_production/results_true.dat @@ -1,8 +1,8 @@ tally 1: 8.610000E-01 7.413210E-01 -9.503000E-01 -9.030701E-01 +9.493000E-01 +9.011705E-01 0.000000E+00 0.000000E+00 0.000000E+00 @@ -16,12 +16,12 @@ tally 2: 1.573004E+00 4.296434E-04 1.845934E-07 -8.124327E-01 -6.600469E-01 +2.337049E-01 +5.461796E-02 0.000000E+00 0.000000E+00 -8.124327E-01 -6.600469E-01 +2.337049E-01 +5.461796E-02 0.000000E+00 0.000000E+00 0.000000E+00 @@ -53,40 +53,40 @@ tally 3: 4.104374E+12 4.296582E-04 1.846062E-07 -8.034000E-01 -6.454516E-01 -6.951747E+03 -4.832678E+07 +2.286000E-01 +5.225796E-02 +7.054033E+03 +4.975938E+07 0.000000E+00 0.000000E+00 -8.034000E-01 -6.454516E-01 -6.951747E+03 -4.832678E+07 +2.286000E-01 +5.225796E-02 +7.054033E+03 +4.975938E+07 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -1.762393E+05 -3.106028E+10 +1.764573E+05 +3.113718E+10 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -1.762393E+05 -3.106028E+10 +1.764573E+05 +3.113718E+10 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -7.631073E+03 -5.823328E+07 +7.691658E+03 +5.916160E+07 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -7.631073E+03 -5.823328E+07 +7.691658E+03 +5.916160E+07 0.000000E+00 0.000000E+00 tally 4: @@ -102,16 +102,16 @@ tally 4: 4.104374E+12 0.000000E+00 0.000000E+00 -2.294000E-01 -5.262436E-02 -6.947074E+03 -4.826184E+07 +2.286000E-01 +5.225796E-02 +7.054033E+03 +4.975938E+07 0.000000E+00 0.000000E+00 -8.034000E-01 -6.454516E-01 -6.951747E+03 -4.832678E+07 +2.286000E-01 +5.225796E-02 +7.054033E+03 +4.975938E+07 0.000000E+00 0.000000E+00 0.000000E+00 @@ -122,8 +122,8 @@ tally 4: 0.000000E+00 0.000000E+00 0.000000E+00 -1.762393E+05 -3.106028E+10 +1.764573E+05 +3.113718E+10 0.000000E+00 0.000000E+00 0.000000E+00 @@ -134,7 +134,7 @@ tally 4: 0.000000E+00 0.000000E+00 0.000000E+00 -7.631073E+03 -5.823328E+07 +7.691658E+03 +5.916160E+07 0.000000E+00 0.000000E+00 diff --git a/tests/regression_tests/photon_production_fission/results_true.dat b/tests/regression_tests/photon_production_fission/results_true.dat index c3ad3c803f0..ac91b63a13e 100644 --- a/tests/regression_tests/photon_production_fission/results_true.dat +++ b/tests/regression_tests/photon_production_fission/results_true.dat @@ -1,12 +1,12 @@ k-combined: -2.268512E+00 8.628052E-03 +2.294874E+00 2.454640E-02 tally 1: -2.657963E+00 -2.355039E+00 +2.691351E+00 +2.415076E+00 0.000000E+00 0.000000E+00 -2.657963E+00 -2.355039E+00 +2.691351E+00 +2.415076E+00 0.000000E+00 0.000000E+00 0.000000E+00 @@ -18,52 +18,52 @@ tally 1: 0.000000E+00 0.000000E+00 tally 2: -2.640348E+00 -2.323851E+00 -4.246717E+08 -6.011634E+16 +2.654218E+00 +2.348806E+00 +4.260252E+08 +6.051306E+16 0.000000E+00 0.000000E+00 -2.640348E+00 -2.323851E+00 -4.246717E+08 -6.011634E+16 +2.654218E+00 +2.348806E+00 +4.260252E+08 +6.051306E+16 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.355438E+06 -1.849734E+12 +2.507232E+06 +2.096890E+12 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.355438E+06 -1.849734E+12 +2.507232E+06 +2.096890E+12 0.000000E+00 0.000000E+00 tally 3: -2.654437E+00 -2.348704E+00 -4.246717E+08 -6.011634E+16 +2.656221E+00 +2.351840E+00 +4.260252E+08 +6.051306E+16 0.000000E+00 0.000000E+00 -2.654437E+00 -2.348704E+00 -4.246717E+08 -6.011634E+16 +2.656221E+00 +2.351840E+00 +4.260252E+08 +6.051306E+16 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.173264E+06 -1.574708E+12 +2.507232E+06 +2.096890E+12 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.355438E+06 -1.849734E+12 +2.507232E+06 +2.096890E+12 0.000000E+00 0.000000E+00 diff --git a/tests/regression_tests/photon_source/results_true.dat b/tests/regression_tests/photon_source/results_true.dat index a8ec212eb8a..fcc75cbca84 100644 --- a/tests/regression_tests/photon_source/results_true.dat +++ b/tests/regression_tests/photon_source/results_true.dat @@ -1,5 +1,5 @@ tally 1: -2.256359E+02 -5.091156E+04 +2.263938E+02 +5.125417E+04 0.000000E+00 0.000000E+00