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 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("PhasedArrayModel");
30 
31 NS_OBJECT_ENSURE_REGISTERED (PhasedArrayModel);
32 
33 std::ostream&
34 operator<< (std::ostream& os, const PhasedArrayModel::ComplexVector& cv)
35 {
36  size_t N = cv.size ();
37 
38  // empty
39  if (N == 0)
40  {
41  os << "[]";
42  return os;
43  }
44 
45  // non-empty
46  os << "[";
47  for (std::size_t i = 0; i < N - 1; ++i)
48  {
49  os << cv[i] << ", ";
50  }
51  os << cv[N - 1] << "]";
52  return os;
53 }
54 
56  : m_isBfVectorValid {false}
57 {}
58 
59 
61 {
62  m_beamformingVector.clear ();
63 }
64 
65 
66 TypeId
68 {
69  static TypeId tid = TypeId ("ns3::PhasedArrayModel")
70  .SetParent<Object> ()
71  .SetGroupName ("Antenna")
72  .AddAttribute ("AntennaElement",
73  "A pointer to the antenna element used by the phased array",
74  PointerValue (CreateObject<IsotropicAntennaModel> ()),
76  MakePointerChecker<AntennaModel> ())
77  ;
78  return tid;
79 }
80 
81 
82 void
84 {
85  NS_LOG_FUNCTION (this << beamformingVector);
86  NS_ASSERT_MSG (beamformingVector.size () == GetNumberOfElements (),
87  beamformingVector.size () << " != " << GetNumberOfElements ());
88  m_beamformingVector = beamformingVector;
89  m_isBfVectorValid = true;
90 }
91 
92 
95 {
96  NS_LOG_FUNCTION (this);
97  NS_ASSERT_MSG (m_isBfVectorValid, "The beamforming vector should be Set before it's Get, and should refer to the current array configuration");
98  return m_beamformingVector;
99 }
100 
101 
102 double
104 {
105  double norm = 0;
106 
107  for (uint64_t i = 0; i < vector.size (); i++)
108  {
109  norm += std::norm (vector[i]);
110  }
111 
112  return std::sqrt (norm);
113 
114 }
115 
116 
119 {
120  NS_LOG_FUNCTION (this << a);
121 
122  ComplexVector beamformingVector = GetSteeringVector (a);
123  double norm = ComputeNorm (beamformingVector);
124 
125  for (uint64_t i = 0; i < beamformingVector.size (); i++)
126  {
127  beamformingVector[i] = std::conj (beamformingVector[i]) / norm;
128  }
129 
130  return beamformingVector;
131 }
132 
133 
134 
137 {
138  ComplexVector steeringVector;
139  steeringVector.resize (GetNumberOfElements ());
140  for (uint64_t i = 0; i < GetNumberOfElements (); i++)
141  {
142  Vector loc = GetElementLocation (i);
143  double phase = -2 * M_PI * (sin (a.GetInclination ()) * cos (a.GetAzimuth ()) * loc.x +
144  sin (a.GetInclination ()) * sin (a.GetAzimuth ()) * loc.y +
145  cos (a.GetInclination ()) * loc.z);
146  steeringVector[i] = std::polar<double> (1.0, phase);
147  }
148  return steeringVector;
149 }
150 
151 
152 void
154 {
155  NS_LOG_FUNCTION (this);
156  m_antennaElement = antennaElement;
157 }
158 
159 
162 {
163  NS_LOG_FUNCTION (this);
164  return m_antennaElement;
165 }
166 
167 
168 } /* namespace ns3 */
169 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetAntennaElement(Ptr< AntennaModel > antennaElement)
Sets the antenna model to be used.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static TypeId GetTypeId(void)
bool m_isBfVectorValid
ensures the validity of the beamforming vector
ComplexVector m_beamformingVector
the beamforming vector in use
virtual uint64_t GetNumberOfElements(void) const =0
Returns the number of antenna elements.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Ptr< AntennaModel > m_antennaElement
the model of the antenna element in use
ComplexVector GetBeamformingVector(void) const
Returns the beamforming vector that is currently being used.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ComplexVector GetSteeringVector(Angles a) const
Returns the steering vector that points toward the specified position.
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:227
double GetAzimuth(void) const
Getter for azimuth angle.
Definition: angles.cc:222
virtual Vector GetElementLocation(uint64_t index) const =0
Returns the location of the antenna element with the specified index, normalized with respect to the ...
virtual ~PhasedArrayModel(void)
Destructor.
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
#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
PhasedArrayModel(void)
Constructor.
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
const double norm
Normalization to obtain randoms on [0,1).
Definition: rng-stream.cc:64
double GetInclination(void) const
Getter for inclination angle.
Definition: angles.cc:229
Ptr< const AntennaModel > GetAntennaElement(void) const
Returns a pointer to the AntennaModel instance used to model the elements of the array.
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
static double ComputeNorm(const ComplexVector &vector)
Utility method to compute the euclidean norm of a ComplexVector.