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

openmc-dev / openmc / 19476608580

18 Nov 2025 06:15PM UTC coverage: 81.528% (-0.4%) from 81.961%
19476608580

Pull #3339

github

web-flow
Merge 25c21d84d into 7815d3a68
Pull Request #3339: Enable Scikit-Build-Core Support

16890 of 23555 branches covered (71.7%)

Branch coverage included in aggregate %.

34 of 34 new or added lines in 3 files covered. (100.0%)

376 existing lines in 7 files now uncovered.

54523 of 64038 relevant lines covered (85.14%)

42168701.72 hits per line

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

56.0
/src/random_dist.cpp
1
#include "openmc/random_dist.h"
2

3
#include <cmath>
4

5
#include "openmc/constants.h"
6
#include "openmc/random_lcg.h"
7

8
namespace openmc {
9

10
double uniform_distribution(double a, double b, uint64_t* seed)
682,132,175✔
11
{
12
  return a + (b - a) * prn(seed);
682,132,175✔
13
}
14

15
int64_t uniform_int_distribution(int64_t a, int64_t b, uint64_t* seed)
5,247,000✔
16
{
17
  return a + static_cast<int64_t>(prn(seed) * (b - a + 1));
5,247,000✔
18
}
19

20
double maxwell_spectrum(double T, uint64_t* seed)
13,532,242✔
21
{
22
  // Set the random numbers
23
  double r1 = prn(seed);
13,532,242✔
24
  double r2 = prn(seed);
13,532,242✔
25
  double r3 = prn(seed);
13,532,242✔
26

27
  // determine cosine of pi/2*r
28
  double c = std::cos(PI / 2. * r3);
13,532,242✔
29

30
  // Determine outgoing energy
31
  return -T * (std::log(r1) + std::log(r2) * c * c);
13,532,242✔
32
}
33

34
double watt_spectrum(double a, double b, uint64_t* seed)
13,384,006✔
35
{
36
  double w = maxwell_spectrum(a, seed);
13,384,006✔
37
  return w + 0.25 * a * a * b +
13,384,006✔
38
         uniform_distribution(-1., 1., seed) * std::sqrt(a * a * b * w);
13,384,006✔
39
}
40

UNCOV
41
double normal_variate(double mean, double standard_deviation, uint64_t* seed)
×
42
{
43
  // Sample a normal variate using Marsaglia's polar method
44
  double x, y, r2;
45
  do {
UNCOV
46
    x = uniform_distribution(-1., 1., seed);
×
UNCOV
47
    y = uniform_distribution(-1., 1., seed);
×
UNCOV
48
    r2 = x * x + y * y;
×
UNCOV
49
  } while (r2 > 1 || r2 == 0);
×
UNCOV
50
  double z = std::sqrt(-2.0 * std::log(r2) / r2);
×
UNCOV
51
  return mean + standard_deviation * z * x;
×
52
}
53

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