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
Rename ParticlePdg to PDGNumber
  • Loading branch information
paulromano committed Jan 27, 2026
commit 49e189c6945ba68f4c3dc79add56c44473d7af07
8 changes: 4 additions & 4 deletions include/openmc/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace openmc {
// may not result in any benefits if not enough particles are present for them
// to achieve consistent locality improvements.
struct EventQueueItem {
int64_t idx; //!< particle index in event-based particle buffer
ParticlePdg type; //!< particle PDG
int64_t material; //!< material that particle is in
double E; //!< particle energy
int64_t idx; //!< particle index in event-based particle buffer
PDGNumber type; //!< particle PDG
int64_t material; //!< material that particle is in
double E; //!< particle energy

// Constructors
EventQueueItem() = default;
Expand Down
6 changes: 3 additions & 3 deletions 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, ParticlePdg type);
bool create_secondary(double wgt, Direction u, double E, PDGNumber type);

//! split a particle
//
Expand Down Expand Up @@ -127,9 +127,9 @@ class Particle : public ParticleData {
//! Functions
//============================================================================

std::string particle_pdg_to_str(ParticlePdg type);
std::string particle_pdg_to_str(PDGNumber type);

ParticlePdg str_to_particle_pdg(std::string_view str);
PDGNumber str_to_particle_pdg(std::string_view str);

void add_surf_source_to_bank(Particle& p, const Surface& surf);

Expand Down
16 changes: 8 additions & 8 deletions include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct SourceSite {
double wgt {1.0};
int delayed_group {0};
int surf_id {SURFACE_NONE};
ParticlePdg particle;
PDGNumber 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};
ParticlePdg particle;
PDGNumber 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 {
ParticlePdg particle;
PDGNumber particle;
std::vector<TrackState> states;
};

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

ParticlePdg type_ {PDG_NEUTRON};
PDGNumber type_ {PDG_NEUTRON};

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

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

// Current particle energy, energy before collision,
// and corresponding multigroup group indices. Energy
Expand Down
52 changes: 26 additions & 26 deletions include/openmc/particle_pdg.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ namespace openmc {
// Canonical PDG particle identifier (standard-layout, trivially copyable)
//------------------------------------------------------------------------------

struct ParticlePdg {
struct PDGNumber {
int32_t value;
};

static_assert(std::is_standard_layout_v<ParticlePdg>,
"ParticlePdg must be standard-layout");
static_assert(std::is_trivially_copyable_v<ParticlePdg>,
static_assert(
std::is_standard_layout_v<PDGNumber>, "ParticlePdg must be standard-layout");
static_assert(std::is_trivially_copyable_v<PDGNumber>,
"ParticlePdg must be trivially copyable");
static_assert(
offsetof(ParticlePdg, value) == 0, "ParticlePdg value must be at offset 0");
static_assert(sizeof(ParticlePdg) == sizeof(int32_t),
offsetof(PDGNumber, value) == 0, "ParticlePdg value must be at offset 0");
static_assert(sizeof(PDGNumber) == sizeof(int32_t),
"ParticlePdg must be same size as int32_t");

constexpr bool operator==(ParticlePdg lhs, ParticlePdg rhs)
constexpr bool operator==(PDGNumber lhs, PDGNumber rhs)
{
return lhs.value == rhs.value;
}
constexpr bool operator!=(ParticlePdg lhs, ParticlePdg rhs)
constexpr bool operator!=(PDGNumber lhs, PDGNumber rhs)
{
return lhs.value != rhs.value;
}
constexpr bool operator<(ParticlePdg lhs, ParticlePdg rhs)
constexpr bool operator<(PDGNumber lhs, PDGNumber rhs)
{
return lhs.value < rhs.value;
}
Expand All @@ -49,20 +49,20 @@ constexpr bool operator<(ParticlePdg lhs, ParticlePdg rhs)
// PDG constants (canonical particle identity)
//------------------------------------------------------------------------------

inline constexpr ParticlePdg PDG_NEUTRON {2112};
inline constexpr ParticlePdg PDG_PHOTON {22};
inline constexpr ParticlePdg PDG_ELECTRON {11};
inline constexpr ParticlePdg PDG_POSITRON {-11};
inline constexpr ParticlePdg PDG_PROTON {2212};
inline constexpr ParticlePdg PDG_DEUTERON {1000010020};
inline constexpr ParticlePdg PDG_TRITON {1000010030};
inline constexpr ParticlePdg PDG_ALPHA {1000020040};
inline constexpr PDGNumber PDG_NEUTRON {2112};
inline constexpr PDGNumber PDG_PHOTON {22};
inline constexpr PDGNumber PDG_ELECTRON {11};
inline constexpr PDGNumber PDG_POSITRON {-11};
inline constexpr PDGNumber PDG_PROTON {2212};
inline constexpr PDGNumber PDG_DEUTERON {1000010020};
inline constexpr PDGNumber PDG_TRITON {1000010030};
inline constexpr PDGNumber PDG_ALPHA {1000020040};

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

constexpr int transport_index_from_pdg(ParticlePdg pdg)
constexpr int transport_index_from_pdg(PDGNumber pdg)
{
switch (pdg.value) {
case PDG_NEUTRON.value:
Expand All @@ -78,7 +78,7 @@ constexpr int transport_index_from_pdg(ParticlePdg pdg)
}
}

constexpr bool is_transport_pdg(ParticlePdg pdg)
constexpr bool is_transport_pdg(PDGNumber pdg)
{
return transport_index_from_pdg(pdg) != C_NONE;
}
Expand All @@ -88,25 +88,25 @@ constexpr bool is_transport_pdg(ParticlePdg pdg)
//------------------------------------------------------------------------------

// Convert a particle identifier string to PDG.
ParticlePdg str_to_particle_pdg(std::string_view str);
PDGNumber str_to_particle_pdg(std::string_view str);

// Convert PDG to a canonical string (known names or GNDS nuclide name).
std::string particle_pdg_to_str(ParticlePdg pdg);
std::string particle_pdg_to_str(PDGNumber pdg);

// Legacy enum code (0..3) to PDG conversion
ParticlePdg legacy_particle_code_to_pdg(int code);
PDGNumber legacy_particle_code_to_pdg(int code);

// GNDS nuclide name to PDG nuclear code (100ZZZAAAI)
ParticlePdg particle_pdg_from_nuclide_name(std::string_view gnds);
PDGNumber particle_pdg_from_nuclide_name(std::string_view gnds);

// PDG nuclear code to GNDS nuclide name (e.g., "Fe57", "Am242_m1")
std::string nuclide_name_from_particle_pdg(ParticlePdg pdg);
std::string nuclide_name_from_particle_pdg(PDGNumber pdg);

// Build a PDG nuclear code from Z, A, and isomer level
ParticlePdg particle_pdg_from_zam(int Z, int A, int m);
PDGNumber particle_pdg_from_zam(int Z, int A, int m);

// Check for PDG nuclear code (100ZZZAAAI)
bool is_nuclear_pdg(ParticlePdg pdg);
bool is_nuclear_pdg(PDGNumber pdg);

} // namespace openmc

Expand Down
2 changes: 1 addition & 1 deletion include/openmc/reaction_product.h
Original file line number Diff line number Diff line change
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;

ParticlePdg particle_; //!< Particle PDG
PDGNumber particle_; //!< Particle PDG
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
12 changes: 6 additions & 6 deletions include/openmc/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class IndependentSource : public Source {
SourceSite sample(uint64_t* seed) const override;

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

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

private:
// Data members
ParticlePdg particle_ {PDG_NEUTRON}; //!< Type of particle emitted
UPtrSpace space_; //!< Spatial distribution
UPtrAngle angle_; //!< Angular distribution
UPtrDist energy_; //!< Energy distribution
UPtrDist time_; //!< Time distribution
PDGNumber particle_ {PDG_NEUTRON}; //!< Type of particle emitted
UPtrSpace space_; //!< Spatial distribution
UPtrAngle angle_; //!< Angular distribution
UPtrDist energy_; //!< Energy distribution
UPtrDist time_; //!< Time distribution
};

//==============================================================================
Expand Down
6 changes: 3 additions & 3 deletions include/openmc/tallies/filter_particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class ParticleFilter : public Filter {
//----------------------------------------------------------------------------
// Accessors

const vector<ParticlePdg>& particles() const { return particles_; }
const vector<PDGNumber>& particles() const { return particles_; }

void set_particles(span<ParticlePdg> particles);
void set_particles(span<PDGNumber> particles);

private:
//----------------------------------------------------------------------------
// Data members

vector<ParticlePdg> particles_;
vector<PDGNumber> particles_;
};

} // namespace openmc
Expand Down
6 changes: 3 additions & 3 deletions include/openmc/weight_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class WeightWindows {

void set_bounds(span<const double> lower_bounds, double ratio);

void set_particle_type(ParticlePdg p_type);
void set_particle_type(PDGNumber p_type);

double survival_ratio() const { return survival_ratio_; }

Expand Down Expand Up @@ -188,14 +188,14 @@ class WeightWindows {
const xt::xtensor<double, 2>& upper_ww_bounds() const { return upper_ww_; }
xt::xtensor<double, 2>& upper_ww_bounds() { return upper_ww_; }

ParticlePdg particle_type() const { return particle_type_; }
PDGNumber particle_type() const { return particle_type_; }

private:
//----------------------------------------------------------------------------
// Data members
int32_t id_; //!< Unique ID
int64_t index_; //!< Index into weight windows vector
ParticlePdg particle_type_ {
PDGNumber particle_type_ {
PDG_NEUTRON}; //!< Particle type to apply weight windows to
vector<double> energy_bounds_; //!< Energy boundaries [eV]
xt::xtensor<double, 2> lower_ww_; //!< Lower weight window bounds (shape:
Expand Down
2 changes: 1 addition & 1 deletion src/mcpl_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ inline void ensure_mcpl_ready_or_fatal()
SourceSite mcpl_particle_to_site(const mcpl_particle_repr_t* particle_repr)
{
SourceSite site;
site.particle = ParticlePdg {static_cast<int32_t>(particle_repr->pdgcode)};
site.particle = PDGNumber {static_cast<int32_t>(particle_repr->pdgcode)};

// Copy position and direction
site.r.x = particle_repr->position[0];
Expand Down
2 changes: 1 addition & 1 deletion src/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ double Particle::speed() const
}

bool Particle::create_secondary(
double wgt, Direction u, double E, ParticlePdg type)
double wgt, Direction u, double E, PDGNumber type)
{
// If energy is below cutoff for this particle, don't create secondary
// particle
Expand Down
20 changes: 10 additions & 10 deletions src/particle_pdg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool parse_gnds_nuclide(std::string_view name, int& Z, int& A, int& m)

} // namespace

ParticlePdg str_to_particle_pdg(std::string_view str)
PDGNumber str_to_particle_pdg(std::string_view str)
{
std::string s {str};
strtrim(s);
Expand All @@ -124,7 +124,7 @@ ParticlePdg str_to_particle_pdg(std::string_view str)
throw std::invalid_argument {"Invalid PDG code: " + value_str};
}
int32_t value = std::stoi(value_str);
return ParticlePdg {value};
return PDGNumber {value};
}

if (lower == "neutron" || lower == "n")
Expand All @@ -146,13 +146,13 @@ ParticlePdg str_to_particle_pdg(std::string_view str)

if (is_integer_string(s)) {
int32_t value = std::stoi(s);
return ParticlePdg {value};
return PDGNumber {value};
}

return particle_pdg_from_nuclide_name(s);
}

std::string particle_pdg_to_str(ParticlePdg pdg)
std::string particle_pdg_to_str(PDGNumber pdg)
{
if (pdg == PDG_NEUTRON)
return "neutron";
Expand All @@ -172,7 +172,7 @@ std::string particle_pdg_to_str(ParticlePdg pdg)
return "pdg:" + std::to_string(pdg.value);
}

ParticlePdg legacy_particle_code_to_pdg(int code)
PDGNumber legacy_particle_code_to_pdg(int code)
{
switch (code) {
case 0:
Expand All @@ -189,7 +189,7 @@ ParticlePdg legacy_particle_code_to_pdg(int code)
}
}

ParticlePdg particle_pdg_from_nuclide_name(std::string_view gnds)
PDGNumber particle_pdg_from_nuclide_name(std::string_view gnds)
{
int Z = 0;
int A = 0;
Expand All @@ -200,7 +200,7 @@ ParticlePdg particle_pdg_from_nuclide_name(std::string_view gnds)
return particle_pdg_from_zam(Z, A, m);
}

std::string nuclide_name_from_particle_pdg(ParticlePdg pdg)
std::string nuclide_name_from_particle_pdg(PDGNumber pdg)
{
if (!is_nuclear_pdg(pdg)) {
throw std::invalid_argument {
Expand All @@ -224,16 +224,16 @@ std::string nuclide_name_from_particle_pdg(ParticlePdg pdg)
return name;
}

ParticlePdg particle_pdg_from_zam(int Z, int A, int m)
PDGNumber particle_pdg_from_zam(int Z, int A, int m)
{
if (Z <= 0 || Z > 999 || A <= 0 || A > 999 || m < 0 || m > 9) {
throw std::invalid_argument {"Invalid Z/A/m for nuclear PDG code."};
}
int32_t code = 1000000000 + Z * 10000 + A * 10 + m;
return ParticlePdg {code};
return PDGNumber {code};
}

bool is_nuclear_pdg(ParticlePdg pdg)
bool is_nuclear_pdg(PDGNumber pdg)
{
int32_t code = pdg.value;
if (code < 1000000000)
Expand Down
2 changes: 1 addition & 1 deletion src/particle_restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void read_particle_restart(Particle& p, RunMode& previous_run_mode)
int type;
read_dataset(file_id, "type", type);
p.type() = legacy_particle_codes ? legacy_particle_code_to_pdg(type)
: ParticlePdg {type};
: PDGNumber {type};
read_dataset(file_id, "weight", p.wgt());
read_dataset(file_id, "energy", p.E());
read_dataset(file_id, "xyz", p.r());
Expand Down
2 changes: 1 addition & 1 deletion src/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace openmc {

namespace {

void validate_pdg_or_fatal(ParticlePdg pdg, const std::string& context)
void validate_pdg_or_fatal(PDGNumber pdg, const std::string& context)
{
if (is_transport_pdg(pdg))
return;
Expand Down
Loading