def test_cutoff_construction(nuclide_bundle): u235 = nuclide_bundle.u235 u238 = nuclide_bundle.u238 pu239 = nuclide_bundle.pu239 # defaults helper = FissionYieldCutoffHelper(nuclide_bundle, 1) assert helper.constant_yields == { "U238": u238.yield_data[5.0e5], "Pu239": pu239.yield_data[5e5]} assert helper.thermal_yields == {"U235": u235.yield_data[0.0253]} assert helper.fast_yields == {"U235": u235.yield_data[5e5]} # use 14 MeV yields helper = FissionYieldCutoffHelper(nuclide_bundle, 1, fast_energy=14e6) assert helper.constant_yields == { "U238": u238.yield_data[5.0e5], "Pu239": pu239.yield_data[5e5]} assert helper.thermal_yields == {"U235": u235.yield_data[0.0253]} assert helper.fast_yields == {"U235": u235.yield_data[14e6]} # specify missing thermal yields -> use 0.0253 helper = FissionYieldCutoffHelper(nuclide_bundle, 1, thermal_energy=1) assert helper.thermal_yields == {"U235": u235.yield_data[0.0253]} assert helper.fast_yields == {"U235": u235.yield_data[5e5]} # request missing fast yields -> use epithermal helper = FissionYieldCutoffHelper(nuclide_bundle, 1, fast_energy=1e4) assert helper.thermal_yields == {"U235": u235.yield_data[0.0253]} assert helper.fast_yields == {"U235": u235.yield_data[5e5]} # higher cutoff energy -> obtain fast and "faster" yields helper = FissionYieldCutoffHelper(nuclide_bundle, 1, cutoff=1e6, thermal_energy=5e5, fast_energy=14e6) assert helper.constant_yields == {"U238": u238.yield_data[5e5]} assert helper.thermal_yields == { "U235": u235.yield_data[5e5], "Pu239": pu239.yield_data[5e5]} assert helper.fast_yields == { "U235": u235.yield_data[14e6], "Pu239": pu239.yield_data[2e6]} # test super low and super high cutoff energies helper = FissionYieldCutoffHelper( nuclide_bundle, 1, thermal_energy=0.001, cutoff=0.002) assert helper.fast_yields == {} assert helper.thermal_yields == {} assert helper.constant_yields == { "U235": u235.yield_data[0.0253], "U238": u238.yield_data[5e5], "Pu239": pu239.yield_data[5e5]} helper = FissionYieldCutoffHelper( nuclide_bundle, 1, cutoff=15e6, fast_energy=17e6) assert helper.thermal_yields == {} assert helper.fast_yields == {} assert helper.constant_yields == { "U235": u235.yield_data[14e6], "U238": u238.yield_data[5e5], "Pu239": pu239.yield_data[2e6]}
def test_cutoff_helper(materials, nuclide_bundle, therm_frac): helper = FissionYieldCutoffHelper(nuclide_bundle, len(materials), cutoff=1e6, fast_energy=14e6) helper.generate_tallies(materials, [0]) non_zero_nucs = [n.name for n in nuclide_bundle] tally_nucs = helper.update_tally_nuclides(non_zero_nucs) assert tally_nucs == ["Pu239", "U235"] # Check tallies fission_tally = helper._fission_rate_tally assert fission_tally is not None filters = fission_tally.filters assert len(filters) == 2 assert isinstance(filters[0], lib.MaterialFilter) assert len(filters[0].bins) == len(materials) assert isinstance(filters[1], lib.EnergyFilter) # lower, cutoff, and upper energy assert len(filters[1].bins) == 3 # Emulate building tallies # material x energy, tallied_nuclides, 3 tally_data = proxy_tally_data(fission_tally) helper._fission_rate_tally = Mock() helper_flux = 1e6 tally_data[0] = therm_frac * helper_flux tally_data[1] = (1 - therm_frac) * helper_flux helper._fission_rate_tally.mean = tally_data helper.unpack() # expected results of shape (n_mats, 2, n_tnucs) expected_results = np.empty((1, 2, len(tally_nucs))) expected_results[:, 0] = therm_frac expected_results[:, 1] = 1 - therm_frac assert helper.results == pytest.approx(expected_results) actual_yields = helper.weighted_yields(0) assert actual_yields["U238"] == nuclide_bundle.u238.yield_data[5e5] for nuc in tally_nucs: assert actual_yields[nuc] == (helper.thermal_yields[nuc] * therm_frac + helper.fast_yields[nuc] * (1 - therm_frac))
def test_cutoff_failure(key): with pytest.raises(TypeError, match=key): FissionYieldCutoffHelper(None, None, **{key: None}) with pytest.raises(ValueError, match=key): FissionYieldCutoffHelper(None, None, **{key: -1})