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

openmc-dev / openmc / 23097215950

14 Mar 2026 09:58PM UTC coverage: 81.435% (-0.1%) from 81.58%
23097215950

push

github

web-flow
Implement angular PDF evaluation for angle-energy distributions (#3550)

Co-authored-by: Your Name <you@example.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <guyste@post.bgu.ac.il>
Co-authored-by: Eliezer214 <110336440+Eliezer214@users.noreply.github.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

17596 of 25365 branches covered (69.37%)

Branch coverage included in aggregate %.

67 of 181 new or added lines in 12 files covered. (37.02%)

3 existing lines in 1 file now uncovered.

58033 of 67505 relevant lines covered (85.97%)

44708275.34 hits per line

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

80.0
/src/distribution_angle.cpp
1
#include "openmc/distribution_angle.h"
2

3
#include <cmath> // for abs, copysign
4

5
#include "openmc/tensor.h"
6

7
#include "openmc/endf.h"
8
#include "openmc/hdf5_interface.h"
9
#include "openmc/math_functions.h"
10
#include "openmc/random_lcg.h"
11
#include "openmc/search.h"
12
#include "openmc/vector.h" // for vector
13

14
namespace openmc {
15

16
//==============================================================================
17
// AngleDistribution implementation
18
//==============================================================================
19

20
AngleDistribution::AngleDistribution(hid_t group)
3,110,959✔
21
{
22
  // Get incoming energies
23
  read_dataset(group, "energy", energy_);
3,110,959✔
24
  int n_energy = energy_.size();
3,110,959✔
25

26
  // Get outgoing energy distribution data
27
  vector<int> offsets;
3,110,959✔
28
  vector<int> interp;
3,110,959✔
29
  hid_t dset = open_dataset(group, "mu");
3,110,959✔
30
  read_attribute(dset, "offsets", offsets);
3,110,959✔
31
  read_attribute(dset, "interpolation", interp);
3,110,959✔
32
  tensor::Tensor<double> temp;
3,110,959✔
33
  read_dataset(dset, temp);
3,110,959✔
34
  close_dataset(dset);
3,110,959✔
35

36
  for (int i = 0; i < n_energy; ++i) {
29,961,519✔
37
    // Determine number of outgoing energies
38
    int j = offsets[i];
26,850,560✔
39
    int n;
26,850,560✔
40
    if (i < n_energy - 1) {
26,850,560✔
41
      n = offsets[i + 1] - j;
23,739,601✔
42
    } else {
43
      n = temp.shape(1) - j;
6,221,918!
44
    }
45

46
    // Create and initialize tabular distribution
47
    tensor::View<double> xs = temp.slice(0, tensor::range(j, j + n));
26,850,560✔
48
    tensor::View<double> ps = temp.slice(1, tensor::range(j, j + n));
26,850,560✔
49
    tensor::View<double> cs = temp.slice(2, tensor::range(j, j + n));
26,850,560✔
50
    vector<double> x {xs.begin(), xs.end()};
26,850,560✔
51
    vector<double> p {ps.begin(), ps.end()};
26,850,560✔
52
    vector<double> c {cs.begin(), cs.end()};
26,850,560✔
53

54
    // To get answers that match ACE data, for now we still use the tabulated
55
    // CDF values that were passed through to the HDF5 library. At a later
56
    // time, we can remove the CDF values from the HDF5 library and
57
    // reconstruct them using the PDF
58
    Tabular* mudist =
26,850,560✔
59
      new Tabular {x.data(), p.data(), n, int2interp(interp[i]), c.data()};
26,850,560✔
60

61
    distribution_.emplace_back(mudist);
26,850,560✔
62
  }
107,402,240✔
63
}
3,110,959✔
64

65
double AngleDistribution::sample(double E, uint64_t* seed) const
846,557,830✔
66
{
67
  // Find energy bin and calculate interpolation factor
68
  int i;
846,557,830✔
69
  double r;
846,557,830✔
70
  get_energy_index(energy_, E, i, r);
846,557,830✔
71

72
  // Sample between the ith and (i+1)th bin
73
  if (r > prn(seed))
846,557,830✔
74
    ++i;
348,926,625✔
75

76
  // Sample i-th distribution
77
  double mu = distribution_[i]->sample(seed).first;
846,557,830✔
78

79
  // Make sure mu is in range [-1,1] and return
80
  if (std::abs(mu) > 1.0)
846,557,830!
81
    mu = std::copysign(1.0, mu);
×
82
  return mu;
846,557,830✔
83
}
84

NEW
85
double AngleDistribution::evaluate(double E, double mu) const
×
86
{
87
  // Find energy bin and calculate interpolation factor
NEW
88
  int i;
×
NEW
89
  double r;
×
NEW
90
  get_energy_index(energy_, E, i, r);
×
91

NEW
92
  double pdf = 0.0;
×
NEW
93
  if (r > 0.0)
×
NEW
94
    pdf += r * distribution_[i + 1]->evaluate(mu);
×
NEW
95
  if (r < 1.0)
×
NEW
96
    pdf += (1.0 - r) * distribution_[i]->evaluate(mu);
×
NEW
97
  return pdf;
×
98
}
99

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