A Discrete-Event Network Simulator
API
phased-array-model.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 "phased-array-model.h"
19 
20 #include <ns3/boolean.h>
21 #include <ns3/double.h>
22 #include <ns3/isotropic-antenna-model.h>
23 #include <ns3/log.h>
24 #include <ns3/pointer.h>
25 #include <ns3/uinteger.h>
26 
27 namespace ns3
28 {
29 
31 
32 NS_LOG_COMPONENT_DEFINE("PhasedArrayModel");
33 
34 NS_OBJECT_ENSURE_REGISTERED(PhasedArrayModel);
35 
36 std::ostream&
37 operator<<(std::ostream& os, const PhasedArrayModel::ComplexVector& cv)
38 {
39  size_t N = cv.GetSize();
40 
41  // empty
42  if (N == 0)
43  {
44  os << "[]";
45  return os;
46  }
47 
48  // non-empty
49  os << "[";
50  for (std::size_t i = 0; i < N - 1; ++i)
51  {
52  os << cv[i] << ", ";
53  }
54  os << cv[N - 1] << "]";
55  return os;
56 }
57 
59  : m_isBfVectorValid{false}
60 {
61  m_id = m_idCounter++;
62 }
63 
65 {
66 }
67 
68 TypeId
70 {
71  static TypeId tid =
72  TypeId("ns3::PhasedArrayModel")
73  .SetParent<Object>()
74  .SetGroupName("Antenna")
75  .AddAttribute("AntennaElement",
76  "A pointer to the antenna element used by the phased array",
77  PointerValue(CreateObject<IsotropicAntennaModel>()),
79  MakePointerChecker<AntennaModel>());
80  return tid;
81 }
82 
83 void
85 {
86  NS_LOG_FUNCTION(this << beamformingVector);
87  NS_ASSERT_MSG(beamformingVector.GetSize() == GetNumberOfElements(),
88  beamformingVector.GetSize() << " != " << GetNumberOfElements());
89  m_beamformingVector = beamformingVector;
90  m_isBfVectorValid = true;
91 }
92 
95 {
96  NS_LOG_FUNCTION(this);
98  "The beamforming vector should be Set before it's Get, and should refer to the "
99  "current array configuration");
100  return m_beamformingVector;
101 }
102 
105 {
106  NS_LOG_FUNCTION(this << a);
107 
108  ComplexVector beamformingVector = GetSteeringVector(a);
109  double normRes = norm(beamformingVector);
110 
111  for (size_t i = 0; i < GetNumberOfElements(); i++)
112  {
113  beamformingVector[i] = std::conj(beamformingVector[i]) / normRes;
114  }
115 
116  return beamformingVector;
117 }
118 
121 {
122  ComplexVector steeringVector(GetNumberOfElements());
123  for (size_t i = 0; i < GetNumberOfElements(); i++)
124  {
125  Vector loc = GetElementLocation(i);
126  double phase = -2 * M_PI *
127  (sin(a.GetInclination()) * cos(a.GetAzimuth()) * loc.x +
128  sin(a.GetInclination()) * sin(a.GetAzimuth()) * loc.y +
129  cos(a.GetInclination()) * loc.z);
130  steeringVector[i] = std::polar<double>(1.0, phase);
131  }
132  return steeringVector;
133 }
134 
135 void
137 {
138  NS_LOG_FUNCTION(this);
139  m_antennaElement = antennaElement;
140 }
141 
144 {
145  NS_LOG_FUNCTION(this);
146  return m_antennaElement;
147 }
148 
149 uint32_t
151 {
152  return m_id;
153 }
154 
155 } /* 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
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable...
Definition: matrix-array.h:83
A base class which provides memory management and object aggregation.
Definition: object.h:89
static uint32_t m_idCounter
the ID counter that is used to determine the unique antenna array ID
ComplexVector GetSteeringVector(Angles a) const
Returns the steering vector that points toward the specified position.
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.
PhasedArrayModel()
Constructor.
Ptr< AntennaModel > m_antennaElement
the model of the antenna element in use
Ptr< const AntennaModel > GetAntennaElement() const
Returns a pointer to the AntennaModel instance used to model the elements of the array.
void SetAntennaElement(Ptr< AntennaModel > antennaElement)
Sets the antenna model to be used.
ComplexVector GetBeamformingVector() const
Returns the beamforming vector that is currently being used.
bool m_isBfVectorValid
ensures the validity of the beamforming vector
double norm(const ComplexVector &complexVector) const
Computes the Frobenius norm of the complex vector.
~PhasedArrayModel() override
Destructor.
uint32_t m_id
the ID of this antenna array instance
virtual size_t GetNumberOfElements() const =0
Returns the number of antenna elements.
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
ComplexVector m_beamformingVector
the beamforming vector in use
static TypeId GetTypeId()
Get the type ID.
Hold objects of type Ptr<T>.
Definition: pointer.h:37
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
size_t GetSize() const
Definition: val-array.h:403
#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:86
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:231
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129