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 * 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
21
22#include <ns3/boolean.h>
23#include <ns3/double.h>
24#include <ns3/log.h>
25#include <ns3/pointer.h>
26#include <ns3/uinteger.h>
27
28namespace ns3
29{
30
32
33NS_LOG_COMPONENT_DEFINE("PhasedArrayModel");
34
35NS_OBJECT_ENSURE_REGISTERED(PhasedArrayModel);
36
37std::ostream&
38operator<<(std::ostream& os, const PhasedArrayModel::ComplexVector& cv)
39{
40 size_t N = cv.GetSize();
41
42 // empty
43 if (N == 0)
44 {
45 os << "[]";
46 return os;
47 }
48
49 // non-empty
50 os << "[";
51 for (std::size_t i = 0; i < N - 1; ++i)
52 {
53 os << cv[i] << ", ";
54 }
55 os << cv[N - 1] << "]";
56 return os;
57}
58
60 : m_isBfVectorValid{false}
61{
62 m_id = m_idCounter++;
63}
64
66{
67}
68
71{
72 static TypeId tid =
73 TypeId("ns3::PhasedArrayModel")
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 return tid;
82}
83
84void
86{
87 NS_LOG_FUNCTION(this << beamformingVector);
88 NS_ASSERT_MSG(beamformingVector.GetSize() == GetNumberOfElements(),
89 beamformingVector.GetSize() << " != " << GetNumberOfElements());
90 m_beamformingVector = beamformingVector;
91 m_isBfVectorValid = true;
92}
93
96{
97 NS_LOG_FUNCTION(this);
99 "The beamforming vector should be Set before it's Get, and should refer to the "
100 "current array configuration");
101 return m_beamformingVector;
102}
103
106{
107 NS_LOG_FUNCTION(this << a);
108
109 ComplexVector beamformingVector = GetSteeringVector(a);
110 double normRes = norm(beamformingVector);
111
112 for (size_t i = 0; i < GetNumberOfElements(); i++)
113 {
114 beamformingVector[i] = std::conj(beamformingVector[i]) / normRes;
115 }
116
117 return beamformingVector;
118}
119
122{
123 ComplexVector steeringVector(GetNumberOfElements());
124 for (size_t i = 0; i < GetNumberOfElements(); i++)
125 {
126 Vector loc = GetElementLocation(i);
127 double phase = -2 * M_PI *
128 (sin(a.GetInclination()) * cos(a.GetAzimuth()) * loc.x +
129 sin(a.GetInclination()) * sin(a.GetAzimuth()) * loc.y +
130 cos(a.GetInclination()) * loc.z);
131 steeringVector[i] = std::polar<double>(1.0, phase);
132 }
133 return steeringVector;
134}
135
136void
138{
139 NS_LOG_FUNCTION(this);
140 m_antennaElement = antennaElement;
141}
142
145{
146 NS_LOG_FUNCTION(this);
147 return m_antennaElement;
148}
149
152{
153 return m_id;
154}
155
156} /* 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:246
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
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
~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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:930
size_t GetSize() const
Definition: val-array.h:400
#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)
Definition: pointer.h:227
#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
const double norm
Normalization to obtain randoms on [0,1).
Definition: rng-stream.cc:66
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:159