Different distribution of Neutron density in openmc_plasma_source

Hii
I was trying to model a tokamak source using openmc_plasma_source utility in openmc and I added following lines to source definition as given in the test code (similar to tokamak_source.py in example folder of utility) to print neutron_source_density attributes as it is shown in graphs of the same.

data=my_plasma.neutron_source_density
print(data)

I got 1000 diff points denoting neutron density(/src/cm3/s), till this no issue.

but as soon as I re-run I got those 1000 points different. I calculated average of neutron source density in each case which differs by 1-3 percent. I don’ t understand that why this distribution nos. are changing, does’nt it should be same at every run when no change in any other input?

I am sorry if I asked something very trivial but I really have no idea.

I am putting here input code which I tried (changed tokamak_source.py file with my parameters)


import openmc
from openmc_plasma_source import TokamakSource
import openmc_plasma_source.plotting as plt2
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize
import matplotlib as mpl
from matplotlib import cm
import numpy as np

minimal geometry

sphere_surface = openmc.Sphere(r=1000.0, boundary_type=“vacuum”)
cell = openmc.Cell(region=-sphere_surface)
geometry = openmc.Geometry([cell])

create a plasma source

my_plasma = TokamakSource(
elongation=2,
ion_density_centre=1.78e20,
ion_density_peaking_factor=1,
ion_density_pedestal=1.78e20,
ion_density_separatrix=3e19,

ion_temperature_centre=45.9,

ion_temperature_centre=4.71,

ion_temperature_centre=45.9,
ion_temperature_peaking_factor=8.06,

ion_temperature_pedestal=6.09,

ion_temperature_pedestal=0.427,

ion_temperature_pedestal=6.09,
ion_temperature_separatrix=0.1,

major_radius=9.06,

minor_radius=2.92258,

major_radius=150,
minor_radius=90,
pedestal_radius=0.8 * 90,
mode="H",
shafranov_factor=0.44789,

triangularity=0.270,

 triangularity=0.5,
ion_temperature_beta=4,

ion_temperature_beta=3.86,

)

Tell OpenMC we’re going to use our custom source

settings = openmc.Settings()
settings.run_mode = “fixed source”
settings.batches = 10
settings.particles = 1000
settings.source = my_plasma.sources

model = openmc.model.Model(
materials=None, geometry=geometry, settings=settings
)

model.run()

data=my_plasma.neutron_source_density
print(data)

create a figure and axis

fig, ax = plt.subplots()

plot the tokamak source with a color scale

norm = Normalize()
scatter = plt2.scatter_tokamak_source(my_plasma, quantity=“neutron_source_density”, ax=ax, cmap=‘viridis’, norm=norm)

create a ScalarMappable object for the colorbar

sm = plt.cm.ScalarMappable(cmap=‘viridis’, norm=norm )
#sm = plt.cm.ScalarMappable(cmap=‘viridis’)
sm.set_array()

add a colorbar

plt.colorbar(sm, ax=ax, label=‘Neutron Source Density [per cm^3/s]’)

show the plot

plt.show()

plt2.plot_tokamak_source_3D(my_plasma, quantity=“neutron_source_density”)

show the plot

plt.show()

data=my_plasma.neutron_source_density
print(data)


Currently the RZ location of the coordiates are randomly selected each time a plasma source is created.

So they will be slightly different each time. This can be reduced by sampling more that 1000 points. Or alternatively you can change the sampling method used one these two lines of code openmc-plasma-source/src/openmc_plasma_source/tokamak_source.py at 64e4aa13f1e81efb8d0e16d7b76acb40bacce468 · fusion-energy/openmc-plasma-source · GitHub

Im actually working on that package at the moment and trying to improve it. This can be one of the improvements to look into. I’m hoping to first improve the energy distribution then move it to using mesh sources (which will fix the reproducibility bug you noticed). Next openmc release supports mesh sources so hopefully a release of openmc-plasma-source will get it fixed just after the next openmc release.

1 Like

I’ve just put in a pull request that should fix this issue. It would be great if you could let me know if this works for you

added grid for sampling a, alpha by shimwell · Pull Request #91 · fusion-energy/openmc-plasma-source (github.com)

First I am sorry for delayed reply.
I tried same changes you made in added grid for sampling a, alpha by shimwell · Pull Request #91 · fusion-energy/openmc-plasma-source · GitHub in my tokamak_source.py file of package and then I ran my input file to print neutron density values. But again values seem changing.

Am I not doing it properly because I understood that you did some changes in sampling by adding 4 lines for a and alpha sampling.

The new version of openmc-plasma-source is now on pypi. So it should be possible to install with

pip install==0.3.1