A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
10
11#include "ns3/boolean.h"
12#include "ns3/double.h"
13#include "ns3/log.h"
14#include "ns3/pointer.h"
15#include "ns3/uinteger.h"
16
17#include <algorithm>
18#include <cmath>
19
20namespace ns3
21{
22
25
26NS_LOG_COMPONENT_DEFINE("PhasedArrayModel");
27
29
37
41
44{
45 static TypeId tid =
46 TypeId("ns3::PhasedArrayModel")
48 .SetGroupName("Antenna")
49 .AddAttribute("AntennaElement",
50 "A pointer to the antenna element used by the phased array",
54 return tid;
55}
56
57std::pair<double, double>
59{
60 if (GetNumElems() == 0)
61 {
62 return {0.0, 0.0};
63 }
64 Vector minLoc = GetElementLocation(0);
65 Vector maxLoc = minLoc;
66 for (size_t i = 1; i < GetNumElems(); i++)
67 {
68 const Vector loc = GetElementLocation(i);
69 minLoc =
70 Vector(std::min(minLoc.x, loc.x), std::min(minLoc.y, loc.y), std::min(minLoc.z, loc.z));
71 maxLoc =
72 Vector(std::max(maxLoc.x, loc.x), std::max(maxLoc.y, loc.y), std::max(maxLoc.z, loc.z));
73 }
74 return {std::hypot(maxLoc.x - minLoc.x, maxLoc.y - minLoc.y), maxLoc.z - minLoc.z};
75}
76
77void
79{
80 NS_LOG_FUNCTION(this << beamformingVector);
81 NS_ASSERT_MSG(beamformingVector.GetSize() == GetNumElems(),
82 beamformingVector.GetSize() << " != " << GetNumElems());
83 m_beamformingVector = beamformingVector;
84 m_isBfVectorValid = true;
85}
86
89{
90 NS_LOG_FUNCTION(this);
92 "The beamforming vector should be Set before it's Get, and should refer to the "
93 "current array configuration");
95}
96
99{
100 NS_LOG_FUNCTION(this);
102 "The beamforming vector should be Set before it's Get, and should refer to the "
103 "current array configuration");
104 return m_beamformingVector;
105}
106
109{
110 NS_LOG_FUNCTION(this << a);
111
112 ComplexVector beamformingVector = GetSteeringVector(a);
113 // The normalization takes into account the total number of ports as only a
114 // portion (K,L) of beam weights associated with a specific port are non-zero.
115 // See 3GPP Section 5.2.2 36.897. This normalization corresponds to
116 // a sub-array partition model (which is different from the full-connection
117 // model). Note that the total number of ports used to perform normalization
118 // is the ratio between the total number of antenna elements and the
119 // number of antenna elements per port.
120 double normRes = norm(beamformingVector) / sqrt(GetNumPorts());
121
122 for (size_t i = 0; i < GetNumElems(); i++)
123 {
124 beamformingVector[i] = std::conj(beamformingVector[i]) / normRes;
125 }
126
127 return beamformingVector;
128}
129
132{
133 ComplexVector steeringVector(GetNumElems());
134 for (size_t i = 0; i < GetNumElems(); i++)
135 {
136 Vector loc = GetElementLocation(i);
137 double phase = -2 * M_PI *
138 (sin(a.GetInclination()) * cos(a.GetAzimuth()) * loc.x +
139 sin(a.GetInclination()) * sin(a.GetAzimuth()) * loc.y +
140 cos(a.GetInclination()) * loc.z);
141 steeringVector[i] = std::polar<double>(1.0, phase);
142 }
143 return steeringVector;
144}
145
146void
148{
149 NS_LOG_FUNCTION(this);
150 m_antennaElement = antennaElement;
151}
152
159
162{
163 return m_id;
164}
165
166bool
168{
169 // Check that channel needs update
170 bool needsUpdate = m_outOfDateAntennaPairChannel.GetValue(m_id, antennaB->m_id);
171
172 // Assume the channel will be updated (needsUpdate == true), reset these
173 m_outOfDateAntennaPairChannel.SetValue(m_id, antennaB->m_id, false);
174 return needsUpdate;
175}
176
177void
179{
180 m_outOfDateAntennaPairChannel.SetValueAdjacent(m_id, true);
181}
182
183} /* namespace ns3 */
Class holding the azimuth and inclination angles of spherical coordinates.
Definition angles.h:107
double GetInclination() const
Getter for inclination angle.
Definition angles.cc:236
double GetAzimuth() const
Getter for azimuth angle.
Definition angles.cc:230
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Class implementing the phased array model virtual base class.
const PhasedArrayModel::ComplexVector & GetBeamformingVectorRef() const
Returns the const reference of the beamforming vector that is currently being used.
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 ...
virtual uint16_t GetNumPorts() const =0
Get the number of ports.
uint32_t GetId() const
Returns the ID of this antenna array instance.
virtual std::pair< double, double > GetApertures() const
Returns the horizontal and vertical apertures of the array, i.e., the extents of the element location...
static SymmetricAdjacencyMatrix< bool > m_outOfDateAntennaPairChannel
matrix indicating whether a channel matrix between a pair of antennas needs to be updated after a cha...
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.
bool IsChannelOutOfDate(Ptr< const PhasedArrayModel > antennaB) const
Returns whether the channel needs to be updated due to antenna setting changes.
ComplexMatrixArray ComplexVector
the underlying Valarray
ComplexVector GetBeamformingVector() const
Returns the beamforming vector that is currently being used.
bool m_isBfVectorValid
ensures the validity of the beamforming vector
void InvalidateChannels() const
After changing the antenna settings, InvalidateChannels() should be called to mark up-to-date channel...
~PhasedArrayModel() override
Destructor.
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
virtual size_t GetNumElems() const =0
Returns the number of antenna elements.
static TypeId GetTypeId()
Get the type ID.
AttributeValue implementation for Pointer.
Definition pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
A class representing a symmetric adjacency matrix.
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
size_t GetSize() const
Definition val-array.h:394
#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:76
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:250
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:273
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
const double norm
Normalization to obtain randoms on [0,1).
Definition rng-stream.cc:54
Every class exported by the ns3 library is enclosed in the ns3 namespace.