A Discrete-Event Network Simulator
API
cosine-antenna-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
22 #include <ns3/log.h>
23 #include <ns3/double.h>
24 #include <cmath>
25 
26 #include "antenna-model.h"
27 #include "cosine-antenna-model.h"
28 
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("CosineAntennaModel");
33 
34 NS_OBJECT_ENSURE_REGISTERED (CosineAntennaModel);
35 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::CosineAntennaModel")
42  .SetGroupName ("Antenna")
43  .AddConstructor<CosineAntennaModel> ()
44  .AddAttribute ("VerticalBeamwidth",
45  "The 3 dB vertical beamwidth (degrees). A beamwidth of 360 deg corresponds to constant gain",
46  DoubleValue (360),
49  MakeDoubleChecker<double> (0, 360))
50  .AddAttribute ("HorizontalBeamwidth",
51  "The 3 dB horizontal beamwidth (degrees). A beamwidth of 360 deg corresponds to constant gain",
52  DoubleValue (120),
55  MakeDoubleChecker<double> (0, 360))
56  .AddAttribute ("Orientation",
57  "The angle (degrees) that expresses the orientation of the antenna on the x-y plane relative to the x axis",
58  DoubleValue (0.0),
61  MakeDoubleChecker<double> (-360, 360))
62  .AddAttribute ("MaxGain",
63  "The gain (dB) at the antenna boresight (the direction of maximum gain)",
64  DoubleValue (0.0),
66  MakeDoubleChecker<double> ())
67  ;
68  return tid;
69 }
70 
71 
72 double
74 {
75  NS_LOG_FUNCTION (beamwidthDegrees);
76 
77  // The formula in obtained by inverting the power pattern P(alpha) in a single direction,
78  // while imposing that P(alpha0/2) = 0.5 = -3 dB, with respect to the exponent
79  // See CosineAntennaModel::GetGainDb for more information.
80  //
81  // The undetermined case of alpha0=360 is treated separately.
82  double exponent;
83  if (beamwidthDegrees == 360.0)
84  {
85  exponent = 0.0;
86  }
87  else
88  {
89  exponent = -3.0 / (20 * std::log10 (std::cos (DegreesToRadians (beamwidthDegrees / 4.0))));
90  }
91 
92  return exponent;
93 }
94 
95 
96 double
98 {
99  NS_LOG_FUNCTION (exponent);
100 
101  // The formula in obtained by inverting the power pattern P(alpha) in a single direction,
102  // while imposing that P(alpha0/2) = 0.5 = -3 dB, with respect to the beamwidth.
103  // See CosineAntennaModel::GetGainDb for more information.
104  double beamwidthRadians = 4 * std::acos (std::pow (0.5, 1 / (2 * exponent)));
105  return RadiansToDegrees (beamwidthRadians);
106 }
107 
108 
109 void
110 CosineAntennaModel::SetVerticalBeamwidth (double verticalBeamwidthDegrees)
111 {
112  NS_LOG_FUNCTION (this << verticalBeamwidthDegrees);
113  m_verticalExponent = GetExponentFromBeamwidth (verticalBeamwidthDegrees);
114 }
115 
116 
117 void
118 CosineAntennaModel::SetHorizontalBeamwidth (double horizontalBeamwidthDegrees)
119 {
120  NS_LOG_FUNCTION (this << horizontalBeamwidthDegrees);
121  m_horizontalExponent = GetExponentFromBeamwidth (horizontalBeamwidthDegrees);
122 }
123 
124 
125 double
127 {
129 }
130 
131 
132 double
134 {
136 }
137 
138 
139 void
140 CosineAntennaModel::SetOrientation (double orientationDegrees)
141 {
142  NS_LOG_FUNCTION (this << orientationDegrees);
143  m_orientationRadians = DegreesToRadians (orientationDegrees);
144 }
145 
146 
147 double
149 {
151 }
152 
153 
154 double
156 {
157  NS_LOG_FUNCTION (this << a);
158 
159  // make sure phi is in (-pi, pi]
161 
162  NS_LOG_LOGIC (a);
163 
164  // The element power gain is computed as a product of cosine functions on the two axis
165  // The power pattern of the element is equal to:
166  // P(az,el) = cos(az/2)^2m * cos(pi/2 - incl/2)^2n,
167  // where az is the azimuth angle, and incl is the inclination angle.
168  double gain = (std::pow (std::cos (a.GetAzimuth () / 2), 2 * m_horizontalExponent)) *
169  (std::pow (std::cos ((M_PI / 2 - a.GetInclination ()) / 2), 2 * m_verticalExponent));
170  double gainDb = 10 * std::log10 (gain);
171 
172  NS_LOG_LOGIC ("gain = " << gainDb << " + " << m_maxGain << " dB");
173  return gainDb + m_maxGain;
174 }
175 
176 
177 }
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::Angles::GetInclination
double GetInclination(void) const
Getter for inclination angle.
Definition: angles.cc:229
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cosine-antenna-model.h
ns3::CosineAntennaModel::m_orientationRadians
double m_orientationRadians
orientation in radians in the horizontal direction (bearing)
Definition: cosine-antenna-model.h:112
ns3::CosineAntennaModel::GetBeamwidthFromExponent
static double GetBeamwidthFromExponent(double exponent)
Compute the beamwidth of the cosine antenna model from the exponent.
Definition: cosine-antenna-model.cc:97
ns3::CosineAntennaModel
Cosine Antenna Model.
Definition: cosine-antenna-model.h:50
antenna-model.h
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::CosineAntennaModel::GetGainDb
virtual double GetGainDb(Angles a)
this method is expected to be re-implemented by each antenna model
Definition: cosine-antenna-model.cc:155
ns3::CosineAntennaModel::m_verticalExponent
double m_verticalExponent
exponent of the vertical direction
Definition: cosine-antenna-model.h:110
ns3::CosineAntennaModel::GetVerticalBeamwidth
double GetVerticalBeamwidth(void) const
Get the vertical 3 dB beamwidth of the cosine antenna model.
Definition: cosine-antenna-model.cc:126
ns3::CosineAntennaModel::SetHorizontalBeamwidth
void SetHorizontalBeamwidth(double horizontalBeamwidthDegrees)
Set the horizontal 3 dB beamwidth (bilateral) of the cosine antenna model.
Definition: cosine-antenna-model.cc:118
ns3::AntennaModel
interface for antenna radiation pattern models
Definition: antenna-model.h:45
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::RadiansToDegrees
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45
ns3::MakeDoubleAccessor
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:42
ns3::CosineAntennaModel::SetVerticalBeamwidth
void SetVerticalBeamwidth(double verticalBeamwidthDegrees)
Set the vertical 3 dB beamwidth (bilateral) of the cosine antenna model.
Definition: cosine-antenna-model.cc:110
ns3::Angles
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:119
ns3::Angles::SetAzimuth
void SetAzimuth(double azimuth)
Setter for azimuth angle.
Definition: angles.cc:206
ns3::CosineAntennaModel::GetExponentFromBeamwidth
static double GetExponentFromBeamwidth(double beamwidthDegrees)
Compute the exponent of the cosine antenna model from the beamwidth.
Definition: cosine-antenna-model.cc:73
ns3::Angles::GetAzimuth
double GetAzimuth(void) const
Getter for azimuth angle.
Definition: angles.cc:222
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::CosineAntennaModel::m_horizontalExponent
double m_horizontalExponent
exponent of the horizontal direction
Definition: cosine-antenna-model.h:111
ns3::CosineAntennaModel::GetTypeId
static TypeId GetTypeId()
Definition: cosine-antenna-model.cc:38
ns3::CosineAntennaModel::GetHorizontalBeamwidth
double GetHorizontalBeamwidth(void) const
Get the horizontal 3 dB beamwidth of the cosine antenna model.
Definition: cosine-antenna-model.cc:133
ns3::CosineAntennaModel::m_maxGain
double m_maxGain
antenna gain in dB towards the main orientation
Definition: cosine-antenna-model.h:113
ns3::CosineAntennaModel::SetOrientation
void SetOrientation(double orientationDegrees)
Set the horizontal orientation of the antenna element.
Definition: cosine-antenna-model.cc:140
ns3::CosineAntennaModel::GetOrientation
double GetOrientation(void) const
Get the horizontal orientation of the antenna element.
Definition: cosine-antenna-model.cc:148
ns3::DegreesToRadians
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:38