Skip to content

Commit

Permalink
Merge branch 'improved_energy_distribution' of github.com:fusion-ener…
Browse files Browse the repository at this point in the history
…gy/openmc-plasma-source into improved_energy_distribution
  • Loading branch information
shimwell committed Mar 6, 2024
2 parents 01d326b + 1188867 commit e1c8721
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/openmc_plasma_source/fuel_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_neutron_energy_distribution(
# print("DTmean", DTmean)
DDmean, DDvar = nst.DDprimspecmoments(ion_temperature_kev)
# print("DDmean", DDmean)
#todo make use of these DTvar and DDvar values in muir or gaussian distribution
# todo make use of these DTvar and DDvar values in muir or gaussian distribution

if ["D", "T"] == sorted(set(fuel.keys())):

Expand All @@ -66,8 +66,8 @@ def get_neutron_energy_distribution(

dNdE_TT = strength_TT * nst.dNdE_TT(E_pspec, ion_temperature_kev)
tt_source = openmc.stats.Tabular(E_pspec * 1e6, dNdE_TT)
dd_source = openmc.stats.muir(e0=DDmean*1e6, m_rat=4, kt=ion_temperature)
dt_source = openmc.stats.muir(e0=DTmean*1e6, m_rat=5, kt=ion_temperature)
dd_source = openmc.stats.muir(e0=DDmean * 1e6, m_rat=4, kt=ion_temperature)
dt_source = openmc.stats.muir(e0=DTmean * 1e6, m_rat=5, kt=ion_temperature)
# todo look into combining distributions openmc.data.combine_distributions()
return [tt_source, dd_source, dt_source], [
strength_TT,
Expand All @@ -78,7 +78,7 @@ def get_neutron_energy_distribution(
elif ["D"] == sorted(set(fuel.keys())):

strength_DD = 1.0
dd_source = openmc.stats.muir(e0=DDmean*1e6, m_rat=4, kt=ion_temperature)
dd_source = openmc.stats.muir(e0=DDmean * 1e6, m_rat=4, kt=ion_temperature)
return [dd_source], [strength_DD]

elif ["T"] == sorted(set(fuel.keys())):
Expand Down
45 changes: 27 additions & 18 deletions tests/test_fuel_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,44 @@
from openmc_plasma_source import get_neutron_energy_distribution


@pytest.mark.parametrize("temperature, fuel", [
(2e3, {'D': 1.}),
(2e3, {'T': 1.}),
(2e3, {'T': 0.5, 'D': 0.5}),
(2e3, {'T': 0.2, 'D': 0.8}),
])
@pytest.mark.parametrize(
"temperature, fuel",
[
(2e3, {"D": 1.0}),
(2e3, {"T": 1.0}),
(2e3, {"T": 0.5, "D": 0.5}),
(2e3, {"T": 0.2, "D": 0.8}),
],
)
def test_fuel_with_correct_inputs(temperature, fuel):
# Should accept any non-zero positive inputs to either variable
get_neutron_energy_distribution(temperature, fuel)


@pytest.mark.parametrize("temperature, fuel", [
(2e3, {'D': 1.1}),
(2e3, {'T': 0.9}),
(2e3, {'T': -0.5, 'D': 0.5}),
(2e3, {'T': -0.2, 'D': -0.8}),
])
@pytest.mark.parametrize(
"temperature, fuel",
[
(2e3, {"D": 1.1}),
(2e3, {"T": 0.9}),
(2e3, {"T": -0.5, "D": 0.5}),
(2e3, {"T": -0.2, "D": -0.8}),
],
)
def test_fuel_with_bad_inputs(temperature, fuel):
# Should reject any negative numbers and zeros.
with pytest.raises(ValueError):
get_neutron_energy_distribution(temperature, fuel)


@pytest.mark.parametrize("temperature, fuel", [
(2e3, {'DD': 1.1}),
(2e3, {'DT': 0.9}),
(2e3, {'He3': -0.5, 'D': 0.5}),
(2e3, {1: -0.2, 'D': -0.8}),
])
@pytest.mark.parametrize(
"temperature, fuel",
[
(2e3, {"DD": 1.1}),
(2e3, {"DT": 0.9}),
(2e3, {"He3": -0.5, "D": 0.5}),
(2e3, {1: -0.2, "D": -0.8}),
],
)
def test_fuel_with_incorrect_isotopese(temperature, fuel):
# Should reject anything which is not 'D' or 'T'.
with pytest.raises(ValueError):
Expand Down

0 comments on commit e1c8721

Please sign in to comment.