A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
hexagonal-wraparound-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
9
10#include "ns3/log.h"
11
12#include <algorithm>
13
14constexpr double M_SQRT3 = 1.732050807568877; // sqrt(3)
15
16namespace ns3
17{
18/**
19 * Coefficients used to wraparound a cluster with 7 sites (1 ring)
20 */
21std::vector<Vector2D> WRAPPING_COEFF_CLUSTER7 =
22 {{0.0, 0.0}, {-3.0, 2.0}, {3.0, -2.0}, {-1.5, -2.5}, {1.5, 2.5}, {-4.5, -0.5}, {4.5, 0.5}};
23
24/**
25 * Coefficients used to wraparound a cluster with 19 sites (3 rings)
26 */
27std::vector<Vector2D> WRAPPING_COEFF_CLUSTER19 =
28 {{0.0, 0.0}, {-3.0, -4.0}, {3.0, 4.0}, {-4.5, 3.5}, {4.5, -3.5}, {-7.5, -0.5}, {7.5, 0.5}};
29
30NS_LOG_COMPONENT_DEFINE("HexagonalWraparoundModel");
31
32NS_OBJECT_ENSURE_REGISTERED(HexagonalWraparoundModel);
33
34TypeId
36{
37 static TypeId tid = TypeId("ns3::HexagonalWraparoundModel")
39 .SetGroupName("Spectrum")
40 .AddConstructor<HexagonalWraparoundModel>();
41 return tid;
42}
43
48
50 : m_numSites(numSites)
51{
52 SetSiteDistance(isd);
53}
54
55void
57{
58 m_isd = isd;
59 m_radius = isd / M_SQRT3;
60}
61
62void
64{
65 NS_ASSERT((numSites == 1) || (numSites == 7) || (numSites == 19));
66 m_numSites = numSites;
67}
68
69void
76
77void
78HexagonalWraparoundModel::SetSitePositions(const std::vector<Vector3D>& positions)
79{
80 NS_ASSERT(positions.size() == m_numSites);
81 m_sitePositions = positions;
82}
83
84double
86{
87 return (a - GetVirtualPosition(b, a)).GetLength();
88}
89
90// Wraparound calculation is based on
91// R. S. Panwar and K. M. Sivalingam, "Implementation of wrap
92// around mechanism for system level simulation of LTE cellular
93// networks in NS3," 2017 IEEE 18th International Symposium on
94// A World of Wireless, Mobile and Multimedia Networks (WoWMoM),
95// Macau, 2017, pp. 1-9, doi: 10.1109/WoWMoM.2017.7974289.
98{
100
101 std::vector<double> virtDists;
102 virtDists.resize(m_numSites);
103 std::transform(m_sitePositions.begin(),
104 m_sitePositions.end(),
105 virtDists.begin(),
106 [&](const Vector3D& sitePos) {
107 return (this->GetVirtualPosition(pos, sitePos) - sitePos).GetLength();
108 });
109 auto idx = std::min_element(virtDists.begin(), virtDists.end()) - virtDists.begin();
110 return m_sitePositions[idx];
111}
112
115{
116 NS_ASSERT_MSG((m_numSites == 1) || (m_numSites == 7) || (m_numSites == 19),
117 "invalid numSites: " << m_numSites);
118
119 if (m_numSites == 1)
120 {
121 return txPos;
122 }
123
125
126 std::vector<double> virtDists;
127 virtDists.resize(coeffs.size());
128 std::transform(coeffs.begin(), coeffs.end(), virtDists.begin(), [&](const Vector2D& coeff) {
129 Vector3D virtPos2 = txPos;
130 virtPos2.x += coeff.x * m_radius;
131 virtPos2.y += coeff.y * m_isd;
132 return static_cast<double>((virtPos2 - rxPos).GetLength());
133 });
134
135 auto idx = std::min_element(virtDists.begin(), virtDists.end()) - virtDists.begin();
136 Vector3D offset(m_radius * coeffs[idx].x, m_isd * coeffs[idx].y, 0.0);
137 return txPos + offset;
138}
139
140} // namespace ns3
Vector3D GetSitePosition(const Vector3D &pos) const
Calculate the site position.
void AddSitePosition(const Vector3D &pos)
Add a site position.
static TypeId GetTypeId()
Register this type with the TypeId system.
Vector3D GetVirtualPosition(const Vector3D txPos, const Vector3D rxPos) const override
Get virtual position of txPos with respect to rxPos.
void SetSitePositions(const std::vector< Vector3D > &positions)
Set site positions.
double CalculateDistance(const Vector3D &a, const Vector3D &b) const
Calculate distance after wraparound between two points.
std::vector< Vector3D > m_sitePositions
site positions
void SetSiteDistance(double isd)
Set site distance.
void SetNumSites(uint8_t numSites)
Set number of sites.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
a 2d vector
Definition vector.h:196
a 3d vector
Definition vector.h:35
WraparoundModel()=default
Default constructor.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
constexpr double M_SQRT3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< Vector2D > WRAPPING_COEFF_CLUSTER19
Coefficients used to wraparound a cluster with 19 sites (3 rings)
std::vector< Vector2D > WRAPPING_COEFF_CLUSTER7
Coefficients used to wraparound a cluster with 7 sites (1 ring)