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/circular-aperture-antenna-model.h"
8#include "ns3/double.h"
9#include "ns3/log.h"
10#include "ns3/pointer.h"
11#include "ns3/simulator.h"
12#include "ns3/test.h"
13#include "ns3/uinteger.h"
14#include "ns3/uniform-planar-array.h"
15
16#include <cmath>
17#include <iostream>
18#include <sstream>
19#include <string>
20
21using namespace ns3;
22
23NS_LOG_COMPONENT_DEFINE("TestCircularApertureAntennaModel");
24
25/**
26 * \ingroup antenna-tests
27 *
28 * \brief CircularApertureAntennaModel Test Case
29 *
30 * Note: Since Clang libc++ does not support the Mathematical special functions (P0226R1) yet, this
31 * class falls back to Boost's implementation of cyl_bessel_j whenever the above standard library is
32 * in use. If neither is available in the host system, this class is not compiled.
33 */
35{
36 public:
38
39 /**
40 * \brief Description of a single test point
41 *
42 * Description of a test point, which is characterized
43 * by the CircularApertureAntennaModel parameters,
44 * the directions towards which the antenna gain
45 * is to be tested, and the expected gain value.
46 */
47 struct TestPoint
48 {
49 /**
50 * @brief Constructor
51 *
52 * @param antennaMaxGainDb the antenna maximum possible gain [dB]
53 * @param antennaMinGainDb the antenna minimum possible gain [dB]
54 * @param antennaCircularApertureRadius the radius of the parabolic aperture [m]
55 * @param operatingFrequency operating frequency [Hz]
56 * @param testAzimuth test azimuth [rad]
57 * @param testInclination test inclination [rad]
58 * @param expectedGain the expected gain value [dB]
59 */
60 TestPoint(double antennaMaxGainDb,
61 double antennaMinGainDb,
62 double antennaCircularApertureRadius,
63 double operatingFrequency,
64 double testAzimuth,
65 double testInclination,
66 double expectedGain)
67 : m_antennaMaxGainDb(antennaMaxGainDb),
68 m_antennaMinGainDb(antennaMinGainDb),
69 m_antennaCircularApertureRadius(antennaCircularApertureRadius),
70 m_operatingFrequency(operatingFrequency),
71 m_testAzimuth(DegreesToRadians(testAzimuth)),
72 m_testInclination(DegreesToRadians(testInclination)),
73 m_expectedGain(expectedGain)
74 {
75 }
76
77 double m_antennaMaxGainDb; ///< the antenna maximum possible gain [dB]
78 double m_antennaMinGainDb; ///< the antenna minimum possible gain [dB]
79 double m_antennaCircularApertureRadius; ///< the radius of the parabolic aperture [m]
80 double m_operatingFrequency; ///< operating frequency [Hz]
81 double m_testAzimuth; ///< test azimuth [rad]
82 double m_testInclination; ///< test inclination [rad]
83 double m_expectedGain; ///< the expected gain value [dB]
84 };
85
86 /**
87 * Generate a string containing all relevant parameters
88 * \param testPoint the parameter configuration to be tested
89 * \return the string containing all relevant parameters
90 */
91 static std::string BuildNameString(TestPoint testPoint);
92
93 /**
94 * Test the antenna gain for a specific parameter configuration,
95 * by comparing the antenna gain obtained using CircularApertureAntennaModel::GetGainDb
96 * and the one obtained using MATLAB.
97 *
98 * \param testPoint the parameter configuration to be tested
99 */
100 void TestAntennaGain(TestPoint testPoint);
101
102 private:
103 /**
104 * Run the test
105 */
106 void DoRun() override;
107};
108
110 : TestCase("Creating CircularApertureAntennaModelTestCase")
111{
112}
113
114std::string
116{
117 std::ostringstream oss;
118 oss << " Maximum gain=" << testPoint.m_antennaMaxGainDb << "dB"
119 << " minimum gain=" << testPoint.m_antennaMinGainDb << "dB"
120 << ", antenna aperture radius=" << testPoint.m_antennaCircularApertureRadius << "m"
121 << ", frequency" << testPoint.m_operatingFrequency << "Hz"
122 << ", test inclination=" << RadiansToDegrees(testPoint.m_testInclination) << " deg"
123 << ", test azimuth=" << RadiansToDegrees(testPoint.m_testAzimuth) << " deg";
124 return oss.str();
125}
126
127void
129{
132 "AntennaMaxGainDb",
134 "AntennaMinGainDb",
136 "AntennaCircularApertureRadius",
138 "OperatingFrequency",
140
143 PointerValue(antenna),
144 "NumColumns",
145 UintegerValue(1),
146 "NumRows",
147 UintegerValue(1));
148
149 auto [fieldPhi, fieldTheta] =
150 upa->GetElementFieldPattern(Angles(testPoint.m_testAzimuth, testPoint.m_testInclination),
151 0);
152 // Compute the antenna gain as the squared sum of the field pattern components
153 double gainDb = 10 * log10(fieldPhi * fieldPhi + fieldTheta * fieldTheta);
154 auto log = BuildNameString(testPoint);
155 NS_LOG_INFO(log);
156 NS_TEST_EXPECT_MSG_EQ_TOL(gainDb, testPoint.m_expectedGain, 0.1, log);
157}
158
159void
161{
162 // Vector of test points
163 std::vector<TestPoint> testPoints = {
164 // MaxGainDb MinGainDb Radius (m) Freq (Hz) Azimuth (deg) Incl (deg) ExpGain (dB)
165 // Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
166 // for different frequency
167 {30, -30, 0.5, 2e9, 0, 90, 30},
168 {30, -30, 2, 20e9, 0, 90, 30},
169 // Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
170 // for different max gain
171 {20, -30, 0.5, 2e9, 0, 90, 20},
172 {10, -30, 2, 20e9, 0, 90, 10},
173 // Test invariant: gain always equal to min gain outside of |theta| < 90 deg
174 // for different frequency
175 {30, -100, 0.5, 2e9, 0, 0, -100},
176 {30, -100, 2, 20e9, 0, 0, -100},
177 // Test invariant: gain always equal to min gain outside of |theta| < 90 deg
178 // for different orientations
179 {30, -100, 0.5, 2e9, 180, 90, -100},
180 {30, -100, 2, 20e9, -180, 90, -100},
181 // Fixed elevation to boresight (90deg) and azimuth varying in [-90, 0] deg with steps of 10
182 // degrees
183 {0, -50, 0.10707, 28000000000, -90, 90, -50},
184 {0, -50, 0.10707, 28000000000, -80, 90, -49.8022},
185 {0, -50, 0.10707, 28000000000, -70, 90, -49.1656},
186 {0, -50, 0.10707, 28000000000, -60, 90, -60.9132},
187 {0, -50, 0.10707, 28000000000, -50, 90, -59.2368},
188 {0, -50, 0.10707, 28000000000, -40, 90, -44.6437},
189 {0, -50, 0.10707, 28000000000, -30, 90, -43.9686},
190 {0, -50, 0.10707, 28000000000, -20, 90, -36.3048},
191 {0, -50, 0.10707, 28000000000, -10, 90, -30.5363},
192 {0, -50, 0.10707, 28000000000, 0, 90, 0},
193 // Fixed azimuth to boresight (0 deg) and azimuth varying in [0, 90] deg with steps of 9
194 // degrees
195 {0, -50, 0.10707, 28e9, 0, 0, -50},
196 {0, -50, 0.10707, 28e9, 0, 9, -49.7256},
197 {0, -50, 0.10707, 28e9, 0, 18, -52.9214},
198 {0, -50, 0.10707, 28e9, 0, 27, -48.6077},
199 {0, -50, 0.10707, 28e9, 0, 36, -60.684},
200 {0, -50, 0.10707, 28e9, 0, 45, -55.1468},
201 {0, -50, 0.10707, 28e9, 0, 54, -42.9648},
202 {0, -50, 0.10707, 28e9, 0, 63, -45.6472},
203 {0, -50, 0.10707, 28e9, 0, 72, -48.6378},
204 {0, -50, 0.10707, 28e9, 0, 81, -35.1613},
205 {0, -50, 0.10707, 28e9, 0, 90, 0}};
206
207 // Call TestAntennaGain on each test point
208 for (auto& point : testPoints)
209 {
210 TestAntennaGain(point);
211 }
212}
213
214/**
215 * \ingroup antenna-tests
216 *
217 * \brief UniformPlanarArray Test Suite
218 */
224
230
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
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
TestPoint(double antennaMaxGainDb, double antennaMinGainDb, double antennaCircularApertureRadius, double operatingFrequency, double testAzimuth, double testInclination, double expectedGain)
Constructor.
double m_antennaCircularApertureRadius
the radius of the parabolic aperture [m]
double m_antennaMinGainDb
the antenna minimum possible gain [dB]
double m_antennaMaxGainDb
the antenna maximum possible gain [dB]
static CircularApertureAntennaModelTestSuite staticCircularApertureAntennaModelTestSuiteInstance