Skip to content

Commit

Permalink
Merge pull request #110 from fusion-energy/improve-energy-spectrum
Browse files Browse the repository at this point in the history
Improve energy spectrum plotting
  • Loading branch information
shimwell authored Nov 27, 2024
2 parents f727423 + 0d60c08 commit aafda85
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ jobs:
python examples/plot_tokamak_ion_temperature.py
python examples/plot_tokamak_neutron_source_density.py
python examples/plot_tokamak_neutron_source_strengths.py
python examples/plot_energy_spectra.py
39 changes: 39 additions & 0 deletions examples/plot_energy_spectra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import matplotlib.pyplot as plt
from openmc_plasma_source import fusion_point_source

import numpy as np

tritium_factions = np.linspace(0, 1, 3)
tritium_factions = np.concatenate([tritium_factions, [0.99]])
tritium_factions = np.sort(tritium_factions)

for tritium_fraction in tritium_factions:
fuel = {"D": 1 - tritium_fraction, "T": tritium_fraction}

if fuel["D"] == 0:
fuel = {"T": 1}
if fuel["T"] == 0:
fuel = {"D": 1}
my_source = fusion_point_source(
coordinate=(0, 0, 0), temperature=20000.0, fuel=fuel
)

# Plot the source energy distribution
energies = my_source[0].energy.sample(n_samples=int(5e6))

data, bins, _ = plt.hist(
energies / 1e6,
bins=1000,
histtype="step",
label=f"{1-tritium_fraction:.0%} D - {tritium_fraction:.0%} T",
density=True,
# alpha=0.5,
)

plt.xlabel("Energy (MeV)")
plt.ylabel("Neturon energy distribution")
plt.yscale("log")
plt.legend()
plt.ylim(bottom=1e-3)
plt.savefig("energy_spectra.svg")
plt.show()
19 changes: 7 additions & 12 deletions examples/point_source_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
}, # note this is mainly tritium fuel so that TT reactions are more likely
)


# Tell OpenMC we're going to use our custom source
settings = openmc.Settings()
settings.run_mode = "fixed source"
Expand All @@ -34,16 +35,10 @@

model.run()

# Plot the source energy distribution
energies = my_source[0].energy.sample(n_samples=10000)
import matplotlib.pyplot as plt

# optionally if you would like to plot the energy of particles then another package can be used
# https://github.com/fusion-energy/openmc_source_plotter

from openmc_source_plotter import plot_source_energy

plot = plot_source_energy(
this=settings,
n_samples=2000000, # increase this value for a smoother plot
energy_bins=np.linspace(0, 16e6, 1000),
yaxis_type="log",
)
plot.show()
plt.hist(energies, bins=1000)
plt.xlim(14e6 - 2e6, 14e6 + 2e6)
plt.show()
4 changes: 2 additions & 2 deletions src/openmc_plasma_source/fuel_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_neutron_energy_distribution(
# 1.0 neutron yield, all reactions scaled by this value
num_of_vals = 100
# single grid for TT neutrons
E_pspec = np.linspace(0, 12e6, num_of_vals) # E_pspec is exspected in MeV units
E_pspec = np.linspace(0, 12e6, num_of_vals) # E_pspec is exspected in eV units

DDmean = neutron_energy_mean(ion_temperature=ion_temperature, reaction="DD")
DTmean = neutron_energy_mean(ion_temperature=ion_temperature, reaction="DT")
Expand All @@ -165,7 +165,7 @@ def get_neutron_energy_distribution(
if reactions == ["TT"]:
strength_TT = 1.0
dNdE_TT = strength_TT * nst.dNdE_TT(E_pspec, ion_temperature)
tt_source = openmc.stats.Tabular(E_pspec * 1e6, dNdE_TT)
tt_source = openmc.stats.Tabular(E_pspec, dNdE_TT)
return tt_source

elif reactions == ["DD"]:
Expand Down

0 comments on commit aafda85

Please sign in to comment.