A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-value.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-value.h"
10
11#include "ns3/log.h"
12#include "ns3/math.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("SpectrumValue");
18
22
28
29double&
31{
32 return m_values.at(index);
33}
34
35const double&
36SpectrumValue::operator[](size_t index) const
37{
38 return m_values.at(index);
39}
40
43{
44 return m_spectrumModel->GetUid();
45}
46
52
53Values::const_iterator
55{
56 return m_values.begin();
57}
58
59Values::const_iterator
61{
62 return m_values.end();
63}
64
65Values::iterator
67{
68 return m_values.begin();
69}
70
71Values::iterator
73{
74 return m_values.end();
75}
76
77Bands::const_iterator
79{
80 return m_spectrumModel->Begin();
81}
82
83Bands::const_iterator
85{
86 return m_spectrumModel->End();
87}
88
89void
91{
92 auto it1 = m_values.begin();
93 auto it2 = x.m_values.begin();
94
95 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
96 NS_ASSERT(m_values.size() == x.m_values.size());
97
98 while (it1 != m_values.end())
99 {
100 *it1 += *it2;
101 ++it1;
102 ++it2;
103 }
104}
105
106void
108{
109 auto it1 = m_values.begin();
110
111 while (it1 != m_values.end())
112 {
113 *it1 += s;
114 ++it1;
115 }
116}
117
118void
120{
121 auto it1 = m_values.begin();
122 auto it2 = x.m_values.begin();
123
124 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
125 NS_ASSERT(m_values.size() == x.m_values.size());
126
127 while (it1 != m_values.end())
128 {
129 *it1 -= *it2;
130 ++it1;
131 ++it2;
132 }
133}
134
135void
137{
138 Add(-s);
139}
140
141void
143{
144 auto it1 = m_values.begin();
145 auto it2 = x.m_values.begin();
146
147 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
148 NS_ASSERT(m_values.size() == x.m_values.size());
149
150 while (it1 != m_values.end())
151 {
152 *it1 *= *it2;
153 ++it1;
154 ++it2;
155 }
156}
157
158void
160{
161 auto it1 = m_values.begin();
162
163 while (it1 != m_values.end())
164 {
165 *it1 *= s;
166 ++it1;
167 }
168}
169
170void
172{
173 auto it1 = m_values.begin();
174 auto it2 = x.m_values.begin();
175
176 NS_ASSERT(m_spectrumModel == x.m_spectrumModel);
177 NS_ASSERT(m_values.size() == x.m_values.size());
178
179 while (it1 != m_values.end())
180 {
181 *it1 /= *it2;
182 ++it1;
183 ++it2;
184 }
185}
186
187void
189{
190 NS_LOG_FUNCTION(this << s);
191 auto it1 = m_values.begin();
192
193 while (it1 != m_values.end())
194 {
195 *it1 /= s;
196 ++it1;
197 }
198}
199
200void
202{
203 auto it1 = m_values.begin();
204
205 while (it1 != m_values.end())
206 {
207 *it1 = -(*it1);
208 ++it1;
209 }
210}
211
212void
214{
215 int i = 0;
216 while (i < (int)m_values.size() - n)
217 {
218 m_values.at(i) = m_values.at(i + n);
219 i++;
220 }
221 while (i < (int)m_values.size())
222 {
223 m_values.at(i) = 0;
224 i++;
225 }
226}
227
228void
230{
231 int i = m_values.size() - 1;
232 while (i - n >= 0)
233 {
234 m_values.at(i) = m_values.at(i - n);
235 i = i - 1;
236 }
237 while (i >= 0)
238 {
239 m_values.at(i) = 0;
240 --i;
241 }
242}
243
244void
246{
247 NS_LOG_FUNCTION(this << exp);
248 auto it1 = m_values.begin();
249
250 while (it1 != m_values.end())
251 {
252 *it1 = std::pow(*it1, exp);
253 ++it1;
254 }
255}
256
257void
259{
260 NS_LOG_FUNCTION(this << base);
261 auto it1 = m_values.begin();
262
263 while (it1 != m_values.end())
264 {
265 *it1 = std::pow(base, *it1);
266 ++it1;
267 }
268}
269
270void
272{
273 NS_LOG_FUNCTION(this);
274 auto it1 = m_values.begin();
275
276 while (it1 != m_values.end())
277 {
278 *it1 = std::log10(*it1);
279 ++it1;
280 }
281}
282
283void
285{
286 NS_LOG_FUNCTION(this);
287 auto it1 = m_values.begin();
288
289 while (it1 != m_values.end())
290 {
291 *it1 = log2(*it1);
292 ++it1;
293 }
294}
295
296void
298{
299 NS_LOG_FUNCTION(this);
300 auto it1 = m_values.begin();
301
302 while (it1 != m_values.end())
303 {
304 *it1 = std::log(*it1);
305 ++it1;
306 }
307}
308
309double
311{
312 double s = 0;
313 auto it1 = x.ConstValuesBegin();
314 while (it1 != x.ConstValuesEnd())
315 {
316 s += (*it1) * (*it1);
317 ++it1;
318 }
319 return std::sqrt(s);
320}
321
322double
324{
325 double s = 0;
326 auto it1 = x.ConstValuesBegin();
327 while (it1 != x.ConstValuesEnd())
328 {
329 s += (*it1);
330 ++it1;
331 }
332 return s;
333}
334
335double
337{
338 double s = 0;
339 auto it1 = x.ConstValuesBegin();
340 while (it1 != x.ConstValuesEnd())
341 {
342 s *= (*it1);
343 ++it1;
344 }
345 return s;
346}
347
348double
350{
351 double i = 0;
352 auto vit = arg.ConstValuesBegin();
353 auto bit = arg.ConstBandsBegin();
354 while (vit != arg.ConstValuesEnd())
355 {
356 NS_ASSERT(bit != arg.ConstBandsEnd());
357 i += (*vit) * (bit->fh - bit->fl);
358 ++vit;
359 ++bit;
360 }
361 NS_ASSERT(bit == arg.ConstBandsEnd());
362 return i;
363}
364
367{
369 *p = *this;
370 return p;
371
372 // return Copy<SpectrumValue> (*this)
373}
374
375/**
376 * @brief Output stream operator
377 * @param os output stream
378 * @param pvf the SpectrumValue to print
379 * @return an output stream
380 */
381std::ostream&
382operator<<(std::ostream& os, const SpectrumValue& pvf)
383{
384 auto it1 = pvf.ConstValuesBegin();
385 bool first = true;
386 while (it1 != pvf.ConstValuesEnd())
387 {
388 if (!first)
389 {
390 os << " ";
391 }
392 else
393 {
394 first = false;
395 }
396 os << *it1;
397 ++it1;
398 }
399 return os;
400}
401
402SpectrumValue
403operator+(const SpectrumValue& lhs, const SpectrumValue& rhs)
404{
405 SpectrumValue res = lhs;
406 res.Add(rhs);
407 return res;
408}
409
410bool
412{
413 return (lhs.m_values == rhs.m_values);
414}
415
416bool
418{
419 return (lhs.m_values != rhs.m_values);
420}
421
423operator+(const SpectrumValue& lhs, double rhs)
424{
425 SpectrumValue res = lhs;
426 res.Add(rhs);
427 return res;
428}
429
431operator+(double lhs, const SpectrumValue& rhs)
432{
433 SpectrumValue res = rhs;
434 res.Add(lhs);
435 return res;
436}
437
439operator-(const SpectrumValue& lhs, const SpectrumValue& rhs)
440{
441 SpectrumValue res = rhs;
442 res.ChangeSign();
443 res.Add(lhs);
444 return res;
445}
446
448operator-(const SpectrumValue& lhs, double rhs)
449{
450 SpectrumValue res = lhs;
451 res.Subtract(rhs);
452 return res;
453}
454
456operator-(double lhs, const SpectrumValue& rhs)
457{
458 SpectrumValue res = rhs;
459 res.Subtract(lhs);
460 return res;
461}
462
464operator*(const SpectrumValue& lhs, const SpectrumValue& rhs)
465{
466 SpectrumValue res = lhs;
467 res.Multiply(rhs);
468 return res;
469}
470
472operator*(const SpectrumValue& lhs, double rhs)
473{
474 SpectrumValue res = lhs;
475 res.Multiply(rhs);
476 return res;
477}
478
480operator*(double lhs, const SpectrumValue& rhs)
481{
482 SpectrumValue res = rhs;
483 res.Multiply(lhs);
484 return res;
485}
486
488operator/(const SpectrumValue& lhs, const SpectrumValue& rhs)
489{
490 SpectrumValue res = lhs;
491 res.Divide(rhs);
492 return res;
493}
494
496operator/(const SpectrumValue& lhs, double rhs)
497{
498 SpectrumValue res = lhs;
499 res.Divide(rhs);
500 return res;
501}
502
504operator/(double lhs, const SpectrumValue& rhs)
505{
506 SpectrumValue res = rhs;
507 res.Divide(lhs);
508 return res;
509}
510
513{
514 return rhs;
515}
516
519{
520 SpectrumValue res = rhs;
521 res.ChangeSign();
522 return res;
523}
524
526Pow(double lhs, const SpectrumValue& rhs)
527{
528 SpectrumValue res = rhs;
529 res.Exp(lhs);
530 return res;
531}
532
534Pow(const SpectrumValue& lhs, double rhs)
535{
536 SpectrumValue res = lhs;
537 res.Pow(rhs);
538 return res;
539}
540
543{
544 SpectrumValue res = arg;
545 res.Log10();
546 return res;
547}
548
551{
552 SpectrumValue res = arg;
553 res.Log2();
554 return res;
555}
556
559{
560 SpectrumValue res = arg;
561 res.Log();
562 return res;
563}
564
567{
568 Add(rhs);
569 return *this;
570}
571
574{
575 Subtract(rhs);
576 return *this;
577}
578
581{
582 Multiply(rhs);
583 return *this;
584}
585
588{
589 Divide(rhs);
590 return *this;
591}
592
595{
596 Add(rhs);
597 return *this;
598}
599
602{
603 Subtract(rhs);
604 return *this;
605}
606
609{
610 Multiply(rhs);
611 return *this;
612}
613
616{
617 Divide(rhs);
618 return *this;
619}
620
623{
624 auto it1 = m_values.begin();
625
626 while (it1 != m_values.end())
627 {
628 *it1 = rhs;
629 ++it1;
630 }
631 return *this;
632}
633
635SpectrumValue::operator<<(int n) const
636{
637 SpectrumValue res = *this;
638 res.ShiftLeft(n);
639 return res;
640}
641
644{
645 SpectrumValue res = *this;
646 res.ShiftRight(n);
647 return res;
648}
649
652{
653 return m_values.size();
654}
655
656const double&
658{
659 return m_values.at(pos);
660}
661
662} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
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.
SpectrumValue operator<<(int n) const
left shift operator
void ShiftLeft(int n)
Shift the values to the left.
Ptr< SpectrumValue > Copy() const
Values m_values
Set of values which implement the codomain of the functions in the Function Space defined by Spectrum...
SpectrumValue(Ptr< const SpectrumModel > sm)
SpectrumValue constructor.
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)
void Log()
Applies a Log to each the elements.
void Log2()
Applies a Log2 to each the elements.
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)
void Log10()
Applies a Log10 to each the elements.
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:439
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:146
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)