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

openmc-dev / openmc / 23367229037

20 Mar 2026 11:54PM UTC coverage: 81.453% (-0.1%) from 81.58%
23367229037

Pull #3877

github

web-flow
Merge 7af343511 into 3ce6cbfdd
Pull Request #3877: Add VTKHDF output support for all structured mesh types (#3620)

17595 of 25365 branches covered (69.37%)

Branch coverage included in aggregate %.

128 of 133 new or added lines in 1 file covered. (96.24%)

372 existing lines in 15 files now uncovered.

58192 of 67679 relevant lines covered (85.98%)

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

32
  // Read emission mode and decay rate
33
  read_attribute(group, "emission_mode", temp);
3,397,414✔
34
  if (temp == "prompt") {
3,397,414✔
35
    emission_mode_ = EmissionMode::prompt;
3,314,848✔
36
  } else if (temp == "delayed") {
82,566!
37
    emission_mode_ = EmissionMode::delayed;
82,566✔
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) {
3,397,414✔
44
    if (attribute_exists(group, "decay_rate")) {
82,566!
45
      read_attribute(group, "decay_rate", decay_rate_);
82,566✔
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");
3,397,414✔
55

56
  int n;
3,397,414✔
57
  read_attribute(group, "n_distribution", n);
3,397,414✔
58

59
  for (int i = 0; i < n; ++i) {
6,795,750✔
60
    std::string s {"distribution_"};
3,398,336✔
61
    s.append(std::to_string(i));
6,796,672✔
62
    hid_t dgroup = open_group(group, s.c_str());
3,398,336✔
63

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

71
    // Determine distribution type and read data
72
    read_attribute(dgroup, "type", temp);
3,398,336✔
73
    if (temp == "uncorrelated") {
3,398,336✔
74
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
3,277,898✔
75
    } else if (temp == "correlated") {
120,438✔
76
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
50,214✔
77
    } else if (temp == "nbody") {
70,224✔
78
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
732✔
79
    } else if (temp == "kalbach-mann") {
69,492!
80
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
69,492✔
81
    }
82

83
    close_group(dgroup);
3,398,336✔
84
  }
3,398,336✔
85
}
3,397,414✔
86

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

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

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

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

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

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

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

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

128
  return *distribution_.back();
50,963,812✔
129
}
130

131
void ReactionProduct::sample(
50,965,033✔
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);
50,965,033✔
135
}
50,965,033✔
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