Code_TYMPAN  4.4.0
Industrial site acoustic simulation
spectrum_matrix.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) 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.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
17 
18 namespace tympan
19 {
20 SpectrumMatrix::SpectrumMatrix(size_t nb_receptors, size_t nb_sources) : _nb_sources(nb_sources)
21 {
23 }
24 
25 SpectrumMatrix::SpectrumMatrix() : _nb_sources(0) {}
26 
28 {
29  // Build matrix
30  resize(matrix.data.size(), matrix._nb_sources);
31  // number of sources
32  _nb_sources = matrix._nb_sources;
33  // Copy spectra
34  for (size_t i = 0; i < data.size(); i++)
35  {
36  for (size_t j = 0; j < _nb_sources; j++)
37  {
38  data[i][j] = matrix.data[i][j];
39  }
40  }
41 }
42 
43 void SpectrumMatrix::resize(size_t nb_receptors, size_t nb_sources)
44 {
46 
47  if (data.size() > 0)
48  {
49  data.clear();
50  }
51 
52  data.reserve(nb_receptors);
53 
54  Spectrum nullSpectrum(0);
55  nullSpectrum.setType(SPECTRE_TYPE_LP);
56  nullSpectrum.setEtat(SPECTRE_ETAT_LIN);
57 
58  for (size_t i = 0; i < nb_receptors; i++)
59  {
60  data.push_back(std::vector<Spectrum>(nb_sources, nullSpectrum));
61  }
62 
63  assert(data.size() == nb_receptors);
64 }
65 
66 const Spectrum& SpectrumMatrix::operator()(size_t receptor_idx, size_t sources_idx) const
67 {
68  assert(receptor_idx < nb_receptors());
69  assert(sources_idx < nb_sources());
70  return data[receptor_idx][sources_idx];
71 }
72 
73 Spectrum& SpectrumMatrix::operator()(size_t receptor_idx, size_t sources_idx)
74 {
75  assert(receptor_idx < nb_receptors());
76  assert(sources_idx < nb_sources());
77  return data[receptor_idx][sources_idx];
78 }
79 
80 void SpectrumMatrix::setSpectre(size_t receptor_idx, size_t sources_idx, Spectrum spectrum)
81 {
82  assert(receptor_idx < nb_receptors());
83  assert(sources_idx < nb_sources());
84  data[receptor_idx][sources_idx] = spectrum;
85 }
86 
87 const std::vector<Spectrum>& SpectrumMatrix::by_receptor(size_t receptor_idx) const
88 {
89  assert(receptor_idx < nb_receptors());
90  return data[receptor_idx];
91 }
92 
94 {
95  assert(receptor_idx < nb_receptors());
96  data[receptor_idx].clear();
97 }
98 } // namespace tympan
void setEtat(TYSpectreEtat etat)
Force the spectrum state (to use carefully ...)
Definition: spectre.h:169
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:153
Spectrum matrix N*M used to store results. N is the number of receptors. M is the number of sources.
const std::vector< Spectrum > & by_receptor(size_t receptor_idx) const
Return a vector of Spectrum for a receptor.
size_t nb_sources() const
Number of columns (sources) of the matrix.
SpectrumMatrix()
Default constructor.
void clearReceptor(size_t receptor_idx)
Clear the matrix for the a given receptor.
size_t nb_receptors() const
Number of rows (receptors) of the matrix.
void setSpectre(size_t receptor_idx, size_t sources_idx, Spectrum spectrum)
Set a Spectrum into the matrix.
const Spectrum & operator()(size_t receptor_idx, size_t sources_idx) const
operator()
impl_matrix_t data
Matrix.
void resize(size_t nb_receptors, size_t nb_sources)
Resize the matrix (data is cleared)
size_t receptor_idx
Definition: entities.hpp:413
@ SPECTRE_ETAT_LIN
Definition: spectre.h:46
@ SPECTRE_TYPE_LP
Definition: spectre.h:31