A Discrete-Event Network Simulator
API
phased-array-model.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3* Copyright (c) 2020 University of Padova, Dep. of Information Engineering, SIGNET lab.
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
19#include "phased-array-model.h"
20#include <ns3/isotropic-antenna-model.h>
21#include <ns3/log.h>
22#include <ns3/double.h>
23#include <ns3/uinteger.h>
24#include <ns3/boolean.h>
25#include <ns3/pointer.h>
26
27namespace ns3 {
28
30
31NS_LOG_COMPONENT_DEFINE ("PhasedArrayModel");
32
33NS_OBJECT_ENSURE_REGISTERED (PhasedArrayModel);
34
35std::ostream&
36operator<< (std::ostream& os, const PhasedArrayModel::ComplexVector& cv)
37{
38 size_t N = cv.size ();
39
40 // empty
41 if (N == 0)
42 {
43 os << "[]";
44 return os;
45 }
46
47 // non-empty
48 os << "[";
49 for (std::size_t i = 0; i < N - 1; ++i)
50 {
51 os << cv[i] << ", ";
52 }
53 os << cv[N - 1] << "]";
54 return os;
55}
56
58 : m_isBfVectorValid {false}
59{
60 m_id = m_idCounter++;
61}
62
63
65{
66 m_beamformingVector.clear ();
67}
68
69
72{
73 static TypeId tid = TypeId ("ns3::PhasedArrayModel")
74 .SetParent<Object> ()
75 .SetGroupName ("Antenna")
76 .AddAttribute ("AntennaElement",
77 "A pointer to the antenna element used by the phased array",
78 PointerValue (CreateObject<IsotropicAntennaModel> ()),
80 MakePointerChecker<AntennaModel> ())
81 ;
82 return tid;
83}
84
85
86void
88{
89 NS_LOG_FUNCTION (this << beamformingVector);
90 NS_ASSERT_MSG (beamformingVector.size () == GetNumberOfElements (),
91 beamformingVector.size () << " != " << GetNumberOfElements ());
92 m_beamformingVector = beamformingVector;
93 m_isBfVectorValid = true;
94}
95
96
99{
100 NS_LOG_FUNCTION (this);
101 NS_ASSERT_MSG (m_isBfVectorValid, "The beamforming vector should be Set before it's Get, and should refer to the current array configuration");
102 return m_beamformingVector;
103}
104
105
106double
108{
109 double norm = 0;
110
111 for (uint64_t i = 0; i < vector.size (); i++)
112 {
113 norm += std::norm (vector[i]);
114 }
115
116 return std::sqrt (norm);
117
118}
119
120
123{
124 NS_LOG_FUNCTION (this << a);
125
126 ComplexVector beamformingVector = GetSteeringVector (a);
127 double norm = ComputeNorm (beamformingVector);
128
129 for (uint64_t i = 0; i < beamformingVector.size (); i++)
130 {
131 beamformingVector[i] = std::conj (beamformingVector[i]) / norm;
132 }
133
134 return beamformingVector;
135}
136
137
138
141{
142 ComplexVector steeringVector;
143 steeringVector.resize (GetNumberOfElements ());
144 for (uint64_t i = 0; i < GetNumberOfElements (); i++)
145 {
146 Vector loc = GetElementLocation (i);
147 double phase = -2 * M_PI * (sin (a.GetInclination ()) * cos (a.GetAzimuth ()) * loc.x +
148 sin (a.GetInclination ()) * sin (a.GetAzimuth ()) * loc.y +
149 cos (a.GetInclination ()) * loc.z);
150 steeringVector[i] = std::polar<double> (1.0, phase);
151 }
152 return steeringVector;
153}
154
155
156void
158{
159 NS_LOG_FUNCTION (this);
160 m_antennaElement = antennaElement;
161}
162
163
166{
167 NS_LOG_FUNCTION (this);
168 return m_antennaElement;
169}
170
173{
174 return m_id;
175}
176
177} /* namespace ns3 */
178
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
A base class which provides memory management and object aggregation.
Definition: object.h:88
static uint32_t m_idCounter
the ID counter that is used to determine the unique antenna array ID
Ptr< const AntennaModel > GetAntennaElement(void) const
Returns a pointer to the AntennaModel instance used to model the elements of the array.
ComplexVector GetSteeringVector(Angles a) const
Returns the steering vector that points toward the specified position.
PhasedArrayModel(void)
Constructor.
virtual ~PhasedArrayModel(void)
Destructor.
virtual Vector GetElementLocation(uint64_t index) const =0
Returns the location of the antenna element with the specified index, normalized with respect to the ...
uint32_t GetId() const
Returns the ID of this antenna array instance.
ComplexVector GetBeamformingVector(void) const
Returns the beamforming vector that is currently being used.
Ptr< AntennaModel > m_antennaElement
the model of the antenna element in use
void SetAntennaElement(Ptr< AntennaModel > antennaElement)
Sets the antenna model to be used.
virtual uint64_t GetNumberOfElements(void) const =0
Returns the number of antenna elements.
bool m_isBfVectorValid
ensures the validity of the beamforming vector
static double ComputeNorm(const ComplexVector &vector)
Utility method to compute the euclidean norm of a ComplexVector.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_id
the ID of this antenna array instance
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
ComplexVector m_beamformingVector
the beamforming vector in use
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
Hold objects of type Ptr<T>.
Definition: pointer.h:37
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#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:88
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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
const double norm
Normalization to obtain randoms on [0,1).
Definition: rng-stream.cc:64
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139