Code_TYMPAN  4.4.0
Industrial site acoustic simulation
acoustic_path.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 
16 #include <vector>
17 #include <cassert>
19 #include "acoustic_path.h"
20 
22  : distNextEvent(0.0), distEndEvent(0.0), distPrevNext(0.0), angle(0.0), angletheta(0.0), type(TY_NO_TYPE),
23  idFace1(-9999), idFace2(-9999), previous(NULL), next(NULL), endEvent(NULL)
24 {
25 }
26 
28  : pos(pt), distNextEvent(0.0), distEndEvent(0.0), distPrevNext(0.0), angle(0.0), angletheta(0.0),
29  type(TY_NO_TYPE), idFace1(-9999), idFace2(-9999), previous(NULL), next(NULL), endEvent(NULL)
30 {
31 }
32 
34 {
35  *this = ev;
36 }
37 
39 {
40  if (previous)
41  delete previous;
42  if (next)
43  delete next;
44  if (endEvent)
45  delete endEvent;
46 }
47 
49 {
50  pos = other.pos;
52  distEndEvent = other.distEndEvent;
53  distPrevNext = other.distPrevNext;
54  angle = other.angle;
55  angletheta = other.angletheta;
56  type = other.type;
57  idFace1 = other.idFace1;
58  idFace2 = other.idFace2;
59  previous = other.previous;
60  next = other.next;
61  endEvent = other.endEvent;
62 
63  return *this;
64 }
65 
66 // ===================================================================================================================================================
67 
68 double acoustic_path::sampler_step = 20.0;
69 
71 
73 {
74  *this = ray;
75 }
76 
78 {
80 }
81 
83 {
84  for (unsigned int i = 0; i < _events.size(); i++)
85  {
86  if (_events[i] != NULL)
87  {
88  delete _events[i];
89  _events[i] = NULL;
90  }
91  }
92 
93  _events.clear();
94 }
95 
97 {
98  _identifiant = other.getIdentifiant();
99  source_idx = other.source_idx;
100  receptor_idx = other.receptor_idx;
103 
104  for (unsigned int i = 0; i < other._events.size(); i++)
105  {
106  _events.push_back(new acoustic_event(*(other._events.at(i))));
107  }
108 
109  return *this;
110 }
111 
113 {
114  assert(other);
115 
116  cleanEventsTab();
117 
118  _identifiant = other->_identifiant;
119  source_idx = other->source_idx;
120  receptor_idx = other->receptor_idx;
123 
124  for (size_t i = 0; i < other->getEvents().size(); i++)
125  {
126  addEvent(new acoustic_event(*(other->getEvents().at(i))));
127  }
128 
129  return true;
130 }
131 
132 void acoustic_path::setSource(unsigned int source_idx_, OPoint3D& globalPosition)
133 {
134  source_idx = source_idx_;
135  _posSourceGlobal = globalPosition;
136 }
137 
138 void acoustic_path::setRecepteur(unsigned int receptor_idx_, OPoint3D& globalPosition)
139 {
140  receptor_idx = receptor_idx_;
141  _posReceptGlobal = globalPosition;
142 }
143 
145 {
146  double length = 0.0;
147  for (unsigned int i = 0; i < _events.size(); i++)
148  {
149  length += _events.at(i)->distNextEvent;
150  }
151 
152  return length;
153 }
154 
155 std::vector<int> acoustic_path::getIndexOfEvents(const int& eventType) const
156 {
157  std::vector<int> eventsIndexList;
158  for (size_t i = 0; i < _events.size(); i++)
159  {
160  if (_events[i]->type & eventType)
161  {
162  eventsIndexList.push_back(static_cast<int>(i));
163  }
164  }
165 
166  return eventsIndexList;
167 }
168 
170 {
171  assert(tyRay);
172 
173  cleanEventsTab(); // Clean old tab of events
174 
175  const tab_acoustic_events& tabEvents = tyRay->getEvents();
176 
177  std::vector<int> tabIndexEvents = tyRay->getIndexOfEvents(eventType);
178 
179  for (unsigned int i = 0; i < tabIndexEvents.size(); i++)
180  {
181  addEvent(tabEvents.at(tabIndexEvents.at(i)));
182  }
183 }
184 
186 {
187  std::vector<int> idxList = getIndexOfEvents(eventType);
188 
189  unsigned int j = 0;
190  double length = 0.;
191  for (size_t i = 0; i < idxList.size() - 1; i++)
192  {
193  length = 0.;
194  j = idxList[i];
195  do
196  {
197  length += _events.at(j)->pos.distFrom(_events.at(j + 1)->pos);
198  j++;
199  } while (j != idxList[i + 1]);
200 
201  _events.at(idxList.at(i))->distNextEvent = length;
202  }
203 }
204 
206 {
207  for (unsigned int i = 1; i < _events.size() - 1; i++)
208  {
209  if (_events.at(i)->type & eventType)
210  {
211  OVector3D vec1(_events.at(i)->pos, _events.at(i - 1)->pos);
212  OVector3D vec2(_events.at(i)->pos, _events.at(i + 1)->pos);
213 
214  _events.at(i)->angle = (M_PI - vec1.angle(vec2)) / 2.;
215  }
216  }
217 }
218 
220 {
221  std::vector<int> tabIndex = getIndexOfEvents(TYREFLEXION | TYREFLEXIONSOL | TYRECEPTEUR);
222  unsigned int k = 0;
223 
224  for (unsigned int j = 0; j < _events.size() - 1; j++)
225  {
226  _events.at(j)->next = _events.at(j + 1);
227 
228  if (j > 0)
229  {
230  _events.at(j)->previous = _events.at(j - 1);
231  }
232  if (j == _events.size() - 2)
233  {
234  _events.at(j + 1)->previous = _events.at(j);
235  }
236 
237  if (j == tabIndex[k])
238  {
239  k++;
240  }
241 
242  _events.at(j)->endEvent = _events.at(tabIndex[k]);
243  }
244 }
245 
247 {
248  vec3 P0 = OPoint3Dtovec3(_events[0]->pos);
249  vec3 P1 = OPoint3Dtovec3(_events[1]->pos);
250  vec3 v0(P0, P1);
251  vec3 v1(v0);
252  vec3 v2(v0);
253  v1.z = 0;
254  v2.y = 0;
255  v0.normalize();
256  v1.normalize();
257  v2.normalize();
258 
259  // Angle phi
260  double result = v0 * v1;
261  int sign = v0.z > 0 ? 1 : -1;
262  double angle = ::acos(result) * sign;
263 
264  _events[0]->angle = angle;
265 
266  // Angle theta
267  result = v0 * v2;
268  sign = v0.y > 0 ? 1 : -1;
269  angle = ::acos(result) * sign;
270  angle = v0.x < 0 ? M_PI - angle : angle;
271 
272  _events[0]->angletheta = angle;
273 }
ACOUSTIC_EVENT_TYPES
Definition: acoustic_path.h:22
@ TYREFLEXION
Definition: acoustic_path.h:25
@ TYRECEPTEUR
Definition: acoustic_path.h:29
@ TY_NO_TYPE
Definition: acoustic_path.h:23
@ TYREFLEXIONSOL
Definition: acoustic_path.h:26
std::vector< acoustic_event * > tab_acoustic_events
Definition: acoustic_path.h:69
The 3D point class.
Definition: 3d.h:487
The 3D vector class.
Definition: 3d.h:298
double angle(const OVector3D &vector) const
Computes the angle between this vector and another vector.
Definition: 3d.cpp:243
This class store data and provide functions to manipulate event in the acoustic context.
Definition: acoustic_path.h:40
double distNextEvent
Distance between this event and the next one in TYRay's list of events.
Definition: acoustic_path.h:54
acoustic_event & operator=(const acoustic_event &other)
ACOUSTIC_EVENT_TYPES type
Event type.
Definition: acoustic_path.h:60
double distEndEvent
Definition: acoustic_path.h:55
double distPrevNext
Distance between event-1 and event +1.
Definition: acoustic_path.h:57
OPoint3D pos
Event position.
Definition: acoustic_path.h:53
int idFace1
Face id on which the event happens (reflection & diffraction)
Definition: acoustic_path.h:61
double angle
Ray incident angle (for a shooting angle - plan x,z -)
Definition: acoustic_path.h:58
int idFace2
Face id on which the event happens (diffraction only)
Definition: acoustic_path.h:62
acoustic_event * next
Pointer to the next event in TYRay's list of events.
Definition: acoustic_path.h:64
acoustic_event()
Default constructor.
~acoustic_event()
Destructor.
acoustic_event * endEvent
Definition: acoustic_path.h:65
double angletheta
Shooting angle on a horizontal plane (x,y)
Definition: acoustic_path.h:59
acoustic_event * previous
Pointer to the previous event in TYRay's list of events.
Definition: acoustic_path.h:63
Acoustic path.
Definition: acoustic_path.h:78
OPoint3D _posReceptGlobal
Receptor position in the global frame.
virtual void cleanEventsTab()
clean tab of events
virtual void addEvent(acoustic_event *TYEvent)
Add an event to the events list of the ray.
virtual ~acoustic_path()
Destructor.
virtual double getLength()
Return total length of the ray taking account of all events.
static double sampler_step
max size of step between events after spatial sampling
virtual bool deepCopy(acoustic_path *pOther)
Deep copy of a ray mainly the events tab.
unsigned int source_idx
Source id.
virtual unsigned int getIdentifiant() const
Get the ray id.
virtual void setNextDistance(ACOUSTIC_EVENT_TYPES eventType)
Compute distance between events of the type "eventType" and set distNextEvent to each event matching ...
virtual acoustic_path & operator=(const acoustic_path &other)
equal operator
virtual void setSource(unsigned int source_idx_, OPoint3D &globalPosition)
Set the ray source.
unsigned int _identifiant
Ray id.
OPoint3D _posSourceGlobal
Source position in the global frame.
acoustic_path()
Default constructor.
virtual void setRecepteur(unsigned int receptor_idx_, OPoint3D &globalPosition)
Set the ray receptor. The last polyline point is updated.
virtual std::vector< int > getIndexOfEvents(const int &eventType) const
return a tab of indexes of events of the same type in a ray you can merge two types of events (exampl...
void compute_shot_angle()
Compute shot angle from source.
unsigned int receptor_idx
Receptor id.
virtual void copyEvents(const acoustic_path *tyRay, ACOUSTIC_EVENT_TYPES eventType)
copy only events matching eventType to _events tab
void build_links_between_events()
TYRayEvent has to know is direct neighbourg (before and after him)
tab_acoustic_events _events
Events vector containing the events list (and their positions) of the associated ray.
virtual tab_acoustic_events & getEvents()
Get the events list of the ray.
virtual void setAngles(ACOUSTIC_EVENT_TYPES eventType)
Compute angles of incoming ray segment at event point.
3D vector Vector defined with 3 float numbers
Definition: mathlib.h:114
base_t normalize(void)
Definition: mathlib.h:250
2D Vector Vector defined with 2 float numbers
Definition: mathlib.h:479
#define M_PI
Pi.
Definition: color.cpp:25
Math library.
vec3 OPoint3Dtovec3(const OPoint3D &_p)
Converts a OPoint3D to vec3.
Definition: mathlib.h:446