Code_TYMPAN  4.4.0
Industrial site acoustic simulation
acoustic_path.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2014> <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 <vector>
17 #include <cassert>
20 #include "acoustic_path.h"
21 
23  : distNextEvent(0.0), distEndEvent(0.0), distPrevNext(0.0), angle(0.0), angletheta(0.0), type(TY_NO_TYPE),
24  idFace1(-9999), idFace2(-9999), previous(NULL), next(NULL), endEvent(NULL)
25 {
26 }
27 
29  : pos(pt), distNextEvent(0.0), distEndEvent(0.0), distPrevNext(0.0), angle(0.0), angletheta(0.0),
30  type(TY_NO_TYPE), idFace1(-9999), idFace2(-9999), previous(NULL), next(NULL), endEvent(NULL)
31 {
32 }
33 
35 {
36  *this = ev;
37 }
38 
40 {
41  if (previous)
42  delete previous;
43  if (next)
44  delete next;
45  if (endEvent)
46  delete endEvent;
47 }
48 
50 {
51  pos = other.pos;
53  distEndEvent = other.distEndEvent;
54  distPrevNext = other.distPrevNext;
55  angle = other.angle;
56  angletheta = other.angletheta;
57  type = other.type;
58  idFace1 = other.idFace1;
59  idFace2 = other.idFace2;
60  previous = other.previous;
61  next = other.next;
62  endEvent = other.endEvent;
63 
64  return *this;
65 }
66 
67 // ===================================================================================================================================================
68 
69 double acoustic_path::sampler_step = 20.0;
70 
72 
74 {
75  *this = ray;
76 }
77 
79 {
81 }
82 
84 {
85  for (unsigned int i = 0; i < _events.size(); i++)
86  {
87  if (_events[i] != NULL)
88  {
89  delete _events[i];
90  _events[i] = NULL;
91  }
92  }
93 
94  _events.clear();
95 }
96 
98 {
99  _identifiant = other.getIdentifiant();
100  source_idx = other.source_idx;
101  receptor_idx = other.receptor_idx;
104 
105  for (unsigned int i = 0; i < other._events.size(); i++)
106  {
107  _events.push_back(new acoustic_event(*(other._events.at(i))));
108  }
109 
110  return *this;
111 }
112 
114 {
115  assert(other);
116 
117  cleanEventsTab();
118 
119  _identifiant = other->_identifiant;
120  source_idx = other->source_idx;
121  receptor_idx = other->receptor_idx;
124 
125  for (size_t i = 0; i < other->getEvents().size(); i++)
126  {
127  addEvent(new acoustic_event(*(other->getEvents().at(i))));
128  }
129 
130  return true;
131 }
132 
133 void acoustic_path::setSource(unsigned int source_idx_, OPoint3D& globalPosition)
134 {
135  source_idx = source_idx_;
136  _posSourceGlobal = globalPosition;
137 }
138 
139 void acoustic_path::setRecepteur(unsigned int receptor_idx_, OPoint3D& globalPosition)
140 {
141  receptor_idx = receptor_idx_;
142  _posReceptGlobal = globalPosition;
143 }
144 
146 {
147  double length = 0.0;
148  for (unsigned int i = 0; i < _events.size(); i++)
149  {
150  length += _events.at(i)->distNextEvent;
151  }
152 
153  return length;
154 }
155 
156 std::vector<int> acoustic_path::getIndexOfEvents(const int& eventType) const
157 {
158  std::vector<int> eventsIndexList;
159  for (size_t i = 0; i < _events.size(); i++)
160  {
161  if (_events[i]->type & eventType)
162  {
163  eventsIndexList.push_back(static_cast<int>(i));
164  }
165  }
166 
167  return eventsIndexList;
168 }
169 
171 {
172  assert(tyRay);
173 
174  cleanEventsTab(); // Clean old tab of events
175 
176  const tab_acoustic_events& tabEvents = tyRay->getEvents();
177 
178  std::vector<int> tabIndexEvents = tyRay->getIndexOfEvents(eventType);
179 
180  for (unsigned int i = 0; i < tabIndexEvents.size(); i++)
181  {
182  addEvent(tabEvents.at(tabIndexEvents.at(i)));
183  }
184 }
185 
187 {
188  std::vector<int> idxList = getIndexOfEvents(eventType);
189 
190  unsigned int j = 0;
191  double length = 0.;
192  for (size_t i = 0; i < idxList.size() - 1; i++)
193  {
194  length = 0.;
195  j = idxList[i];
196  do
197  {
198  length += _events.at(j)->pos.distFrom(_events.at(j + 1)->pos);
199  j++;
200  } while (j != idxList[i + 1]);
201 
202  _events.at(idxList.at(i))->distNextEvent = length;
203  }
204 }
205 
207 {
208  for (unsigned int i = 1; i < _events.size() - 1; i++)
209  {
210  if (_events.at(i)->type & eventType)
211  {
212  OVector3D vec1(_events.at(i)->pos, _events.at(i - 1)->pos);
213  OVector3D vec2(_events.at(i)->pos, _events.at(i + 1)->pos);
214 
215  _events.at(i)->angle = (M_PI - vec1.angle(vec2)) / 2.;
216  }
217  }
218 }
219 
221 {
222  std::vector<int> tabIndex = getIndexOfEvents(TYREFLEXION | TYREFLEXIONSOL | TYRECEPTEUR);
223  unsigned int k = 0;
224 
225  for (unsigned int j = 0; j < _events.size() - 1; j++)
226  {
227  _events.at(j)->next = _events.at(j + 1);
228 
229  if (j > 0)
230  {
231  _events.at(j)->previous = _events.at(j - 1);
232  }
233  if (j == _events.size() - 2)
234  {
235  _events.at(j + 1)->previous = _events.at(j);
236  }
237 
238  if (j == tabIndex[k])
239  {
240  k++;
241  }
242 
243  _events.at(j)->endEvent = _events.at(tabIndex[k]);
244  }
245 }
246 
248 {
249  vec3 P0 = OPoint3Dtovec3(_events[0]->pos);
250  vec3 P1 = OPoint3Dtovec3(_events[1]->pos);
251  vec3 v0(P0, P1);
252  vec3 v1(v0);
253  vec3 v2(v0);
254  v1.z = 0;
255  v2.y = 0;
256  v0.normalize();
257  v1.normalize();
258  v2.normalize();
259 
260  // Angle phi
261  double result = v0 * v1;
262  int sign = v0.z > 0 ? 1 : -1;
263  double angle = ::acos(result) * sign;
264 
265  _events[0]->angle = angle;
266 
267  // Angle theta
268  result = v0 * v2;
269  sign = v0.y > 0 ? 1 : -1;
270  angle = ::acos(result) * sign;
271  angle = v0.x < 0 ? M_PI - angle : angle;
272 
273  _events[0]->angletheta = angle;
274 }
All base classes related to 3D manipulation.
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:108
base_t normalize(void)
Definition: mathlib.h:244
2D Vector Vector defined with 2 float numbers
Definition: mathlib.h:473
#define M_PI
Pi.
Definition: color.cpp:25
Math library.
vec3 OPoint3Dtovec3(const OPoint3D &_p)
Converts a OPoint3D to vec3.
Definition: mathlib.h:440