From dcde3d81392b7bceed7643b52e1eb0e92820b690 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 27 Nov 2024 09:49:54 -0500 Subject: [PATCH 1/6] simplified example --- examples/point_source_example.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/point_source_example.py b/examples/point_source_example.py index 852309b..e575006 100644 --- a/examples/point_source_example.py +++ b/examples/point_source_example.py @@ -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" @@ -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() From ff03ebfc8751bed00d65abf77cc9e82467217fe1 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 27 Nov 2024 09:49:58 -0500 Subject: [PATCH 2/6] fixed bug --- src/openmc_plasma_source/fuel_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openmc_plasma_source/fuel_types.py b/src/openmc_plasma_source/fuel_types.py index c021060..0cbfeee 100644 --- a/src/openmc_plasma_source/fuel_types.py +++ b/src/openmc_plasma_source/fuel_types.py @@ -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") @@ -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"]: From 1dddffe59f593334cc5180c3af5ed05db7072a18 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 27 Nov 2024 09:58:10 -0500 Subject: [PATCH 3/6] added new example --- examples/plot_energy_spectra.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 examples/plot_energy_spectra.py diff --git a/examples/plot_energy_spectra.py b/examples/plot_energy_spectra.py new file mode 100644 index 0000000..3ed340b --- /dev/null +++ b/examples/plot_energy_spectra.py @@ -0,0 +1,34 @@ +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=100000) + + plt.hist( + energies / 1e6, + bins=1000, + histtype="step", + label=f"{1-tritium_fraction:.0%} D - {tritium_fraction:.0%} T", + ) + +plt.xlabel("Energy (MeV)") +plt.ylabel("Number of neutrons") +plt.legend() +plt.show() From 6e86fbf843fcb800c9e13b635a394240d3372fc6 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 27 Nov 2024 09:58:31 -0500 Subject: [PATCH 4/6] added example to CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8366f51..5938e69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 From fbfd22497a180b544f1040687419cda1a4e7c2d7 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 27 Nov 2024 11:34:55 -0500 Subject: [PATCH 5/6] logscale + density plot --- examples/plot_energy_spectra.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/plot_energy_spectra.py b/examples/plot_energy_spectra.py index 3ed340b..5a93893 100644 --- a/examples/plot_energy_spectra.py +++ b/examples/plot_energy_spectra.py @@ -19,16 +19,19 @@ ) # Plot the source energy distribution - energies = my_source[0].energy.sample(n_samples=100000) + energies = my_source[0].energy.sample(n_samples=int(5e6)) - plt.hist( + 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("Number of neutrons") +plt.ylabel("Neturon energy distribution") +plt.yscale("log") plt.legend() plt.show() From 0d60c08244e557bd596b31bef424667721d72bc8 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 27 Nov 2024 11:50:56 -0500 Subject: [PATCH 6/6] export to svg --- examples/plot_energy_spectra.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/plot_energy_spectra.py b/examples/plot_energy_spectra.py index 5a93893..db51b90 100644 --- a/examples/plot_energy_spectra.py +++ b/examples/plot_energy_spectra.py @@ -34,4 +34,6 @@ plt.ylabel("Neturon energy distribution") plt.yscale("log") plt.legend() +plt.ylim(bottom=1e-3) +plt.savefig("energy_spectra.svg") plt.show()