5#include "beam-manager.h"
7#include <ns3/boolean.h>
10#include <ns3/simulator.h>
11#include <ns3/uinteger.h>
16NS_LOG_COMPONENT_DEFINE(
"BeamManager");
17NS_OBJECT_ENSURE_REGISTERED(BeamManager);
27 m_antennaArray = antennaArray;
31PhasedArrayModel::ComplexVector
43Ptr<const UniformPlanarArray>
46 return m_antennaArray;
58 TypeId(
"ns3::BeamManager").SetParent<Object>().AddConstructor<BeamManager>();
63BeamManager::SetPredefinedBeam(PhasedArrayModel::ComplexVector predefinedBeam)
65 NS_LOG_FUNCTION(
this);
66 NS_ABORT_MSG_IF(predefinedBeam.GetSize() == 0,
"Cannot assign an empty predefined beam");
67 NS_ABORT_MSG_IF(predefinedBeam.GetSize() != m_antennaArray->GetNumElems(),
68 "Cannot assign a predefined beamforming vector whose dimension is not "
69 "compatible with antenna array");
74BeamManager::SetPredefinedBeam(uint16_t sector,
double elevation)
76 NS_LOG_FUNCTION(
this);
78 BeamId(sector, elevation));
84 NS_LOG_INFO(
"Save beamforming vector toward device with node id:"
85 << device->GetNode()->GetId() <<
" with BeamId:" << bfv.second);
87 if (m_predefinedDirTxRxW.first.GetSize() != 0)
89 NS_LOG_WARN(
"Saving beamforming vector for device, while there is also a predefined "
90 "beamforming vector defined to be used for all transmissions.");
93 if (device !=
nullptr)
95 BeamformingStorage::iterator iter = m_beamformingVectorMap.find(device);
96 if (iter != m_beamformingVectorMap.end())
102 m_beamformingVectorMap.insert(std::make_pair(device, bfv));
110 NS_LOG_FUNCTION(
this);
112 BeamformingStorage::iterator it = m_beamformingVectorMap.find(device);
113 if (it == m_beamformingVectorMap.end())
115 NS_LOG_INFO(
"Could not find the beamforming vector for the provided device");
119 if (m_predefinedDirTxRxW.first.GetSize() != 0)
121 m_antennaArray->SetBeamformingVector(m_predefinedDirTxRxW.first);
130 NS_LOG_INFO(
"Beamforming vector found");
131 m_antennaArray->SetBeamformingVector(it->second.first);
135PhasedArrayModel::ComplexVector
138 return m_antennaArray->GetBeamformingVector();
144 NS_LOG_FUNCTION(
this);
146 UintegerValue numRows;
147 UintegerValue numColumns;
148 m_antennaArray->GetAttribute(
"NumRows", numRows);
149 m_antennaArray->GetAttribute(
"NumColumns", numColumns);
158 if (numRows.Get() != m_numRows || numColumns.Get() != m_numColumns ||
159 m_isPolDual != m_antennaArray->IsDualPol())
161 m_isPolDual = m_antennaArray->IsDualPol();
162 m_numPortElems = m_antennaArray->GetNumElemsPerPort();
163 m_numRows = numRows.Get();
164 m_numColumns = numColumns.Get();
168 m_antennaArray->SetBeamformingVector(m_omniTxRxW.first);
171PhasedArrayModel::ComplexVector
174 NS_LOG_FUNCTION(
this);
175 PhasedArrayModel::ComplexVector beamformingVector;
176 BeamformingStorage::const_iterator it = m_beamformingVectorMap.find(device);
177 if (it != m_beamformingVectorMap.end())
179 beamformingVector = it->second.first;
185 if (m_predefinedDirTxRxW.first.GetSize() != 0)
187 beamformingVector = m_predefinedDirTxRxW.first;
191 beamformingVector = m_antennaArray->GetBeamformingVector();
194 return beamformingVector;
201 BeamformingStorage::const_iterator it = m_beamformingVectorMap.find(device);
202 if (it != m_beamformingVectorMap.end())
204 beamId = it->second.second;
210 if (m_predefinedDirTxRxW.first.GetSize() != 0)
212 beamId = m_predefinedDirTxRxW.second;
225 NS_LOG_INFO(
"Set sector to : " << (
unsigned)sector <<
", and elevation to: " << elevation);
232 NS_LOG_INFO(
"Set azimuth to : " << (
unsigned)azimuth <<
", and zenith to:" << zenith);
Representation of a beam id.
static TypeId GetTypeId()
GetTypeId.
BeamManager()
BeamManager constructor.
void SetSectorAz(double azimuth, double zenith) const
Set the Sector.
PhasedArrayModel::ComplexVector GetVector(const BeamformingVector &v) const
Get weight vector from a BeamformingVector.
virtual PhasedArrayModel::ComplexVector GetBeamformingVector(const Ptr< NetDevice > &device) const
Function that returns the beamforming vector weights that is used to communicated with a specified de...
virtual PhasedArrayModel::ComplexVector GetCurrentBeamformingVector()
Function that returns the beamforming vector that is currently being used by the antenna.
BeamId GetBeamId(const BeamformingVector &v) const
Extract the beam id from the beamforming vector specified.
virtual void ChangeToQuasiOmniBeamformingVector()
Change current beamforming vector to quasi-omni beamforming vector.
void Configure(const Ptr< UniformPlanarArray > &antennaArray)
Configures quasi-omni beamforming vector.
void SetSector(uint16_t sector, double elevation) const
Set the Sector.
Ptr< const UniformPlanarArray > GetAntenna() const
Get a pointer to the current antenna.
~BeamManager() override
~BeamManager
virtual void ChangeBeamformingVector(const Ptr< const NetDevice > &device)
Change the beamforming vector for tx/rx to/from specified device.
virtual void SaveBeamformingVector(const BeamformingVector &bfv, const Ptr< const NetDevice > &device)
Function that saves the beamforming weights of the antenna for transmission or reception to/from a sp...
const BeamId PREDEFINED_BEAM_ID
Reserved ID for the predefined directional beam if it cannot be expressed through sector and elevatio...
std::pair< PhasedArrayModel::ComplexVector, BeamId > BeamformingVector
Physical representation of a beam.
PhasedArrayModel::ComplexVector CreateDirectionalBfvAz(const Ptr< const UniformPlanarArray > &antenna, double azimuth, double zenith)
Creates a beamforming vector for a given azimuth and zenith.
const BeamId OMNI_BEAM_ID
Name of the OMNI beam.
PhasedArrayModel::ComplexVector CreateQuasiOmniBfv(const Ptr< const UniformPlanarArray > &antenna)
Create a quasi omni beamforming vector.
PhasedArrayModel::ComplexVector CreateDirectionalBfv(const Ptr< const UniformPlanarArray > &antenna, uint16_t sector, double elevation)
Creates a beamforming vector for a given sector and elevation.