A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include "spectrum-model.h"
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13
14#include <cmath>
15#include <cstddef>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("SpectrumModel");
21
22bool
23operator==(const SpectrumModel& lhs, const SpectrumModel& rhs)
24{
25 return (lhs.m_uid == rhs.m_uid);
26}
27
29
30SpectrumModel::SpectrumModel(const std::vector<double>& centerFreqs)
31{
32 NS_ASSERT(centerFreqs.size() > 1);
33 m_uid = ++m_uidCount;
34
35 for (auto it = centerFreqs.begin(); it != centerFreqs.end(); ++it)
36 {
37 BandInfo e;
38 e.fc = *it;
39 if (it == centerFreqs.begin())
40 {
41 double delta = ((*(it + 1)) - (*it)) / 2;
42 e.fl = *it - delta;
43 e.fh = *it + delta;
44 }
45 else if (it == centerFreqs.end() - 1)
46 {
47 double delta = ((*it) - (*(it - 1))) / 2;
48 e.fl = *it - delta;
49 e.fh = *it + delta;
50 }
51 else
52 {
53 e.fl = ((*it) + (*(it - 1))) / 2;
54 e.fh = ((*(it + 1)) + (*it)) / 2;
55 }
56 m_bands.push_back(e);
57 }
58}
59
61{
62 m_uid = ++m_uidCount;
63 NS_LOG_INFO("creating new SpectrumModel, m_uid=" << m_uid);
64 m_bands = bands;
65}
66
68 : m_bands(std::move(bands))
69{
70 m_uid = ++m_uidCount;
71 NS_LOG_INFO("creating new SpectrumModel, m_uid=" << m_uid);
72}
73
74Bands::const_iterator
76{
77 return m_bands.begin();
78}
79
80Bands::const_iterator
82{
83 return m_bands.end();
84}
85
86size_t
88{
89 return m_bands.size();
90}
91
94{
95 return m_uid;
96}
97
98bool
100{
101 for (auto myIt = Begin(); myIt != End(); ++myIt)
102 {
103 for (auto otherIt = other.Begin(); otherIt != other.End(); ++otherIt)
104 {
105 if (std::max(myIt->fl, otherIt->fl) < std::min(myIt->fh, otherIt->fh))
106 {
107 return false;
108 }
109 }
110 }
111 return true;
112}
113
114} // namespace ns3
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
static SpectrumModelUid_t m_uidCount
counter to assign m_uids
SpectrumModelUid_t m_uid
unique id for a given set of frequencies
SpectrumModel(const std::vector< double > &centerFreqs)
This constructs a SpectrumModel based on a given set of frequencies, which is assumed to be sorted by...
Bands::const_iterator End() const
Const Iterator to the model Bands container end.
size_t GetNumBands() const
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
SpectrumModelUid_t GetUid() const
Bands m_bands
Actual definition of frequency bands within this SpectrumModel.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:146
std::vector< BandInfo > Bands
Container of BandInfo.
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
STL namespace.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband