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
Refactor back to ParticleType that stores PDG number
  • Loading branch information
paulromano committed Jan 28, 2026
commit c942f5987a1a34c1f501c2bb151a1da97a740044
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ list(APPEND libopenmc_SOURCES
src/particle.cpp
src/particle_data.cpp
src/particle_restart.cpp
src/pdg_number.cpp
src/particle_type.cpp
src/photon.cpp
src/physics.cpp
src/physics_common.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/openmc/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace openmc {
// to achieve consistent locality improvements.
struct EventQueueItem {
int64_t idx; //!< particle index in event-based particle buffer
PDGNumber type; //!< particle PDG
ParticleType type; //!< particle type
int64_t material; //!< material that particle is in
double E; //!< particle energy

Expand Down
2 changes: 1 addition & 1 deletion include/openmc/particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Particle : public ParticleData {
//! \param E Energy of the secondary particle in [eV]
//! \param type Particle type
//! \return Whether a secondary particle was created
bool create_secondary(double wgt, Direction u, double E, PDGNumber type);
bool create_secondary(double wgt, Direction u, double E, ParticleType type);

//! split a particle
//
Expand Down
16 changes: 7 additions & 9 deletions include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "openmc/array.h"
#include "openmc/constants.h"
#include "openmc/pdg_number.h"
#include "openmc/particle_type.h"
#include "openmc/position.h"
#include "openmc/random_lcg.h"
#include "openmc/tallies/filter_match.h"
Expand Down Expand Up @@ -46,7 +46,7 @@ struct SourceSite {
double wgt {1.0};
int delayed_group {0};
int surf_id {SURFACE_NONE};
PDGNumber particle;
ParticleType particle;

// Extra attributes that don't show up in source written to file
int parent_nuclide {-1};
Expand All @@ -68,7 +68,7 @@ struct CollisionTrackSite {
int material_id {0};
int universe_id {0};
int n_collision {0};
PDGNumber particle;
ParticleType particle;
int64_t parent_id;
int64_t progeny_id;
};
Expand All @@ -87,7 +87,7 @@ struct TrackState {

//! Full history of a single particle's track states
struct TrackStateHistory {
PDGNumber particle;
ParticleType particle;
std::vector<TrackState> states;
};

Expand Down Expand Up @@ -494,7 +494,7 @@ class ParticleData : public GeometryState {
MacroXS macro_xs_;
CacheDataMG mg_xs_cache_;

PDGNumber type_ {PDG_NEUTRON};
ParticleType type_;

double E_;
double E_last_;
Expand Down Expand Up @@ -590,10 +590,8 @@ class ParticleData : public GeometryState {
const CacheDataMG& mg_xs_cache() const { return mg_xs_cache_; }

// Particle type (n, p, e, gamma, etc)
PDGNumber& type() { return type_; }
const PDGNumber& type() const { return type_; }
PDGNumber& pdg() { return type_; }
const PDGNumber& pdg() const { return type_; }
ParticleType& type() { return type_; }
const ParticleType& type() const { return type_; }

// Current particle energy, energy before collision,
// and corresponding multigroup group indices. Energy
Expand Down
142 changes: 142 additions & 0 deletions include/openmc/particle_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//==============================================================================
// ParticleType class definition
//==============================================================================

#ifndef OPENMC_PARTICLE_TYPE_H
#define OPENMC_PARTICLE_TYPE_H

#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <type_traits>

#include "openmc/constants.h"

namespace openmc {

//------------------------------------------------------------------------------
// PDG constants (canonical particle identity as simple integers)
//------------------------------------------------------------------------------

inline constexpr int32_t PDG_NEUTRON = 2112;
inline constexpr int32_t PDG_PHOTON = 22;
inline constexpr int32_t PDG_ELECTRON = 11;
inline constexpr int32_t PDG_POSITRON = -11;
inline constexpr int32_t PDG_PROTON = 2212;
inline constexpr int32_t PDG_DEUTERON = 1000010020;
inline constexpr int32_t PDG_TRITON = 1000010030;
inline constexpr int32_t PDG_ALPHA = 1000020040;

//------------------------------------------------------------------------------
// ParticleType class (standard-layout, trivially copyable)
//------------------------------------------------------------------------------

class ParticleType {
public:
//----------------------------------------------------------------------------
// Constructors

// Default constructor: defaults to neutron
constexpr ParticleType() : pdg_number_(PDG_NEUTRON) {}

// Constructor from PDG code
constexpr explicit ParticleType(int32_t pdg_number) : pdg_number_(pdg_number)
{}

// Constructor from particle name string (e.g., "neutron", "photon", "Fe56")
explicit ParticleType(std::string_view str);

// Constructor from Z, A, and metastable state for nuclear particles
constexpr ParticleType(int Z, int A, int m = 0)
: pdg_number_(1000000000 + Z * 10000 + A * 10 + m)
{}

//----------------------------------------------------------------------------
// Accessors

// Accessor for the underlying PDG number
constexpr int32_t pdg_number() const { return pdg_number_; }

//----------------------------------------------------------------------------
// Methods

// Convert to string representation
std::string str() const;

// Check if this represents a nucleus (vs elementary particle)
constexpr bool is_nucleus() const
{
// PDG nuclear codes are >= 1000000000 (100ZZZAAAI format)
return pdg_number_ >= 1000000000;
}

private:
int32_t pdg_number_;
};

//------------------------------------------------------------------------------
// Static assertions to ensure standard-layout and trivially copyable
//------------------------------------------------------------------------------

static_assert(std::is_standard_layout_v<ParticleType>,
"ParticleType must be standard-layout");
static_assert(std::is_trivially_copyable_v<ParticleType>,
"ParticleType must be trivially copyable");
static_assert(sizeof(ParticleType) == sizeof(int32_t),
"ParticleType must be same size as int32_t");

//------------------------------------------------------------------------------
// Comparison operators (free functions for symmetry)
//------------------------------------------------------------------------------

constexpr bool operator==(ParticleType lhs, ParticleType rhs)
{
return lhs.pdg_number() == rhs.pdg_number();
}

constexpr bool operator!=(ParticleType lhs, ParticleType rhs)
{
return lhs.pdg_number() != rhs.pdg_number();
}

constexpr bool operator<(ParticleType lhs, ParticleType rhs)
{
return lhs.pdg_number() < rhs.pdg_number();
}

//------------------------------------------------------------------------------
// Transport indexing helpers (for dense arrays keyed by transport kind)
//------------------------------------------------------------------------------

constexpr int transport_index(ParticleType type)
{
switch (type.pdg_number()) {
case PDG_NEUTRON:
return 0;
case PDG_PHOTON:
return 1;
case PDG_ELECTRON:
return 2;
case PDG_POSITRON:
return 3;
default:
return C_NONE;
}
}

constexpr bool is_transportable(ParticleType type)
{
return transport_index(type) != C_NONE;
}

//------------------------------------------------------------------------------
// Legacy conversion helpers
//------------------------------------------------------------------------------

// Legacy enum code (0..3) to ParticleType conversion
ParticleType legacy_particle_index_to_type(int code);

} // namespace openmc

#endif // OPENMC_PARTICLE_TYPE_H
113 changes: 0 additions & 113 deletions include/openmc/pdg_number.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/openmc/reaction_product.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "openmc/chain.h"
#include "openmc/endf.h"
#include "openmc/memory.h" // for unique_ptr
#include "openmc/particle.h"
#include "openmc/particle_type.h"
#include "openmc/vector.h" // for vector

namespace openmc {
Expand Down Expand Up @@ -49,7 +49,7 @@ class ReactionProduct {
//! \param[inout] seed Pseudorandom seed pointer
void sample(double E_in, double& E_out, double& mu, uint64_t* seed) const;

PDGNumber particle_; //!< Particle PDG
ParticleType particle_; //!< Particle type
EmissionMode emission_mode_; //!< Emission mode
double decay_rate_; //!< Decay rate (for delayed neutron precursors) in [1/s]
unique_ptr<Function1D> yield_; //!< Yield as a function of energy
Expand Down
6 changes: 3 additions & 3 deletions include/openmc/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "openmc/distribution_multi.h"
#include "openmc/distribution_spatial.h"
#include "openmc/memory.h"
#include "openmc/particle.h"
#include "openmc/particle_type.h"
#include "openmc/vector.h"

namespace openmc {
Expand Down Expand Up @@ -127,7 +127,7 @@ class IndependentSource : public Source {
SourceSite sample(uint64_t* seed) const override;

// Properties
PDGNumber particle_type() const { return particle_; }
ParticleType particle_type() const { return particle_; }

// Make observing pointers available
SpatialDistribution* space() const { return space_.get(); }
Expand All @@ -148,7 +148,7 @@ class IndependentSource : public Source {

private:
// Data members
PDGNumber particle_ {PDG_NEUTRON}; //!< Type of particle emitted
ParticleType particle_; //!< Type of particle emitted
UPtrSpace space_; //!< Spatial distribution
UPtrAngle angle_; //!< Angular distribution
UPtrDist energy_; //!< Energy distribution
Expand Down
Loading