Skip to content

Commit b3870f0

Browse files
antenna: Enforce minimum and maximum gain values of CircularApertureAntennaModel
1 parent 83000d9 commit b3870f0

File tree

3 files changed

+56
-33
lines changed

3 files changed

+56
-33
lines changed

src/antenna/model/circular-aperture-antenna-model.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "antenna-model.h"
1818

19+
#include "ns3/boolean.h"
1920
#include "ns3/double.h"
2021
#include "ns3/log.h"
2122

@@ -65,7 +66,12 @@ CircularApertureAntennaModel::GetTypeId()
6566
"The maximum gain value in dB of the antenna",
6667
DoubleValue(1),
6768
MakeDoubleAccessor(&CircularApertureAntennaModel::SetMaxGain),
68-
MakeDoubleChecker<double>(0.0));
69+
MakeDoubleChecker<double>(0.0))
70+
.AddAttribute("ForceGainBounds",
71+
"Force GetGainDb to [AntennaMinGainDb, AntennaMaxGainDb] range",
72+
BooleanValue(true),
73+
MakeBooleanAccessor(&CircularApertureAntennaModel::m_forceGainBounds),
74+
MakeBooleanChecker());
6975
return tid;
7076
}
7177

@@ -174,6 +180,10 @@ CircularApertureAntennaModel::GetGainDb(Angles a)
174180
gain = std::cyl_bessel_j(1, kasintheta) / kasintheta;
175181
#endif
176182
gain = 10 * log10(4 * gain * gain) + m_maxGain;
183+
if (m_forceGainBounds)
184+
{
185+
gain = std::min(std::max(gain, m_minGain), m_maxGain);
186+
}
177187
}
178188

179189
return gain;

src/antenna/model/circular-aperture-antenna-model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class CircularApertureAntennaModel : public AntennaModel
122122
double m_operatingFrequencyHz; //!< antenna operating frequency in Hz
123123
double m_maxGain; //!< antenna gain in dB towards the main orientation
124124
double m_minGain; //!< antenna min gain in dB
125+
bool m_forceGainBounds; //!< enforce maximum and minimum gains (disabled for testing)
125126
};
126127

127128
} // namespace ns3

src/antenna/test/test-circular-aperture-antenna.cc

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: GPL-2.0-only
55
*/
66

7+
#include "ns3/boolean.h"
78
#include "ns3/circular-aperture-antenna-model.h"
89
#include "ns3/double.h"
910
#include "ns3/log.h"
@@ -56,21 +57,24 @@ class CircularApertureAntennaModelTestCase : public TestCase
5657
* @param testAzimuth test azimuth [rad]
5758
* @param testInclination test inclination [rad]
5859
* @param expectedGain the expected gain value [dB]
60+
* @param forceGainBounds restrict or not gain range to [antennaMinGainDb, antennaMaxGainDb]
5961
*/
6062
TestPoint(double antennaMaxGainDb,
6163
double antennaMinGainDb,
6264
double antennaCircularApertureRadius,
6365
double operatingFrequency,
6466
double testAzimuth,
6567
double testInclination,
66-
double expectedGain)
68+
double expectedGain,
69+
bool forceGainBounds)
6770
: m_antennaMaxGainDb(antennaMaxGainDb),
6871
m_antennaMinGainDb(antennaMinGainDb),
6972
m_antennaCircularApertureRadius(antennaCircularApertureRadius),
7073
m_operatingFrequency(operatingFrequency),
7174
m_testAzimuth(DegreesToRadians(testAzimuth)),
7275
m_testInclination(DegreesToRadians(testInclination)),
73-
m_expectedGain(expectedGain)
76+
m_expectedGain(expectedGain),
77+
m_forceGainBounds(forceGainBounds)
7478
{
7579
}
7680

@@ -81,6 +85,7 @@ class CircularApertureAntennaModelTestCase : public TestCase
8185
double m_testAzimuth; ///< test azimuth [rad]
8286
double m_testInclination; ///< test inclination [rad]
8387
double m_expectedGain; ///< the expected gain value [dB]
88+
bool m_forceGainBounds; ///< enable bounds checking for GetGainDb
8489
};
8590

8691
/**
@@ -136,7 +141,9 @@ CircularApertureAntennaModelTestCase::TestAntennaGain(TestPoint testPoint)
136141
"AntennaCircularApertureRadius",
137142
DoubleValue(testPoint.m_antennaCircularApertureRadius),
138143
"OperatingFrequency",
139-
DoubleValue(testPoint.m_operatingFrequency));
144+
DoubleValue(testPoint.m_operatingFrequency),
145+
"ForceGainBounds",
146+
BooleanValue(testPoint.m_forceGainBounds));
140147

141148
Ptr<UniformPlanarArray> upa =
142149
CreateObjectWithAttributes<UniformPlanarArray>("AntennaElement",
@@ -164,45 +171,50 @@ CircularApertureAntennaModelTestCase::DoRun()
164171
// MaxGainDb MinGainDb Radius (m) Freq (Hz) Azimuth (deg) Incl (deg) ExpGain (dB)
165172
// Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
166173
// for different frequency
167-
{30, -30, 0.5, 2e9, 0, 90, 30},
168-
{30, -30, 2, 20e9, 0, 90, 30},
174+
{30, -30, 0.5, 2e9, 0, 90, 30, false},
175+
{30, -30, 2, 20e9, 0, 90, 30, false},
169176
// Test invariant: gain always equal to max gain at boresight (inclination 90, azimuth = 0)
170177
// for different max gain
171-
{20, -30, 0.5, 2e9, 0, 90, 20},
172-
{10, -30, 2, 20e9, 0, 90, 10},
178+
{20, -30, 0.5, 2e9, 0, 90, 20, false},
179+
{10, -30, 2, 20e9, 0, 90, 10, false},
173180
// Test invariant: gain always equal to min gain outside of |theta| < 90 deg
174181
// for different frequency
175-
{30, -100, 0.5, 2e9, 0, 0, -100},
176-
{30, -100, 2, 20e9, 0, 0, -100},
182+
{30, -100, 0.5, 2e9, 0, 0, -100, false},
183+
{30, -100, 2, 20e9, 0, 0, -100, false},
177184
// Test invariant: gain always equal to min gain outside of |theta| < 90 deg
178185
// for different orientations
179-
{30, -100, 0.5, 2e9, 180, 90, -100},
180-
{30, -100, 2, 20e9, -180, 90, -100},
186+
{30, -100, 0.5, 2e9, 180, 90, -100, false},
187+
{30, -100, 2, 20e9, -180, 90, -100, false},
181188
// Fixed elevation to boresight (90deg) and azimuth varying in [-90, 0] deg with steps of 10
182189
// 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},
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},
193202
// Fixed azimuth to boresight (0 deg) and azimuth varying in [0, 90] deg with steps of 9
194203
// 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}};
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}};
206218

207219
// Call TestAntennaGain on each test point
208220
for (auto& point : testPoints)

0 commit comments

Comments
 (0)