A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
test-circular-aperture-antenna.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 University of Padova, Dep. of Information Engineering, SIGNET lab.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "ns3/boolean.h"
8#include "ns3/circular-aperture-antenna-model.h"
9#include "ns3/double.h"
10#include "ns3/log.h"
11#include "ns3/pointer.h"
12#include "ns3/simulator.h"
13#include "ns3/test.h"
14#include "ns3/uinteger.h"
15#include "ns3/uniform-planar-array.h"
16
17#include <cmath>
18#include <iostream>
19#include <sstream>
20#include <string>
21
22using namespace ns3;
23
24NS_LOG_COMPONENT_DEFINE("TestCircularApertureAntennaModel");
25
26/**
27 * @ingroup antenna-tests
28 *
29 * @brief CircularApertureAntennaModel Test Case
30 *
31 * Note: Since Clang libc++ does not support the Mathematical special functions (P0226R1) yet, this
32 * class falls back to Boost's implementation of cyl_bessel_j whenever the above standard library is
33 * in use. If neither is available in the host system, this class is not compiled.
34 */
36{
37 public:
39
40 /**
41 * @brief Description of a single test point
42 *
43 * Description of a test point, which is characterized
44 * by the CircularApertureAntennaModel parameters,
45 * the directions towards which the antenna gain
46 * is to be tested, and the expected gain value.
47 */
48 struct TestPoint
49 {
50 /**
51 * @brief Constructor
52 *
53 * @param antennaMaxGainDb the antenna maximum possible gain [dB]
54 * @param antennaMinGainDb the antenna minimum possible gain [dB]
55 * @param antennaCircularApertureRadius the radius of the parabolic aperture [m]
56 * @param operatingFrequency operating frequency [Hz]
57 * @param testAzimuth test azimuth [rad]
58 * @param testInclination test inclination [rad]
59 * @param expectedGain the expected gain value [dB]
60 * @param forceGainBounds restrict or not gain range to [antennaMinGainDb, antennaMaxGainDb]
61 */
62 TestPoint(double antennaMaxGainDb,
63 double antennaMinGainDb,
64 double antennaCircularApertureRadius,
65 double operatingFrequency,
66 double testAzimuth,
67 double testInclination,
68 double expectedGain,
69 bool forceGainBounds)
70 : m_antennaMaxGainDb(antennaMaxGainDb),
71 m_antennaMinGainDb(antennaMinGainDb),
72 m_antennaCircularApertureRadius(antennaCircularApertureRadius),
73 m_operatingFrequency(operatingFrequency),
74 m_testAzimuth(DegreesToRadians(testAzimuth)),
75 m_testInclination(DegreesToRadians(testInclination)),
76 m_expectedGain(expectedGain),
77 m_forceGainBounds(forceGainBounds)
78 {
79 }
80
81 double m_antennaMaxGainDb; ///< the antenna maximum possible gain [dB]
82 double m_antennaMinGainDb; ///< the antenna minimum possible gain [dB]
83 double m_antennaCircularApertureRadius; ///< the radius of the parabolic aperture [m]
84 double m_operatingFrequency; ///< operating frequency [Hz]
85 double m_testAzimuth; ///< test azimuth [rad]
86 double m_testInclination; ///< test inclination [rad]
87 double m_expectedGain; ///< the expected gain value [dB]
88 bool m_forceGainBounds; ///< enable bounds checking for GetGainDb
89 };
90
91 /**
92 * Generate a string containing all relevant parameters
93 * @param testPoint the parameter configuration to be tested
94 * @return the string containing all relevant parameters
95 */
96 static std::string BuildNameString(TestPoint testPoint);
97
98 /**
99 * Test the antenna gain for a specific parameter configuration,
100 * by comparing the antenna gain obtained using CircularApertureAntennaModel::GetGainDb
101 * and the one obtained using MATLAB.
102 *
103 * @param testPoint the parameter configuration to be tested
104 */
105 void TestAntennaGain(TestPoint testPoint);
106
107 private:
108 /**
109 * Run the test
110 */
111 void DoRun() override;
112};
113
115 : TestCase("Creating CircularApertureAntennaModelTestCase")
116{
117}
118
119std::string
121{
122 std::ostringstream oss;
123 oss << " Maximum gain=" << testPoint.m_antennaMaxGainDb << "dB"
124 << " minimum gain=" << testPoint.m_antennaMinGainDb << "dB"
125 << ", antenna aperture radius=" << testPoint.m_antennaCircularApertureRadius << "m"
126 << ", frequency" << testPoint.m_operatingFrequency << "Hz"
127 << ", test inclination=" << RadiansToDegrees(testPoint.m_testInclination) << " deg"
128 << ", test azimuth=" << RadiansToDegrees(testPoint.m_testAzimuth) << " deg";
129 return oss.str();
130}
131
132void
134{
137 "AntennaMaxGainDb",
139 "AntennaMinGainDb",
141 "AntennaCircularApertureRadius",
143 "OperatingFrequency",
145 "ForceGainBounds",
147
150 PointerValue(antenna),
151 "NumColumns",
152 UintegerValue(1),
153 "NumRows",
154 UintegerValue(1));
155
156 auto [fieldPhi, fieldTheta] =
157 upa->GetElementFieldPattern(Angles(testPoint.m_testAzimuth, testPoint.m_testInclination),
158 0);
159 // Compute the antenna gain as the squared sum of the field pattern components
160 double gainDb = 10 * log10(fieldPhi * fieldPhi + fieldTheta * fieldTheta);
161 auto log = BuildNameString(testPoint);
162 NS_LOG_INFO(log);
163 NS_TEST_EXPECT_MSG_EQ_TOL(gainDb, testPoint.m_expectedGain, 0.1, log);
164}
165
166void
168{
169 // Vector of test points
170 std::vector<TestPoint> testPoints = {
171 // MaxGainDb MinGainDb Radius (m) Freq (Hz) Azimuth (deg) Incl (deg) ExpGain (dB)
172 // Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
173 // for different frequency
174 {30, -30, 0.5, 2e9, 0, 90, 30, false},
175 {30, -30, 2, 20e9, 0, 90, 30, false},
176 // Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
177 // for different max gain
178 {20, -30, 0.5, 2e9, 0, 90, 20, false},
179 {10, -30, 2, 20e9, 0, 90, 10, false},
180 // Test invariant: gain always equal to min gain outside of |theta| < 90 deg
181 // for different frequency
182 {30, -100, 0.5, 2e9, 0, 0, -100, false},
183 {30, -100, 2, 20e9, 0, 0, -100, false},
184 // Test invariant: gain always equal to min gain outside of |theta| < 90 deg
185 // for different orientations
186 {30, -100, 0.5, 2e9, 180, 90, -100, false},
187 {30, -100, 2, 20e9, -180, 90, -100, false},
188 // Fixed elevation to boresight (90deg) and azimuth varying in [-90, 0] deg with steps of 10
189 // degrees
190 {0, -50, 0.10707, 28000000000, -90, 90, -50, false},
191 {0, -50, 0.10707, 28000000000, -80, 90, -49.8022, false},
192 {0, -50, 0.10707, 28000000000, -70, 90, -49.1656, false},
193 {0, -50, 0.10707, 28000000000, -60, 90, -60.9132, false},
194 {0, -50, 0.10707, 28000000000, -60, 90, -50, true},
195 {0, -50, 0.10707, 28000000000, -50, 90, -59.2368, false},
196 {0, -50, 0.10707, 28000000000, -50, 90, -50, true},
197 {0, -50, 0.10707, 28000000000, -40, 90, -44.6437, false},
198 {0, -50, 0.10707, 28000000000, -30, 90, -43.9686, false},
199 {0, -50, 0.10707, 28000000000, -20, 90, -36.3048, false},
200 {0, -50, 0.10707, 28000000000, -10, 90, -30.5363, false},
201 {0, -50, 0.10707, 28000000000, 0, 90, 0, false},
202 // Fixed azimuth to boresight (0 deg) and azimuth varying in [0, 90] deg with steps of 9
203 // degrees
204 {0, -50, 0.10707, 28e9, 0, 0, -50, false},
205 {0, -50, 0.10707, 28e9, 0, 9, -49.7256, false},
206 {0, -50, 0.10707, 28e9, 0, 18, -52.9214, false},
207 {0, -50, 0.10707, 28e9, 0, 18, -50, true},
208 {0, -50, 0.10707, 28e9, 0, 27, -48.6077, false},
209 {0, -50, 0.10707, 28e9, 0, 36, -60.684, false},
210 {0, -50, 0.10707, 28e9, 0, 36, -50, true},
211 {0, -50, 0.10707, 28e9, 0, 45, -55.1468, false},
212 {0, -50, 0.10707, 28e9, 0, 45, -50, true},
213 {0, -50, 0.10707, 28e9, 0, 54, -42.9648, false},
214 {0, -50, 0.10707, 28e9, 0, 63, -45.6472, false},
215 {0, -50, 0.10707, 28e9, 0, 72, -48.6378, false},
216 {0, -50, 0.10707, 28e9, 0, 81, -35.1613, false},
217 {0, -50, 0.10707, 28e9, 0, 90, 0, false}};
218
219 // Call TestAntennaGain on each test point
220 for (auto& point : testPoints)
221 {
222 TestAntennaGain(point);
223 }
224}
225
226/**
227 * @ingroup antenna-tests
228 *
229 * @brief UniformPlanarArray Test Suite
230 */
236
242
CircularApertureAntennaModel Test Case.
static std::string BuildNameString(TestPoint testPoint)
Generate a string containing all relevant parameters.
void TestAntennaGain(TestPoint testPoint)
Test the antenna gain for a specific parameter configuration, by comparing the antenna gain obtained ...
Class holding the azimuth and inclination angles of spherical coordinates.
Definition angles.h:107
AttributeValue implementation for Boolean.
Definition boolean.h:26
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition test.h:500
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition angles.cc:28
double RadiansToDegrees(double radians)
converts radians to degrees
Definition angles.cc:34
bool m_forceGainBounds
enable bounds checking for GetGainDb
double m_antennaCircularApertureRadius
the radius of the parabolic aperture [m]
double m_antennaMinGainDb
the antenna minimum possible gain [dB]
TestPoint(double antennaMaxGainDb, double antennaMinGainDb, double antennaCircularApertureRadius, double operatingFrequency, double testAzimuth, double testInclination, double expectedGain, bool forceGainBounds)
Constructor.
double m_antennaMaxGainDb
the antenna maximum possible gain [dB]
static CircularApertureAntennaModelTestSuite staticCircularApertureAntennaModelTestSuiteInstance