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

openmc-dev / openmc / 7071649772

02 Dec 2023 05:35PM UTC coverage: 84.541% (+0.02%) from 84.524%
7071649772

push

github

web-flow
Mesh Source Class (#2759)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Co-authored-by: Jonathan Shimwell <drshimwell@gmail.com>

220 of 231 new or added lines in 12 files covered. (95.24%)

53 existing lines in 2 files now uncovered.

47205 of 55837 relevant lines covered (84.54%)

34203579.09 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,949✔
16
  pugi::xml_node node)
17
{
18
  // Check for type of angular distribution
19
  std::string type;
3,949✔
20
  if (check_for_node(node, "type"))
3,949✔
21
    type = get_node_value(node, "type", true, true);
3,949✔
22
  if (type == "isotropic") {
3,949✔
23
    return UPtrAngle {new Isotropic()};
301✔
24
  } else if (type == "monodirectional") {
3,648✔
25
    return UPtrAngle {new Monodirectional(node)};
3,615✔
26
  } else if (type == "mu-phi") {
33✔
27
    return UPtrAngle {new PolarAzimuthal(node)};
33✔
28
  } else {
NEW
29
    fatal_error(fmt::format(
×
30
      "Invalid angular distribution for external source: {}", type));
31
  }
32
}
3,949✔
33

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

38
UnitSphereDistribution::UnitSphereDistribution(pugi::xml_node node)
3,648✔
39
{
40
  // Read reference directional unit vector
41
  if (check_for_node(node, "reference_uvw")) {
3,648✔
42
    auto u_ref = get_node_array<double>(node, "reference_uvw");
3,648✔
43
    if (u_ref.size() != 3)
3,648✔
44
      fatal_error("Angular distribution reference direction must have "
×
45
                  "three parameters specified.");
46
    u_ref_ = Direction(u_ref.data());
3,648✔
47
  }
3,648✔
48
}
3,648✔
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)
33✔
59
  : UnitSphereDistribution {node}
33✔
60
{
61
  if (check_for_node(node, "mu")) {
33✔
62
    pugi::xml_node node_dist = node.child("mu");
33✔
63
    mu_ = distribution_from_xml(node_dist);
33✔
64
  } else {
65
    mu_ = UPtrDist {new Uniform(-1., 1.)};
×
66
  }
67

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

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

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

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

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

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

101
Direction Isotropic::sample(uint64_t* seed) const
14,016,091✔
102
{
103
  return isotropic_direction(seed);
14,016,091✔
104
}
105

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

110
Direction Monodirectional::sample(uint64_t* seed) const
2,864,124✔
111
{
112
  return u_ref_;
2,864,124✔
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

© 2026 Coveralls, Inc