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

openmc-dev / openmc / 20470828925

23 Dec 2025 08:24PM UTC coverage: 81.898% (-0.04%) from 81.94%
20470828925

Pull #3550

github

web-flow
Merge b067e7f24 into 3f06a42ab
Pull Request #3550: [Point Detector] Add distribution get_pdf functionality

17078 of 23776 branches covered (71.83%)

Branch coverage included in aggregate %.

48 of 212 new or added lines in 13 files covered. (22.64%)

4 existing lines in 2 files now uncovered.

55208 of 64487 relevant lines covered (85.61%)

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

31
  // Read emission mode and decay rate
32
  read_attribute(group, "emission_mode", temp);
3,235,804✔
33
  if (temp == "prompt") {
3,235,804✔
34
    emission_mode_ = EmissionMode::prompt;
3,156,634✔
35
  } else if (temp == "delayed") {
79,170!
36
    emission_mode_ = EmissionMode::delayed;
79,170✔
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,235,804✔
43
    if (attribute_exists(group, "decay_rate")) {
79,170!
44
      read_attribute(group, "decay_rate", decay_rate_);
79,170✔
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,235,804✔
54

55
  int n;
56
  read_attribute(group, "n_distribution", n);
3,235,804✔
57

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

63
    // Read applicability
64
    if (n > 1) {
3,236,745✔
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,236,745✔
72
    if (temp == "uncorrelated") {
3,236,745✔
73
      distribution_.push_back(make_unique<UncorrelatedAngleEnergy>(dgroup));
3,122,860✔
74
    } else if (temp == "correlated") {
113,885✔
75
      distribution_.push_back(make_unique<CorrelatedAngleEnergy>(dgroup));
46,535✔
76
    } else if (temp == "nbody") {
67,350✔
77
      distribution_.push_back(make_unique<NBodyPhaseSpace>(dgroup));
752✔
78
    } else if (temp == "kalbach-mann") {
66,598!
79
      distribution_.push_back(make_unique<KalbachMann>(dgroup));
66,598✔
80
    }
81

82
    close_group(dgroup);
3,236,745✔
83
  }
3,236,745✔
84
}
3,235,804✔
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
47,467,943✔
110
{
111
  auto n = applicability_.size();
47,467,943✔
112
  if (n > 1) {
47,467,943✔
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];
47,466,865✔
128
  }
UNCOV
129
}
×
130

131
void ReactionProduct::sample(
47,467,943✔
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);
47,467,943✔
135
}
47,467,943✔
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

© 2025 Coveralls, Inc