A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
spectrum-converter.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-converter.h
"
10
11
#include <ns3/assert.h>
12
#include <ns3/log.h>
13
14
#include <algorithm>
15
16
namespace
ns3
17
{
18
19
NS_LOG_COMPONENT_DEFINE
(
"SpectrumConverter"
);
20
21
SpectrumConverter::SpectrumConverter
()
22
{
23
}
24
25
SpectrumConverter::SpectrumConverter
(
Ptr<const SpectrumModel>
fromSpectrumModel,
26
Ptr<const SpectrumModel>
toSpectrumModel)
27
{
28
NS_LOG_FUNCTION
(
this
);
29
m_fromSpectrumModel
= fromSpectrumModel;
30
m_toSpectrumModel
= toSpectrumModel;
31
32
size_t
rowPtr = 0;
33
for
(
auto
toit = toSpectrumModel->Begin(); toit != toSpectrumModel->End(); ++toit)
34
{
35
size_t
colInd = 0;
36
for
(
auto
fromit = fromSpectrumModel->Begin(); fromit != fromSpectrumModel->End(); ++fromit)
37
{
38
double
c =
GetCoefficient
(*fromit, *toit);
39
NS_LOG_LOGIC
(
"("
<< fromit->fl <<
","
<< fromit->fh <<
")"
40
<<
" --> "
41
<<
"("
<< toit->fl <<
","
<< toit->fh <<
")"
42
<<
" = "
<< c);
43
if
(c > 0)
44
{
45
m_conversionMatrix
.push_back(c);
46
m_conversionColInd
.push_back(colInd);
47
rowPtr++;
48
}
49
colInd++;
50
}
51
m_conversionRowPtr
.push_back(rowPtr);
52
}
53
}
54
55
double
56
SpectrumConverter::GetCoefficient
(
const
BandInfo
& from,
const
BandInfo
& to)
const
57
{
58
NS_LOG_FUNCTION
(
this
);
59
double
coeff = std::min(from.
fh
, to.
fh
) - std::max(from.
fl
, to.
fl
);
60
coeff = std::max(0.0, coeff);
61
coeff = std::min(1.0, coeff / (to.
fh
- to.
fl
));
62
return
coeff;
63
}
64
65
Ptr<SpectrumValue>
66
SpectrumConverter::Convert
(
Ptr<const SpectrumValue>
fvvf)
const
67
{
68
NS_ASSERT
(*(fvvf->GetSpectrumModel()) == *
m_fromSpectrumModel
);
69
70
Ptr<SpectrumValue>
tvvf =
Create<SpectrumValue>
(
m_toSpectrumModel
);
71
72
auto
tvit = tvvf->ValuesBegin();
73
size_t
i = 0;
// Index of conversion coefficient
74
75
for
(
auto
convIt =
m_conversionRowPtr
.begin(); convIt !=
m_conversionRowPtr
.end(); ++convIt)
76
{
77
double
sum = 0;
78
while
(i < *convIt)
79
{
80
sum += (*fvvf)[
m_conversionColInd
.at(i)] *
m_conversionMatrix
.at(i);
81
i++;
82
}
83
*tvit = sum;
84
++tvit;
85
}
86
87
return
tvvf;
88
}
89
90
}
// namespace ns3
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::SpectrumConverter::m_conversionMatrix
std::vector< double > m_conversionMatrix
matrix of conversion coefficients stored in Compressed Row Storage format
Definition
spectrum-converter.h:67
ns3::SpectrumConverter::m_fromSpectrumModel
Ptr< const SpectrumModel > m_fromSpectrumModel
the SpectrumModel this SpectrumConverter instance can convert from
Definition
spectrum-converter.h:73
ns3::SpectrumConverter::GetCoefficient
double GetCoefficient(const BandInfo &from, const BandInfo &to) const
Calculate the coefficient for value conversion between elements.
Definition
spectrum-converter.cc:56
ns3::SpectrumConverter::SpectrumConverter
SpectrumConverter()
Definition
spectrum-converter.cc:21
ns3::SpectrumConverter::m_toSpectrumModel
Ptr< const SpectrumModel > m_toSpectrumModel
the SpectrumModel this SpectrumConverter instance can convert to
Definition
spectrum-converter.h:76
ns3::SpectrumConverter::Convert
Ptr< SpectrumValue > Convert(Ptr< const SpectrumValue > vvf) const
Convert a particular ValueVsFreq instance to.
Definition
spectrum-converter.cc:66
ns3::SpectrumConverter::m_conversionRowPtr
std::vector< size_t > m_conversionRowPtr
offset of rows in m_conversionMatrix
Definition
spectrum-converter.h:69
ns3::SpectrumConverter::m_conversionColInd
std::vector< size_t > m_conversionColInd
column of each non-zero element in m_conversionMatrix
Definition
spectrum-converter.h:71
NS_ASSERT
#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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition
log.h:271
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
spectrum-converter.h
ns3::BandInfo
The building block of a SpectrumModel.
Definition
spectrum-model.h:42
ns3::BandInfo::fl
double fl
lower limit of subband
Definition
spectrum-model.h:43
ns3::BandInfo::fh
double fh
upper limit of subband
Definition
spectrum-model.h:45
src
spectrum
model
spectrum-converter.cc
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0