A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
circular-aperture-antenna-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 University of Padova, Dep. of Information Engineering, SIGNET lab.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mattia Sandri <mattia.sandri@unipd.it>
7 */
8
10
11// The host system uses Clang libc++, which does not support the Mathematical special functions
12// (P0226R1) and Boost's implementation of cyl_bessel_j has been found.
13#ifdef NEED_AND_HAVE_BOOST_BESSEL_FUNC
14#include <boost/math/special_functions/bessel.hpp>
15#endif
16
17#include "antenna-model.h"
18
19#include "ns3/boolean.h"
20#include "ns3/double.h"
21#include "ns3/log.h"
22
23#include <math.h>
24
25/**
26 * @file
27 * @ingroup antenna
28 * Class CircularApertureAntennaModel implementation.
29 */
30
31namespace
32{
33constexpr double C = 299792458.0; ///< speed of light in vacuum, in m/s
34} // namespace
35
36namespace ns3
37{
38NS_LOG_COMPONENT_DEFINE("CircularApertureAntennaModel");
39
40NS_OBJECT_ENSURE_REGISTERED(CircularApertureAntennaModel);
41
42TypeId
44{
45 static TypeId tid =
46 TypeId("ns3::CircularApertureAntennaModel")
48 .SetGroupName("Antenna")
49 .AddConstructor<CircularApertureAntennaModel>()
50 .AddAttribute("AntennaCircularApertureRadius",
51 "The radius of the aperture of the antenna, in meters",
52 DoubleValue(0.5),
55 .AddAttribute("OperatingFrequency",
56 "The operating frequency in Hz of the antenna",
57 DoubleValue(2e9),
60 .AddAttribute("AntennaMinGainDb",
61 "The minimum gain value in dB of the antenna",
62 DoubleValue(-100.0),
65 .AddAttribute("AntennaMaxGainDb",
66 "The maximum gain value in dB of the antenna",
67 DoubleValue(1),
70 .AddAttribute("ForceGainBounds",
71 "Force GetGainDb to [AntennaMinGainDb, AntennaMaxGainDb] range",
72 BooleanValue(true),
75 return tid;
76}
77
78void
80{
81 NS_LOG_FUNCTION(this << aMeter);
82 NS_ASSERT_MSG(aMeter > 0, "Setting invalid aperture radius: " << aMeter);
83 m_apertureRadiusMeter = aMeter;
84}
85
86double
91
92void
94{
95 NS_LOG_FUNCTION(this << freqHz);
96 NS_ASSERT_MSG(freqHz > 0, "Setting invalid operating frequency: " << freqHz);
98}
99
100double
105
106void
108{
109 NS_LOG_FUNCTION(this << gainDb);
110 m_maxGain = gainDb;
111}
112
113double
118
119void
121{
122 NS_LOG_FUNCTION(this << gainDb);
123 m_minGain = gainDb;
124}
125
126double
131
132double
134{
135 NS_LOG_FUNCTION(this << a);
136
137 // In 3GPP TR 38.811 v15.4.0, Section 6.4.1, the gain depends on a single angle only.
138 // We assume that this angle represents the angle between the vectors corresponding
139 // to the cartesian coordinates of the provided spherical coordinates, and the spherical
140 // coordinates (r = 1, azimuth = 0, elevation = PI/2)
141 double theta1 = a.GetInclination();
142 double theta2 = M_PI_2; // reference direction
143
144 // Convert to ISO range: the input azimuth angle phi is in [-pi,pi],
145 // while the ISO convention for spherical to cartesian coordinates
146 // assumes phi in [0,2*pi].
147 double phi1 = M_PI + a.GetAzimuth();
148 double phi2 = M_PI; // reference direction
149
150 // Convert the spherical coordinates of the boresight and the incoming ray
151 // to Cartesian coordinates
152 Vector p1(sin(theta1) * cos(phi1), sin(theta1) * sin(phi1), cos(theta1));
153 Vector p2(sin(theta2) * cos(phi2), sin(theta2) * sin(phi2), cos(theta2));
154
155 // Calculate the angle between the antenna boresight and the incoming ray
156 double theta = acos(p1 * p2);
157
158 double gain = 0;
159 if (theta == 0)
160 {
161 gain = m_maxGain;
162 }
163 // return value of std::arccos is in [0, PI] deg
164 else if (theta >= M_PI_2)
165 {
166 // This is an approximation. 3GPP TR 38.811 does not provide indications
167 // on the antenna field pattern outside its PI degrees FOV.
168 gain = m_minGain;
169 }
170 else // 0 < theta < |PI/2|
171 {
172 // 3GPP TR 38.811 v15.4.0, Section 6.4.1
173 double k = (2 * M_PI * m_operatingFrequencyHz) / C;
174 double kasintheta = k * m_apertureRadiusMeter * sin(theta);
175// If needed, fall back to Boost cyl_bessel_j
176#ifdef NEED_AND_HAVE_BOOST_BESSEL_FUNC
177 gain = boost::math::cyl_bessel_j(1, kasintheta) / kasintheta;
178// Otherwise, use the std implementation
179#else
180 gain = std::cyl_bessel_j(1, kasintheta) / kasintheta;
181#endif
182 gain = 10 * log10(4 * gain * gain) + m_maxGain;
184 {
185 gain = std::min(std::max(gain, m_minGain), m_maxGain);
186 }
187 }
188
189 return gain;
190}
191
192} // namespace ns3
Class CircularApertureAntennaModel declaration.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition angles.h:107
double GetInclination() const
Getter for inclination angle.
Definition angles.cc:236
double GetAzimuth() const
Getter for azimuth angle.
Definition angles.cc:230
interface for antenna radiation pattern models
AttributeValue implementation for Boolean.
Definition boolean.h:26
double m_maxGain
antenna gain in dB towards the main orientation
void SetApertureRadius(double aMeter)
Set the antenna aperture radius.
void SetOperatingFrequency(double freqHz)
Set the antenna operating frequency.
double m_apertureRadiusMeter
antenna aperture radius in meters
bool m_forceGainBounds
enforce maximum and minimum gains (disabled for testing)
double m_operatingFrequencyHz
antenna operating frequency in Hz
void SetMinGain(double gainDb)
Set the antenna min gain.
double GetMaxGain() const
Return the antenna max gain.
double GetOperatingFrequency() const
Return the antenna operating frequency.
double GetMinGain() const
Return the antenna min gain.
double GetGainDb(Angles a) override
Get the gain in dB, using Bessel equation of first kind and first order.
void SetMaxGain(double gainDb)
Set the antenna max gain.
static TypeId GetTypeId()
Register this type.
double GetApertureRadius() const
Return the antenna aperture radius.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition boolean.h:70
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition double.h:32
#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
log2() macro definition; to deal with Bug 1467 .
Every class exported by the ns3 library is enclosed in the ns3 namespace.