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

openmc-dev / openmc / 17444981192

03 Sep 2025 08:14PM UTC coverage: 84.747%. First build
17444981192

Pull #3550

github

web-flow
Merge e2de1c407 into 591856472
Pull Request #3550: [Point Detector] Add distribution get_pdf functionality

0 of 336 new or added lines in 10 files covered. (0.0%)

52937 of 62465 relevant lines covered (84.75%)

37875629.96 hits per line

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

76.62
/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_thermal.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,204,327✔
26
{
27
  // Read particle type
28
  std::string temp;
3,204,327✔
29
  read_attribute(group, "particle", temp);
3,204,327✔
30
  particle_ = str_to_particle_type(temp);
3,204,327✔
31

32
  // Read emission mode and decay rate
33
  read_attribute(group, "emission_mode", temp);
3,204,327✔
34
  if (temp == "prompt") {
3,204,327✔
35
    emission_mode_ = EmissionMode::prompt;
3,131,451✔
36
  } else if (temp == "delayed") {
72,876✔
37
    emission_mode_ = EmissionMode::delayed;
72,876✔
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,204,327✔
44
    if (attribute_exists(group, "decay_rate")) {
72,876✔
45
      read_attribute(group, "decay_rate", decay_rate_);
72,876✔
46
    } else if (particle_ == ParticleType::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,204,327✔
55

56
  int n;
57
  read_attribute(group, "n_distribution", n);
3,204,327✔
58

59
  for (int i = 0; i < n; ++i) {
6,409,624✔
60
    std::string s {"distribution_"};
3,205,297✔
61
    s.append(std::to_string(i));
3,205,297✔
62
    hid_t dgroup = open_group(group, s.c_str());
3,205,297✔
63

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

71
    // Determine distribution type and read data
72
    read_attribute(dgroup, "type", temp);
3,205,297✔
73
    if (temp == "uncorrelated") {
3,205,297✔
74
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
3,094,649✔
75
    } else if (temp == "correlated") {
110,648✔
76
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
46,593✔
77
    } else if (temp == "nbody") {
64,055✔
78
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
712✔
79
    } else if (temp == "kalbach-mann") {
63,343✔
80
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
63,343✔
81
    }
82

83
    close_group(dgroup);
3,205,297✔
84
  }
3,205,297✔
85
}
3,204,327✔
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
void ReactionProduct::sample(
38,380,644✔
111
  double E_in, double& E_out, double& mu, uint64_t* seed) const
112
{
113
  auto n = applicability_.size();
38,380,644✔
114
  if (n > 1) {
38,380,644✔
115
    double prob = 0.0;
1,078✔
116
    double c = prn(seed);
1,078✔
117
    for (int i = 0; i < n; ++i) {
1,881✔
118
      // Determine probability that i-th energy distribution is sampled
119
      prob += applicability_[i](E_in);
1,881✔
120

121
      // If i-th distribution is sampled, sample energy from the distribution
122
      if (c <= prob) {
1,881✔
123
        distribution_[i]->sample(E_in, E_out, mu, seed);
1,078✔
124
        break;
1,078✔
125
      }
126
    }
127
  } else {
128
    // If only one distribution is present, go ahead and sample it
129
    distribution_[0]->sample(E_in, E_out, mu, seed);
38,379,566✔
130
  }
131
}
38,380,644✔
132

NEW
133
double ReactionProduct::get_pdf(
×
134
  double E_in, double mu, double& E_out, uint64_t* seed) const
135
{
136

137
  int distribution_index;
NEW
138
  auto n = applicability_.size();
×
NEW
139
  if (n > 1) {
×
NEW
140
    double prob = 0.0;
×
NEW
141
    double c = prn(seed);
×
NEW
142
    for (int i = 0; i < n; ++i) {
×
143
      // Determine probability that i-th energy distribution is sampled
NEW
144
      prob += applicability_[i](E_in);
×
145

146
      // If i-th distribution is sampled, sample energy from the distribution
NEW
147
      if (c <= prob) {
×
148
        // distribution_[i]->sample(E_in, E_out, mu, seed);
NEW
149
        distribution_index = i;
×
NEW
150
        break;
×
151
      }
152
    }
153
  } else {
NEW
154
    distribution_index = 0;
×
155
  }
156
  // now extract pdf
157

NEW
158
  AngleEnergy* angleEnergyPtr = distribution_[distribution_index].get();
×
NEW
159
  return angleEnergyPtr->get_pdf(E_in, mu, E_out, seed);
×
160
}
161

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

© 2025 Coveralls, Inc