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

openmc-dev / openmc / 21489819490

29 Jan 2026 06:21PM UTC coverage: 80.077% (-1.9%) from 81.953%
21489819490

Pull #3757

github

web-flow
Merge d08626053 into f7a734189
Pull Request #3757: Testing point detectors

16004 of 22621 branches covered (70.75%)

Branch coverage included in aggregate %.

94 of 518 new or added lines in 26 files covered. (18.15%)

1021 existing lines in 52 files now uncovered.

53779 of 64524 relevant lines covered (83.35%)

8016833.26 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)
66✔
18
{
19
  read_attribute(group, "n_particles", n_bodies_);
66✔
20
  read_attribute(group, "total_mass", mass_ratio_);
66✔
21
  read_attribute(group, "atomic_weight_ratio", A_);
66✔
22
  read_attribute(group, "q_value", Q_);
66✔
23
}
66✔
24

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

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

34
  double y;
35
  double r1, r2, r3, r4, r5, r6;
36
  switch (n_bodies_) {
40!
37
  case 3:
40✔
38
    y = maxwell_spectrum(1.0, seed);
40✔
39
    break;
40✔
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);
40✔
62
  return E_max * v;
40✔
63
}
64

65
void NBodyPhaseSpace::sample(
40✔
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);
40✔
71

72
  E_out = sample_energy(E_in, seed);
40✔
73
}
40✔
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