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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include "ns3/circular-aperture-antenna-model.h"
19#include "ns3/double.h"
20#include "ns3/log.h"
21#include "ns3/pointer.h"
22#include "ns3/simulator.h"
23#include "ns3/test.h"
24#include "ns3/uinteger.h"
25#include "ns3/uniform-planar-array.h"
26
27#include <cmath>
28#include <iostream>
29#include <sstream>
30#include <string>
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("TestCircularApertureAntennaModel");
35
36/**
37 * \ingroup antenna-tests
38 *
39 * \brief CircularApertureAntennaModel Test Case
40 *
41 * Note: Since Clang libc++ does not support the Mathematical special functions (P0226R1) yet, this
42 * class falls back to Boost's implementation of cyl_bessel_j whenever the above standard library is
43 * in use. If neither is available in the host system, this class is not compiled.
44 */
46{
47 public:
49
50 /**
51 * \brief Description of a single test point
52 *
53 * Description of a test point, which is characterized
54 * by the CircularApertureAntennaModel parameters,
55 * the directions towards which the antenna gain
56 * is to be tested, and the expected gain value.
57 */
58 struct TestPoint
59 {
60 /**
61 * @brief Constructor
62 *
63 * @param antennaMaxGainDb the antenna maximum possible gain [dB]
64 * @param antennaMinGainDb the antenna minimum possible gain [dB]
65 * @param antennaCircularApertureRadius the radius of the parabolic aperture [m]
66 * @param operatingFrequency operating frequency [Hz]
67 * @param testAzimuth test azimuth [rad]
68 * @param testInclination test inclination [rad]
69 * @param expectedGain the expected gain value [dB]
70 */
71 TestPoint(double antennaMaxGainDb,
72 double antennaMinGainDb,
73 double antennaCircularApertureRadius,
74 double operatingFrequency,
75 double testAzimuth,
76 double testInclination,
77 double expectedGain)
78 : m_antennaMaxGainDb(antennaMaxGainDb),
79 m_antennaMinGainDb(antennaMinGainDb),
80 m_antennaCircularApertureRadius(antennaCircularApertureRadius),
81 m_operatingFrequency(operatingFrequency),
82 m_testAzimuth(DegreesToRadians(testAzimuth)),
83 m_testInclination(DegreesToRadians(testInclination)),
84 m_expectedGain(expectedGain)
85 {
86 }
87
88 double m_antennaMaxGainDb; ///< the antenna maximum possible gain [dB]
89 double m_antennaMinGainDb; ///< the antenna minimum possible gain [dB]
90 double m_antennaCircularApertureRadius; ///< the radius of the parabolic aperture [m]
91 double m_operatingFrequency; ///< operating frequency [Hz]
92 double m_testAzimuth; ///< test azimuth [rad]
93 double m_testInclination; ///< test inclination [rad]
94 double m_expectedGain; ///< the expected gain value [dB]
95 };
96
97 /**
98 * Generate a string containing all relevant parameters
99 * \param testPoint the parameter configuration to be tested
100 * \return the string containing all relevant parameters
101 */
102 static std::string BuildNameString(TestPoint testPoint);
103
104 /**
105 * Test the antenna gain for a specific parameter configuration,
106 * by comparing the antenna gain obtained using CircularApertureAntennaModel::GetGainDb
107 * and the one obtained using MATLAB.
108 *
109 * \param testPoint the parameter configuration to be tested
110 */
111 void TestAntennaGain(TestPoint testPoint);
112
113 private:
114 /**
115 * Run the test
116 */
117 void DoRun() override;
118};
119
121 : TestCase("Creating CircularApertureAntennaModelTestCase")
122{
123}
124
125std::string
127{
128 std::ostringstream oss;
129 oss << " Maximum gain=" << testPoint.m_antennaMaxGainDb << "dB"
130 << " minimum gain=" << testPoint.m_antennaMinGainDb << "dB"
131 << ", antenna aperture radius=" << testPoint.m_antennaCircularApertureRadius << "m"
132 << ", frequency" << testPoint.m_operatingFrequency << "Hz"
133 << ", test inclination=" << RadiansToDegrees(testPoint.m_testInclination) << " deg"
134 << ", test azimuth=" << RadiansToDegrees(testPoint.m_testAzimuth) << " deg";
135 return oss.str();
136}
137
138void
140{
142 CreateObjectWithAttributes<CircularApertureAntennaModel>(
143 "AntennaMaxGainDb",
145 "AntennaMinGainDb",
147 "AntennaCircularApertureRadius",
149 "OperatingFrequency",
151
153 CreateObjectWithAttributes<UniformPlanarArray>("AntennaElement",
154 PointerValue(antenna),
155 "NumColumns",
156 UintegerValue(1),
157 "NumRows",
158 UintegerValue(1));
159
160 auto [fieldPhi, fieldTheta] =
161 upa->GetElementFieldPattern(Angles(testPoint.m_testAzimuth, testPoint.m_testInclination),
162 0);
163 // Compute the antenna gain as the squared sum of the field pattern components
164 double gainDb = 10 * log10(fieldPhi * fieldPhi + fieldTheta * fieldTheta);
165 auto log = BuildNameString(testPoint);
166 NS_LOG_INFO(log);
167 NS_TEST_EXPECT_MSG_EQ_TOL(gainDb, testPoint.m_expectedGain, 0.1, log);
168}
169
170void
172{
173 // Vector of test points
174 std::vector<TestPoint> testPoints = {
175 // MaxGainDb MinGainDb Radius (m) Freq (Hz) Azimuth (deg) Incl (deg) ExpGain (dB)
176 // Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
177 // for different frequency
178 {30, -30, 0.5, 2e9, 0, 90, 30},
179 {30, -30, 2, 20e9, 0, 90, 30},
180 // Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
181 // for different max gain
182 {20, -30, 0.5, 2e9, 0, 90, 20},
183 {10, -30, 2, 20e9, 0, 90, 10},
184 // Test invariant: gain always equal to min gain outside of |theta| < 90 deg
185 // for different frequency
186 {30, -100, 0.5, 2e9, 0, 0, -100},
187 {30, -100, 2, 20e9, 0, 0, -100},
188 // Test invariant: gain always equal to min gain outside of |theta| < 90 deg
189 // for different orientations
190 {30, -100, 0.5, 2e9, 180, 90, -100},
191 {30, -100, 2, 20e9, -180, 90, -100},
192 // Fixed elevation to boresight (90deg) and azimuth varying in [-90, 0] deg with steps of 10
193 // degrees
194 {0, -50, 0.10707, 28000000000, -90, 90, -50},
195 {0, -50, 0.10707, 28000000000, -80, 90, -49.8022},
196 {0, -50, 0.10707, 28000000000, -70, 90, -49.1656},
197 {0, -50, 0.10707, 28000000000, -60, 90, -60.9132},
198 {0, -50, 0.10707, 28000000000, -50, 90, -59.2368},
199 {0, -50, 0.10707, 28000000000, -40, 90, -44.6437},
200 {0, -50, 0.10707, 28000000000, -30, 90, -43.9686},
201 {0, -50, 0.10707, 28000000000, -20, 90, -36.3048},
202 {0, -50, 0.10707, 28000000000, -10, 90, -30.5363},
203 {0, -50, 0.10707, 28000000000, 0, 90, 0},
204 // Fixed azimuth to boresight (0 deg) and azimuth varying in [0, 90] deg with steps of 9
205 // degrees
206 {0, -50, 0.10707, 28e9, 0, 0, -50},
207 {0, -50, 0.10707, 28e9, 0, 9, -49.7256},
208 {0, -50, 0.10707, 28e9, 0, 18, -52.9214},
209 {0, -50, 0.10707, 28e9, 0, 27, -48.6077},
210 {0, -50, 0.10707, 28e9, 0, 36, -60.684},
211 {0, -50, 0.10707, 28e9, 0, 45, -55.1468},
212 {0, -50, 0.10707, 28e9, 0, 54, -42.9648},
213 {0, -50, 0.10707, 28e9, 0, 63, -45.6472},
214 {0, -50, 0.10707, 28e9, 0, 72, -48.6378},
215 {0, -50, 0.10707, 28e9, 0, 81, -35.1613},
216 {0, -50, 0.10707, 28e9, 0, 90, 0}};
217
218 // Call TestAntennaGain on each test point
219 for (auto& point : testPoints)
220 {
221 TestAntennaGain(point);
222 }
223}
224
225/**
226 * \ingroup antenna-tests
227 *
228 * \brief UniformPlanarArray Test Suite
229 */
231{
232 public:
234};
235
237 : TestSuite("circular-aperture-antenna-test", Type::UNIT)
238{
240}
241
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:118
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
AttributeValue implementation for Pointer.
Definition: pointer.h:48
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:302
A suite of tests to run.
Definition: test.h:1273
Type
Type of test.
Definition: test.h:1280
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:511
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45
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