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"
28
29
30namespace ns3 {
31
32NS_LOG_COMPONENT_DEFINE ("CosineAntennaModel");
33
34NS_OBJECT_ENSURE_REGISTERED (CosineAntennaModel);
35
36
37TypeId
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
72double
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
96double
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
109void
110CosineAntennaModel::SetVerticalBeamwidth (double verticalBeamwidthDegrees)
111{
112 NS_LOG_FUNCTION (this << verticalBeamwidthDegrees);
113 m_verticalExponent = GetExponentFromBeamwidth (verticalBeamwidthDegrees);
114}
115
116
117void
118CosineAntennaModel::SetHorizontalBeamwidth (double horizontalBeamwidthDegrees)
119{
120 NS_LOG_FUNCTION (this << horizontalBeamwidthDegrees);
121 m_horizontalExponent = GetExponentFromBeamwidth (horizontalBeamwidthDegrees);
122}
123
124
125double
127{
129}
130
131
132double
134{
136}
137
138
139void
140CosineAntennaModel::SetOrientation (double orientationDegrees)
141{
142 NS_LOG_FUNCTION (this << orientationDegrees);
143 m_orientationRadians = DegreesToRadians (orientationDegrees);
144}
145
146
147double
149{
151}
152
153
154double
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}
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:119
double GetInclination(void) const
Getter for inclination angle.
Definition: angles.cc:231
double GetAzimuth(void) const
Getter for azimuth angle.
Definition: angles.cc:224
void SetAzimuth(double azimuth)
Setter for azimuth angle.
Definition: angles.cc:208
interface for antenna radiation pattern models
Definition: antenna-model.h:56
Cosine Antenna Model.
double m_maxGain
antenna gain in dB towards the main orientation
void SetHorizontalBeamwidth(double horizontalBeamwidthDegrees)
Set the horizontal 3 dB beamwidth (bilateral) of the cosine antenna model.
double GetOrientation(void) const
Get the horizontal orientation of the antenna element.
virtual double GetGainDb(Angles a)
this method is expected to be re-implemented by each antenna model
static double GetBeamwidthFromExponent(double exponent)
Compute the beamwidth of the cosine antenna model from the exponent.
static double GetExponentFromBeamwidth(double beamwidthDegrees)
Compute the exponent of the cosine antenna model from the beamwidth.
static TypeId GetTypeId()
Get the type ID.
double GetVerticalBeamwidth(void) const
Get the vertical 3 dB beamwidth of the cosine antenna model.
double GetHorizontalBeamwidth(void) const
Get the horizontal 3 dB beamwidth of the cosine antenna model.
double m_verticalExponent
exponent of the vertical direction
void SetVerticalBeamwidth(double verticalBeamwidthDegrees)
Set the vertical 3 dB beamwidth (bilateral) of the cosine antenna model.
void SetOrientation(double orientationDegrees)
Set the horizontal orientation of the antenna element.
double m_orientationRadians
orientation in radians in the horizontal direction (bearing)
double m_horizontalExponent
exponent of the horizontal direction
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:42
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:40
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:47