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

openmc-dev / openmc / 25631610076

10 May 2026 02:44PM UTC coverage: 81.026% (-0.4%) from 81.388%
25631610076

Pull #3757

github

web-flow
Merge debc5a921 into d56cda254
Pull Request #3757: Testing point detectors

17769 of 25812 branches covered (68.84%)

Branch coverage included in aggregate %.

51 of 373 new or added lines in 25 files covered. (13.67%)

3 existing lines in 2 files now uncovered.

58805 of 68694 relevant lines covered (85.6%)

40257430.53 hits per line

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

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

3
#include <cassert>
4
#include <string> // for string
5

6
#include <fmt/core.h>
7

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

19
namespace openmc {
20

21
//==============================================================================
22
// ReactionProduct implementation
23
//==============================================================================
24

25
ReactionProduct::ReactionProduct(hid_t group)
2,561,117✔
26
{
27
  // Read particle type
28
  std::string temp;
2,561,117✔
29
  read_attribute(group, "particle", temp);
2,561,117✔
30
  particle_ = ParticleType {temp};
2,561,117✔
31

32
  // Read emission mode and decay rate
33
  read_attribute(group, "emission_mode", temp);
2,561,117✔
34
  if (temp == "prompt") {
2,561,117✔
35
    emission_mode_ = EmissionMode::prompt;
2,499,557✔
36
  } else if (temp == "delayed") {
61,560!
37
    emission_mode_ = EmissionMode::delayed;
61,560✔
38
  } else if (temp == "total") {
×
39
    emission_mode_ = EmissionMode::total;
×
40
  }
41

42
  // Read decay rate for delayed emission
43
  if (emission_mode_ == EmissionMode::delayed) {
2,561,117✔
44
    if (attribute_exists(group, "decay_rate")) {
61,560!
45
      read_attribute(group, "decay_rate", decay_rate_);
61,560✔
46
    } else if (particle_.is_neutron()) {
×
47
      warning(fmt::format("Decay rate doesn't exist for delayed neutron "
×
48
                          "emission ({}).",
49
        object_name(group)));
×
50
    }
51
  }
52

53
  // Read secondary particle yield
54
  yield_ = read_function(group, "yield");
2,561,117✔
55

56
  int n;
2,561,117✔
57
  read_attribute(group, "n_distribution", n);
2,561,117✔
58

59
  for (int i = 0; i < n; ++i) {
5,122,933✔
60
    std::string s {"distribution_"};
2,561,816✔
61
    s.append(std::to_string(i));
5,123,632✔
62
    hid_t dgroup = open_group(group, s.c_str());
2,561,816✔
63

64
    // Read applicability
65
    if (n > 1) {
2,561,816✔
66
      hid_t app = open_dataset(dgroup, "applicability");
1,332✔
67
      applicability_.emplace_back(app);
1,332✔
68
      close_dataset(app);
1,332✔
69
    }
70

71
    // Determine distribution type and read data
72
    read_attribute(dgroup, "type", temp);
2,561,816✔
73
    if (temp == "uncorrelated") {
2,561,816✔
74
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
2,471,737✔
75
    } else if (temp == "correlated") {
90,079✔
76
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
37,736✔
77
    } else if (temp == "nbody") {
52,343✔
78
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
557✔
79
    } else if (temp == "kalbach-mann") {
51,786!
80
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
51,786✔
81
    }
82

83
    close_group(dgroup);
2,561,816✔
84
  }
2,561,816✔
85
}
2,561,117✔
86

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

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

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

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

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

110
AngleEnergy& ReactionProduct::sample_dist(double E_in, uint64_t* seed) const
46,749,344✔
111
{
112
  assert(!distribution_.empty());
46,749,344!
113

114
  auto n = applicability_.size();
46,749,344✔
115
  if (n > 1) {
46,749,344✔
116
    double prob = 0.0;
888✔
117
    double c = prn(seed);
888✔
118
    for (int i = 0; i < n; ++i) {
1,520!
119
      // Determine probability that i-th energy distribution is sampled
120
      prob += applicability_[i](E_in);
1,520✔
121

122
      // If i-th distribution is sampled, sample energy from the distribution
123
      if (c <= prob)
1,520✔
124
        return *distribution_[i];
888✔
125
    }
126
  }
127

128
  return *distribution_.back();
46,748,456✔
129
}
130

131
void ReactionProduct::sample(
46,749,344✔
132
  double E_in, double& E_out, double& mu, uint64_t* seed) const
133
{
134
  sample_dist(E_in, seed).sample(E_in, E_out, mu, seed);
46,749,344✔
135
}
46,749,344✔
136

NEW
137
double ReactionProduct::sample_energy_and_pdf(double E_in, double mu,
×
138
  double& E_out, uint64_t* seed, bool is_com, double awr) const
139
{
NEW
140
  return sample_dist(E_in, seed)
×
NEW
141
    .sample_energy_and_pdf(E_in, mu, E_out, seed, is_com, awr);
×
142
}
143

144
} // 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