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

openmc-dev / openmc / 23034959969

13 Mar 2026 03:32AM UTC coverage: 81.385% (-0.2%) from 81.564%
23034959969

Pull #3550

github

web-flow
Merge 85f0fcdee into 4bda85f17
Pull Request #3550: [Point Detector] Add distribution get_pdf functionality

17579 of 25382 branches covered (69.26%)

Branch coverage included in aggregate %.

67 of 189 new or added lines in 12 files covered. (35.45%)

41 existing lines in 3 files now uncovered.

57995 of 67478 relevant lines covered (85.95%)

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

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

56
  int n;
3,362,126✔
57
  read_attribute(group, "n_distribution", n);
3,362,126✔
58

59
  for (int i = 0; i < n; ++i) {
6,725,174✔
60
    std::string s {"distribution_"};
3,363,048✔
61
    s.append(std::to_string(i));
6,726,096✔
62
    hid_t dgroup = open_group(group, s.c_str());
3,363,048✔
63

64
    // Read applicability
65
    if (n > 1) {
3,363,048✔
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,363,048✔
73
    if (temp == "uncorrelated") {
3,363,048✔
74
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
3,243,974✔
75
    } else if (temp == "correlated") {
119,074✔
76
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
49,422✔
77
    } else if (temp == "nbody") {
69,652✔
78
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
732✔
79
    } else if (temp == "kalbach-mann") {
68,920!
80
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
68,920✔
81
    }
82

83
    close_group(dgroup);
3,363,048✔
84
  }
3,363,048✔
85
}
3,362,126✔
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,794,898✔
111
{
112
  assert(!distribution_.empty());
50,794,898!
113

114
  auto n = applicability_.size();
50,794,898✔
115
  if (n > 1) {
50,794,898✔
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,793,677✔
129
}
130

131
void ReactionProduct::sample(
50,794,898✔
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,794,898✔
135
}
50,794,898✔
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