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

openmc-dev / openmc / 23910205296

02 Apr 2026 04:14PM UTC coverage: 81.224% (-0.3%) from 81.567%
23910205296

Pull #3766

github

web-flow
Merge 264dcb1ef into 8223099ed
Pull Request #3766: Approximate multigroup velocity

17579 of 25426 branches covered (69.14%)

Branch coverage included in aggregate %.

24 of 25 new or added lines in 4 files covered. (96.0%)

710 existing lines in 29 files now uncovered.

58015 of 67642 relevant lines covered (85.77%)

31291841.44 hits per line

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

83.33
/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)
1,869,643✔
26
{
27
  // Read particle type
28
  std::string temp;
1,869,643✔
29
  read_attribute(group, "particle", temp);
1,869,643✔
30
  particle_ = ParticleType {temp};
1,869,643✔
31

32
  // Read emission mode and decay rate
33
  read_attribute(group, "emission_mode", temp);
1,869,643✔
34
  if (temp == "prompt") {
1,869,643✔
35
    emission_mode_ = EmissionMode::prompt;
1,824,049✔
36
  } else if (temp == "delayed") {
45,594!
37
    emission_mode_ = EmissionMode::delayed;
45,594✔
38
  } else if (temp == "total") {
×
UNCOV
39
    emission_mode_ = EmissionMode::total;
×
40
  }
41

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

53
  // Read secondary particle yield
54
  yield_ = read_function(group, "yield");
1,869,643✔
55

56
  int n;
1,869,643✔
57
  read_attribute(group, "n_distribution", n);
1,869,643✔
58

59
  for (int i = 0; i < n; ++i) {
3,739,790✔
60
    std::string s {"distribution_"};
1,870,147✔
61
    s.append(std::to_string(i));
3,740,294✔
62
    hid_t dgroup = open_group(group, s.c_str());
1,870,147✔
63

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

71
    // Determine distribution type and read data
72
    read_attribute(dgroup, "type", temp);
1,870,147✔
73
    if (temp == "uncorrelated") {
1,870,147✔
74
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
1,803,634✔
75
    } else if (temp == "correlated") {
66,513✔
76
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
27,745✔
77
    } else if (temp == "nbody") {
38,768✔
78
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
399✔
79
    } else if (temp == "kalbach-mann") {
38,369!
80
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
38,369✔
81
    }
82

83
    close_group(dgroup);
1,870,147✔
84
  }
1,870,147✔
85
}
1,869,643✔
86

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

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

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

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

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

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

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

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

128
  return *distribution_.back();
27,849,071✔
129
}
130

131
void ReactionProduct::sample(
27,849,737✔
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);
27,849,737✔
135
}
27,849,737✔
136

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

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