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

openmc-dev / openmc / 23507153321

24 Mar 2026 06:58PM UTC coverage: 81.345% (-0.2%) from 81.556%
23507153321

Pull #3832

github

web-flow
Merge d5a5551bc into 6cd39073b
Pull Request #3832: Allowing multiple cells in surface source banking

17647 of 25494 branches covered (69.22%)

Branch coverage included in aggregate %.

94 of 97 new or added lines in 4 files covered. (96.91%)

868 existing lines in 32 files now uncovered.

58180 of 67723 relevant lines covered (85.91%)

44492259.78 hits per line

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

48.94
/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)
732✔
18
{
19
  read_attribute(group, "n_particles", n_bodies_);
732✔
20
  read_attribute(group, "total_mass", mass_ratio_);
732✔
21
  read_attribute(group, "atomic_weight_ratio", A_);
732✔
22
  read_attribute(group, "q_value", Q_);
732✔
23
}
732✔
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✔
UNCOV
40
  case 4:
×
UNCOV
41
    r1 = prn(seed);
×
UNCOV
42
    r2 = prn(seed);
×
UNCOV
43
    r3 = prn(seed);
×
UNCOV
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

UNCOV
75
double NBodyPhaseSpace::sample_energy_and_pdf(
×
76
  double E_in, double mu, double& E_out, uint64_t* seed) const
77
{
UNCOV
78
  E_out = sample_energy(E_in, seed);
×
UNCOV
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