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

openmc-dev / openmc / 19058781736

04 Nov 2025 05:26AM UTC coverage: 82.008% (-3.1%) from 85.155%
19058781736

Pull #3252

github

web-flow
Merge b8a72730f into bd76fc056
Pull Request #3252: Adding vtkhdf option to write vtk data

16714 of 23236 branches covered (71.93%)

Branch coverage included in aggregate %.

61 of 66 new or added lines in 1 file covered. (92.42%)

3175 existing lines in 103 files now uncovered.

54243 of 63288 relevant lines covered (85.71%)

43393337.77 hits per line

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

79.05
/src/distribution_multi.cpp
1
#include "openmc/distribution_multi.h"
2

3
#include <algorithm> // for move
4
#include <cmath>     // for sqrt, sin, cos, max
5

6
#include "openmc/constants.h"
7
#include "openmc/error.h"
8
#include "openmc/math_functions.h"
9
#include "openmc/random_dist.h"
10
#include "openmc/random_lcg.h"
11
#include "openmc/xml_interface.h"
12

13
namespace openmc {
14

15
unique_ptr<UnitSphereDistribution> UnitSphereDistribution::create(
3,171 ✔
16
  pugi::xml_node node)
17
{
18
  // Check for type of angular distribution
19
  std::string type;
3,171 ✔
20
  if (check_for_node(node, "type"))
3,171 !
21
    type = get_node_value(node, "type", true, true);
3,171 ✔
22
  if (type == "isotropic") {
3,171 ✔
23
    return UPtrAngle {new Isotropic()};
255 ✔
24
  } else if (type == "monodirectional") {
2,916 ✔
25
    return UPtrAngle {new Monodirectional(node)};
2,878 ✔
26
  } else if (type == "mu-phi") {
38 !
27
    return UPtrAngle {new PolarAzimuthal(node)};
38 ✔
28
  } else {
29
    fatal_error(fmt::format(
×
30
      "Invalid angular distribution for external source: {}", type));
31
  }
32
}
3,171 ✔
33

34
//==============================================================================
35
// UnitSphereDistribution implementation
36
//==============================================================================
37

38
UnitSphereDistribution::UnitSphereDistribution(pugi::xml_node node)
2,916 ✔
39
{
40
  // Read reference directional unit vector
41
  if (check_for_node(node, "reference_uvw")) {
2,916 !
42
    auto u_ref = get_node_array<double>(node, "reference_uvw");
2,916 ✔
43
    if (u_ref.size() != 3)
2,916 !
44
      fatal_error("Angular distribution reference direction must have "
×
45
                  "three parameters specified.");
46
    u_ref_ = Direction(u_ref.data());
2,916 ✔
47
  }
2,916 ✔
48
}
2,916 ✔
49

50
//==============================================================================
51
// PolarAzimuthal implementation
52
//==============================================================================
53

54
PolarAzimuthal::PolarAzimuthal(Direction u, UPtrDist mu, UPtrDist phi)
×
55
  : UnitSphereDistribution {u}, mu_ {std::move(mu)}, phi_ {std::move(phi)}
×
56
{}
×
57

58
PolarAzimuthal::PolarAzimuthal(pugi::xml_node node)
38 ✔
59
  : UnitSphereDistribution {node}
38 ✔
60
{
61
  // Read reference directional unit vector
62
  if (check_for_node(node, "reference_vwu")) {
38 !
63
    auto v_ref = get_node_array<double>(node, "reference_vwu");
38 ✔
64
    if (v_ref.size() != 3)
38 !
65
      fatal_error("Angular distribution reference v direction must have "
×
66
                  "three parameters specified.");
67
    v_ref_ = Direction(v_ref.data());
38 ✔
68
  }
38 ✔
69
  w_ref_ = u_ref_.cross(v_ref_);
38 ✔
70
  if (check_for_node(node, "mu")) {
38 !
71
    pugi::xml_node node_dist = node.child("mu");
38 ✔
72
    mu_ = distribution_from_xml(node_dist);
38 ✔
73
  } else {
UNCOV
74
    mu_ = UPtrDist {new Uniform(-1., 1.)};
×
75
  }
76

77
  if (check_for_node(node, "phi")) {
38 !
78
    pugi::xml_node node_dist = node.child("phi");
38 ✔
79
    phi_ = distribution_from_xml(node_dist);
38 ✔
80
  } else {
UNCOV
81
    phi_ = UPtrDist {new Uniform(0.0, 2.0 * PI)};
×
82
  }
83
}
38 ✔
84

85
Direction PolarAzimuthal::sample(uint64_t* seed) const
25,300 ✔
86
{
87
  // Sample cosine of polar angle
88
  double mu = mu_->sample(seed);
25,300 ✔
89
  if (mu == 1.0)
25,300 ✔
90
    return u_ref_;
759 ✔
91
  if (mu == -1.0)
24,541 ✔
92
    return -u_ref_;
1,628 ✔
93

94
  // Sample azimuthal angle
95
  double phi = phi_->sample(seed);
22,913 ✔
96

97
  double f = std::sqrt(1 - mu * mu);
22,913 ✔
98

99
  return mu * u_ref_ + f * std::cos(phi) * v_ref_ + f * std::sin(phi) * w_ref_;
22,913 ✔
100
}
101

102
//==============================================================================
103
// Isotropic implementation
104
//==============================================================================
105

106
Direction isotropic_direction(uint64_t* seed)
114,603,812 ✔
107
{
108
  double phi = uniform_distribution(0., 2.0 * PI, seed);
114,603,812 ✔
109
  double mu = uniform_distribution(-1., 1., seed);
114,603,812 ✔
110
  return {mu, std::sqrt(1.0 - mu * mu) * std::cos(phi),
114,603,812 ✔
111
    std::sqrt(1.0 - mu * mu) * std::sin(phi)};
114,603,812 ✔
112
}
113

114
Direction Isotropic::sample(uint64_t* seed) const
20,795,457 ✔
115
{
116
  return isotropic_direction(seed);
20,795,457 ✔
117
}
118

119
//==============================================================================
120
// Monodirectional implementation
121
//==============================================================================
122

123
Direction Monodirectional::sample(uint64_t* seed) const
12,466,334 ✔
124
{
125
  return u_ref_;
12,466,334 ✔
126
}
127

128
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc