A Python package for extracting and plotting the locations, directions, energy distributions of OpenMC source particles.
Project description
A Python package for plotting the positions, directions or energy distributions of OpenMC sources.
Installation
pip install openmc_source_plotter
Features
The package simply extends the default openmc.IndependentSourceBase
and openmc.Model
to provides additional functions that:
- extract the positions, directions and energy of particles
- visualise a source with respect to:
- direction
- energy
- position
Or just provide the initial particles with sample_initial_particles
Example plots
Below are some basic examples, for more examples see the examples folder for example usage scripts.
Plot of energy distribution of the source
import openmc
import openmc_source_plotter # extends openmc.IndependentSource with plotting functions
# initialises a new source object
my_source = openmc.IndependentSource()
# sets the energy distribution to a muir distribution neutrons for DT fusion neutrons
my_source.energy = openmc.stats.muir(e0=14080000.0, m_rat=5.0, kt=20000.0)
# plots the particle energy distribution
plot = my_source.plot_source_energy(n_samples=2000)
plot.show()
Plot of energy distribution of two sources
import openmc
import openmc_source_plotter # extends openmc.IndependentSource with plotting functions
# initialises a new source object
my_dt_source = openmc.IndependentSource()
# sets the energy distribution to a muir distribution DT neutrons
my_dt_source.energy = openmc.stats.muir(e0=14080000.0, m_rat=5.0, kt=20000.0)
# initialises a new source object
my_dd_source = openmc.IndependentSource()
# sets the energy distribution to a muir distribution DD neutrons
my_dd_source.energy = openmc.stats.muir(e0=2080000.0, m_rat=2.0, kt=20000.0)
# plots the particle energy distribution by building on the first plot
figure1 = my_dd_source.plot_source_energy(n_samples=10000)
figure2 = my_dt_source.plot_source_energy(figure=figure1, n_samples=10000)
figure2.show()
Plot direction of particles
import openmc
import openmc_source_plotter # extends openmc.IndependentSource with plotting functions
# initializes a new source object
my_source = openmc.IndependentSource()
# sets the direction to isotropic
my_source.angle = openmc.stats.Isotropic()
# plots the particle energy distribution
plot = my_source.plot_source_direction(n_samples=200)
plot.show()
Plot position of particles
import openmc
import openmc_source_plotter # extends openmc.IndependentSource with plotting functions
# initialises a new source object
my_source = openmc.IndependentSource()
# the distribution of radius is just a single value
radius = openmc.stats.Discrete([10], [1])
# the distribution of source z values is just a single value
z_values = openmc.stats.Discrete([0], [1])
# the distribution of source azimuthal angles
# values is a uniform distribution between 0 and 2 Pi
angle = openmc.stats.Uniform(a=0.0, b=2 * 3.14159265359)
# this makes the ring source using the three distributions and a radius
my_source.space = openmc.stats.CylindricalIndependent(
r=radius, phi=angle, z=z_values, origin=(0.0, 0.0, 0.0)
)
# plots the particle energy distribution
plot = my_source.plot_source_position()
plot.show()
Extract particle objects
A list of openmc.Particle
objects can be obtained using model.sample_initial_particles()
or openmc.SourceBase.sample_initial_particles()
import openmc
import openmc_source_plotter # extents openmc.Model with sample_initial_particles method
settings = openmc.Settings()
settings.particles = 1
settings.batches = 1
my_source = openmc.IndependentSource()
my_source.energy = openmc.stats.muir(e0=14080000.0, m_rat=5.0, kt=20000.0)
settings.source = my_source
materials = openmc.Materials()
sph = openmc.Sphere(r=100, boundary_type="vacuum")
cell = openmc.Cell(region=-sph)
geometry = openmc.Geometry([cell])
model = openmc.Model(geometry, materials, settings)
particles = model.sample_initial_particles(n_samples=10)
print(particles)
>>>[<SourceParticle: neutron at E=1.440285e+07 eV>, <SourceParticle: neutron at E=1.397691e+07 eV>, <SourceParticle: neutron at E=1.393681e+07 eV>, <SourceParticle: neutron at E=1.470896e+07 eV>, <SourceParticle: neutron at E=1.460563e+07 eV>, <SourceParticle: neutron at E=1.420684e+07 eV>, <SourceParticle: neutron at E=1.413932e+07 eV>, <SourceParticle: neutron at E=1.412428e+07 eV>, <SourceParticle: neutron at E=1.464779e+07 eV>, <SourceParticle: neutron at E=1.391648e+07 eV>]
print(particles[0].E)
>>>1.440285e+07
Related packages
Tokamak sources can also be plotted using the openmc-plasma-source package
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for openmc_source_plotter-0.6.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bbb763dfe3ec35effce1c3b2f72f414c46ca32725269c22ce05544d168bb644 |
|
MD5 | 85fc74490c77ed0ebf3e4f8298d140f4 |
|
BLAKE2b-256 | b5edf2cbf7bb310ab8a65a966ad56ed1098487e5c3d4e820b0eb8eab7d9eb92d |
Hashes for openmc_source_plotter-0.6.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df1a9d26dfdfd546f42ce812314456d1aa0f2fb5e31f21d8e1c5021355136148 |
|
MD5 | 192d4c383d2a398086a523efb374da53 |
|
BLAKE2b-256 | eaa55a057c2acf2003200b26205e340cdc2aeb624aca83fef021a66ed8ec04e1 |