Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYChemin.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 "TYChemin.h"
18 
19 TYChemin::TYChemin() : _typeChemin(TYTypeChemin::CHEMIN_DIRECT), _longueur(0.0), _distance(0.0)
20 {
21  _attenuations.clear();
22  _eq_path = new acoustic_path();
23 }
24 
26 {
27  *this = other;
28 }
29 
31 {
32  if (tympan::SolverConfiguration::get()->KeepRays == false && _eq_path != nullptr)
33  {
35  }
36  _attenuations.clear();
37 }
38 
40 {
41  if (this != &other)
42  {
43  _typeChemin = other._typeChemin;
44  _distance = other._distance;
45  _longueur = other._longueur;
46  _eq_path = other._eq_path;
48  }
49 
50  return *this;
51 }
52 
53 bool TYChemin::operator==(const TYChemin& other) const
54 {
55  if (this != &other)
56  {
57  if (_typeChemin != other._typeChemin)
58  {
59  return false;
60  }
61  if (_distance != other._distance)
62  {
63  return false;
64  }
65  if (_longueur != other._longueur)
66  {
67  return false;
68  }
69  if (_eq_path != other._eq_path)
70  {
71  return false;
72  };
73  if (_attenuations != other._attenuations)
74  {
75  return false;
76  }
77  }
78 
79  return true;
80 }
81 
82 bool TYChemin::operator!=(const TYChemin& other) const
83 {
84  return !operator==(other);
85 }
86 
87 void TYChemin::calcAttenuation(const TYTabEtape& tabEtapes, const AtmosphericConditions& atmos, double dp,
88  double hs, double hr, double Gs, double Gm, double Gr)
89 {
90  unsigned int i = 0;
91 
92  switch (_typeChemin)
93  {
96  tabEtapes[0]._Absorption; // S = Source directivity index
98  atmos.compute_length_absorption_oct(_longueur); // Aatm = alpha * d
99  calcGroundAttenuations(dp, hs, hr, Gs, Gm, Gr);
100  break;
101 
104  atmos.compute_length_absorption_oct(_longueur); // Aatm = alpha * d
105  calcGroundAttenuations(dp, hs, hr, Gs, Gm, Gr);
107  tabEtapes[0]._Absorption; // S = Source directivity index
108  // We multiply steps absorptions from second
110  for (i = 1; i < tabEtapes.size(); i++)
111  {
114  (OSpectreOctave(1.0) -
115  tabEtapes[i]._Absorption); // Product of directivty factor and reflexion coefficients
116  }
117  break;
118 
119  default:
120  break;
121  }
122 
123  build_eq_path(tabEtapes);
124 }
125 
126 void TYChemin::computeBarAttenuation(const OSpectreOctave& Dz, const bool vertical, const bool left)
127 {
128  if (vertical)
129  {
135  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
136  {
137  if (Agr.getTabValReel()[i] > 0)
138  {
140  Agr.getTabValReel()[i];
141  }
142  if (_attenuations[TYTypeAttenuation::ATTENUATION_BAR_TOP].getTabValReel()[i] < 0)
143  {
145  }
146  }
147  }
148  else
149  {
150  if (left)
151  {
154  }
155  else
156  {
159  }
160  }
161 }
162 
164 {
165  return _attenuations[type];
166 }
167 
168 void TYChemin::setAttenuationBarWhenNoPath(bool vertical, bool left)
169 {
170  if (vertical)
171  {
173  }
174  else
175  {
176  if (left)
177  {
179  }
180  else
181  {
183  }
184  }
185 }
186 
187 void TYChemin::build_eq_path(const TYTabEtape& tabEtapes)
188 {
189 
190  for (size_t i = 0; i < tabEtapes.size(); i++)
191  {
192  _eq_path->addEvent(tabEtapes[i].asEvent());
193  }
194 }
195 
197 {
198  acoustic_event* receptor_event = new acoustic_event();
199  receptor_event->pos = ptR;
200  receptor_event->type = TYRECEPTEUR;
201  _eq_path->addEvent(receptor_event);
202  return _eq_path;
203 }
204 
205 void TYChemin::calcGroundAttenuations(double dp, double hs, double hr, double Gs, double Gm, double Gr)
206 {
207  // Main method for flat ground or with constant slope
208  // Compute zones dimensions
209  bool bHasIntermediateZone = dp > 30 * (hs + hr);
210 
211  double q = 0.0;
212  if (bHasIntermediateZone)
213  {
214  q = 1 - 30 * (hs + hr) / dp;
215  }
216 
217  // Compute ground attenuations for source, receptor and middle zones
221 }
222 
223 OSpectreOctave TYChemin::calcGroundAttenuationSR(double dp, double h, double G)
224 {
225  double a = 1.5 + 3.0 * exp(-0.12 * (h - 5) * (h - 5)) * (1 - exp(-dp / 50.0)) +
226  5.7 * exp(-0.09 * h * h) * (1 - exp(-2.8 * pow(10, -6) * dp * dp));
227  double b = 1.5 + 8.6 * exp(-0.09 * h * h) * (1 - exp(-dp / 50.0));
228  double c = 1.5 + 14.0 * exp(-0.46 * h * h) * (1 - exp(-dp / 50.0));
229  double d = 1.5 + 5.0 * exp(-0.9 * h * h) * (1 - exp(-dp / 50.0));
230 
231  const double As[9]{-1.5, -1.5, -1.5 + G * a, -1.5 + G * b, -1.5 + G * c,
232  -1.5 + G * d, -1.5 * (1 - G), -1.5 * (1 - G), -1.5 * (1 - G)};
233  return OSpectreOctave{As, 9, 0};
234 }
235 
237 {
238  OSpectreOctave Agr_m = OSpectreOctave{0.0};
239  if (q != 0.0)
240  {
241  const double Am[9]{-3.0 * q, -3.0 * q, -3 * q * (1 - Gm),
242  -3 * q * (1 - Gm), -3 * q * (1 - Gm), -3 * q * (1 - Gm),
243  -3 * q * (1 - Gm), -3 * q * (1 - Gm), -3 * q * (1 - Gm)};
244  Agr_m = OSpectreOctave{Am, 9, 0};
245  }
246  return Agr_m;
247 }
248 
249 ::std::ostream& operator<<(::std::ostream& out, const TYTypeChemin& value)
250 {
251  static std::map<TYTypeChemin, std::string> strings;
252  if (strings.size() == 0)
253  {
254  strings[TYTypeChemin::CHEMIN_DIRECT] = "DIRECT";
255  strings[TYTypeChemin::CHEMIN_SOL] = "SOL";
256  strings[TYTypeChemin::CHEMIN_ECRAN] = "ECRAN";
257  strings[TYTypeChemin::CHEMIN_REFLEX] = "REFLEX";
258  }
259 
260  return out << strings[value];
261 }
::std::ostream & operator<<(::std::ostream &out, const TYTypeChemin &value)
Definition: TYChemin.cpp:249
TYTypeAttenuation
Definition: TYChemin.h:42
TYTypeChemin
Definition: TYChemin.h:32
std::deque< TYEtape > TYTabEtape
TYEtape collection.
Definition: TYEtape.h:193
Representation of one of the most optimal path between source and receptor: S—>R.
@ CHEMIN_DIRECT
Definition: TYChemin.h:33
NxReal c
Definition: NxVec3.cpp:317
@ TYRECEPTEUR
Definition: acoustic_path.h:29
Class for the definition of atmospheric conditions.
OSpectreOctave compute_length_absorption_oct(double length) const
The 3D point class.
Definition: 3d.h:487
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
OSpectreOctave calcGroundAttenuationM(double q, double Gm)
Definition: TYChemin.cpp:236
double _distance
Direct distance between source and receptor.
Definition: TYChemin.h:236
OSpectreOctave & getAttenuation()
Return the path attenuation.
Definition: TYChemin.h:134
void calcAttenuation(const TYTabEtape &tabEtapes, const AtmosphericConditions &atmos, double dp=0.0, double hs=0.0, double hr=0.0, double Gs=0.5, double Gm=0.5, double Gr=0.5)
Definition: TYChemin.cpp:87
void computeBarAttenuation(const OSpectreOctave &Dz, const bool vertical, const bool left)
Definition: TYChemin.cpp:126
TYChemin()
Constructor.
Definition: TYChemin.cpp:19
bool operator==(const TYChemin &other) const
Operator ==.
Definition: TYChemin.cpp:53
virtual ~TYChemin()
Destructor.
Definition: TYChemin.cpp:30
TYTypeChemin _typeChemin
Path type (has an influence on the algorithm)
Definition: TYChemin.h:230
acoustic_path * _eq_path
Equivalent acoustic_path.
Definition: TYChemin.h:246
bool operator!=(const TYChemin &other) const
Operator !=.
Definition: TYChemin.cpp:82
TYChemin & operator=(const TYChemin &other)
Operator =.
Definition: TYChemin.cpp:39
OSpectreOctave calcGroundAttenuationSR(double dp, double h, double G)
Definition: TYChemin.cpp:223
void calcGroundAttenuations(double distance, double hs, double hr, double Gs, double Gm, double Gr)
Definition: TYChemin.cpp:205
void build_eq_path(const TYTabEtape &tabEtapes)
Definition: TYChemin.cpp:187
std::map< TYTypeAttenuation, OSpectreOctave > _attenuations
Attenuations spectra of the path.
Definition: TYChemin.h:239
void setAttenuationBarWhenNoPath(bool vertical, bool left)
Set attenuation bar to max to traduce the lack of diffracted ray on this path.
Definition: TYChemin.cpp:168
acoustic_path * get_ray(OPoint3D ptR)
Definition: TYChemin.cpp:196
double _longueur
Total path length.
Definition: TYChemin.h:233
This class store data and provide functions to manipulate event in the acoustic context.
Definition: acoustic_path.h:40
ACOUSTIC_EVENT_TYPES type
Event type.
Definition: acoustic_path.h:60
OPoint3D pos
Event position.
Definition: acoustic_path.h:53
Acoustic path.
Definition: acoustic_path.h:78
virtual void cleanEventsTab()
clean tab of events
virtual void addEvent(acoustic_event *TYEvent)
Add an event to the events list of the ray.
static LPSolverConfiguration get()
Get the configuration.
Definition: config.cpp:93
This file provides class for solver configuration.