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

openmc-dev / openmc / 25472760865

07 May 2026 02:32AM UTC coverage: 80.952% (-0.4%) from 81.374%
25472760865

Pull #3757

github

web-flow
Merge 4928ac803 into e542b2f03
Pull Request #3757: Testing point detectors

17726 of 25786 branches covered (68.74%)

Branch coverage included in aggregate %.

44 of 386 new or added lines in 25 files covered. (11.4%)

81 existing lines in 3 files now uncovered.

58569 of 68461 relevant lines covered (85.55%)

47138839.61 hits per line

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

44.23
/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)
765✔
18
{
19
  read_attribute(group, "n_particles", n_bodies_);
765✔
20
  read_attribute(group, "total_mass", mass_ratio_);
765✔
21
  read_attribute(group, "atomic_weight_ratio", A_);
765✔
22
  read_attribute(group, "q_value", Q_);
765✔
23
}
765✔
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;
440✔
35
  double r1, r2, r3, r4, r5, r6;
440✔
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:
×
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(double E_in, double mu,
×
76
  double& E_out, uint64_t* seed, bool is_com, double awr) const
77
{
78
  E_out = sample_energy(E_in, seed);
×
NEW
79
  double jac = 1.0;
×
NEW
80
  if (is_com)
×
NEW
81
    jac = get_jac_and_transform(E_in, mu, E_out, seed, awr);
×
NEW
82
  return jac * 0.5;
×
83
}
84

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