OpenMC/openmc/particle_restart.py
Paul Romano b41e22f68b
Refactor ParticleType to use PDG Monte Carlo numbering scheme (#3756)
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: Amanda Lund <alund1187@gmail.com>
2026-02-03 07:23:24 +00:00

61 lines
1.8 KiB
Python

import h5py
import openmc.checkvalue as cv
from .particle_type import ParticleType
_VERSION_PARTICLE_RESTART = 2
class Particle:
"""Information used to restart a specific particle that caused a simulation to
fail.
Parameters
----------
filename : str
Path to the particle restart file
Attributes
----------
current_batch : int
The batch containing the particle
generations_per_batch : int
Number of generations per batch
current_generation : int
The generation containing the particle
n_particles : int
Number of particles per generation
run_mode : int
Type of simulation (criticality or fixed source)
id : long
Identifier of the particle
type : openmc.ParticleType
Particle type
weight : float
Weight of the particle
energy : float
Energy of the particle in eV
xyz : list of float
Position of the particle
uvw : list of float
Directional cosines of the particle
"""
def __init__(self, filename):
with h5py.File(filename, 'r') as f:
# Ensure filetype and version are correct
cv.check_filetype_version(f, 'particle restart', _VERSION_PARTICLE_RESTART)
self.current_batch = f['current_batch'][()]
self.current_generation = f['current_generation'][()]
self.energy = f['energy'][()]
self.generations_per_batch = f['generations_per_batch'][()]
self.id = f['id'][()]
self.type = ParticleType(f['type'][()])
self.n_particles = f['n_particles'][()]
self.run_mode = f['run_mode'][()].decode()
self.uvw = f['uvw'][()]
self.weight = f['weight'][()]
self.xyz = f['xyz'][()]