Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticModel.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 <deque>
17 #include <list>
18 #include <cmath>
19 #include <algorithm>
20 #include "Tympan/core/defines.h"
26 #include "TYAcousticModel.h"
27 
29 
31  : _useSol(true), _useReflex(false), _propaCond(0), _interference(false), _paramH(10.0)
32 {
33 }
34 
36 
38 {
40  // Calcul avec sol reel
41  _useSol = config->UseRealGround;
42  // Calcul avec reflexion sur les parois verticales
43  _useReflex = config->UseReflection;
44  // Calcul en conditions favorables
45  _propaCond = config->PropaConditions;
46  // Definit l'atmosphere courante du site
47  double pression = config->AtmosPressure;
48  double temperature = config->AtmosTemperature;
49  double hygrometrie = config->AtmosHygrometry;
50 
52  std::unique_ptr<AtmosphericConditions>(new AtmosphericConditions(pression, temperature, hygrometrie));
53  // Calcul avec interference
54  _interference = config->ModSummation;
55  // Compute wave length
57  // Coefficient multiplicateur pour le calcul des reflexions supplementaires en condition favorable
58  _paramH = config->H1parameter;
59 }
60 
62 {
63  OPoint3D pt1{penteMoyenne._ptA};
64  OPoint3D pt2{penteMoyenne._ptB};
65  OPoint3D pt3{};
66  pt3._z = pt1._z;
67 
68  if (pt2._x != pt1._x)
69  {
70  pt3._y = pt1._y + 1;
71  pt3._x = (pt1._y - pt2._y) * (pt3._y - pt1._y) / (pt2._x - pt1._x) + (pt1._x);
72  }
73  else
74  {
75  if (pt1._y != pt2._y)
76  {
77  pt3._x = pt1._x + 1;
78  pt3._y = (pt2._x - pt1._x) * (pt3._x - pt1._x) / (pt1._y - pt2._y) + (pt1._y);
79  }
80  else // pt1 and pt2 coincide, we shift pt2, building an horizontal plane
81  {
82  pt2._x = pt1._x + 1;
83  pt2._y = pt1._y - 1;
84  pt3._y = pt1._y + 1;
85  pt3._x = (pt1._y - pt2._y) * (pt3._y - pt1._y) / (pt2._x - pt1._x) + (pt1._x);
86  }
87  }
88 
89  return OPlan{pt1, pt2, pt3};
90 }
91 
92 void TYAcousticModel::meanSlope(const OSegment3D& director, OSegment3D& slope) const
93 {
94  // Search for primitives under the two segment extremities
95 
96  // To begin : initialize slope
97  slope = director;
98  TYSolver& solver = getSolver();
99 
100  // first one
101  OPoint3D pt = director._ptA;
102  pt._z += 1000.;
103  vec3 start = OPoint3Dtovec3(pt);
104  Ray ray1(start, vec3(0., 0., -1.));
105 
106  std::list<Intersection> LI;
107 
108  double distance1 = static_cast<double>(solver.getScene()->getAccelerator()->traverse(&ray1, LI));
109  assert(distance1 > 0.);
110  assert(!LI.empty());
111 
112  unsigned int indexFace = LI.begin()->p->getPrimitiveId();
113 
114  // Avoid cases where the extremities are above infrastructure elements
115  while (solver.getTabPolygon()[indexFace].is_infra())
116  {
117  start.z = (decimal)std::min(std::min(solver.getTabPolygon()[indexFace].tabPoint[0]._z,
118  solver.getTabPolygon()[indexFace].tabPoint[1]._z),
119  solver.getTabPolygon()[indexFace].tabPoint[2]._z);
120  Ray ray(start, vec3(0, 0, -1));
121  ray.setMaxt(20000);
122  std::list<Intersection> LI2;
123  double distance = static_cast<double>(solver.getScene()->getAccelerator()->traverse(&ray, LI2));
124  // assert(distance > 0.);
125  if (LI2.empty() || distance < 0.)
126  break;
127  distance1 += distance;
128  indexFace = LI2.begin()->p->getPrimitiveId();
129  }
130 
131  // Second one
132  LI.clear();
133  pt = director._ptB;
134  pt._z += 1000.;
135  start = OPoint3Dtovec3(pt);
136  Ray ray2(start, vec3(0., 0., -1.));
137 
138  double distance2 = static_cast<double>(solver.getScene()->getAccelerator()->traverse(&ray2, LI));
139  // An error can occur if some elements are outside of the grip (emprise)
140  assert(distance2 > 0.);
141  assert(!LI.empty());
142 
143  indexFace = LI.begin()->p->getPrimitiveId();
144 
145  // Avoid cases where the extremities are above infrastructure elements
146  while (solver.getTabPolygon()[indexFace].is_infra())
147  {
148  start.z = (decimal)std::min(std::min(solver.getTabPolygon()[indexFace].tabPoint[0]._z,
149  solver.getTabPolygon()[indexFace].tabPoint[1]._z),
150  solver.getTabPolygon()[indexFace].tabPoint[2]._z);
151  Ray ray(start, vec3(0, 0, -1));
152  ray.setMaxt(20000);
153  std::list<Intersection> LI2;
154  double distance = static_cast<double>(solver.getScene()->getAccelerator()->traverse(&ray, LI2));
155  // assert(distance > 0.);
156  if (LI2.empty() || distance < 0.)
157  break;
158  distance2 += distance;
159  indexFace = LI2.begin()->p->getPrimitiveId();
160  }
161 
162  // Compute projection on the ground of segment points suppose sol is under the points ...
163  slope._ptA._z = director._ptA._z - (distance1 - 1000.);
164  slope._ptB._z = director._ptB._z - (distance2 - 1000.);
165 }
#define min(a, b)
Representation of one of the most optimal path between source and receptor: S—>R.
virtual decimal traverse(Ray *r, std::list< Intersection > &result) const
Run this accelerator.
Definition: Accelerator.h:68
Class for the definition of atmospheric conditions.
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:31
The 3D point class.
Definition: 3d.h:487
Class to define a segment.
Definition: 3d.h:1141
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1253
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1255
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Definition: Ray.h:38
void setMaxt(decimal _maxt)
set the maxt
Definition: Ray.h:406
Accelerator * getAccelerator() const
Get the accelerator.
Definition: Scene.h:82
void init()
Initialize the acoustic model.
std::unique_ptr< AtmosphericConditions > _pSolverAtmos
virtual TYSolver & getSolver() const =0
void meanSlope(const OSegment3D &director, OSegment3D &slope) const
Create a segment corresponding to the projection of "director" segment on the ground.
virtual ~TYAcousticModel()
OPlan buildMeanSlopePlan(const OSegment3D &penteMoyenne) const
virtual void computeWaveLength()=0
Compute the wave length for the considered solver.
Class which represents the Solver for 9613 family solvers.
Definition: TYSolver.h:36
const Scene * getScene() const
Get the Scene.
Definition: TYSolver.h:71
const std::vector< TYStructSurfIntersect > & getTabPolygon() const
Get the array of polygons.
Definition: TYSolver.h:57
3D vector Vector defined with 3 float numbers
Definition: mathlib.h:114
static LPSolverConfiguration get()
Get the configuration.
Definition: config.cpp:94
This file provides class for solver configuration.
Math library.
float decimal
Definition: mathlib.h:45
vec3 OPoint3Dtovec3(const OPoint3D &_p)
Converts a OPoint3D to vec3.
Definition: mathlib.h:446
base_vec3< decimal > vec3
Definition: mathlib.h:387
boost::shared_ptr< SolverConfiguration > LPSolverConfiguration
Definition: interfaces.h:25