Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSolverHelper.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 
17 #include <QtCore/qdir.h>
18 #include <fstream>
19 
20 const std::vector<double> tabFreq = {31.5, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0};
21 const std::vector<double> dAWeighting = {-39.5, -26.2, -16.1, -8.6, -3.2, 0.0, 1.2, 1.0, -1.1};
22 const char* SEP = ";";
23 const std::streamsize PRECISION = 2;
24 
25 void TYSolverHelper::exportResults17534(const std::vector<PathResults> pathsResults,
26  const OSpectreOctave& SLp, const AtmosphericConditions& atmos)
27 {
28  QString qFileName =
29  QDir::toNativeSeparators("C:/projects/tympan_tools/17534-3/output/results_17534_format.csv");
30  std::ofstream ofs;
31  ofs.open(qFileName.toStdString().c_str(), std::ios_base::out);
32  if (ofs.is_open())
33  {
34  ofs.setf(std::ios::fixed, std::ios::floatfield);
35  ofs.precision(PRECISION);
36 
37  for (auto& currentPathResults : pathsResults)
38  {
39  ofs << "Path id : " << SEP << currentPathResults.path_id << "\n";
40  ofs << "Path type : " << SEP << currentPathResults.pathType << "\n";
41  // Array titles
42  ofs << "Quantity" << SEP << "Unit" << SEP << "Values" << SEP << SEP << SEP << SEP << SEP << SEP
43  << SEP << SEP << "\n";
44 
45  // Frequencies
46  ofs << "f" << SEP << "Hz" << SEP;
47  for (int col = 0; col < tabFreq.size(); col++)
48  {
49  ofs << tabFreq[col] << SEP;
50  }
51  ofs << std::endl;
52 
53  // Lw
54  printQuantity(ofs, currentPathResults.LW, "Lw");
55 
56  // Dc
57  printQuantity(ofs, currentPathResults.Dc, "Dc");
58 
59  // Atmospherical attenuation coefficient
60  ofs << "alpha-atm" << SEP << "dB/km" << SEP;
61  for (int col = 0; col < tabFreq.size(); col++)
62  {
63  ofs << atmos.get_absorption_spectrum_oct().getTabValReel()[col] << SEP;
64  }
65  ofs << std::endl;
66 
67  // Atmospherical attenuation
68  printQuantity(ofs, currentPathResults.Aatm, "Aatm");
69 
70  // Ground attenuations
71  printQuantity(ofs, currentPathResults.Agr_s, "Agr_s");
72  printQuantity(ofs, currentPathResults.Agr_r, "Agr_r");
73  printQuantity(ofs, currentPathResults.Agr_m, "Agr_m");
74  printQuantity(ofs, currentPathResults.Agr_s + currentPathResults.Agr_r + currentPathResults.Agr_m,
75  "Agr");
76 
77  // Barrier attenuations
78  printQuantity(ofs, currentPathResults.Dz_top, "Dz_top");
79  printQuantity(ofs, currentPathResults.Dz_left, "Dz_left");
80  printQuantity(ofs, currentPathResults.Dz_right, "Dz_right");
81 
82  printQuantity(ofs, currentPathResults.Abar_top, "Abar_top");
83  printQuantity(ofs, currentPathResults.Abar_left, "Abar_left");
84  printQuantity(ofs, currentPathResults.Abar_right, "Abar_right");
85  printQuantity(ofs, currentPathResults.Abar, "Abar");
86 
87  // Geometrical spreading attenuation
88  printQuantity(ofs, currentPathResults.Adiv, "Adiv");
89 
90  // Level
91  printLevel(ofs, currentPathResults.L, "L");
92  ofs << std::endl;
93  }
94 
95  // Print global result sum of paths results
96  printLevel(ofs, SLp, "Lglobal");
97  ofs << std::endl;
98 
99  ofs.close();
100  }
101 }
102 
103 void TYSolverHelper::printQuantity(std::ofstream& ofs, const OSpectreOctave Att, const char* quantity)
104 {
105  ofs << quantity << SEP << "dB" << SEP;
106  for (int col = 0; col < tabFreq.size(); col++)
107  {
108  ofs << Att.getTabValReel()[col] << SEP;
109  }
110  ofs << std::endl;
111 }
112 
113 void TYSolverHelper::printLevel(std::ofstream& ofs, const OSpectreOctave L, const char* quantity)
114 {
115  // Level
116  ofs << quantity << SEP << "dB" << SEP;
117  for (int col = 0; col < tabFreq.size(); col++)
118  {
119  ofs << L.getTabValReel()[col] << SEP;
120  }
121  ofs << L.valGlobDBLin() << SEP;
122  ofs << std::endl;
123 
124  // A-weighting
125  ofs << "A-weighting" << SEP << "dB" << SEP;
126  for (int col = 0; col < tabFreq.size(); col++)
127  {
128  ofs << dAWeighting[col] << SEP;
129  }
130  ofs << std::endl;
131 
132  // A-Level
133  ofs << quantity << "A" << SEP << "dBA" << SEP;
134  for (int col = 0; col < tabFreq.size(); col++)
135  {
136  ofs << L.getTabValReel()[col] + dAWeighting[col] << SEP;
137  }
138  ofs << L.valGlobDBA() << SEP;
139  ofs << std::endl;
140 }
const std::streamsize PRECISION
const std::vector< double > tabFreq
const char * SEP
const std::vector< double > dAWeighting
Class for the definition of atmospheric conditions.
OSpectreOctave get_absorption_spectrum_oct() const
Get absorption spectrum for octave band computation.
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
Definition: spectre.cpp:683
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
Definition: spectre.cpp:671
double * getTabValReel() override
Get an array of the real values of the spectrum.
Definition: spectre.h:613
static void printQuantity(std::ofstream &ofs, const OSpectreOctave Att, const char *quantity)
static void printLevel(std::ofstream &ofs, const OSpectreOctave L, const char *quantity)
static void exportResults17534(const std::vector< PathResults > pathsResults, const OSpectreOctave &SLp, const AtmosphericConditions &atmos)