A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-value.cc
Go to the documentation of this file.
1
2/*
3 * Copyright (c) 2009 CTTC
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Nicola Baldo <nbaldo@cttc.es>
8 */
9
10#include "spectrum-value.h"
11
12#include <ns3/log.h>
13#include <ns3/math.h>
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("SpectrumValue");
19
23
25 : m_spectrumModel(sof),
26 m_values(sof->GetNumBands())
27{
28}
29
30double&
32{
33 return m_values.at(index);
34}
35
36const double&
37SpectrumValue::operator[](size_t index) const
38{
39 return m_values.at(index);
40}
41
44{
45 return m_spectrumModel->GetUid();
46}
47
53
54Values::const_iterator
56{
57 return m_values.begin();
58}
59
60Values::const_iterator
62{
63 return m_values.end();
64}
65
66Values::iterator
68{
69 return m_values.begin();
70}
71
72Values::iterator
74{
75 return m_values.end();
76}
77
78Bands::const_iterator
80{
81 return m_spectrumModel->Begin();
82}
83
84Bands::const_iterator
86{
87 return m_spectrumModel->End();
88}
89
90void
92{
93 auto it1 = m_values.begin();
94 auto it2 = x.m_values.begin();
95
96 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
97 NS_ASSERT(m_values.size() == x.m_values.size());
98
99 while (it1 != m_values.end())
100 {
101 *it1 += *it2;
102 ++it1;
103 ++it2;
104 }
105}
106
107void
109{
110 auto it1 = m_values.begin();
111
112 while (it1 != m_values.end())
113 {
114 *it1 += s;
115 ++it1;
116 }
117}
118
119void
121{
122 auto it1 = m_values.begin();
123 auto it2 = x.m_values.begin();
124
125 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
126 NS_ASSERT(m_values.size() == x.m_values.size());
127
128 while (it1 != m_values.end())
129 {
130 *it1 -= *it2;
131 ++it1;
132 ++it2;
133 }
134}
135
136void
138{
139 Add(-s);
140}
141
142void
144{
145 auto it1 = m_values.begin();
146 auto it2 = x.m_values.begin();
147
148 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
149 NS_ASSERT(m_values.size() == x.m_values.size());
150
151 while (it1 != m_values.end())
152 {
153 *it1 *= *it2;
154 ++it1;
155 ++it2;
156 }
157}
158
159void
161{
162 auto it1 = m_values.begin();
163
164 while (it1 != m_values.end())
165 {
166 *it1 *= s;
167 ++it1;
168 }
169}
170
171void
173{
174 auto it1 = m_values.begin();
175 auto it2 = x.m_values.begin();
176
177 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
178 NS_ASSERT(m_values.size() == x.m_values.size());
179
180 while (it1 != m_values.end())
181 {
182 *it1 /= *it2;
183 ++it1;
184 ++it2;
185 }
186}
187
188void
190{
191 NS_LOG_FUNCTION(this << s);
192 auto it1 = m_values.begin();
193
194 while (it1 != m_values.end())
195 {
196 *it1 /= s;
197 ++it1;
198 }
199}
200
201void
203{
204 auto it1 = m_values.begin();
205
206 while (it1 != m_values.end())
207 {
208 *it1 = -(*it1);
209 ++it1;
210 }
211}
212
213void
215{
216 int i = 0;
217 while (i < (int)m_values.size() - n)
218 {
219 m_values.at(i) = m_values.at(i + n);
220 i++;
221 }
222 while (i < (int)m_values.size())
223 {
224 m_values.at(i) = 0;
225 i++;
226 }
227}
228
229void
231{
232 int i = m_values.size() - 1;
233 while (i - n >= 0)
234 {
235 m_values.at(i) = m_values.at(i - n);
236 i = i - 1;
237 }
238 while (i >= 0)
239 {
240 m_values.at(i) = 0;
241 --i;
242 }
243}
244
245void
247{
248 NS_LOG_FUNCTION(this << exp);
249 auto it1 = m_values.begin();
250
251 while (it1 != m_values.end())
252 {
253 *it1 = std::pow(*it1, exp);
254 ++it1;
255 }
256}
257
258void
260{
261 NS_LOG_FUNCTION(this << base);
262 auto it1 = m_values.begin();
263
264 while (it1 != m_values.end())
265 {
266 *it1 = std::pow(base, *it1);
267 ++it1;
268 }
269}
270
271void
273{
274 NS_LOG_FUNCTION(this);
275 auto it1 = m_values.begin();
276
277 while (it1 != m_values.end())
278 {
279 *it1 = std::log10(*it1);
280 ++it1;
281 }
282}
283
284void
286{
287 NS_LOG_FUNCTION(this);
288 auto it1 = m_values.begin();
289
290 while (it1 != m_values.end())
291 {
292 *it1 = log2(*it1);
293 ++it1;
294 }
295}
296
297void
299{
300 NS_LOG_FUNCTION(this);
301 auto it1 = m_values.begin();
302
303 while (it1 != m_values.end())
304 {
305 *it1 = std::log(*it1);
306 ++it1;
307 }
308}
309
310double
312{
313 double s = 0;
314 auto it1 = x.ConstValuesBegin();
315 while (it1 != x.ConstValuesEnd())
316 {
317 s += (*it1) * (*it1);
318 ++it1;
319 }
320 return std::sqrt(s);
321}
322
323double
325{
326 double s = 0;
327 auto it1 = x.ConstValuesBegin();
328 while (it1 != x.ConstValuesEnd())
329 {
330 s += (*it1);
331 ++it1;
332 }
333 return s;
334}
335
336double
338{
339 double s = 0;
340 auto it1 = x.ConstValuesBegin();
341 while (it1 != x.ConstValuesEnd())
342 {
343 s *= (*it1);
344 ++it1;
345 }
346 return s;
347}
348
349double
351{
352 double i = 0;
353 auto vit = arg.ConstValuesBegin();
354 auto bit = arg.ConstBandsBegin();
355 while (vit != arg.ConstValuesEnd())
356 {
357 NS_ASSERT(bit != arg.ConstBandsEnd());
358 i += (*vit) * (bit->fh - bit->fl);
359 ++vit;
360 ++bit;
361 }
362 NS_ASSERT(bit == arg.ConstBandsEnd());
363 return i;
364}
365
368{
370 *p = *this;
371 return p;
372
373 // return Copy<SpectrumValue> (*this)
374}
375
376/**
377 * \brief Output stream operator
378 * \param os output stream
379 * \param pvf the SpectrumValue to print
380 * \return an output stream
381 */
382std::ostream&
383operator<<(std::ostream& os, const SpectrumValue& pvf)
384{
385 auto it1 = pvf.ConstValuesBegin();
386 bool first = true;
387 while (it1 != pvf.ConstValuesEnd())
388 {
389 if (!first)
390 {
391 os << " ";
392 }
393 else
394 {
395 first = false;
396 }
397 os << *it1;
398 ++it1;
399 }
400 return os;
401}
402
403SpectrumValue
404operator+(const SpectrumValue& lhs, const SpectrumValue& rhs)
405{
406 SpectrumValue res = lhs;
407 res.Add(rhs);
408 return res;
409}
410
411bool
413{
414 return (lhs.m_values == rhs.m_values);
415}
416
417bool
419{
420 return (lhs.m_values != rhs.m_values);
421}
422
424operator+(const SpectrumValue& lhs, double rhs)
425{
426 SpectrumValue res = lhs;
427 res.Add(rhs);
428 return res;
429}
430
432operator+(double lhs, const SpectrumValue& rhs)
433{
434 SpectrumValue res = rhs;
435 res.Add(lhs);
436 return res;
437}
438
440operator-(const SpectrumValue& lhs, const SpectrumValue& rhs)
441{
442 SpectrumValue res = rhs;
443 res.ChangeSign();
444 res.Add(lhs);
445 return res;
446}
447
449operator-(const SpectrumValue& lhs, double rhs)
450{
451 SpectrumValue res = lhs;
452 res.Subtract(rhs);
453 return res;
454}
455
457operator-(double lhs, const SpectrumValue& rhs)
458{
459 SpectrumValue res = rhs;
460 res.Subtract(lhs);
461 return res;
462}
463
465operator*(const SpectrumValue& lhs, const SpectrumValue& rhs)
466{
467 SpectrumValue res = lhs;
468 res.Multiply(rhs);
469 return res;
470}
471
473operator*(const SpectrumValue& lhs, double rhs)
474{
475 SpectrumValue res = lhs;
476 res.Multiply(rhs);
477 return res;
478}
479
481operator*(double lhs, const SpectrumValue& rhs)
482{
483 SpectrumValue res = rhs;
484 res.Multiply(lhs);
485 return res;
486}
487
489operator/(const SpectrumValue& lhs, const SpectrumValue& rhs)
490{
491 SpectrumValue res = lhs;
492 res.Divide(rhs);
493 return res;
494}
495
497operator/(const SpectrumValue& lhs, double rhs)
498{
499 SpectrumValue res = lhs;
500 res.Divide(rhs);
501 return res;
502}
503
505operator/(double lhs, const SpectrumValue& rhs)
506{
507 SpectrumValue res = rhs;
508 res.Divide(lhs);
509 return res;
510}
511
514{
515 return rhs;
516}
517
520{
521 SpectrumValue res = rhs;
522 res.ChangeSign();
523 return res;
524}
525
527Pow(double lhs, const SpectrumValue& rhs)
528{
529 SpectrumValue res = rhs;
530 res.Exp(lhs);
531 return res;
532}
533
535Pow(const SpectrumValue& lhs, double rhs)
536{
537 SpectrumValue res = lhs;
538 res.Pow(rhs);
539 return res;
540}
541
544{
545 SpectrumValue res = arg;
546 res.Log10();
547 return res;
548}
549
552{
553 SpectrumValue res = arg;
554 res.Log2();
555 return res;
556}
557
560{
561 SpectrumValue res = arg;
562 res.Log();
563 return res;
564}
565
568{
569 Add(rhs);
570 return *this;
571}
572
575{
576 Subtract(rhs);
577 return *this;
578}
579
582{
583 Multiply(rhs);
584 return *this;
585}
586
589{
590 Divide(rhs);
591 return *this;
592}
593
596{
597 Add(rhs);
598 return *this;
599}
600
603{
604 Subtract(rhs);
605 return *this;
606}
607
610{
611 Multiply(rhs);
612 return *this;
613}
614
617{
618 Divide(rhs);
619 return *this;
620}
621
624{
625 auto it1 = m_values.begin();
626
627 while (it1 != m_values.end())
628 {
629 *it1 = rhs;
630 ++it1;
631 }
632 return *this;
633}
634
636SpectrumValue::operator<<(int n) const
637{
638 SpectrumValue res = *this;
639 res.ShiftLeft(n);
640 return res;
641}
642
645{
646 SpectrumValue res = *this;
647 res.ShiftRight(n);
648 return res;
649}
650
653{
654 return m_values.size();
655}
656
657const double&
659{
660 return m_values.at(pos);
661}
662
663} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Set of values corresponding to a given SpectrumModel.
double & operator[](size_t index)
Access value at given frequency index.
void Subtract(const SpectrumValue &x)
Subtracts a SpectrumValue (element by element subtraction)
Values::const_iterator ConstValuesBegin() const
Bands::const_iterator ConstBandsEnd() const
void Divide(const SpectrumValue &x)
Divides by a SpectrumValue (element to element division)
SpectrumValue & operator=(double rhs)
Assign each component of *this to the value of the Right Hand Side of the operator.
Values::iterator ValuesBegin()
void Exp(double base)
Modifies each element so that it is the base raised to each element value.
Bands::const_iterator ConstBandsBegin() const
void ChangeSign()
Change the values sign.
friend SpectrumValue Log2(const SpectrumValue &arg)
friend SpectrumValue Log10(const SpectrumValue &arg)
SpectrumValue operator<<(int n) const
left shift operator
void ShiftLeft(int n)
Shift the values to the left.
Ptr< SpectrumValue > Copy() const
friend SpectrumValue Log(const SpectrumValue &arg)
Values m_values
Set of values which implement the codomain of the functions in the Function Space defined by Spectrum...
uint32_t GetValuesN() const
Get the number of values stored in the array.
Values::iterator ValuesEnd()
Ptr< const SpectrumModel > GetSpectrumModel() const
SpectrumValue & operator*=(const SpectrumValue &rhs)
Multiply *this by the Right Hand Side of the operator, component by component.
Ptr< const SpectrumModel > m_spectrumModel
The spectrum model.
void ShiftRight(int n)
Shift the values to the right.
void Add(const SpectrumValue &x)
Add a SpectrumValue (element to element addition)
void Multiply(const SpectrumValue &x)
Multiplies for a SpectrumValue (element to element multiplication)
SpectrumModelUid_t GetSpectrumModelUid() const
SpectrumValue & operator/=(const SpectrumValue &rhs)
Divide *this by the Right Hand Side of the operator, component by component.
SpectrumValue & operator+=(const SpectrumValue &rhs)
Add the Right Hand Side of the operator to *this, component by component.
Values::const_iterator ConstValuesEnd() const
SpectrumValue & operator-=(const SpectrumValue &rhs)
Subtract the Right Hand Side of the operator from *this, component by component.
SpectrumValue operator>>(int n) const
right shift operator
friend SpectrumValue Pow(const SpectrumValue &lhs, double rhs)
const double & ValuesAt(uint32_t pos) const
Get the value element at the position.
#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
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition int64x64.h:121
int64x64_t operator-(const int64x64_t &lhs, const int64x64_t &rhs)
Subtraction operator.
Definition int64x64.h:91
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition int64x64.h:76
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition int64x64.h:106
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Definition first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition callback.h:658
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
SpectrumValue Pow(double lhs, const SpectrumValue &rhs)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
double Integral(const SpectrumValue &arg)
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
SpectrumValue Log2(const SpectrumValue &arg)
SpectrumValue Log10(const SpectrumValue &arg)
double Norm(const SpectrumValue &x)
SpectrumValue Log(const SpectrumValue &arg)
double Prod(const SpectrumValue &x)
double Sum(const SpectrumValue &x)