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  tympan::LPSolverConfiguration configuration)
54 {
55  int nbTrajectsForOneSource = 0;
56  int nbTrajectsTotal = 0;
57  tympan::SolverConfiguration::set(configuration);
58  // Use grid accelerating structure instead of KDTree (default value)
60  "Overwriting Acccelerator solver parameter to 1 (grid accelerating structure)");
61  tympan::SolverConfiguration::get()->Accelerator = 1;
62  // Creation de la collection de thread
64 
65  // Creation du face selector
66  if (!_faceSelector)
67  {
69  }
70 
71  // Creation du path finder
73  {
75  }
76 
77  // Creation du acoustic model
79 
80  // On calcule la structure
81  if (buildCalcStruct(aproblem))
82  {
84  }
85  else
86  {
87  return false;
88  }
89 
90  // Initialisation du path finder
91  _acousticPathFinder->init();
92 
93  // Initialisation du acoustic model
94  /*_acousticModel->init();*/
96 
97  tympan::SpectrumMatrix& matrix = aresult.get_data();
98  matrix.resize(aproblem.nreceptors(), aproblem.nsources());
99  tab_acoustic_path& tabRays = aresult.get_path_data();
100  tabRays.clear();
101 
102  // construction trajets et ajout des taches associees
103  for (unsigned int i = 0; i < aproblem.nsources(); i++)
104  {
105  // On reset la thread pool
106  _pool->begin(static_cast<unsigned int>(aproblem.nreceptors()));
107  // reset deque and liberate memory
108  // _tabTrajets.clear();
109  clearTabTrajets();
110  nbTrajectsForOneSource = 0;
111 
112  for (unsigned int j = 0; j < aproblem.nreceptors(); j++)
113  {
114  addNewTaskForOneTrajetSrcRcp(aproblem, i, j, nbTrajectsForOneSource, nbTrajectsTotal);
115  nbTrajectsTotal++;
116  nbTrajectsForOneSource++;
117  }
118 
119  // launch threads
120  _pool->startPool();
121 
122  if (!_pool->end())
123  {
124  return false;
125  }
126 
127  // Displaying rays in the GUI
128  bool keepRays = tympan::SolverConfiguration::get()->KeepRays;
129  if (keepRays == true)
130  {
131  displayRaysInGUI(tabRays);
132  }
133 
134  buildResultsMatrix(nbTrajectsForOneSource, matrix);
135 
136  deleteTrajets();
137  }
138 
139  return true;
140 }
141 
142 void TYSolver::selectFaces(std::deque<TYSIntersection>& tabIntersect, const OSegment3D& rayon,
143  const string& sourceVolumeId)
144 {
145  getFaceSelector()->selectFaces(tabIntersect, _tabPolygon, rayon, sourceVolumeId);
146 }
147 
148 std::unique_ptr<TYFaceSelector> TYSolver::make_face_selector()
149 {
150  return std::unique_ptr<TYFaceSelector>(new TYFaceSelector());
151 }
152 
153 std::unique_ptr<TYAcousticPathFinder> TYSolver::make_path_finder()
154 {
155  return std::unique_ptr<TYAcousticPathFinder>(new TYAcousticPathFinder(*this));
156 }
157 
159 {
160  _tabPolygon.clear();
161  const tympan::nodes_pool_t& nodes = aproblem.nodes();
162  const tympan::triangle_pool_t& triangles = aproblem.triangles();
163 
164  _tabPolygon.reserve(triangles.size());
165 
166  OPoint3D pts[3];
167  for (unsigned int i = 0; i < triangles.size(); i++)
168  {
169  pts[0] = nodes[triangles[i].n[0]];
170  pts[1] = nodes[triangles[i].n[1]];
171  pts[2] = nodes[triangles[i].n[2]];
172 
174  OGeometrie::computeNormal(pts, 3, SI.normal);
175 
176  SI.volume_id = triangles[i].volume_id;
177  SI.tabPoint.push_back(pts[0]);
178  SI.tabPoint.push_back(pts[1]);
179  SI.tabPoint.push_back(pts[2]);
180  SI.material = triangles[i].made_of.get();
181 
182  _tabPolygon.push_back(SI);
183  }
184 
185  return true;
186 }
187 
189 {
190  if (_tabPolygon.empty())
191  {
192  return false;
193  }
194 
195  _scene->clean();
196 
197  Material* m = new Material(); // Only for compatibility, may be suppressed;
198 
199  vec3 pos;
200 
201  for (unsigned int i = 0; i < _tabPolygon.size(); i++)
202  {
203  // Recuperation et convertion de la normale de la surface
204 
205  unsigned int a, b, c;
206 
207  pos = OPoint3Dtovec3(_tabPolygon[i].tabPoint[0]);
208  _scene->addVertex(pos, a);
209 
210  pos = OPoint3Dtovec3(_tabPolygon[i].tabPoint[1]);
211  _scene->addVertex(pos, b);
212 
213  pos = OPoint3Dtovec3(_tabPolygon[i].tabPoint[2]);
214  _scene->addVertex(pos, c);
215 
216  if (dynamic_cast<tympan::AcousticGroundMaterial*>(_tabPolygon[i].material))
217  {
218  // Set last parameter true means triangle is part of the ground
219  (Triangle*)_scene->addTriangle(a, b, c, m, true);
220  }
221  else
222  {
223  (Triangle*)_scene->addTriangle(a, b, c, m);
224  }
225  }
226 
227  _scene->finish(); // Build accelerating structure
228 
229  return true;
230 }
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:163
void startPool()
Definition: threading.cpp:171
bool end()
End solver.
Definition: threading.cpp:181
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:143
std::unique_ptr< TYFaceSelector > _faceSelector
Pointer to the TYFaceSelector.
Definition: TYSolver.h:83
std::unique_ptr< TYAcousticPathFinder > make_path_finder()
TYAcousticPathFinder builder.
Definition: TYSolver.cpp:153
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:148
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:188
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:142
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:84
virtual bool solve(const tympan::AcousticProblemModel &aproblem, tympan::AcousticResultModel &aresult, tympan::LPSolverConfiguration configuration)
Launch the resolution and get the results.
Definition: TYSolver.cpp:52
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.
bool buildCalcStruct(const tympan::AcousticProblemModel &aproblem)
Definition: TYSolver.cpp:158
OThreadPool * _pool
Definition: TYSolver.h:145
TYFaceSelector * getFaceSelector()
Get the face selector.
Definition: TYSolver.h:56
std::unique_ptr< TYFaceSelector > make_face_selector()
TYFaceSelector builder.
Definition: TYSolver.cpp:148
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:214
Describe surface intersections.
tympan::AcousticMaterialBase * material
Reference to a material.
string volume_id
Volume id.
TabPoint3D tabPoint
Array of points used for the preselection.
OVector3D normal
Normal vector to a face.