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 * 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 * Author: Mattia Sandri <mattia.sandri@unipd.it>
18 */
19
21
22// The host system uses Clang libc++, which does not support the Mathematical special functions
23// (P0226R1) and Boost's implementation of cyl_bessel_j has been found.
24#ifdef NEED_AND_HAVE_BOOST_BESSEL_FUNC
25#include <boost/math/special_functions/bessel.hpp>
26#endif
27
28#include "antenna-model.h"
29
30#include <ns3/double.h>
31#include <ns3/log.h>
32
33#include <math.h>
34
35/**
36 * \file
37 * \ingroup antenna
38 * Class CircularApertureAntennaModel implementation.
39 */
40
41namespace
42{
43constexpr double C = 299792458.0; ///< speed of light in vacuum, in m/s
44} // namespace
45
46namespace ns3
47{
48NS_LOG_COMPONENT_DEFINE("CircularApertureAntennaModel");
49
50NS_OBJECT_ENSURE_REGISTERED(CircularApertureAntennaModel);
51
52TypeId
54{
55 static TypeId tid =
56 TypeId("ns3::CircularApertureAntennaModel")
58 .SetGroupName("Antenna")
59 .AddConstructor<CircularApertureAntennaModel>()
60 .AddAttribute("AntennaCircularApertureRadius",
61 "The radius of the aperture of the antenna, in meters",
62 DoubleValue(0.5),
64 MakeDoubleChecker<double>(0.0))
65 .AddAttribute("OperatingFrequency",
66 "The operating frequency in Hz of the antenna",
67 DoubleValue(2e9),
69 MakeDoubleChecker<double>(0.0))
70 .AddAttribute("AntennaMinGainDb",
71 "The minimum gain value in dB of the antenna",
72 DoubleValue(-100.0),
74 MakeDoubleChecker<double>())
75 .AddAttribute("AntennaMaxGainDb",
76 "The maximum gain value in dB of the antenna",
77 DoubleValue(1),
79 MakeDoubleChecker<double>(0.0));
80 return tid;
81}
82
83void
85{
86 NS_LOG_FUNCTION(this << aMeter);
87 NS_ASSERT_MSG(aMeter > 0, "Setting invalid aperture radius: " << aMeter);
88 m_apertureRadiusMeter = aMeter;
89}
90
91double
93{
95}
96
97void
99{
100 NS_LOG_FUNCTION(this << freqHz);
101 NS_ASSERT_MSG(freqHz > 0, "Setting invalid operating frequency: " << freqHz);
102 m_operatingFrequencyHz = freqHz;
103}
104
105double
107{
109}
110
111void
113{
114 NS_LOG_FUNCTION(this << gainDb);
115 m_maxGain = gainDb;
116}
117
118double
120{
121 return m_maxGain;
122}
123
124void
126{
127 NS_LOG_FUNCTION(this << gainDb);
128 m_minGain = gainDb;
129}
130
131double
133{
134 return m_minGain;
135}
136
137double
139{
140 NS_LOG_FUNCTION(this << a);
141
142 // In 3GPP TR 38.811 v15.4.0, Section 6.4.1, the gain depends on a single angle only.
143 // We assume that this angle represents the angle between the vectors corresponding
144 // to the cartesian coordinates of the provided spherical coordinates, and the spherical
145 // coordinates (r = 1, azimuth = 0, elevation = PI/2)
146 double theta1 = a.GetInclination();
147 double theta2 = M_PI_2; // reference direction
148
149 // Convert to ISO range: the input azimuth angle phi is in [-pi,pi],
150 // while the ISO convention for spherical to cartesian coordinates
151 // assumes phi in [0,2*pi].
152 double phi1 = M_PI + a.GetAzimuth();
153 double phi2 = M_PI; // reference direction
154
155 // Convert the spherical coordinates of the boresight and the incoming ray
156 // to Cartesian coordinates
157 Vector p1(sin(theta1) * cos(phi1), sin(theta1) * sin(phi1), cos(theta1));
158 Vector p2(sin(theta2) * cos(phi2), sin(theta2) * sin(phi2), cos(theta2));
159
160 // Calculate the angle between the antenna boresight and the incoming ray
161 double theta = acos(p1 * p2);
162
163 double gain = 0;
164 if (theta == 0)
165 {
166 gain = m_maxGain;
167 }
168 // return value of std::arccos is in [0, PI] deg
169 else if (theta >= M_PI_2)
170 {
171 // This is an approximation. 3GPP TR 38.811 does not provide indications
172 // on the antenna field pattern outside its PI degrees FOV.
173 gain = m_minGain;
174 }
175 else // 0 < theta < |PI/2|
176 {
177 // 3GPP TR 38.811 v15.4.0, Section 6.4.1
178 double k = (2 * M_PI * m_operatingFrequencyHz) / C;
179 double kasintheta = k * m_apertureRadiusMeter * sin(theta);
180// If needed, fall back to Boost cyl_bessel_j
181#ifdef NEED_AND_HAVE_BOOST_BESSEL_FUNC
182 gain = boost::math::cyl_bessel_j(1, kasintheta) / kasintheta;
183// Otherwise, use the std implementation
184#else
185 gain = std::cyl_bessel_j(1, kasintheta) / kasintheta;
186#endif
187 gain = 10 * log10(4 * gain * gain) + m_maxGain;
188 }
189
190 return gain;
191}
192
193} // namespace ns3
Class CircularApertureAntennaModel declaration.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:247
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:241
interface for antenna radiation pattern models
Definition: antenna-model.h:55
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
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:42
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#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:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:46
log2() macro definition; to deal with Bug 1467.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43