Code_TYMPAN  4.2.0
Industrial site acoustic simulation
TYANIME3DSolver.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <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 <iostream>
17 #include <sstream>
18 #include <cmath>
19 #include <vector>
20 
30 #include "TYANIME3DSolver.h"
31 
32 //#define __ONLY_RAYS__ // To test only raytracing without acoustics
33 
35 {
36  _tabPolygon = NULL;
37 }
38 
40 {
41  purge();
42 }
43 
45 {
46  if (_tabPolygon)
47  {
48  delete [] _tabPolygon;
49  }
50 
51  _tabPolygon = NULL;
52 }
53 
55 {
57  _pAtmos = std::unique_ptr<AtmosphericConditions>( new AtmosphericConditions(config->AtmosPressure, config->AtmosTemperature, config->AtmosHygrometry) );
58 }
59 
62  tympan::LPSolverConfiguration configuration)
63 {
64  tympan::SolverConfiguration::set(configuration);
66  // Recupration (once for all) des sources et des rcepteurs
67  init();
68 
69  // Recuperation du tableau de rayon de la structure resultat
70  tab_acoustic_path& tabRays = aresult.get_path_data();
71 
72  // Construction de la liste des faces utilise pour le calcul
73  TYANIME3DFaceSelector fs(aproblem);
74  bool bRet = fs.exec(_tabPolygon, _tabPolygonSize);
75  if (!bRet) { return false; }
76 
77  // Ray tracing computation
79  if ( !apf.exec() ) { return false; }
80 
81 #ifndef __ONLY_RAYS__
82 
84  // Calculs acoustiques sur les rayons via la methode ANIME3D
86 
87 
88  TYANIME3DAcousticModel aam(tabRays, _tabPolygon, aproblem, *_pAtmos);
89 
90  // calcul de la matrice de pression totale pour chaque couple (S,R)
91  OTab2DSpectreComplex tabSpectre = aam.ComputeAcousticModel();
92  OSpectre sLP; // spectre de pression pour chaque couple (S,R)
93 
94  tympan::SpectrumMatrix& matrix = aresult.get_data();
95  matrix.resize(aproblem.nreceptors(), aproblem.nsources());
96 
97  for (int i = 0; i < static_cast<int>(aproblem.nsources()); i++) // boucle sur les sources
98  {
99  for (int j = 0; j < static_cast<int>(aproblem.nreceptors()); j++) // boucle sur les recepteurs
100  {
101  tabSpectre[i][j].setEtat(SPECTRE_ETAT_LIN);
102  tabSpectre[i][j].setType(SPECTRE_TYPE_LP);
103 
104  matrix(j, i) = tabSpectre[i][j];
105  }
106  }
107 
108 #else
109 
110  tympan::SpectrumMatrix& matrix = aresult.get_data();
111  matrix.resize(aproblem.nreceptors(), aproblem.nsources());
112 
113  size_t nb_srcs = aproblem.nsources();
114  size_t nb_rcpt = aproblem.nreceptors();
115 
116  for (int i = 0; i < static_cast<int>(aproblem.nsources()); i++) // boucle sur les sources
117  {
118  for (int j = 0; j < static_cast<int>(aproblem.nreceptors()); j++) // boucle sur les recepteurs
119  {
120  tympan::Spectrum sLP;
122 
123  matrix(j, i) = sLP;
124  }
125  }
126 
127 #endif //__ONLY_RAYS__
128 
129  // Do not keep rays (for a noise map for example)
130  if (config->Anime3DKeepRays == false) { tabRays.clear(); }
131 
132  // Curve rays (as in meteo field) if meteo is activated
133  if (config->UseMeteo)
134  {
135  for (unsigned int i = 0; i < tabRays.size(); i++)
136  {
137  tabRays[i]->tyRayCorrection( apf.get_geometry_modifier() );
138  }
139  }
140 
141  if (config->showScene)
142  {
143  apf.get_geometry_modifier()->save_to_file("computed_nappe.ply");
144  apf.getRayTracer().getScene()->export_to_ply("computing_scene.ply");
145  }
146 
147  return true;
148 }
149 
This file provides the top-level declaration for the acoustic result model.
This file provides the top-level declaration for the acoustic problem model.
IGeometryModifier * get_geometry_modifier()
Get the geometry modifier.
size_t nreceptors() const
Return the total number of receptors.
Research of acoustic paths for the ANIME3D method.
bool exec()
Launch the research of acoustic paths.
bool exec(TYStructSurfIntersect *&tabPolygon, size_t &tabPolygonSize)
Build list of faces.
void resize(size_t nb_receptors, size_t nb_sources)
Resize the matrix (data is cleared)
Simulation & getRayTracer()
Get ray tracing object.
This file provides class for solver configuration.
SpectrumMatrix & get_data()
Return the results matrix.
TYStructSurfIntersect * _tabPolygon
Array containing all the informations relative to a site geometry and associated material to each fac...
virtual void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:101
~TYANIME3DSolver()
Destructor of ANIME3DSolver.
virtual bool solve(const tympan::AcousticProblemModel &aproblem, tympan::AcousticResultModel &aresult, tympan::LPSolverConfiguration configuration)
Resolution with the ANIME3D method.
Scene * getScene()
Get a pointer to the scene.
Definition: Simulation.h:74
size_t _tabPolygonSize
Array size of _tabPolygon.
Spectrum matrix N*M used to store results. N is the number of receptors. M is the number of sources...
TYANIME3DSolver()
Constructor of ANIME3DSolver.
static void set(LPSolverConfiguration config)
Set a configuration.
Definition: config.cpp:108
virtual void save_to_file(std::string fileName)=0
Export to a file.
Class to describe the acoustic problem.
virtual void purge()
Clean memory after being used in a calculation.
boost::shared_ptr< SolverConfiguration > LPSolverConfiguration
Definition: interfaces.h:24
Building class of the faces list used by the ray tracer and the acoustic solver.
size_t nsources() const
Return the total number of sources.
tab_acoustic_path & get_path_data()
Return the array of the acoustic paths.
Contains the results of the model solved.
Class for the definition of atmospheric conditions.
Acoustic model of ANIME3D method.
Store acoustic power values for different frequencies.
Definition: spectre.h:49
void export_to_ply(std::string fileName)
Export the Scene to a PLY format file named fileName.
Definition: Scene.cpp:169
std::vector< acoustic_path * > tab_acoustic_path
std::unique_ptr< AtmosphericConditions > _pAtmos
OTab2DSpectreComplex ComputeAcousticModel()
Complete calculation of the acoustic model ANIME3D.
static LPSolverConfiguration get()
Get the configuration.
Definition: config.cpp:99
void init()
Initialize some data structures used by ANIME3D.
std::vector< std::vector< OSpectreComplex > > OTab2DSpectreComplex
OTabSpectreComplex 2D array.
Definition: spectre.h:444