Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e2f47cc
Initial cut at PDG number implementation
paulromano Jan 23, 2026
ab23ed3
Fix broken build and update one test
paulromano Jan 23, 2026
49e189c
Rename ParticlePdg to PDGNumber
paulromano Jan 27, 2026
cb76a45
Rename header/source to pdg_number.h/cpp
paulromano Jan 27, 2026
a6ca46c
Rename function names
paulromano Jan 27, 2026
e79a082
More renaming
paulromano Jan 27, 2026
e80e742
Remove duplicate declarations
paulromano Jan 27, 2026
fa7942e
Rename ParticleType to PDGNumber on Python side
paulromano Jan 27, 2026
c942f59
Refactor back to ParticleType that stores PDG number
paulromano Jan 28, 2026
f8840b9
Use factory methods
paulromano Jan 28, 2026
2896db5
Introduce is_neutron and is_photon methods
paulromano Jan 28, 2026
1615818
Cleanup
paulromano Jan 28, 2026
9bef229
Clean up validation
paulromano Jan 28, 2026
3c31ec6
More cleanup
paulromano Jan 28, 2026
1b2b9fe
Simplifications around ParticleType on Python side
paulromano Jan 28, 2026
dccd52c
Clean up Python ParticleType
paulromano Jan 28, 2026
b84ebd3
No bump for weight windows file format
paulromano Jan 28, 2026
4310612
Better use of ParticleType in tracks.py
paulromano Jan 28, 2026
505d65c
Use ParticleType for WeightWindows.particle_type
paulromano Jan 28, 2026
d44eb2e
Use ParticleType for IndependentSource.particle
paulromano Jan 28, 2026
81b01b0
Move ParticleType to its own file
paulromano Jan 29, 2026
ceb5ed9
Change ParticleType to normal class on Python side
paulromano Jan 29, 2026
6885c8b
Remove extra dunder methods
paulromano Jan 29, 2026
70a199d
Add tests for ParticleType
paulromano Jan 29, 2026
4d629b4
Merge branch 'develop' into particle-type-pdg
paulromano Jan 29, 2026
73cae62
Fix C++ style formatting
paulromano Jan 29, 2026
67561a0
Fix failing tests
paulromano Jan 29, 2026
7d830ab
Update openmc/weight_windows.py
GuySten Jan 29, 2026
46d05d3
Update include/openmc/particle_type.h per @amandalund suggestion
paulromano Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better use of ParticleType in tracks.py
  • Loading branch information
paulromano committed Jan 28, 2026
commit 4310612d5613a2d6dab95227e6f73d4827f42223
4 changes: 2 additions & 2 deletions docs/source/usersguide/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ below.
{
openmc::SourceSite particle;
// weight
particle.particle = openmc::PDG_NEUTRON;
particle.particle = openmc::ParticleType::neutron();
particle.wgt = 1.0;
// position
double angle = 2.0 * M_PI * openmc::prn(seed);
Expand Down Expand Up @@ -477,7 +477,7 @@ parameters to the source class when it is created:
{
openmc::SourceSite particle;
// weight
particle.particle = openmc::PDG_NEUTRON;
particle.particle = openmc::ParticleType::neutron();
particle.wgt = 1.0;
// position
particle.r.x = 0.0;
Expand Down
3 changes: 3 additions & 0 deletions openmc/lib/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
_dll.openmc_new_filter.argtypes = [c_char_p, POINTER(c_int32)]
_dll.openmc_new_filter.restype = c_int
_dll.openmc_new_filter.errcheck = _error_handler
_dll.openmc_particle_filter_get_bins.argtypes = [c_int32, POINTER(c_int32)]
_dll.openmc_particle_filter_get_bins.restype = c_int
_dll.openmc_particle_filter_get_bins.errcheck = _error_handler
_dll.openmc_spatial_legendre_filter_get_order.argtypes = [c_int32, POINTER(c_int)]
_dll.openmc_spatial_legendre_filter_get_order.restype = c_int
_dll.openmc_spatial_legendre_filter_get_order.errcheck = _error_handler
Expand Down
4 changes: 1 addition & 3 deletions openmc/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
from openmc.stats.univariate import Univariate
from ._xml import get_elem_list, get_text
from .mesh import MeshBase, StructuredMesh, UnstructuredMesh
from .statepoint import _VERSION_STATEPOINT
from .utility_funcs import input_path


_VERSION_STATEPOINT = 18


class SourceBase(ABC):
"""Base class for external sources

Expand Down
22 changes: 5 additions & 17 deletions openmc/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Parameters
----------
particle : openmc.ParticleType
Type of the particle (PDG-backed)
Type of the particle
states : numpy.ndarray
Structured array containing each state of the particle. The structured array
contains the following fields: ``r`` (position; each direction in [cm]),
Expand All @@ -25,7 +25,7 @@

"""
def _particle_track_repr(self):
return f"<ParticleTrack: {self.particle}, {len(self.states)} states>"
return f"<ParticleTrack: {str(self.particle)}, {len(self.states)} states>"
ParticleTrack.__repr__ = _particle_track_repr


Expand Down Expand Up @@ -93,7 +93,7 @@ def filter(self, particle=None, state_filter=None):
Parameters
----------
particle : str or int or openmc.ParticleType
Matching particle type (alias, PDG, or GNDS nuclide)
Matching particle type (name, PDG number, or type)
state_filter : function
Function that takes a state (structured datatype) and returns a bool
depending on some criteria.
Expand Down Expand Up @@ -123,22 +123,10 @@ def filter(self, particle=None, state_filter=None):

"""
matching = []
particle_match = None
if particle is not None:
try:
if isinstance(particle, str):
particle_match = ParticleType(particle)
else:
particle_match = ParticleType(particle)
except (TypeError, ValueError):
track = type(self).__new__(type(self))
track.identifier = self.identifier
track.particle_tracks = []
return track
for t in self:
# Check for matching particle
if particle_match is not None:
if t.particle != particle_match:
if particle is not None:
if t.particle != ParticleType(particle):
continue

# Apply arbitrary state filter
Expand Down
4 changes: 3 additions & 1 deletion tests/unit_tests/test_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ def test_filter(sphere_model, run_in_tmpdir):
assert matches == tracks
matches = tracks.filter(state_filter=lambda s: s['E'] > 0.0)
assert matches == tracks
matches = tracks.filter(particle='bunnytron')
matches = tracks.filter(particle='proton')
assert matches == []
with pytest.raises(ValueError):
tracks.filter(particle='bunnytron')


def test_write_to_vtk(sphere_model):
Expand Down