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

openmc-dev / openmc / 21098472432

17 Jan 2026 05:50PM UTC coverage: 81.806% (-0.3%) from 82.058%
21098472432

Pull #3550

github

web-flow
Merge 903af78a1 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%)

43330780.84 hits per line

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

51.02
/src/secondary_nbody.cpp
1
#include "openmc/secondary_nbody.h"
2

3
#include <cmath> // for log
4

5
#include "openmc/constants.h"
6
#include "openmc/hdf5_interface.h"
7
#include "openmc/math_functions.h"
8
#include "openmc/random_dist.h"
9
#include "openmc/random_lcg.h"
10

11
namespace openmc {
12

13
//==============================================================================
14
// NBodyPhaseSpace implementation
15
//==============================================================================
16

17
NBodyPhaseSpace::NBodyPhaseSpace(hid_t group)
752✔
18
{
19
  read_attribute(group, "n_particles", n_bodies_);
752✔
20
  read_attribute(group, "total_mass", mass_ratio_);
752✔
21
  read_attribute(group, "atomic_weight_ratio", A_);
752✔
22
  read_attribute(group, "q_value", Q_);
752✔
23
}
752✔
24

25
double NBodyPhaseSpace::sample_energy(double E_in, uint64_t* seed) const
440✔
26
{
27
  // Determine E_max parameter
28
  double Ap = mass_ratio_;
440✔
29
  double E_max = (Ap - 1.0) / Ap * (A_ / (A_ + 1.0) * E_in + Q_);
440✔
30

31
  // x is essentially a Maxwellian distribution
32
  double x = maxwell_spectrum(1.0, seed);
440✔
33

34
  double y;
35
  double r1, r2, r3, r4, r5, r6;
36
  switch (n_bodies_) {
440!
37
  case 3:
440✔
38
    y = maxwell_spectrum(1.0, seed);
440✔
39
    break;
440✔
40
  case 4:
×
41
    r1 = prn(seed);
×
42
    r2 = prn(seed);
×
43
    r3 = prn(seed);
×
44
    y = -std::log(r1 * r2 * r3);
×
45
    break;
×
46
  case 5:
×
47
    r1 = prn(seed);
×
48
    r2 = prn(seed);
×
49
    r3 = prn(seed);
×
50
    r4 = prn(seed);
×
51
    r5 = prn(seed);
×
52
    r6 = prn(seed);
×
53
    y = -std::log(r1 * r2 * r3 * r4) -
×
54
        std::log(r5) * std::pow(std::cos(PI / 2.0 * r6), 2);
×
55
    break;
×
56
  default:
×
NEW
57
    fatal_error("N-body phase space with >5 bodies.");
×
58
  }
59

60
  // Now determine v and E_out
61
  double v = x / (x + y);
440✔
62
  return E_max * v;
440✔
63
}
64

65
void NBodyPhaseSpace::sample(
440✔
66
  double E_in, double& E_out, double& mu, uint64_t* seed) const
67
{
68
  // By definition, the distribution of the angle is isotropic for an N-body
69
  // phase space distribution
70
  mu = uniform_distribution(-1., 1., seed);
440✔
71

72
  E_out = sample_energy(E_in, seed);
440✔
73
}
440✔
74

NEW
75
double NBodyPhaseSpace::sample_energy_and_pdf(
×
76
  double E_in, double mu, double& E_out, uint64_t* seed) const
77
{
NEW
78
  E_out = sample_energy(E_in, seed);
×
NEW
79
  return 0.5;
×
80
}
81

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