forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistribution_multi.cpp
96 lines (78 loc) · 2.82 KB
/
distribution_multi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "openmc/distribution_multi.h"
#include <algorithm> // for move
#include <cmath> // for sqrt, sin, cos, max
#include "openmc/constants.h"
#include "openmc/error.h"
#include "openmc/math_functions.h"
#include "openmc/random_dist.h"
#include "openmc/random_lcg.h"
#include "openmc/xml_interface.h"
namespace openmc {
//==============================================================================
// UnitSphereDistribution implementation
//==============================================================================
UnitSphereDistribution::UnitSphereDistribution(pugi::xml_node node)
{
// Read reference directional unit vector
if (check_for_node(node, "reference_uvw")) {
auto u_ref = get_node_array<double>(node, "reference_uvw");
if (u_ref.size() != 3)
fatal_error("Angular distribution reference direction must have "
"three parameters specified.");
u_ref_ = Direction(u_ref.data());
}
}
//==============================================================================
// PolarAzimuthal implementation
//==============================================================================
PolarAzimuthal::PolarAzimuthal(Direction u, UPtrDist mu, UPtrDist phi)
: UnitSphereDistribution {u}, mu_ {std::move(mu)}, phi_ {std::move(phi)}
{}
PolarAzimuthal::PolarAzimuthal(pugi::xml_node node)
: UnitSphereDistribution {node}
{
if (check_for_node(node, "mu")) {
pugi::xml_node node_dist = node.child("mu");
mu_ = distribution_from_xml(node_dist);
} else {
mu_ = UPtrDist {new Uniform(-1., 1.)};
}
if (check_for_node(node, "phi")) {
pugi::xml_node node_dist = node.child("phi");
phi_ = distribution_from_xml(node_dist);
} else {
phi_ = UPtrDist {new Uniform(0.0, 2.0 * PI)};
}
}
Direction PolarAzimuthal::sample(uint64_t* seed) const
{
// Sample cosine of polar angle
double mu = mu_->sample(seed);
if (mu == 1.0)
return u_ref_;
// Sample azimuthal angle
double phi = phi_->sample(seed);
return rotate_angle(u_ref_, mu, &phi, seed);
}
//==============================================================================
// Isotropic implementation
//==============================================================================
Direction isotropic_direction(uint64_t* seed)
{
double phi = uniform_distribution(0., 2.0 * PI, seed);
double mu = uniform_distribution(-1., 1., seed);
return {mu, std::sqrt(1.0 - mu * mu) * std::cos(phi),
std::sqrt(1.0 - mu * mu) * std::sin(phi)};
}
Direction Isotropic::sample(uint64_t* seed) const
{
return isotropic_direction(seed);
}
//==============================================================================
// Monodirectional implementation
//==============================================================================
Direction Monodirectional::sample(uint64_t* seed) const
{
return u_ref_;
}
} // namespace openmc