Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTrajet.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #include "TYTrajet.h"
18 
20  : asrc(asrc_), arcpt(arcpt_), _distance(0.0)
21 {
22  _ptS = asrc.position;
25  // build_tab_rays();
26 }
27 
28 TYTrajet::TYTrajet(const TYTrajet& other) : asrc(other.asrc), arcpt(other.arcpt)
29 {
30  *this = other;
31  if (tympan::SolverConfiguration::get()->KeepRays == false)
32  {
33  for (unsigned int i = 0; i < _tabRays.size(); i++)
34  {
35  delete _tabRays.at(i);
36  _tabRays.at(i) = nullptr;
37  }
38  _tabRays.clear();
39  }
40 }
41 
43 {
44  reset();
45 }
46 
48 {
49  _chemins.clear();
50  _cheminsDirect.clear();
51 }
52 
54 {
55  if (this != &other)
56  {
57  _chemins = other._chemins;
58  _ptS = other._ptS;
59  _ptR = other._ptR;
60  _distance = other._distance;
61  _sLP = other._sLP;
62  asrc = other.asrc;
63  arcpt = other.arcpt;
64  asrc_idx = other.asrc_idx;
65  arcpt_idx = other.arcpt_idx;
66  }
67  return *this;
68 }
69 
70 bool TYTrajet::operator==(const TYTrajet& other) const
71 {
72  if (this != &other)
73  {
74  if (_chemins != other._chemins)
75  {
76  return false;
77  }
78  if (_ptS != other._ptS)
79  {
80  return false;
81  }
82  if (_ptR != other._ptR)
83  {
84  return false;
85  }
86  if (_distance != other._distance)
87  {
88  return false;
89  }
90  if (_sLP != other._sLP)
91  {
92  return false;
93  };
94  // if (asrc != other.asrc) { return false; };
95  // if (arcpt != other.arcpt) ;
96  if (asrc_idx != other.asrc_idx)
97  {
98  return false;
99  };
100  if (arcpt_idx != other.arcpt_idx)
101  {
102  return false;
103  };
104  }
105 
106  return true;
107 }
108 
109 bool TYTrajet::operator!=(const TYTrajet& other) const
110 {
111  return !operator==(other);
112 }
113 
114 void TYTrajet::addChemin(const TYChemin& chemin)
115 {
116  _chemins.push_back(chemin);
117 }
118 
120 {
121  _cheminsDirect.push_back(chemin);
122 }
123 
125 {
126  return _chemins[0].getAttenuation();
127 }
128 
130 {
132  OSpectreOctave sTemp;
133  int firstReflex = -1;
134  unsigned int indiceDebutEffetEcran = 0;
135  unsigned int i;
136 
137  // On calcule l'attenuation sur le trajet direct (sauf chemins reflechis).
138  for (i = 0; i < this->_chemins.size(); i++)
139  {
140  // Si un ecran est present, on ne traite pas les reflexions (dans un premier temp ...)
141  if ((_chemins[0].getType() == TYTypeChemin::CHEMIN_ECRAN) &&
142  (_chemins[i].getType() == TYTypeChemin::CHEMIN_REFLEX))
143  {
144  firstReflex = i;
145  break;
146  }
147  sTemp = _chemins[i].getAttenuation();
148  s = s + sTemp * sTemp; // somme des carres des modules
149  }
150 
151  // Dans le cas d'un ecran, on compare l'attenuation obtenue a celle du trajet direct
152  // pour eviter les effets d'amplification (plus de bruit avec l'ecran que sans ecran ...)
153  if (_chemins[0].getType() == TYTypeChemin::CHEMIN_ECRAN)
154  {
156 
157  for (i = 0; i < _cheminsDirect.size(); i++)
158  {
159  sTemp = _cheminsDirect[i].getAttenuation();
160  attDirect = attDirect + sTemp * sTemp;
161  }
162 
163  // On regarde l'attenuation globale obtenue pour chaque frequence,
164  // on la compare a celle obtenue sur le trajet sans ecran,
165  // si elle est superieure a 1 alors on prend la valeur obtenue pour le trajet sans ecran
166  for (i = 0; i < s.getNbValues(); i++)
167  {
168  if (s.getTabValReel()[i] < attDirect.getTabValReel()[i])
169  {
170  indiceDebutEffetEcran = i; // On prend note de l'indice
171  break; // Si l'ecran commence a attenuer plus que le trajet direct, il faut sortir de la
172  // boucle
173  }
174  } //*/
175 
176  if (firstReflex != -1) // S'il y a une reflexion sur un ecran
177  {
178  // On rajoute la contribution des chemins reflechis
179  // 1. Aux chemins normaux et aux chemins directs
180  for (i = firstReflex; i < _chemins.size(); i++)
181  {
182  sTemp = _chemins[i].getAttenuation() * _chemins[i].getAttenuation();
183  s = s + sTemp;
184  attDirect = attDirect + sTemp;
185  }
186 
187  // On remplace la contribution du trajet direct pour toutes les frequences ou cela est necessaire
188  for (i = 0; i < indiceDebutEffetEcran; i++)
189  {
190  s.getTabValReel()[i] = attDirect.getTabValReel()[i];
191  }
192  }
193  }
194  build_tab_rays();
195  return s;
196 }
197 
199 {
200  _tabRays.clear();
201  for (size_t i = 0; i < _chemins.size(); i++)
202  {
203  _tabRays.push_back(_chemins[i].get_ray(_ptR));
204  }
205 }
206 
207 std::vector<acoustic_path*>& TYTrajet::get_tab_rays()
208 {
209  return _tabRays;
210 }
NxReal s
Definition: NxVec3.cpp:317
Class for the definition of atmospheric conditions.
double distFrom(const OPoint3D &pt) const
Computes the distance from this point to another.
Definition: 3d.cpp:371
static OSpectreOctave getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
Definition: spectre.cpp:1616
double * getTabValReel() override
Get an array of the real values of the spectrum.
Definition: spectre.h:613
Representation of one of the most optimal path between source and receptor: S—>R. The class TYChemin ...
Definition: TYChemin.h:71
This class TYTrajet (journey) links a couple Source-Receptor and a collection of paths,...
Definition: TYTrajet.h:35
tympan::AcousticReceptor & arcpt
Business receptor.
Definition: TYTrajet.h:229
OPoint3D _ptS
Source point definition in the site frame.
Definition: TYTrajet.h:235
OSpectreOctave getPEnergetique(const AtmosphericConditions &atmos)
Compute the acoustic pressure in octave bands on the journey.
Definition: TYTrajet.cpp:129
OPoint3D _ptR
Receptor point definition in the site frame.
Definition: TYTrajet.h:238
void build_tab_rays()
Definition: TYTrajet.cpp:198
TYTabChemin _chemins
Paths collection.
Definition: TYTrajet.h:241
void addCheminDirect(const TYChemin &chemin)
Add a new path to the array of direct paths.
Definition: TYTrajet.cpp:119
TYTrajet & operator=(const TYTrajet &other)
Operator =.
Definition: TYTrajet.cpp:53
OSpectreOctave getPNoOp()
Return the attenuation without computation (computed by an external function)
Definition: TYTrajet.cpp:124
void addChemin(const TYChemin &chemin)
Add a new path.
Definition: TYTrajet.cpp:114
std::vector< acoustic_path * > _tabRays
Vector of rays equivalent to chemin.
Definition: TYTrajet.h:254
bool operator!=(const TYTrajet &other) const
Operator !=.
Definition: TYTrajet.cpp:109
tympan::source_idx asrc_idx
Definition: TYTrajet.h:226
OSpectreOctave _sLP
Definition: TYTrajet.h:251
TYTabChemin _cheminsDirect
Direct paths collection (without obstacles)
Definition: TYTrajet.h:244
virtual ~TYTrajet()
Destructor.
Definition: TYTrajet.cpp:42
tympan::receptor_idx arcpt_idx
Definition: TYTrajet.h:230
void reset()
Reset method.
Definition: TYTrajet.cpp:47
tympan::AcousticSource & asrc
Business source.
Definition: TYTrajet.h:225
std::vector< acoustic_path * > & get_tab_rays()
Definition: TYTrajet.cpp:207
double _distance
Distance between source and receptor.
Definition: TYTrajet.h:247
bool operator==(const TYTrajet &other) const
Operator ==.
Definition: TYTrajet.cpp:70
TYTrajet(tympan::AcousticSource &asrc_, tympan::AcousticReceptor &arcpt_)
Constructor.
Definition: TYTrajet.cpp:19
Describes an acoustic receptor.
Definition: entities.hpp:388
Point position
Destructor.
Definition: entities.hpp:392
Describes an acoustic source.
Definition: entities.hpp:366
Point position
Destructor.
Definition: entities.hpp:371
static LPSolverConfiguration get()
Get the configuration.
Definition: config.cpp:93
This file provides class for solver configuration.