A Discrete-Event Network Simulator
API
uniform-planar-array.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 "uniform-planar-array.h"
19 
20 #include <ns3/boolean.h>
21 #include <ns3/double.h>
22 #include <ns3/log.h>
23 #include <ns3/uinteger.h>
24 
25 namespace ns3
26 {
27 
28 NS_LOG_COMPONENT_DEFINE("UniformPlanarArray");
29 
30 NS_OBJECT_ENSURE_REGISTERED(UniformPlanarArray);
31 
34 {
35 }
36 
38 {
39 }
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::UniformPlanarArray")
47  .AddConstructor<UniformPlanarArray>()
48  .SetGroupName("Antenna")
49  .AddAttribute(
50  "AntennaHorizontalSpacing",
51  "Horizontal spacing between antenna elements, in multiples of wave length",
52  DoubleValue(0.5),
55  MakeDoubleChecker<double>(0.0))
56  .AddAttribute("AntennaVerticalSpacing",
57  "Vertical spacing between antenna elements, in multiples of wave length",
58  DoubleValue(0.5),
61  MakeDoubleChecker<double>(0.0))
62  .AddAttribute("NumColumns",
63  "Horizontal size of the array",
64  UintegerValue(4),
67  MakeUintegerChecker<uint32_t>(1))
68  .AddAttribute("NumRows",
69  "Vertical size of the array",
70  UintegerValue(4),
73  MakeUintegerChecker<uint32_t>(1))
74  .AddAttribute("BearingAngle",
75  "The bearing angle in radians",
76  DoubleValue(0.0),
78  MakeDoubleChecker<double>(-M_PI, M_PI))
79  .AddAttribute("DowntiltAngle",
80  "The downtilt angle in radians",
81  DoubleValue(0.0),
83  MakeDoubleChecker<double>(-M_PI, M_PI))
84  .AddAttribute("PolSlantAngle",
85  "The polarization slant angle in radians",
86  DoubleValue(0.0),
88  MakeDoubleChecker<double>(-M_PI, M_PI));
89  return tid;
90 }
91 
92 void
94 {
95  NS_LOG_FUNCTION(this << n);
96  if (n != m_numColumns)
97  {
98  m_isBfVectorValid = false;
99  }
100  m_numColumns = n;
101 }
102 
103 uint32_t
105 {
106  return m_numColumns;
107 }
108 
109 void
111 {
112  NS_LOG_FUNCTION(this << n);
113  if (n != m_numRows)
114  {
115  m_isBfVectorValid = false;
116  }
117  m_numRows = n;
118 }
119 
120 uint32_t
122 {
123  return m_numRows;
124 }
125 
126 void
128 {
129  m_alpha = alpha;
130  m_cosAlpha = cos(m_alpha);
131  m_sinAlpha = sin(m_alpha);
132 }
133 
134 void
136 {
137  m_beta = beta;
138  m_cosBeta = cos(m_beta);
139  m_sinBeta = sin(m_beta);
140 }
141 
142 void
144 {
145  m_polSlant = polSlant;
146  m_cosPolSlant = cos(m_polSlant);
147  m_sinPolSlant = sin(m_polSlant);
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION(this << s);
154  NS_ABORT_MSG_IF(s <= 0, "Trying to set an invalid spacing: " << s);
155 
156  if (s != m_disH)
157  {
158  m_isBfVectorValid = false;
159  }
160  m_disH = s;
161 }
162 
163 double
165 {
166  return m_disH;
167 }
168 
169 void
171 {
172  NS_LOG_FUNCTION(this << s);
173  NS_ABORT_MSG_IF(s <= 0, "Trying to set an invalid spacing: " << s);
174 
175  if (s != m_disV)
176  {
177  m_isBfVectorValid = false;
178  }
179  m_disV = s;
180 }
181 
182 double
184 {
185  return m_disV;
186 }
187 
188 std::pair<double, double>
190 {
191  NS_LOG_FUNCTION(this << a);
192 
193  // convert the theta and phi angles from GCS to LCS using eq. 7.1-7 and 7.1-8 in 3GPP TR 38.901
194  // NOTE we assume a fixed slant angle of 0 degrees
195  double cosIncl = cos(a.GetInclination());
196  double sinIncl = sin(a.GetInclination());
197  double cosAzim = cos(a.GetAzimuth() - m_alpha);
198  double sinAzim = sin(a.GetAzimuth() - m_alpha);
199  double thetaPrime = std::acos(m_cosBeta * cosIncl + m_sinBeta * cosAzim * sinIncl);
200  double phiPrime =
201  std::arg(std::complex<double>(m_cosBeta * sinIncl * cosAzim - m_sinBeta * cosIncl,
202  sinAzim * sinIncl));
203  Angles aPrime(phiPrime, thetaPrime);
204  NS_LOG_DEBUG(a << " -> " << aPrime);
205 
206  // compute the antenna element field patterns using eq. 7.3-4 and 7.3-5 in 3GPP TR 38.901,
207  // using the configured polarization slant angle (m_polSlant)
208  // NOTE: the slant angle (assumed to be 0) differs from the polarization slant angle
209  // (m_polSlant, given by the attribute), in 3GPP TR 38.901
210  double aPrimeDb = m_antennaElement->GetGainDb(aPrime);
211  double fieldThetaPrime = pow(10, aPrimeDb / 20) * m_cosPolSlant; // convert to linear magnitude
212  double fieldPhiPrime = pow(10, aPrimeDb / 20) * m_sinPolSlant; // convert to linear magnitude
213 
214  // compute psi using eq. 7.1-15 in 3GPP TR 38.901, assuming that the slant
215  // angle (gamma) is 0
216  double psi = std::arg(std::complex<double>(m_cosBeta * sinIncl - m_sinBeta * cosIncl * cosAzim,
217  m_sinBeta * sinAzim));
218  NS_LOG_DEBUG("psi " << psi);
219 
220  // convert the antenna element field pattern to GCS using eq. 7.1-11
221  // in 3GPP TR 38.901
222  double fieldTheta = cos(psi) * fieldThetaPrime - sin(psi) * fieldPhiPrime;
223  double fieldPhi = sin(psi) * fieldThetaPrime + cos(psi) * fieldPhiPrime;
225  << " " << RadiansToDegrees(a.GetInclination()) << " "
226  << fieldTheta * fieldTheta + fieldPhi * fieldPhi);
227 
228  return std::make_pair(fieldPhi, fieldTheta);
229 }
230 
231 Vector
233 {
234  NS_LOG_FUNCTION(this << index);
235 
236  // compute the element coordinates in the LCS
237  // assume the left bottom corner is (0,0,0), and the rectangular antenna array is on the y-z
238  // plane.
239  double xPrime = 0;
240  double yPrime = m_disH * (index % m_numColumns);
241  double zPrime = m_disV * floor(index / m_numColumns);
242 
243  // convert the coordinates to the GCS using the rotation matrix 7.1-4 in 3GPP
244  // TR 38.901
245  Vector loc;
246  loc.x = m_cosAlpha * m_cosBeta * xPrime - m_sinAlpha * yPrime + m_cosAlpha * m_sinBeta * zPrime;
247  loc.y = m_sinAlpha * m_cosBeta * xPrime + m_cosAlpha * yPrime + m_sinAlpha * m_sinBeta * zPrime;
248  loc.z = -m_sinBeta * xPrime + m_cosBeta * zPrime;
249  return loc;
250 }
251 
252 size_t
254 {
255  return m_numRows * m_numColumns;
256 }
257 
258 } /* namespace ns3 */
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:216
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:210
virtual double GetGainDb(Angles a)=0
this method is expected to be re-implemented by each antenna model
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Class implementing the phased array model virtual base class.
Ptr< AntennaModel > m_antennaElement
the model of the antenna element in use
bool m_isBfVectorValid
ensures the validity of the beamforming vector
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Hold an unsigned integer type.
Definition: uinteger.h:45
double m_cosPolSlant
the cosine of polarization slant angle
double m_disV
antenna spacing in the vertical direction in multiples of wave length
double m_sinAlpha
the sine of alpha
uint32_t GetNumRows() const
Get the number of rows of the phased array.
void SetPolSlant(double polSlant)
Set the polarization slant angle This method sets the polarization slant angle and computes its cosin...
size_t GetNumberOfElements() const override
Returns the number of antenna elements.
double m_disH
antenna spacing in the horizontal direction in multiples of wave length
void SetBeta(double beta)
Set the downtilt angle This method sets the downtilt angle and computes its cosine and sine.
double m_sinPolSlant
the sine polarization slant angle
uint32_t GetNumColumns() const
Get the number of columns of the phased array.
static TypeId GetTypeId()
Get the type ID.
void SetAlpha(double alpha)
Set the bearing angle This method sets the bearing angle and computes its cosine and sine.
double GetAntennaVerticalSpacing() const
Get the vertical spacing for the antenna elements of the phased array.
std::pair< double, double > GetElementFieldPattern(Angles a) const override
Returns the horizontal and vertical components of the antenna element field pattern at the specified ...
double m_polSlant
the polarization slant angle in radians
double m_cosBeta
the cosine of Beta
void SetAntennaVerticalSpacing(double s)
Set the vertical spacing for the antenna elements of the phased array This method resets the stored b...
double GetAntennaHorizontalSpacing() const
Get the horizontal spacing for the antenna elements of the phased array.
~UniformPlanarArray() override
Destructor.
void SetNumRows(uint32_t n)
Set the number of rows of the phased array This method resets the stored beamforming vector to a Comp...
uint32_t m_numRows
number of rows
Vector GetElementLocation(uint64_t index) const override
Returns the location of the antenna element with the specified index assuming the left bottom corner ...
uint32_t m_numColumns
number of columns
double m_alpha
the bearing angle in radians
void SetNumColumns(uint32_t n)
Set the number of columns of the phased array This method resets the stored beamforming vector to a C...
double m_sinBeta
the sine of Beta
void SetAntennaHorizontalSpacing(double s)
Set the horizontal spacing for the antenna elements of the phased array This method resets the stored...
double m_beta
the downtilt angle in radians
double m_cosAlpha
the cosine of alpha
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:43
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:46
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45