9#include "ns3/rng-seed-manager.h"
10#include "ns3/spatial-gaussian-field.h"
36 :
TestCase(
"SpatialGaussianField determinism")
41 void DoRun()
override;
56 const Vector pos(17.3, -4.9, 1.5);
57 const double corrDist = 25.0;
59 const double ref = f.
Sample(7, pos, corrDist);
64 "Sample differs across instances of the same field");
67 "Sample depends on the z coordinate");
73 "Sample ignores the correlation distance");
77 "SampleWindow disagrees with Sample");
79 0.5 * std::erfc(-ref * M_SQRT1_2),
80 "SampleUniform is not the normal CDF of Sample");
83 const double d = f.
Sample(7, pos, 0.0);
87 "Degenerate sample ignores the position");
91 f.
Sample(7, Vector(2.0, 0.0, 0.0), 0.0),
92 "Degenerate sample ignores the high bits of x");
94 f.
Sample(7, Vector(0.0, 2.0, 0.0), 0.0),
95 "Degenerate sample ignores the high bits of y");
123 ?
"SpatialGaussianField statistics (Box-Muller cells)"
124 :
"SpatialGaussianField statistics (Irwin-Hall cells)"),
130 void DoRun()
override;
149 static Vector
Offset(
const Vector& a,
double separation,
double theta);
169 if (wa.ix +
static_cast<int64_t
>(i) == wb.ix +
static_cast<int64_t
>(k))
171 sx += wa.wx[i] * wb.wx[k];
173 if (wa.iy +
static_cast<int64_t
>(i) == wb.iy +
static_cast<int64_t
>(k))
175 sy += wa.wy[i] * wb.wy[k];
179 return sx * sy * wa.invL2Norm * wb.invL2Norm;
185 return Vector(a.x + separation * std::cos(theta), a.y + separation * std::sin(theta), a.z);
196 const uint64_t nFields = 4000;
197 const double corrDist = 20.0;
198 const Vector origin(31.7, -12.3, 0);
203 for (uint64_t key = 0; key < nFields; key++)
205 const double v =
m_field.Sample(key, origin, corrDist);
209 const double mean = sum / nFields;
210 const double var = sum2 / nFields - mean * mean;
219 for (
double ratio : {0.25, 0.5, 1.0, 2.0})
225 for (uint64_t key = 0; key < nFields; key++)
227 const Vector b =
Offset(origin, ratio * corrDist, 2.0 * M_PI * key / nFields);
228 const double va =
m_field.Sample(key, origin, corrDist);
229 const double vb =
m_field.Sample(key, b, corrDist);
235 const double measured = sumAb / std::sqrt(sumA2 * sumB2);
241 "Sampled autocorrelation at " << ratio
242 <<
" correlation distances");
249 double crossing = 0.0;
250 for (
uint32_t k = 0; k < nDirections; k++)
252 const Vector a(origin.x + 0.37 * k, origin.y + 0.11 * k, 0);
253 const double theta = 2.0 * M_PI * k / nDirections;
255 double hi = 2.0 * corrDist;
256 for (
uint32_t it = 0; it < 30; it++)
258 const double mid = 0.5 * (lo + hi);
264 crossing /= nDirections;
268 "Autocorrelation 1/e point in correlation distances");
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
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...
Stateless, position-keyed, spatially-correlated Gaussian random field.
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,...
CellGenerator
Per-cell N(0,1) generator of the white-noise background.
@ IrwinHall
Standardized sum of the four 16-bit chunks of the hashed state (Irwin-Hall), cheaper than Box-Muller;...
@ BoxMuller
Box-Muller transform of two 53-bit uniforms.
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.
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.
@ SHADOW_FADING
Shadow fading, ThreeGppPropagationLossModel.
@ O2I_PENETRATION
Indoor distance and penetration loss, ThreeGppPropagationLossModel.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
@ UNIT
This test suite implements a Unit Test.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
The field must be a pure function of (seed, run, salt, key, position): repeated evaluations agree,...
void DoRun() override
Implementation to actually run this TestCase.
SpatialGaussianFieldDeterminismTestCase()
The marginal of the field must be N(0,1), the sampled autocorrelation must match the exact autocorrel...
SpatialGaussianFieldStatisticsTestCase(SpatialGaussianField::CellGenerator generator)
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
static double ExactAutocorrelation(const Vector &a, const Vector &b, double corrDist)
Exact autocorrelation of the discrete filter between two positions, i.e.
static Vector Offset(const Vector &a, double separation, double theta)
Second position at a separation and angle from a first position.
SpatialGaussianField m_field
the field under test
SpatialGaussianField test suite.
SpatialGaussianFieldTestSuite()
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Namespace for test files, TestCases and TestSuites.
static SpatialGaussianFieldTestSuite g_spatialGaussianFieldTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.