https://github.com/fusion-energy/openmc_source_plotter
A Python package for extracting and plotting the locations, directions, energy distributions of OpenMC source particles
https://github.com/fusion-energy/openmc_source_plotter
coordinates direction energy gamma openmc particle plot source
Last synced: 3 months ago
JSON representation
A Python package for extracting and plotting the locations, directions, energy distributions of OpenMC source particles
- Host: GitHub
- URL: https://github.com/fusion-energy/openmc_source_plotter
- Owner: fusion-energy
- License: mit
- Created: 2021-11-25T21:18:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-10T21:36:38.000Z (almost 2 years ago)
- Last Synced: 2025-10-29T18:58:59.264Z (6 months ago)
- Topics: coordinates, direction, energy, gamma, openmc, particle, plot, source
- Language: Python
- Homepage:
- Size: 153 KB
- Stars: 12
- Watchers: 1
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/ci_with_install.yml)
[](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/python-publish.yml)
A Python package for plotting the positions, directions or energy distributions of OpenMC sources.
# Installation
You will need to have OpenMC version 0.14.0 or newer installed first.
```bash
pip install openmc_source_plotter
```
# Features
The package provides three plotting functions that can plot source data from openmc objects.
- ```plot_source_energy```
- ```plot_source_position```
- ```plot_source_direction```
- ```plot_gamma_emission```
Additionally the package provides a convienient method of sampling particles
- ```sample_initial_particles```
# Example plots
Below are some basic examples, for more examples see the [examples folder](https://github.com/fusion-energy/openmc_source_plotter/tree/main/examples) for example usage scripts.
## Plot of energy distribution of the source
:link:[Link](https://github.com/fusion-energy/openmc_source_plotter/blob/main/examples/example_plot_source_energy.py) to example script.

## Plot of energy distribution of two sources
:link:[Link](https://github.com/fusion-energy/openmc_source_plotter/blob/main/examples/example_plot_two_source_energies.py) to example script.

## Plot direction of particles
:link:[Link](https://github.com/fusion-energy/openmc_source_plotter/blob/main/examples/example_plot_source_direction.py) to example script.

## Plot position of particles
:link:[Link](https://github.com/fusion-energy/openmc_source_plotter/blob/main/examples/example_plot_source_position.py) to example script.

## Plot labeled gamma lines from material
:link:[Link](https://github.com/fusion-energy/openmc_source_plotter/blob/main/examples/example_gamma_spec_plot.py) to example script.

## Extract particle objects
A list of ```openmc.Particle``` objects can be obtained using ```model.sample_initial_particles()``` or ```openmc.SourceBase.sample_initial_particles()```
```python
import openmc
from openmc_source_plotter import sample_initial_particles
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 = sample_initial_particles(this=model, n_samples=10)
print(particles)
>>>[, , , , , , , , , ]
print(particles[0].E)
>>>1.440285e+07
```
## Related packages
Tokamak sources can also be plotted using the [openmc-plasma-source](https://github.com/fusion-energy/openmc-plasma-source) package
