Issue graphing openmc-plasma-source

I’m trying to this script, mostly taken from the openmc plasma source sample tokamak script. Currently, my code is this:

import openmc
import openmc_plasma_source
import openmc_plasma_source.plotting as plt

create a plasma source

my_plasma = openmc_plasma_source.TokamakSource(
elongation=1.557,
ion_density_centre=1.09e20,
ion_density_peaking_factor=1,
ion_density_pedestal=1.09e20,
ion_density_separatrix=3e19,
ion_temperature_centre=45.9,
ion_temperature_peaking_factor=8.06,
ion_temperature_pedestal=6.09,
ion_temperature_separatrix=0.1,
major_radius=9.06,
minor_radius=2.92258,
pedestal_radius=0.8 * 2.92258,
mode=“L”,
shafranov_factor=0.44789,
triangularity=0.270,
ion_temperature_beta=6,
)

Create a single material

iron = openmc.Material()
iron.set_density(“g/cm3”, 5.0)
iron.add_element(“Fe”, 1.0)
mats = openmc.Materials([iron])
mats.cross_sections = “/home/agilan/Downloads/jeff33_hdf5/cross_sections.xml”

Create a 5 cm x 5 cm box filled with iron

cells =
inner_box1 = openmc.ZCylinder(r=600.0)
inner_box2 = openmc.ZCylinder(r=1400.0)
outer_box = openmc.model.rectangular_prism(4000.0, 4000.0, boundary_type=“vacuum”)
cells += [openmc.Cell(fill=iron, region=-inner_box1)]
cells += [openmc.Cell(fill=None, region=+inner_box1 & -inner_box2)]
cells += [openmc.Cell(fill=iron, region=+inner_box2 & outer_box)]
geometry = openmc.Geometry(cells)

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

Finally, define a mesh tally so that we can see the resulting flux

mesh = openmc.RegularMesh()
mesh.lower_left = (-2000.0, -2000.0)
mesh.upper_right = (2000.0, 2000.0)
mesh.dimension = (50, 50)

tally = openmc.Tally()
tally.filters = [openmc.MeshFilter(mesh)]
tally.scores = [“flux”]
tallies = openmc.Tallies([tally])

model = openmc.model.Model(
materials=mats, geometry=geometry, settings=settings, tallies=tallies
)

model.run()

plt.scatter_tokamak_source(my_plasma)
plt.plot_tokamak_source_3D(my_plasma)

The code runs however it doesn’t graph the data anywhere. Does anybody know where I’m screwing up?

Hello,

Maybe you should try to use matplotlib.pyplot.show() method ?

import openmc_plasma_source.plotting as plt2
import matplotlib.pyplot as plt

and at the end of your script :

plt2.scatter_tokamak_source(my_plasma)
plt.show()
plt2.plot_tokamak_source_3D(my_plasma)
plt.show()

Julien

2 Likes