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/double.h>
20#include <ns3/log.h>
21
22#include <math.h>
23
24/**
25 * \file
26 * \ingroup antenna
27 * Class CircularApertureAntennaModel implementation.
28 */
29
30namespace
31{
32constexpr double C = 299792458.0; ///< speed of light in vacuum, in m/s
33} // namespace
34
35namespace ns3
36{
37NS_LOG_COMPONENT_DEFINE("CircularApertureAntennaModel");
38
39NS_OBJECT_ENSURE_REGISTERED(CircularApertureAntennaModel);
40
41TypeId
43{
44 static TypeId tid =
45 TypeId("ns3::CircularApertureAntennaModel")
47 .SetGroupName("Antenna")
48 .AddConstructor<CircularApertureAntennaModel>()
49 .AddAttribute("AntennaCircularApertureRadius",
50 "The radius of the aperture of the antenna, in meters",
51 DoubleValue(0.5),
54 .AddAttribute("OperatingFrequency",
55 "The operating frequency in Hz of the antenna",
56 DoubleValue(2e9),
59 .AddAttribute("AntennaMinGainDb",
60 "The minimum gain value in dB of the antenna",
61 DoubleValue(-100.0),
64 .AddAttribute("AntennaMaxGainDb",
65 "The maximum gain value in dB of the antenna",
66 DoubleValue(1),
69 return tid;
70}
71
72void
74{
75 NS_LOG_FUNCTION(this << aMeter);
76 NS_ASSERT_MSG(aMeter > 0, "Setting invalid aperture radius: " << aMeter);
77 m_apertureRadiusMeter = aMeter;
78}
79
80double
85
86void
88{
89 NS_LOG_FUNCTION(this << freqHz);
90 NS_ASSERT_MSG(freqHz > 0, "Setting invalid operating frequency: " << freqHz);
92}
93
94double
99
100void
102{
103 NS_LOG_FUNCTION(this << gainDb);
104 m_maxGain = gainDb;
105}
106
107double
112
113void
115{
116 NS_LOG_FUNCTION(this << gainDb);
117 m_minGain = gainDb;
118}
119
120double
125
126double
128{
129 NS_LOG_FUNCTION(this << a);
130
131 // In 3GPP TR 38.811 v15.4.0, Section 6.4.1, the gain depends on a single angle only.
132 // We assume that this angle represents the angle between the vectors corresponding
133 // to the cartesian coordinates of the provided spherical coordinates, and the spherical
134 // coordinates (r = 1, azimuth = 0, elevation = PI/2)
135 double theta1 = a.GetInclination();
136 double theta2 = M_PI_2; // reference direction
137
138 // Convert to ISO range: the input azimuth angle phi is in [-pi,pi],
139 // while the ISO convention for spherical to cartesian coordinates
140 // assumes phi in [0,2*pi].
141 double phi1 = M_PI + a.GetAzimuth();
142 double phi2 = M_PI; // reference direction
143
144 // Convert the spherical coordinates of the boresight and the incoming ray
145 // to Cartesian coordinates
146 Vector p1(sin(theta1) * cos(phi1), sin(theta1) * sin(phi1), cos(theta1));
147 Vector p2(sin(theta2) * cos(phi2), sin(theta2) * sin(phi2), cos(theta2));
148
149 // Calculate the angle between the antenna boresight and the incoming ray
150 double theta = acos(p1 * p2);
151
152 double gain = 0;
153 if (theta == 0)
154 {
155 gain = m_maxGain;
156 }
157 // return value of std::arccos is in [0, PI] deg
158 else if (theta >= M_PI_2)
159 {
160 // This is an approximation. 3GPP TR 38.811 does not provide indications
161 // on the antenna field pattern outside its PI degrees FOV.
162 gain = m_minGain;
163 }
164 else // 0 < theta < |PI/2|
165 {
166 // 3GPP TR 38.811 v15.4.0, Section 6.4.1
167 double k = (2 * M_PI * m_operatingFrequencyHz) / C;
168 double kasintheta = k * m_apertureRadiusMeter * sin(theta);
169// If needed, fall back to Boost cyl_bessel_j
170#ifdef NEED_AND_HAVE_BOOST_BESSEL_FUNC
171 gain = boost::math::cyl_bessel_j(1, kasintheta) / kasintheta;
172// Otherwise, use the std implementation
173#else
174 gain = std::cyl_bessel_j(1, kasintheta) / kasintheta;
175#endif
176 gain = 10 * log10(4 * gain * gain) + m_maxGain;
177 }
178
179 return gain;
180}
181
182} // 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
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: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
#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.
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32