Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSolver.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 "Tympan/core/logging.h"
23 #include "TYSolver.h"
26 
28 {
29  // Creation du face selector
31 
32  // Creation du path finder
34 
35  _tabPolygon.clear();
36 
37  _scene = std::unique_ptr<Scene>(new Scene());
38 
39  // Creation de la collection de thread
40  _pool = NULL;
41 }
42 
44 {
45  if (_pool)
46  {
47  delete _pool;
48  }
49  _pool = NULL;
50 }
51 
53 {
54  // Creation du face selector
55  if (!_faceSelector)
56  {
58  }
59 
60  // Creation du path finder
62  {
64  }
65 
66  // Creation du acoustic model
68 }
69 
71  tympan::LPSolverConfiguration configuration)
72 {
73  int nbTrajectsForOneSource = 0;
74  int nbTrajectsTotal = 0;
75  tympan::SolverConfiguration::set(configuration);
76  // Use grid accelerating structure instead of KDTree (default value)
78  "Overwriting Acccelerator solver parameter to 1 (grid accelerating structure)");
79  tympan::SolverConfiguration::get()->Accelerator = 1;
80  // Creation de la collection de thread
82 
83  // Initialize solver
84  init();
85 
86  // On calcule la structure
87  if (buildCalcStruct(aproblem))
88  {
90  }
91  else
92  {
93  return false;
94  }
95 
96  // Initialisation du path finder
97  _acousticPathFinder->init();
98 
99  // Initialisation du acoustic model
100  /*_acousticModel->init();*/
102 
103  tympan::SpectrumMatrix& matrix = aresult.get_data();
104  matrix.resize(aproblem.nreceptors(), aproblem.nsources());
105  tab_acoustic_path& tabRays = aresult.get_path_data();
106  tabRays.clear();
107 
108  // construction trajets et ajout des taches associees
109  for (unsigned int i = 0; i < aproblem.nsources(); i++)
110  {
111  // On reset la thread pool
112  _pool->begin(static_cast<unsigned int>(aproblem.nreceptors()));
113  // reset deque and liberate memory
114  // _tabTrajets.clear();
115  clearTabTrajets();
116  nbTrajectsForOneSource = 0;
117 
118  for (unsigned int j = 0; j < aproblem.nreceptors(); j++)
119  {
120  addNewTaskForOneTrajetSrcRcp(aproblem, i, j, nbTrajectsForOneSource, nbTrajectsTotal);
121  nbTrajectsTotal++;
122  nbTrajectsForOneSource++;
123  }
124 
125  // launch threads
126  _pool->startPool();
127 
128  if (!_pool->end())
129  {
130  return false;
131  }
132 
133  // Displaying rays in the GUI
134  bool keepRays = tympan::SolverConfiguration::get()->KeepRays;
135  if (keepRays == true)
136  {
137  displayRaysInGUI(tabRays);
138  }
139 
140  buildResultsMatrix(nbTrajectsForOneSource, matrix);
141 
142  deleteTrajets();
143  }
144 
145  return true;
146 }
147 
148 void TYSolver::selectFaces(std::deque<TYSIntersection>& tabIntersect, const OSegment3D& rayon,
149  const string& sourceVolumeId)
150 {
151  getFaceSelector()->selectFaces(tabIntersect, _tabPolygon, rayon, sourceVolumeId);
152 }
153 
154 std::unique_ptr<TYFaceSelector> TYSolver::make_face_selector()
155 {
156  return std::unique_ptr<TYFaceSelector>(new TYFaceSelector());
157 }
158 
159 std::unique_ptr<TYAcousticPathFinder> TYSolver::make_path_finder()
160 {
161  return std::unique_ptr<TYAcousticPathFinder>(new TYAcousticPathFinder(*this));
162 }
163 
165 {
166  _tabPolygon.clear();
167  const tympan::nodes_pool_t& nodes = aproblem.nodes();
168  const tympan::triangle_pool_t& triangles = aproblem.triangles();
169 
170  _tabPolygon.reserve(triangles.size());
171 
172  OPoint3D pts[3];
173  for (unsigned int i = 0; i < triangles.size(); i++)
174  {
175  pts[0] = nodes[triangles[i].n[0]];
176  pts[1] = nodes[triangles[i].n[1]];
177  pts[2] = nodes[triangles[i].n[2]];
178 
180  OGeometrie::computeNormal(pts, 3, SI.normal);
181 
182  SI.volume_id = triangles[i].volume_id;
183  SI.tabPoint.push_back(pts[0]);
184  SI.tabPoint.push_back(pts[1]);
185  SI.tabPoint.push_back(pts[2]);
186  SI.material = triangles[i].made_of.get();
187  SI.pFaceGeomData = triangles[i].pFaceGeomData;
188 
189  _tabPolygon.push_back(SI);
190  }
191 
192  return true;
193 }
194 
196 {
197  if (_tabPolygon.empty())
198  {
199  return false;
200  }
201 
202  _scene->clean();
203 
204  Material* m = new Material(); // Only for compatibility, may be suppressed;
205 
206  vec3 pos;
207 
208  for (unsigned int i = 0; i < _tabPolygon.size(); i++)
209  {
210  // Recuperation et convertion de la normale de la surface
211 
212  unsigned int a, b, c;
213 
214  pos = OPoint3Dtovec3(_tabPolygon[i].tabPoint[0]);
215  _scene->addVertex(pos, a);
216 
217  pos = OPoint3Dtovec3(_tabPolygon[i].tabPoint[1]);
218  _scene->addVertex(pos, b);
219 
220  pos = OPoint3Dtovec3(_tabPolygon[i].tabPoint[2]);
221  _scene->addVertex(pos, c);
222 
223  if (dynamic_cast<tympan::AcousticGroundMaterial*>(_tabPolygon[i].material))
224  {
225  // Set last parameter true means triangle is part of the ground
226  (Triangle*)_scene->addTriangle(a, b, c, m, true);
227  }
228  else
229  {
230  (Triangle*)_scene->addTriangle(a, b, c, m);
231  }
232  }
233 
234  _scene->finish(); // Build accelerating structure
235 
236  return true;
237 }
NxReal c
Definition: NxVec3.cpp:317
std::vector< acoustic_path * > tab_acoustic_path
static void computeNormal(OPoint3D *pts, int nbPts, OVector3D &normal)
Computes the normal of the list of points.
Definition: 3d.cpp:1147
virtual void warning(const char *message,...)
Definition: logging.cpp:119
static OMessageManager * get()
Definition: logging.cpp:108
The 3D point class.
Definition: 3d.h:487
Class to define a segment.
Definition: 3d.h:1141
Slave threads collection.
Definition: threading.h:259
void begin(unsigned int count)
Begin solver.
Definition: threading.cpp:168
void startPool()
Definition: threading.cpp:176
bool end()
End solver.
Definition: threading.cpp:186
This class mainly define a mesh (list of Shape) used by the Simulation object.
Definition: Scene.h:51
Build the acoustic path for the 9613 family solvers.
Building class of the faces list.
virtual void selectFaces(std::deque< TYSIntersection > &tabIntersect, const std::vector< TYStructSurfIntersect > &tabPolygon, const OSegment3D &rayon, const string &sourceVolumeId)
Build the array of intersections.
virtual void clearTabTrajets()=0
Clear the specific array of TYTrajet depending on the solver.
std::vector< TYStructSurfIntersect > _tabPolygon
Vector of TYStructSurfIntersect.
Definition: TYSolver.h:149
std::unique_ptr< TYFaceSelector > _faceSelector
Pointer to the TYFaceSelector.
Definition: TYSolver.h:89
std::unique_ptr< TYAcousticPathFinder > make_path_finder()
TYAcousticPathFinder builder.
Definition: TYSolver.cpp:159
virtual void addNewTaskForOneTrajetSrcRcp(const tympan::AcousticProblemModel &aproblem, unsigned int src_index, unsigned int rcp_index, int nbTrajetsForThisSource, int nNbTrajets)=0
Instanciate a new task to compute a Trajet.
std::unique_ptr< Scene > _scene
Pointer to the Scene.
Definition: TYSolver.h:154
virtual ~TYSolver()
Destructor.
Definition: TYSolver.cpp:43
virtual void buildAcousticModel()=0
Build the acoustic model.
TYSolver()
Constructor.
Definition: TYSolver.cpp:27
bool appendTriangleToScene()
Convertion des triangles Tympan en primitives utilisables par ray tracer.
Definition: TYSolver.cpp:195
void selectFaces(std::deque< TYSIntersection > &tabIntersect, const OSegment3D &rayon, const string &sourceVolumeId)
Delegate to _faceSelector the build of the array of intersections.
Definition: TYSolver.cpp:148
virtual void buildResultsMatrix(int nSourceTrajetsNumber, tympan::SpectrumMatrix &matrix)=0
Build the matrix of the results for a given source and all the receptors These results are the result...
std::unique_ptr< TYAcousticPathFinder > _acousticPathFinder
Pointer to the TYAcousticPathFinder.
Definition: TYSolver.h:90
virtual bool solve(const tympan::AcousticProblemModel &aproblem, tympan::AcousticResultModel &aresult, tympan::LPSolverConfiguration configuration)
Launch the resolution and get the results.
Definition: TYSolver.cpp:70
virtual void deleteTrajets()=0
Delete all the Trajets.
virtual void displayRaysInGUI(tab_acoustic_path &tabRays)=0
Keep rays in tab in order to display them in GUI.
void init()
Initialize solver This method must be called after instantiation of a solver.
Definition: TYSolver.cpp:52
bool buildCalcStruct(const tympan::AcousticProblemModel &aproblem)
Definition: TYSolver.cpp:164
OThreadPool * _pool
Definition: TYSolver.h:151
TYFaceSelector * getFaceSelector()
Get the face selector.
Definition: TYSolver.h:62
std::unique_ptr< TYFaceSelector > make_face_selector()
TYFaceSelector builder.
Definition: TYSolver.cpp:154
virtual void initAcousticModel()=0
Initialize the acoustic model.
Triangle class.
Definition: Triangle.h:25
3D vector Vector defined with 3 float numbers
Definition: mathlib.h:114
Describes the ground material, a specific AcousticBuildingMaterial.
Definition: entities.hpp:91
Class to describe the acoustic problem.
size_t nsources() const
Return the total number of sources.
size_t nreceptors() const
Return the total number of receptors.
const nodes_pool_t & nodes() const
Return array of nodes.
const triangle_pool_t & triangles() const
Return array of triangles.
Contains the results of the model solved.
SpectrumMatrix & get_data()
Return the results matrix.
tab_acoustic_path & get_path_data()
Return the array of the acoustic paths.
static void set(LPSolverConfiguration config)
Set a configuration.
Definition: config.cpp:103
static LPSolverConfiguration get()
Get the configuration.
Definition: config.cpp:94
Spectrum matrix N*M used to store results. N is the number of receptors. M is the number of sources.
void resize(size_t nb_receptors, size_t nb_sources)
Resize the matrix (data is cleared)
Math library.
vec3 OPoint3Dtovec3(const OPoint3D &_p)
Converts a OPoint3D to vec3.
Definition: mathlib.h:446
boost::shared_ptr< SolverConfiguration > LPSolverConfiguration
Definition: interfaces.h:25
std::deque< Point > nodes_pool_t
std::deque< AcousticTriangle > triangle_pool_t
Array of AcousticTriangle.
Definition: entities.hpp:227
Describe surface intersections.
tympan::AcousticMaterialBase * material
Reference to a material.
string volume_id
Volume id.
TabPoint3D tabPoint
Array of points used for the preselection.
boost::shared_ptr< tympan::AcousticFaceGeomData > pFaceGeomData
OVector3D normal
Normal vector to a face.