11#include "ns3/rng-seed-manager.h"
21 :
m_salt(static_cast<uint64_t>(salt)),
29 x += 0x9E3779B97F4A7C15ULL;
30 x = (
x ^ (
x >> 30)) * 0xBF58476D1CE4E5B9ULL;
31 x = (
x ^ (
x >> 27)) * 0x94D049BB133111EBULL;
54 const double inv = 1.0 / 9007199254740992.0;
55 const double u1 = (
static_cast<double>(
SplitMix64(h) >> 11) + 1.0) * inv;
56 const double u2 =
static_cast<double>(
SplitMix64(h + 1) >> 11) * inv;
57 return std::sqrt(-2.0 * std::log(u1)) * std::cos(2.0 * M_PI * u2);
61 static_cast<double>((h & 0xFFFF) + ((h >> 16) & 0xFFFF) + ((h >> 32) & 0xFFFF) + (h >> 48));
64 return (sum - 131070.0) * (1.0 / 37837.2267);
77 const double lambda = corrDist / 1.996;
82 const double spacing = 0.5 * lambda;
83 win.
ix =
static_cast<int64_t
>(std::floor(position.x / spacing)) - 6;
84 win.
iy =
static_cast<int64_t
>(std::floor(position.y / spacing)) - 6;
91 win.
wx[k] = std::exp(-std::abs((win.
ix + k) * spacing - position.x) / lambda);
92 win.
wy[k] = std::exp(-std::abs((win.
iy + k) * spacing - position.y) / lambda);
93 wx2Sum += win.
wx[k] * win.
wx[k];
94 wy2Sum += win.
wy[k] * win.
wy[k];
98 win.
invL2Norm = 1.0 / std::sqrt(wx2Sum * wy2Sum);
112 for (int64_t j = 0; std::cmp_less(j,
WINDOW_CELLS); j++)
115 for (int64_t i = 0; std::cmp_less(i,
WINDOW_CELLS); i++)
119 acc += win.
wy[j] * rowAcc;
129 const uint64_t prefix =
Prefix(fieldKey);
135 std::memcpy(&ix, &position.x,
sizeof(ix));
136 std::memcpy(&iy, &position.y,
sizeof(iy));
146 const Vector& position,
147 double corrDist)
const
149 return 0.5 * std::erfc(-
Sample(fieldKey, position, corrDist) * M_SQRT1_2);
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
static uint64_t GetRun()
Get the current run number.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
double SampleWindowFromPrefix(uint64_t prefix, const Window &window) const
Sample the field through a precomputed filter window.
double SampleUniform(uint64_t fieldKey, const Vector &position, double corrDist) const
Sample the field at a position and map it to a U(0,1) variate through the standard normal CDF,...
uint64_t Prefix(uint64_t fieldKey) const
Hash prefix of one field, mixing the global RNG seed and run, the salt and the field key once for all...
static uint64_t SplitMix64(uint64_t x)
SplitMix64 mixing round.
uint64_t m_salt
class-specific salt
CellGenerator
Per-cell N(0,1) generator of the white-noise background.
@ BoxMuller
Box-Muller transform of two 53-bit uniforms.
double CellFromPrefix(uint64_t prefix, int64_t ix, int64_t iy) const
Deterministic N(0,1) value of one cell of the field.
double Sample(uint64_t fieldKey, const Vector &position, double corrDist) const
Sample the spatially-correlated field at a position; a non-positive correlation distance degrades to ...
static constexpr std::size_t WINDOW_CELLS
Number of grid cells per dimension of a filter window.
SpatialGaussianField(Salt salt, CellGenerator generator=CellGenerator::BoxMuller)
Construct a field.
static Window ComputeWindow(const Vector &position, double corrDist)
Compute the filter window of a sampling position.
double SampleWindow(uint64_t fieldKey, const Window &window) const
Sample the field through a precomputed filter window.
CellGenerator m_generator
per-cell N(0,1) generator
Salt
Salts of the fields of every model sampling a SpatialGaussianField.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Filter window of one sampling position (grid origin, separable weights and their L2 normalization),...
int64_t ix
grid x-coordinate of the first window cell
std::array< double, WINDOW_CELLS > wx
separable filter weights along x
int64_t iy
grid y-coordinate of the first window cell
double invL2Norm
reciprocal L2 norm of the 2D weights
std::array< double, WINDOW_CELLS > wy
separable filter weights along y