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

openmc-dev / openmc / 21097490984

17 Jan 2026 04:35PM UTC coverage: 81.806% (-0.3%) from 82.058%
21097490984

Pull #3550

github

web-flow
Merge f14005a81 into 5847b0de2
Pull Request #3550: [Point Detector] Add distribution get_pdf functionality

17223 of 24065 branches covered (71.57%)

Branch coverage included in aggregate %.

48 of 175 new or added lines in 12 files covered. (27.43%)

209 existing lines in 11 files now uncovered.

55660 of 65027 relevant lines covered (85.6%)

43330688.32 hits per line

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

83.7
/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,261,231✔
25
{
26
  // Read particle type
27
  std::string temp;
3,261,231✔
28
  read_attribute(group, "particle", temp);
3,261,231✔
29
  particle_ = str_to_particle_type(temp);
3,261,231✔
30

31
  // Read emission mode and decay rate
32
  read_attribute(group, "emission_mode", temp);
3,261,231✔
33
  if (temp == "prompt") {
3,261,231✔
34
    emission_mode_ = EmissionMode::prompt;
3,181,443✔
35
  } else if (temp == "delayed") {
79,788!
36
    emission_mode_ = EmissionMode::delayed;
79,788✔
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,261,231✔
43
    if (attribute_exists(group, "decay_rate")) {
79,788!
44
      read_attribute(group, "decay_rate", decay_rate_);
79,788✔
45
    } else if (particle_ == ParticleType::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,261,231✔
54

55
  int n;
56
  read_attribute(group, "n_distribution", n);
3,261,231✔
57

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

63
    // Read applicability
64
    if (n > 1) {
3,262,172✔
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,262,172✔
72
    if (temp == "uncorrelated") {
3,262,172✔
73
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
3,147,283✔
74
    } else if (temp == "correlated") {
114,889✔
75
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
46,599✔
76
    } else if (temp == "nbody") {
68,290✔
77
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
752✔
78
    } else if (temp == "kalbach-mann") {
67,538!
79
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
67,538✔
80
    }
81

82
    close_group(dgroup);
3,262,172✔
83
  }
3,262,172✔
84
}
3,261,231✔
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
AngleEnergy& ReactionProduct::sample_dist(double E_in, uint64_t* seed) const
48,117,079✔
110
{
111
  auto n = applicability_.size();
48,117,079✔
112
  if (n > 1) {
48,117,079✔
113
    double prob = 0.0;
1,078✔
114
    double c = prn(seed);
1,078✔
115
    for (int i = 0; i < n; ++i) {
1,837!
116
      // Determine probability that i-th energy distribution is sampled
117
      prob += applicability_[i](E_in);
1,837✔
118

119
      // If i-th distribution is sampled, sample energy from the distribution
120
      if (c <= prob) {
1,837✔
121
        return *distribution_[i];
1,078✔
122
        break;
123
      }
124
    }
125
  } else {
126
    // If only one distribution is present, go ahead and sample it
127
    return *distribution_[0];
48,116,001✔
128
  }
UNCOV
129
}
×
130

131
void ReactionProduct::sample(
48,117,079✔
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);
48,117,079✔
135
}
48,117,079✔
136

NEW
137
double ReactionProduct::sample_energy_and_pdf(
×
138
  double E_in, double mu, double& E_out, uint64_t* seed) const
139
{
NEW
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