A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-value.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
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 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#ifndef SPECTRUM_VALUE_H
21#define SPECTRUM_VALUE_H
22
23#include "spectrum-model.h"
24
25#include <ns3/ptr.h>
26#include <ns3/simple-ref-count.h>
27
28#include <ostream>
29#include <vector>
30
31namespace ns3
32{
33
34/// Container for element values
35typedef std::vector<double> Values;
36
37/**
38 * \ingroup spectrum
39 *
40 * \brief Set of values corresponding to a given SpectrumModel
41 *
42 * This class implements a Function Space which can represent any
43 * function \f$ g: F \in {\sf
44 * R\hspace*{-0.9ex}\rule{0.15ex}{1.5ex}\hspace*{0.9ex}}^N \rightarrow {\sf
45 * R\hspace*{-0.9ex}\rule{0.15ex}{1.5ex}\hspace*{0.9ex}} \f$
46 *
47 * Every instance of this class represent a particular function \f$ g(F) \f$.
48 * The domain of the function space, i.e., \f$ F \f$, is implemented by Bands.
49 * The codomain of the function space is implemented by Values.
50 *
51 * To every possible value of \f$ F\f$ corresponds a different Function
52 * Space.
53 * Mathematical operations are defined in this Function Space; these
54 * operations are implemented by means of operator overloading.
55 *
56 * The intended use of this class is to represent frequency-dependent
57 * things, such as power spectral densities, frequency-dependent
58 * propagation losses, spectral masks, etc.
59 */
60class SpectrumValue : public SimpleRefCount<SpectrumValue>
61{
62 public:
63 /**
64 * @brief SpectrumValue constructor
65 *
66 * @param sm pointer to the SpectrumModel which implements the set of frequencies to which the
67 * values will be referring.
68 *
69 * @warning the intended use if that sm points to a static object
70 * which will be there for the whole simulation. This is reasonable
71 * since the set of frequencies which are to be used in the
72 * simulation is normally known before the simulation starts. Make
73 * sure that the SpectrumModel instance which sm points to has already been
74 * initialized by the time this method is invoked. The main reason is
75 * that if you initialize the SpectrumModel instance afterwards, and
76 * the memory for the underlying std::vector gets reallocated, then
77 * sm will not be a valid reference anymore. Another reason is that
78 * m_values could end up having the wrong size.
79 */
81
83
84 /**
85 * Access value at given frequency index
86 *
87 * @param index the given frequency index
88 *
89 * @return reference to the value
90 */
91 double& operator[](size_t index);
92
93 /**
94 * Access value at given frequency index
95 *
96 * @param index the given frequency index
97 *
98 * @return const reference to the value
99 */
100 const double& operator[](size_t index) const;
101
102 /**
103 *
104 * @return the uid of the embedded SpectrumModel
105 */
107
108 /**
109 *
110 * @return the embedded SpectrumModel
111 */
113
114 /**
115 *
116 *
117 * @return a const iterator pointing to the beginning of the embedded Bands
118 */
119 Bands::const_iterator ConstBandsBegin() const;
120
121 /**
122 *
123 *
124 * @return a const iterator pointing to the end of the embedded Bands
125 */
126 Bands::const_iterator ConstBandsEnd() const;
127
128 /**
129 *
130 *
131 * @return a const iterator pointing to the beginning of the embedded Values
132 */
133 Values::const_iterator ConstValuesBegin() const;
134
135 /**
136 *
137 *
138 * @return a const iterator pointing to the end of the embedded Values
139 */
140 Values::const_iterator ConstValuesEnd() const;
141
142 /**
143 *
144 *
145 * @return an iterator pointing to the beginning of the embedded Values
146 */
147 Values::iterator ValuesBegin();
148
149 /**
150 *
151 *
152 * @return an iterator pointing to the end of the embedded Values
153 */
154 Values::iterator ValuesEnd();
155
156 /**
157 * \brief Get the number of values stored in the array
158 * \return the values array size
159 */
160 uint32_t GetValuesN() const;
161
162 /**
163 * Directly set the values using the std::vector<double>
164 * \param values a reference to the std::vector<double>
165 */
166 inline void SetValues(Values& values)
167 {
169 values.size() == m_spectrumModel->GetNumBands(),
170 "Values size does not correspond to the SpectrumModel in use by this SpectrumValue.");
171 m_values = values;
172 }
173
174 /**
175 * Directly set the values by moving the values from the input std::vector<double>
176 * \param values a reference to the std::vector<double> to be moved
177 */
178 inline void SetValues(Values&& values)
179 {
181 values.size() == m_spectrumModel->GetNumBands(),
182 "Values size does not correspond to the SpectrumModel in use by this SpectrumValue.");
183 m_values = std::move(values);
184 }
185
186 /**
187 * \brief Provides the direct access to the underlying std::vector<double>
188 * that stores the spectrum values.
189 * \return a reference to the stored values
190 */
192 {
193 return m_values;
194 }
195
196 /**
197 * \brief Provides the direct read-only access to the underlying std::vector<double>
198 * that stores the spectrum values.
199 * \return a const reference to the stored values
200 */
201 inline const Values& GetValues() const
202 {
203 return m_values;
204 }
205
206 /**
207 * \brief Get the value element at the position
208 * \param pos position
209 * \return the value element in that position (with bounds checking)
210 */
211 const double& ValuesAt(uint32_t pos) const;
212
213 /**
214 * addition operator
215 *
216 * @param lhs Left Hand Side of the operator
217 * @param rhs Right Hand Side of the operator
218 *
219 * @return the value of lhs + rhs
220 */
221 friend SpectrumValue operator+(const SpectrumValue& lhs, const SpectrumValue& rhs);
222
223 /**
224 * addition operator
225 *
226 * @param lhs Left Hand Side of the operator
227 * @param rhs Right Hand Side of the operator
228 *
229 * @return the value of lhs + rhs
230 */
231 friend SpectrumValue operator+(const SpectrumValue& lhs, double rhs);
232
233 /**
234 * addition operator
235 *
236 * @param lhs Left Hand Side of the operator
237 * @param rhs Right Hand Side of the operator
238 *
239 * @return the value of lhs + rhs
240 */
241 friend SpectrumValue operator+(double lhs, const SpectrumValue& rhs);
242
243 /**
244 * subtraction operator
245 *
246 * @param lhs Left Hand Side of the operator
247 * @param rhs Right Hand Side of the operator
248 *
249 * @return the value of lhs - rhs
250 */
251 friend SpectrumValue operator-(const SpectrumValue& lhs, const SpectrumValue& rhs);
252
253 /**
254 * subtraction operator
255 *
256 * @param lhs Left Hand Side of the operator
257 * @param rhs Right Hand Side of the operator
258 *
259 * @return the value of lhs - rhs
260 */
261 friend SpectrumValue operator-(const SpectrumValue& lhs, double rhs);
262
263 /**
264 * subtraction operator
265 *
266 * @param lhs Left Hand Side of the operator
267 * @param rhs Right Hand Side of the operator
268 *
269 * @return the value of lhs - rhs
270 */
271 friend SpectrumValue operator-(double lhs, const SpectrumValue& rhs);
272
273 /**
274 * multiplication component-by-component (Schur product)
275 *
276 * @param lhs Left Hand Side of the operator
277 * @param rhs Right Hand Side of the operator
278 *
279 * @return the value of lhs * rhs
280 */
281 friend SpectrumValue operator*(const SpectrumValue& lhs, const SpectrumValue& rhs);
282
283 /**
284 * multiplication by a scalar
285 *
286 * @param lhs Left Hand Side of the operator
287 * @param rhs Right Hand Side of the operator
288 *
289 * @return the value of lhs * rhs
290 */
291 friend SpectrumValue operator*(const SpectrumValue& lhs, double rhs);
292
293 /**
294 * multiplication of a scalar
295 *
296 * @param lhs Left Hand Side of the operator
297 * @param rhs Right Hand Side of the operator
298 *
299 * @return the value of lhs * rhs
300 */
301 friend SpectrumValue operator*(double lhs, const SpectrumValue& rhs);
302
303 /**
304 * division component-by-component
305 *
306 * @param lhs Left Hand Side of the operator
307 * @param rhs Right Hand Side of the operator
308 *
309 * @return the value of lhs / rhs
310 */
311 friend SpectrumValue operator/(const SpectrumValue& lhs, const SpectrumValue& rhs);
312
313 /**
314 * division by a scalar
315 *
316 * @param lhs Left Hand Side of the operator
317 * @param rhs Right Hand Side of the operator
318 *
319 * @return the value of *this / rhs
320 */
321 friend SpectrumValue operator/(const SpectrumValue& lhs, double rhs);
322
323 /**
324 * division of a scalar
325 *
326 * @param lhs Left Hand Side of the operator
327 * @param rhs Right Hand Side of the operator
328 *
329 * @return the value of *this / rhs
330 */
331 friend SpectrumValue operator/(double lhs, const SpectrumValue& rhs);
332
333 /**
334 * Compare two spectrum values
335 *
336 * @param lhs Left Hand Side of the operator
337 * @param rhs Right Hand Side of the operator
338 *
339 * @return true if lhs and rhs SpectruValues are equal
340 */
341 friend bool operator==(const SpectrumValue& lhs, const SpectrumValue& rhs);
342
343 /**
344 * Compare two spectrum values
345 *
346 * @param lhs Left Hand Side of the operator
347 * @param rhs Right Hand Side of the operator
348 *
349 * @return true if lhs and rhs SpectruValues are not equal
350 */
351 friend bool operator!=(const SpectrumValue& lhs, const SpectrumValue& rhs);
352
353 /**
354 * unary plus operator
355 *
356 * @param rhs Right Hand Side of the operator
357 * @return the value of *this
358 */
359 friend SpectrumValue operator+(const SpectrumValue& rhs);
360
361 /**
362 * unary minus operator
363 *
364 * @param rhs Right Hand Side of the operator
365 * @return the value of - *this
366 */
367 friend SpectrumValue operator-(const SpectrumValue& rhs);
368
369 /**
370 * left shift operator
371 *
372 * @param n position to shift
373 *
374 * @return the value of *this left shifted by n positions. In other
375 * words, the function of the set of frequencies represented by
376 * *this is left-shifted in frequency by n positions.
377 */
378 SpectrumValue operator<<(int n) const;
379
380 /**
381 * right shift operator
382 *
383 * @param n position to shift
384 *
385 * @return the value of *this right shifted by n positions. In other
386 * words, the function of the set of frequencies represented by
387 * *this is left-shifted in frequency by n positions.
388 */
389 SpectrumValue operator>>(int n) const;
390
391 /**
392 * Add the Right Hand Side of the operator to *this, component by component
393 *
394 * @param rhs the Right Hand Side
395 *
396 * @return a reference to *this
397 */
399
400 /**
401 * Subtract the Right Hand Side of the operator from *this, component by component
402 *
403 * @param rhs the Right Hand Side
404 *
405 * @return a reference to *this
406 */
408
409 /**
410 * Multiply *this by the Right Hand Side of the operator, component by component
411 *
412 * @param rhs the Right Hand Side
413 *
414 * @return a reference to *this
415 */
417
418 /**
419 * Divide *this by the Right Hand Side of the operator, component by component
420 *
421 * @param rhs the Right Hand Side
422 *
423 * @return a reference to *this
424 */
426
427 /**
428 * Add the value of the Right Hand Side of the operator to all
429 * components of *this
430 *
431 * @param rhs the Right Hand Side
432 *
433 * @return a reference to *this
434 */
435 SpectrumValue& operator+=(double rhs);
436
437 /**
438 * Subtract the value of the Right Hand Side of the operator from all
439 * components of *this
440 *
441 * @param rhs the Right Hand Side
442 *
443 * @return a reference to *this
444 */
445 SpectrumValue& operator-=(double rhs);
446
447 /**
448 * Multiply every component of *this by the value of the Right Hand
449 * Side of the operator
450 *
451 * @param rhs the Right Hand Side
452 *
453 * @return a reference to *this
454 */
455 SpectrumValue& operator*=(double rhs);
456
457 /**
458 * Divide every component of *this by the value of the Right Hand
459 * Side of the operator
460 *
461 * @param rhs the Right Hand Side
462 *
463 * @return a reference to *this
464 */
465 SpectrumValue& operator/=(double rhs);
466
467 /**
468 * Assign each component of *this to the value of the Right Hand
469 * Side of the operator
470 *
471 * @param rhs
472 *
473 * @return
474 */
475 SpectrumValue& operator=(double rhs);
476
477 /**
478 *
479 * @param x the operand
480 *
481 * @return the euclidean norm, i.e., the sum of the squares of all
482 * the values in x
483 */
484 friend double Norm(const SpectrumValue& x);
485
486 /**
487 *
488 * @param x the operand
489 *
490 * @return the sum of all
491 * the values in x
492 */
493 friend double Sum(const SpectrumValue& x);
494
495 /**
496 * @param x the operand
497 *
498 * @return the product of all
499 * the values in x
500 */
501 friend double Prod(const SpectrumValue& x);
502
503 /**
504 *
505 *
506 * @param lhs the base
507 * @param rhs the exponent
508 *
509 * @return each value in base raised to the exponent
510 */
511 friend SpectrumValue Pow(const SpectrumValue& lhs, double rhs);
512
513 /**
514 *
515 * @param lhs the base
516 * @param rhs the exponent
517 *
518 * @return the value in base raised to each value in the exponent
519 */
520 friend SpectrumValue Pow(double lhs, const SpectrumValue& rhs);
521
522 /**
523 *
524 *
525 * @param arg the argument
526 *
527 * @return the logarithm in base 10 of all values in the argument
528 */
529 friend SpectrumValue Log10(const SpectrumValue& arg);
530
531 /**
532 *
533 *
534 * @param arg the argument
535 *
536 * @return the logarithm in base 2 of all values in the argument
537 */
538 friend SpectrumValue Log2(const SpectrumValue& arg);
539
540 /**
541 *
542 *
543 * @param arg the argument
544 *
545 * @return the logarithm in base e of all values in the argument
546 */
547 friend SpectrumValue Log(const SpectrumValue& arg);
548
549 /**
550 *
551 *
552 * @param arg the argument
553 *
554 * @return the value of the integral \f$\int_F g(f) df \f$
555 */
556 friend double Integral(const SpectrumValue& arg);
557
558 /**
559 *
560 * @return a Ptr to a copy of this instance
561 */
562 Ptr<SpectrumValue> Copy() const;
563
564 /**
565 * TracedCallback signature for SpectrumValue.
566 *
567 * \param [in] value Value of the traced variable.
568 * \deprecated The non-const \c Ptr<SpectrumPhy> argument
569 * is deprecated and will be changed to \c Ptr<const SpectrumPhy>
570 * in a future release.
571 */
572 typedef void (*TracedCallback)(Ptr<SpectrumValue> value);
573
574 private:
575 /**
576 * Add a SpectrumValue (element to element addition)
577 * \param x SpectrumValue
578 */
579 void Add(const SpectrumValue& x);
580 /**
581 * Add a flat value to all the current elements
582 * \param s flat value
583 */
584 void Add(double s);
585 /**
586 * Subtracts a SpectrumValue (element by element subtraction)
587 * \param x SpectrumValue
588 */
589 void Subtract(const SpectrumValue& x);
590 /**
591 * Subtracts a flat value to all the current elements
592 * \param s flat value
593 */
594 void Subtract(double s);
595 /**
596 * Multiplies for a SpectrumValue (element to element multiplication)
597 * \param x SpectrumValue
598 */
599 void Multiply(const SpectrumValue& x);
600 /**
601 * Multiplies for a flat value to all the current elements
602 * \param s flat value
603 */
604 void Multiply(double s);
605 /**
606 * Divides by a SpectrumValue (element to element division)
607 * \param x SpectrumValue
608 */
609 void Divide(const SpectrumValue& x);
610 /**
611 * Divides by a flat value to all the current elements
612 * \param s flat value
613 */
614 void Divide(double s);
615 /**
616 * Change the values sign
617 */
618 void ChangeSign();
619 /**
620 * Shift the values to the left
621 * \param n number of positions to shift
622 */
623 void ShiftLeft(int n);
624 /**
625 * Shift the values to the right
626 * \param n number of positions to shift
627 */
628 void ShiftRight(int n);
629 /**
630 * Modifies each element so that it each element is raised to the exponent
631 *
632 * \param exp the exponent
633 */
634 void Pow(double exp);
635 /**
636 * Modifies each element so that it is
637 * the base raised to each element value
638 *
639 * \param base the base
640 */
641 void Exp(double base);
642 /**
643 * Applies a Log10 to each the elements
644 */
645 void Log10();
646 /**
647 * Applies a Log2 to each the elements
648 */
649 void Log2();
650 /**
651 * Applies a Log to each the elements
652 */
653 void Log();
654
656
657 /**
658 * Set of values which implement the codomain of the functions in
659 * the Function Space defined by SpectrumValue. There is no restriction
660 * on what these values represent (a transmission power density, a
661 * propagation loss, etc.).
662 *
663 */
665};
666
667std::ostream& operator<<(std::ostream& os, const SpectrumValue& pvf);
668
669double Norm(const SpectrumValue& x);
670double Sum(const SpectrumValue& x);
671double Prod(const SpectrumValue& x);
672SpectrumValue Pow(const SpectrumValue& lhs, double rhs);
673SpectrumValue Pow(double lhs, const SpectrumValue& rhs);
677double Integral(const SpectrumValue& arg);
678
679} // namespace ns3
680
681#endif /* SPECTRUM_VALUE_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A template-based reference counting class.
size_t GetNumBands() const
Set of values corresponding to a given SpectrumModel.
friend SpectrumValue operator-(const SpectrumValue &lhs, const SpectrumValue &rhs)
subtraction operator
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
friend SpectrumValue operator+(const SpectrumValue &lhs, const SpectrumValue &rhs)
addition operator
friend double Prod(const SpectrumValue &x)
Bands::const_iterator ConstBandsEnd() const
void Divide(const SpectrumValue &x)
Divides by a SpectrumValue (element to element division)
friend double Norm(const SpectrumValue &x)
friend bool operator!=(const SpectrumValue &lhs, const SpectrumValue &rhs)
Compare two spectrum values.
friend double Integral(const SpectrumValue &arg)
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)
void SetValues(Values &&values)
Directly set the values by moving the values from the input std::vector<double>
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)
friend SpectrumValue operator/(const SpectrumValue &lhs, const SpectrumValue &rhs)
division component-by-component
Values & GetValues()
Provides the direct access to the underlying std::vector<double> that stores the spectrum values.
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.
friend bool operator==(const SpectrumValue &lhs, const SpectrumValue &rhs)
Compare two spectrum values.
void ShiftRight(int n)
Shift the values to the right.
friend SpectrumValue operator*(const SpectrumValue &lhs, const SpectrumValue &rhs)
multiplication component-by-component (Schur product)
void SetValues(Values &values)
Directly set the values using the std::vector<double>
const Values & GetValues() const
Provides the direct read-only access to the underlying std::vector<double> that stores the spectrum v...
friend double Sum(const SpectrumValue &x)
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.
Forward calls to a chain of Callback.
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SpectrumValue Pow(double lhs, const SpectrumValue &rhs)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
double Integral(const SpectrumValue &arg)
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)
std::vector< double > Values
Container for element values.
double Sum(const SpectrumValue &x)