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

openmc-dev / openmc / 18750783817

23 Oct 2025 01:55PM UTC coverage: 81.273% (-0.6%) from 81.918%
18750783817

Pull #3339

github

web-flow
Merge 3dea40422 into c31032cf2
Pull Request #3339: Enable Scikit-Build-Core Support

16592 of 23295 branches covered (71.23%)

Branch coverage included in aggregate %.

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

588 existing lines in 7 files now uncovered.

53443 of 62878 relevant lines covered (84.99%)

43574323.97 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)
699,112,872✔
11
{
12
  return a + (b - a) * prn(seed);
699,112,872✔
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,696,339✔
21
{
22
  // Set the random numbers
23
  double r1 = prn(seed);
13,696,339✔
24
  double r2 = prn(seed);
13,696,339✔
25
  double r3 = prn(seed);
13,696,339✔
26

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

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

34
double watt_spectrum(double a, double b, uint64_t* seed)
13,548,071✔
35
{
36
  double w = maxwell_spectrum(a, seed);
13,548,071✔
37
  return w + 0.25 * a * a * b +
13,548,071✔
38
         uniform_distribution(-1., 1., seed) * std::sqrt(a * a * b * w);
13,548,071✔
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