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

openmc-dev / openmc / 17475377863

04 Sep 2025 08:05PM UTC coverage: 84.707% (-0.5%) from 85.209%
17475377863

Pull #3550

github

web-flow
Merge ff83fc4b9 into 591856472
Pull Request #3550: [Point Detector] Add distribution get_pdf functionality

0 of 370 new or added lines in 10 files covered. (0.0%)

3 existing lines in 1 file now uncovered.

52947 of 62506 relevant lines covered (84.71%)

38165206.92 hits per line

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

85.71
/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,167✔
16
  pugi::xml_node node)
17
{
18
  // Check for type of angular distribution
19
  std::string type;
3,167✔
20
  if (check_for_node(node, "type"))
3,167✔
21
    type = get_node_value(node, "type", true, true);
3,167✔
22
  if (type == "isotropic") {
3,167✔
23
    return UPtrAngle {new Isotropic()};
255✔
24
  } else if (type == "monodirectional") {
2,912✔
25
    return UPtrAngle {new Monodirectional(node)};
2,874✔
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,167✔
33

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

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

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

UNCOV
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
  if (check_for_node(node, "mu")) {
38✔
62
    pugi::xml_node node_dist = node.child("mu");
38✔
63
    mu_ = distribution_from_xml(node_dist);
38✔
64
  } else {
UNCOV
65
    mu_ = UPtrDist {new Uniform(-1., 1.)};
×
66
  }
67

68
  if (check_for_node(node, "phi")) {
38✔
69
    pugi::xml_node node_dist = node.child("phi");
38✔
70
    phi_ = distribution_from_xml(node_dist);
38✔
71
  } else {
UNCOV
72
    phi_ = UPtrDist {new Uniform(0.0, 2.0 * PI)};
×
73
  }
74
}
38✔
75

76
Direction PolarAzimuthal::sample(uint64_t* seed) const
25,300✔
77
{
78
  // Sample cosine of polar angle
79
  double mu = mu_->sample(seed);
25,300✔
80
  if (mu == 1.0)
25,300✔
81
    return u_ref_;
759✔
82

83
  // Sample azimuthal angle
84
  double phi = phi_->sample(seed);
24,541✔
85

86
  return rotate_angle(u_ref_, mu, &phi, seed);
24,541✔
87
}
88

89
//==============================================================================
90
// Isotropic implementation
91
//==============================================================================
92

93
Direction isotropic_direction(uint64_t* seed)
109,077,489✔
94
{
95
  double phi = uniform_distribution(0., 2.0 * PI, seed);
109,077,489✔
96
  double mu = uniform_distribution(-1., 1., seed);
109,077,489✔
97
  return {mu, std::sqrt(1.0 - mu * mu) * std::cos(phi),
109,077,489✔
98
    std::sqrt(1.0 - mu * mu) * std::sin(phi)};
109,077,489✔
99
}
100

101
Direction Isotropic::sample(uint64_t* seed) const
19,381,238✔
102
{
103
  return isotropic_direction(seed);
19,381,238✔
104
}
105

106
//==============================================================================
107
// Monodirectional implementation
108
//==============================================================================
109

110
Direction Monodirectional::sample(uint64_t* seed) const
12,466,094✔
111
{
112
  return u_ref_;
12,466,094✔
113
}
114

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