• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 21616189382

03 Feb 2026 03:49AM UTC coverage: 81.772% (-0.2%) from 81.993%
21616189382

Pull #3756

github

web-flow
Merge 46d05d381 into fc0d9eec6
Pull Request #3756: Refactor ParticleType to use PDG Monte Carlo numbering scheme

17310 of 24247 branches covered (71.39%)

Branch coverage included in aggregate %.

346 of 501 new or added lines in 32 files covered. (69.06%)

497 existing lines in 8 files now uncovered.

55908 of 65292 relevant lines covered (85.63%)

44288421.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.38
/src/reaction_product.cpp
1
#include "openmc/reaction_product.h"
2

3
#include <string> // for string
4

5
#include <fmt/core.h>
6

7
#include "openmc/endf.h"
8
#include "openmc/error.h"
9
#include "openmc/hdf5_interface.h"
10
#include "openmc/memory.h"
11
#include "openmc/particle.h"
12
#include "openmc/random_lcg.h"
13
#include "openmc/secondary_correlated.h"
14
#include "openmc/secondary_kalbach.h"
15
#include "openmc/secondary_nbody.h"
16
#include "openmc/secondary_uncorrelated.h"
17

18
namespace openmc {
19

20
//==============================================================================
21
// ReactionProduct implementation
22
//==============================================================================
23

24
ReactionProduct::ReactionProduct(hid_t group)
3,316,228✔
25
{
26
  // Read particle type
27
  std::string temp;
3,316,228✔
28
  read_attribute(group, "particle", temp);
3,316,228✔
29
  particle_ = ParticleType {temp};
3,316,228✔
30

31
  // Read emission mode and decay rate
32
  read_attribute(group, "emission_mode", temp);
3,316,228✔
33
  if (temp == "prompt") {
3,316,228✔
34
    emission_mode_ = EmissionMode::prompt;
3,235,240✔
35
  } else if (temp == "delayed") {
80,988!
36
    emission_mode_ = EmissionMode::delayed;
80,988✔
37
  } else if (temp == "total") {
×
38
    emission_mode_ = EmissionMode::total;
×
39
  }
40

41
  // Read decay rate for delayed emission
42
  if (emission_mode_ == EmissionMode::delayed) {
3,316,228✔
43
    if (attribute_exists(group, "decay_rate")) {
80,988!
44
      read_attribute(group, "decay_rate", decay_rate_);
80,988✔
NEW
45
    } else if (particle_.is_neutron()) {
×
46
      warning(fmt::format("Decay rate doesn't exist for delayed neutron "
×
47
                          "emission ({}).",
48
        object_name(group)));
×
49
    }
50
  }
51

52
  // Read secondary particle yield
53
  yield_ = read_function(group, "yield");
3,316,228✔
54

55
  int n;
56
  read_attribute(group, "n_distribution", n);
3,316,228✔
57

58
  for (int i = 0; i < n; ++i) {
6,633,397✔
59
    std::string s {"distribution_"};
3,317,169✔
60
    s.append(std::to_string(i));
3,317,169✔
61
    hid_t dgroup = open_group(group, s.c_str());
3,317,169✔
62

63
    // Read applicability
64
    if (n > 1) {
3,317,169✔
65
      hid_t app = open_dataset(dgroup, "applicability");
1,786✔
66
      applicability_.emplace_back(app);
1,786✔
67
      close_dataset(app);
1,786✔
68
    }
69

70
    // Determine distribution type and read data
71
    read_attribute(dgroup, "type", temp);
3,317,169✔
72
    if (temp == "uncorrelated") {
3,317,169✔
73
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
3,200,106✔
74
    } else if (temp == "correlated") {
117,063✔
75
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
47,797✔
76
    } else if (temp == "nbody") {
69,266✔
77
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
752✔
78
    } else if (temp == "kalbach-mann") {
68,514!
79
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
68,514✔
80
    }
81

82
    close_group(dgroup);
3,317,169✔
83
  }
3,317,169✔
84
}
3,316,228✔
85

86
ReactionProduct::ReactionProduct(const ChainNuclide::Product& product)
132✔
87
{
88
  particle_ = ParticleType::photon();
132✔
89
  emission_mode_ = EmissionMode::delayed;
132✔
90

91
  // Get chain nuclide object for radionuclide
92
  parent_nuclide_ = data::chain_nuclide_map.at(product.name);
132✔
93
  const auto& chain_nuc = data::chain_nuclides[parent_nuclide_].get();
132✔
94

95
  // Determine decay constant in [s^-1]
96
  decay_rate_ = chain_nuc->decay_constant();
132✔
97

98
  // Determine number of photons per decay and set yield
99
  double photon_per_sec = chain_nuc->photon_energy()->integral();
132✔
100
  double photon_per_decay = photon_per_sec / decay_rate_;
132✔
101
  vector<double> coef = {product.branching_ratio * photon_per_decay};
132✔
102
  yield_ = make_unique<Polynomial>(coef);
132✔
103

104
  // Set decay photon angle-energy distribution
105
  distribution_.push_back(
132✔
106
    make_unique<DecayPhotonAngleEnergy>(chain_nuc->photon_energy()));
264✔
107
}
132✔
108

109
void ReactionProduct::sample(
48,822,240✔
110
  double E_in, double& E_out, double& mu, uint64_t* seed) const
111
{
112
  auto n = applicability_.size();
48,822,240✔
113
  if (n > 1) {
48,822,240✔
114
    double prob = 0.0;
1,078✔
115
    double c = prn(seed);
1,078✔
116
    for (int i = 0; i < n; ++i) {
1,837!
117
      // Determine probability that i-th energy distribution is sampled
118
      prob += applicability_[i](E_in);
1,837✔
119

120
      // If i-th distribution is sampled, sample energy from the distribution
121
      if (c <= prob) {
1,837✔
122
        distribution_[i]->sample(E_in, E_out, mu, seed);
1,078✔
123
        break;
1,078✔
124
      }
125
    }
126
  } else {
127
    // If only one distribution is present, go ahead and sample it
128
    distribution_[0]->sample(E_in, E_out, mu, seed);
48,821,162✔
129
  }
130
}
48,822,240✔
131

132
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc