Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYResultat.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 <fstream>
17 #include <iomanip>
18 #include <cassert>
19 #include <QIODevice>
20 
21 #include "Tympan/core/logging.h"
26 #include "TYResultat.h"
27 
28 #if TY_USE_IHM
31 #endif
32 
35 
36 TYResultat::TYResultat() : _bPartial(false), _hideLW(false)
37 {
39 
41 }
42 
44 {
45  *this = other;
46 }
47 
49 {
50  purge();
51 }
52 
54 {
55  if (this != &other)
56  {
57  TYElement::operator=(other);
58  _matrix = other._matrix;
59  _hideLW = other._hideLW;
60  }
61  return *this;
62 }
63 
64 bool TYResultat::operator==(const TYResultat& other) const
65 {
66  if (this != &other)
67  {
68  if (TYElement::operator!=(other))
69  {
70  return false;
71  }
72  if (_hideLW != other._hideLW)
73  {
74  return false;
75  }
76  // if (!(_matrix == other._matrix)) { return false; } // XXX
77  }
78  return true;
79 }
80 
81 bool TYResultat::operator!=(const TYResultat& other) const
82 {
83  return !operator==(other);
84 }
85 
86 std::string TYResultat::toString() const
87 {
88  return "TYResultat";
89 }
90 
92 {
93  DOM_Element domNewElem = TYElement::toXML(domElement);
94  DOM_Document domDoc = domElement.ownerDocument();
95  TYXMLTools::addElementBoolValue(domNewElem, "hide_lw", _hideLW);
96 
97  DOM_Element listSrc = domDoc.createElement("ListSources");
98  domNewElem.appendChild(listSrc);
99 
100  TYMapElementIndex ::iterator iteSrc;
101  for (iteSrc = _sources.begin(); iteSrc != _sources.end(); iteSrc++)
102  {
103  DOM_Element resultEntry = domDoc.createElement("Source");
104  listSrc.appendChild(resultEntry);
105 
106  // ID de la Source
107  resultEntry.setAttribute("srcId", (*iteSrc).first->getID().toString());
108  resultEntry.setAttribute("index", QString(intToStr((*iteSrc).second).c_str()));
109  }
110 
111  DOM_Element listRec = domDoc.createElement("ListRecepteurs");
112  domNewElem.appendChild(listRec);
113 
114  TYMapElementIndex::iterator iteRec;
115  for (iteRec = _recepteurs.begin(); iteRec != _recepteurs.end(); iteRec++)
116  {
117  DOM_Element resultEntry = domDoc.createElement("Recepteur");
118  listRec.appendChild(resultEntry);
119 
120  // ID de la Source
121  resultEntry.setAttribute("recId", (*iteRec).first->getID().toString());
122  resultEntry.setAttribute("index", QString(intToStr((*iteRec).second).c_str()));
123  }
124 
125  DOM_Element listSp = domDoc.createElement("ListSpectres");
126  domNewElem.appendChild(listSp);
127 
128  size_t nbMatrixRcpts = _matrix.nb_receptors();
129  size_t nbMatrixSrcs = _matrix.nb_sources();
130 
131  for (unsigned int i = 0; i < nbMatrixRcpts; i++)
132  {
133  for (unsigned int j = 0; j < nbMatrixSrcs; j++)
134  {
135  DOM_Element resultEntry = domDoc.createElement("SpectreInd");
136  listSp.appendChild(resultEntry);
137 
138  // ID de la Source
139  resultEntry.setAttribute("indexRec", intToStr(i).data());
140  resultEntry.setAttribute("indexSrc", intToStr(j).data());
141 
142  TYSpectre spectre = _matrix(i, j).toDB();
143  spectre.toXML(resultEntry);
144  }
145  }
146 
147  // Export des spectres de puissance de chaque source associees au calcul
148  DOM_Element listLw = domDoc.createElement("ListLw");
149  domNewElem.appendChild(listLw);
150 
151  std::map<TYElement*, LPTYSpectre>::iterator it;
152  for (it = _mapElementSpectre.begin(); it != _mapElementSpectre.end(); it++)
153  {
154  DOM_Element lwEntry = domDoc.createElement("SourceLw");
155  listLw.appendChild(lwEntry);
156 
157  // Ajout de l'id de la source comme attribut
158  lwEntry.setAttribute("srcId", (*it).first->getID().toString());
159 
160  // Ajout du spectre
161  (*it).second->toXML(lwEntry);
162  }
163 
164  return domNewElem;
165 }
166 
168 {
169  TYElement::fromXML(domElement);
170 
171  purge();
172  _bPartial = false; // Les donnees partielles n'ont pas ete enregistrees
173  _hideLW = false;
174 
175  unsigned int i = 0;
176 
177  DOM_Element elemCur;
178  QDomNodeList childs = domElement.childNodes();
179  for (i = 0; i < childs.length(); i++)
180  {
181  elemCur = childs.item(i).toElement();
182  TYXMLTools::getElementBoolValue(elemCur, "hide_lw", _hideLW);
183  if (elemCur.nodeName() == "ListSources")
184  {
185  // Source
186  DOM_Element elemCur2;
187  QDomNodeList childs2 = elemCur.childNodes();
188  for (unsigned int j = 0; j < childs2.length(); j++)
189  {
190  elemCur2 = childs2.item(j).toElement();
191  if (elemCur2.nodeName() == "Source")
192  {
193  QString srcId = TYXMLTools::getElementAttributeToString(elemCur2, "srcId");
194  int index = TYXMLTools::getElementAttributeToInt(elemCur2, "index");
195 
196  TYElement* pSrc = TYElement::getInstance(srcId);
197 
198  if (pSrc)
199  {
200  _sources[pSrc] = index;
201  }
202  }
203  }
204  }
205  else if (elemCur.nodeName() == "ListRecepteurs")
206  {
207  // Source
208  DOM_Element elemCur2;
209  QDomNodeList childs2 = elemCur.childNodes();
210  for (unsigned int j = 0; j < childs2.length(); j++)
211  {
212  elemCur2 = childs2.item(j).toElement();
213  if (elemCur2.nodeName() == "Recepteur")
214  {
215  QString srcRec = TYXMLTools::getElementAttributeToString(elemCur2, "recId");
216  int index = TYXMLTools::getElementAttributeToInt(elemCur2, "index");
217 
219 
220  if (pPtCalcul)
221  {
222  _recepteurs[pPtCalcul] = index;
223  }
224  else
225  {
226  QString message = "One or more receptor(s) not found";
227  OMessageManager::get()->error(message);
228  }
229  }
230  }
231  }
232  }
233 
234  buildMatrix();
235 
237 
238  bool loadOk = true;
239 
240  for (i = 0; i < childs.length(); i++)
241  {
242  elemCur = childs.item(i).toElement();
243 
244  if (elemCur.nodeName() == "ListSpectres")
245  {
246 
247  // Spectre resultat
248  DOM_Element elemCur2;
249  QDomNodeList childs2 = elemCur.childNodes();
250 
251  for (unsigned int j = 0; j < childs2.length(); j++)
252  {
253  elemCur2 = childs2.item(j).toElement();
254  int indSrc = 0, indRec = 0;
255  if (elemCur2.nodeName() == "SpectreInd")
256  {
257  indRec = TYXMLTools::getElementAttributeToInt(elemCur2, "indexRec");
258  indSrc = TYXMLTools::getElementAttributeToInt(elemCur2, "indexSrc");
259 
260  DOM_Element elemCur3;
261  QDomNodeList childs3 = elemCur2.childNodes();
262  for (unsigned int k = 0; k < childs3.length(); k++)
263  {
264  elemCur3 = childs3.item(k).toElement();
265  LPTYSpectre pSpectre = new TYSpectre;
266 
267  if (pSpectre->callFromXMLIfEqual(elemCur3))
268  {
269  loadOk &= setSpectre(indRec, indSrc, *pSpectre);
270  }
271  }
272  }
273  }
274  }
275  else if (elemCur.nodeName() == "ListLw")
276  {
277  // Recuperation des spectres de puissance acoustique des sources
278  DOM_Element elemCur3;
279  QDomNodeList childs3 = elemCur.childNodes();
280  for (unsigned int j = 0; j < childs3.length(); j++)
281  {
282  elemCur3 = childs3.item(j).toElement();
283 
284  if (elemCur3.nodeName() == "SourceLw")
285  {
286  QString srcId = TYXMLTools::getElementAttributeToString(elemCur3, "srcId");
287  TYElement* pSrc = TYElement::getInstance(srcId);
288  if (pSrc)
289  {
290  DOM_Element elemCur4;
291  QDomNodeList childs4 = elemCur3.childNodes();
292  for (unsigned int k = 0; k < childs4.length(); k++)
293  {
294  elemCur4 = childs4.item(k).toElement();
295  LPTYSpectre pSpectre = new TYSpectre();
296 
297  if (pSpectre->callFromXMLIfEqual(elemCur4))
298  {
299  _mapElementSpectre[pSrc] = pSpectre;
300  }
301  }
302  }
303  }
304  }
305  }
306  }
307 
309 
310  if (!loadOk)
311  {
312  return -1;
313  }
314  return 1;
315 }
316 
318 {
319  _matrix.clear();
320  _sources.clear();
321  _recepteurs.clear();
322  _mapEmetteurSources.clear();
323  _backupSources.clear();
325  _mapElementSpectre.clear();
326 
327  setIsAcousticModified(true);
328 }
329 
331 {
332  // use two instructions to avoid order problem between compilers
333  // G. Andrade
334  int idx = static_cast<int>(_sources.size());
335  _sources[pSource] = idx;
336 }
337 
339 {
340  TYSourcePonctuelle* pSource = NULL;
341  for (unsigned int i = 0; i < sources.size(); i++)
342  {
343  pSource = TYSourcePonctuelle::safeDownCast(sources[i]->getElement());
344  addSource(pSource);
345  }
346 }
347 
348 std::vector<LPTYElement> TYResultat::getSources()
349 {
350  std::vector<SmartPtr<TYElement>> listSources;
351  listSources.reserve(_sources.size());
352  std::map<TYElement*, int>::iterator it;
353  for (it = _sources.begin(); it != _sources.end(); it++)
354  {
355  listSources.push_back(SmartPtr<TYElement>((*it).first));
356  }
357 
358  return listSources;
359 }
360 
361 std::vector<LPTYElement> TYResultat::getReceptors()
362 {
363  std::vector<SmartPtr<TYElement>> listReceptors;
364  listReceptors.reserve(_recepteurs.size());
365  std::map<TYElement*, int>::iterator it;
366  for (it = _recepteurs.begin(); it != _recepteurs.end(); it++)
367  {
368  listReceptors.push_back(SmartPtr<TYElement>((*it).first));
369  }
370 
371  return listReceptors;
372 }
373 
375 {
376  TYPointCalcul* pRecepteur = NULL;
377  for (unsigned int j = 0; j < recepteurs.size(); j++)
378  {
379  pRecepteur = TYPointCalcul::safeDownCast(recepteurs[j]->getElement());
380  addRecepteur(pRecepteur);
381  }
382 }
383 
385 {
386  assert(pRecepteur);
387 
388  bool need_to_rebuild(false);
389  // use two instructions to avoid order problem between compilers
390  // G. Andrade
391  TYMapElementIndex::iterator it = _recepteurs.find(pRecepteur);
392  if (it == _recepteurs.end())
393  {
394  int idx = static_cast<int>(_recepteurs.size());
395  _recepteurs[pRecepteur] = idx;
396  need_to_rebuild = true;
397  }
398 
399  // set the receptor ready for the TYCalcul (if needed)
400  dynamic_cast<TYPointCalcul*>(pRecepteur)->setEtat(true);
401 
402  return need_to_rebuild;
403 }
404 
406 {
407  assert(pRecepteur);
408 
409  bool need_to_rebuild(false);
410  TYMapElementIndex::iterator it = _recepteurs.find(pRecepteur);
411  if (it != _recepteurs.end())
412  {
413  _recepteurs.erase(it);
414  need_to_rebuild = true;
415  }
416 
417  // Boucle sur les recepteurs pour les renumeroter
418  unsigned int index = 0;
419  for (it = _recepteurs.begin(), index = 0; it != _recepteurs.end(); it++, index++)
420  {
421  (*it).second = index;
422  }
423 
424  return need_to_rebuild;
425 }
426 
428 {
430 }
431 
433 {
434 
435  assert(pSource);
436  assert(pRecepteur);
437 
438  // Index source
439  int indexSource = _sources[pSource];
440  // Index recepteur
441  int indexRecepteur = _recepteurs[pRecepteur];
442 
443  return setSpectre(indexRecepteur, indexSource, Spectre);
444 }
445 
446 bool TYResultat::setSpectre(int indexRecepteur, int indexSource, OSpectre& Spectre)
447 {
448  return setSpectre(indexRecepteur, indexSource, Spectre, _matrix);
449 }
450 
451 bool TYResultat::setSpectre(int indexRecepteur, int indexSource, OSpectre& Spectre,
452  tympan::SpectrumMatrix& matrix)
453 {
454  matrix(indexRecepteur, indexSource) = Spectre;
455  return true; // TODO return kept for compatibility reasons : to be changed to void later
456 }
457 
459 {
460  OSpectre spectre;
461  spectre.setValid(false);
462  if (_sources.find(pSource) == _sources.end() || _recepteurs.find(pRecepteur) == _recepteurs.end())
463  {
464  return spectre;
465  }
466 
467  // Index source
468  int indexSource = _sources[pSource];
469  // Index recepteur
470  int indexRecepteur = _recepteurs[pRecepteur];
471 
472  return getSpectre(indexRecepteur, indexSource);
473 }
474 
475 const OSpectre& TYResultat::getSpectre(int indexRecepteur, int indexSource) const
476 {
477  return _matrix(indexRecepteur, indexSource);
478 }
479 
480 const OSpectre& TYResultat::getElementSpectre(int indexRecepteur, int indexSource) const
481 {
482  return _backupMatrix(indexRecepteur, indexSource);
483 }
484 
486 {
487  // Index recepteur
488  int indexRecepteur = _recepteurs[pRecepteur];
489  return getSpectres(indexRecepteur);
490 }
491 
492 OTabSpectre TYResultat::getSpectres(const int& indexRecepteur) const
493 {
494  return _matrix.by_receptor(indexRecepteur);
495 }
496 
498 {
499  int indexRecepteur = _recepteurs[pRecepteur];
500  _matrix.clearReceptor(indexRecepteur);
501  _recepteurs.erase(pRecepteur);
502 }
503 
504 LPTYElement TYResultat::getSource(const int& indexSource)
505 {
506  LPTYElement pSrc = NULL;
507 
508  TYMapElementIndex::iterator iter;
509 
510  iter = _sources.begin();
511 
512  while (((*iter).second != indexSource) && (iter != _sources.end()))
513  {
514  iter++;
515  }
516 
517  if (iter != _sources.end())
518  {
519  pSrc = (TYElement*)((*iter).first);
520  }
521 
522  return pSrc;
523 }
524 
526 {
527  LPTYElement pSrc = nullptr;
528 
529  TYMapElementIndex::iterator iter;
530 
531  iter = _backupSources.begin();
532 
533  while (((*iter).second != indexSource) && (iter != _backupSources.end()))
534  {
535  iter++;
536  }
537 
538  if (iter != _backupSources.end())
539  {
540  pSrc = (TYElement*)((*iter).first);
541  }
542 
543  return pSrc;
544 }
545 
546 LPTYPointCalcul TYResultat::getRecepteur(const int& indexRecepteur)
547 {
548  LPTYPointCalcul pPoint = nullptr;
549 
550  TYMapElementIndex::iterator iter;
551 
552  iter = _recepteurs.begin();
553 
554  while ((iter != _recepteurs.end()) && ((*iter).second != indexRecepteur))
555  {
556  iter++;
557  }
558 
559  if (iter != _recepteurs.end())
560  {
561  pPoint = (TYPointCalcul*)(*iter).first;
562  }
563 
564  return pPoint;
565 }
566 
567 void TYResultat::saveSpectre(const QString& filename, TYCalcul* pSubstCalcul /*=NULL*/)
568 {
570 
571  QFile outputFile(filename);
572 
573  if (outputFile.open(QFile::WriteOnly))
574  {
575  QTextStream outStream(&outputFile);
576  outStream.setRealNumberPrecision(2);
577  outStream.setEncoding(QStringConverter::Utf8);
578  outStream.setGenerateByteOrderMark(true);
579 
580  outStream.setRealNumberNotation(QTextStream::FixedNotation);
581 
582  int nbSources = static_cast<int>(getNbOfSources());
583  int nbRecepteurs = static_cast<int>(getNbOfRecepteurs());
584 
585  int nbSpectre = nbSources;
586 
587  std::vector<OSpectre> tabSpectre;
588  tabSpectre.reserve(nbSpectre);
589 
591  for (int col = 0; col < nbRecepteurs; ++col)
592  {
593  // On s'assure que le tableau est vide
594  tabSpectre.clear();
595 
596  // On decale d'une case (affichage des frequences)
597  outStream << ";";
598 
599  // Entete pour synthese au point
600  outStream << "Synthese-" << getRecepteur(col)->getName() << ";";
601 
602  // On recupere le spectre au point
603  LPTYPointCalcul pPtCalc = getRecepteur(col);
604  OSpectre spectre =
605  *pCalcul->getSpectre(pPtCalc->getID()).getRealPointer(); //*pPtCalc->getSpectre(pCalcul);
606  if (pSubstCalcul != NULL)
607  {
608  OSpectre otherSpectum = *pSubstCalcul->getSpectre(pPtCalc->getID()).getRealPointer();
609  spectre = getEmergence(spectre, otherSpectum); //*pPtCalc->getSpectre(pSubstCalcul));
610  }
611  spectre.setType(SPECTRE_TYPE_LP);
612  spectre.toDB();
613  tabSpectre.push_back(spectre);
614 
615  // Puis on boucle sur les contributions par source
616  for (int row = 0; row < nbSources; ++row)
617  {
618  outStream << getSource(row)->getName() << "/" << getRecepteur(col)->getName() << ";";
619 
620  // On profite de la boucle pour remplir le tableau
621  OSpectre spectre = getSpectre(col, row);
622  spectre.setType(SPECTRE_TYPE_LP);
623  spectre = spectre.toDB();
624 
625  tabSpectre.push_back(spectre);
626  }
627 
628  // On fait ensuite une boucle pour chaque frequence sur chaque tableau
629  for (int i = 0; i < 31; ++i)
630  {
631  outStream << "\n";
632  outStream << tabFreq[i] << ";";
633 
634  for (unsigned int j = 0; j < tabSpectre.size(); j++)
635  {
636  outStream << tabSpectre[j].getTabValReel()[i] << ";";
637  }
638  }
639 
640  outStream << "\n";
641  }
642 
643  outputFile.close();
644  }
645 }
646 
648 {
649  int indice;
650  float value;
651  bool operator<(const SortElement& rhs)
652  {
653  return value > rhs.value;
654  }
655 };
656 
657 void TYResultat::saveParamValue(QTextStream& str, TYCalcul* pCalcul)
658 {
659  if (pCalcul != NULL)
660  {
661  str << "Calcul" << ';';
662  str << '\n';
663  str << pCalcul->getName() << ';';
664  str << '\n';
665  str << '\n';
666  }
667 }
668 
670 {
671  if (!substSpectre.isValid())
672  {
673  return substSpectre;
674  }
675 
676  // Emergence = (Bruit particulier (+) Bruit de fond) - Bruit de Fond
677  return getAmbiant(spectre, substSpectre).subst(substSpectre);
678 }
679 
681 {
682  return spectre.sumdB(substSpectre);
683 }
684 
685 double TYResultat::getEmergence(const double& val1, const double& val2)
686 {
687  const double& BdF = val2; // Bruit de fond (pour la lisibilite)
688  const double& bP = val1; // Bruit particulier (pour la lisibilite)
689  double bruitAmbiant = getAmbiant(bP, BdF);
690 
691  return bruitAmbiant - BdF;
692 }
693 
694 double TYResultat::getAmbiant(const double& val1, const double& val2)
695 {
696  const double& BdF = val2; // Bruit de fond (pour la lisibilite)
697  const double& bP = val1; // Bruit particulier (pour la lisibilite)
698  return 10.0 * ::log10(::pow(10.0, (bP / 10.0)) + ::pow(10.0, (BdF / 10.0)));
699 }
700 
701 // Comparateur simple pour le tri alphabétique des noms des récepteurs
702 static bool recepNameLess(const std::pair<QString, int>& a, const std::pair<QString, int>& b)
703 {
704  return QString::compare(a.first, b.first, Qt::CaseInsensitive) < 0;
705 }
706 
707 void TYResultat::saveValue(const QString& filename, const int& affichage, double freq /*=100*/)
708 {
709  QFile outputFile(filename);
710  if (outputFile.open(QFile::WriteOnly))
711  {
712  QTextStream outStream(&outputFile);
713  outStream.setEncoding(QStringConverter::Utf8);
714  outStream.setGenerateByteOrderMark(true);
715 
716  outStream.setRealNumberPrecision(2);
717  outStream.setRealNumberNotation(QTextStream::FixedNotation);
718 
719  unsigned int nbSources = static_cast<int>(getNbOfSources());
720  unsigned int nbRecepteurs = static_cast<int>(getNbOfRecepteurs());
721 
722  // CLM-NT33 - Ajout des parametres du calcul
724  saveParamValue(outStream, pCalcul);
725 
726  switch (affichage)
727  {
728  case 1:
729  outStream << "dBZ" << ';';
730  break;
731  case 2:
732  outStream << "dB(" << freq << "Hz)" << ';';
733  break;
734  case 0:
735  default:
736  outStream << "dBA" << ';';
737  }
738 
739  outStream << "LW" << ';';
740 
741  // --- Prépare (nom, index) des récepteurs et tri alphabétique ---
742  std::vector<std::pair<QString, int>> recepPairs;
743  recepPairs.reserve(nbRecepteurs);
744  for (unsigned int col = 0; col < nbRecepteurs; ++col)
745  {
746  LPTYPointCalcul pt = getRecepteur(static_cast<int>(col));
747  if (pt)
748  recepPairs.push_back(std::make_pair(pt->getName(), static_cast<int>(col)));
749  }
750  std::stable_sort(recepPairs.begin(), recepPairs.end(), recepNameLess);
751  // ---------------------------------------------------------------- // fin préparation ---
752 
753  // Sauvegarde des en-têtes recepteurs (triés)
754  for (size_t k = 0; k < recepPairs.size(); ++k)
755  {
756  outStream << recepPairs[k].first << ';';
757  }
758 
759  // Saut de ligne
760  outStream << '\n';
761 
762  // Ligne de synthese
763  outStream << "Synthese" << ';' << ';';
764  for (size_t k = 0; k < recepPairs.size(); ++k)
765  {
766  int col = recepPairs[k].second;
767  LPTYPointCalcul pPtCalc = getRecepteur(col);
768  LPTYSpectre spectre = pCalcul->getSpectre(pPtCalc->getID());
769 
770  spectre->setType(SPECTRE_TYPE_LP);
771  spectre->toDB();
772 
773  switch (affichage)
774  {
775  case 1:
776  outStream << spectre->valGlobDBLin() << ';';
777  break;
778  case 2:
779  outStream << spectre->getValueReal(freq) << ';';
780  break;
781  case 0:
782  default:
783  outStream << spectre->valGlobDBA() << ';';
784  }
785  }
786 
787  // Saut de ligne
788  outStream << '\n';
789 
790  // On fait un tri decroissant selon les valeurs LW
791  std::list<SortElement> sortArray;
792  for (int row = 0; row < static_cast<int>(nbSources); ++row)
793  {
794  LPTYSpectre puissance = 0;
795  LPTYElement pElement = getSource(row);
796  TYUserSourcePonctuelle* pSource = dynamic_cast<TYUserSourcePonctuelle*>(pElement._pObj);
797  if (pSource != nullptr)
798  {
799  puissance = pSource->getRealPowerSpectrum();
800  }
801  else
802  {
803  TYAcousticVolumeNode* pVolNode = dynamic_cast<TYAcousticVolumeNode*>(pElement._pObj);
804  if (pVolNode != nullptr)
805  {
806  puissance = pVolNode->getRealPowerSpectrum();
807  }
808  else
809  {
810  puissance = TYAcousticLine::safeDownCast(pElement)->getRealPowerSpectrum();
811  }
812  }
813 
814  // Spectre de puissance
815  OSpectre spectre = *puissance;
816  spectre.setType(SPECTRE_TYPE_LW);
817 
818  SortElement pair;
819  pair.indice = row;
820 
821  switch (affichage)
822  {
823  case 1:
824  pair.value = spectre.valGlobDBLin();
825  break;
826  case 2:
827  pair.value = spectre.getValueReal(freq);
828  break;
829  case 0:
830  default:
831  pair.value = spectre.valGlobDBA();
832  }
833 
834  sortArray.push_back(pair);
835  }
836  sortArray.sort();
837 
838  // On traite chaque source avec chaque recepteur (ordre trié)
839  for (std::list<SortElement>::iterator it = sortArray.begin(); it != sortArray.end(); ++it)
840  {
841  outStream << getSource(it->indice)->getName() << ';';
842  outStream << it->value << ';';
843 
844  for (size_t k = 0; k < recepPairs.size(); ++k)
845  {
846  int col = recepPairs[k].second;
847  OSpectre spectre = getSpectre(col, it->indice);
848  spectre.setType(SPECTRE_TYPE_LP);
849  spectre = spectre.toDB();
850 
851  switch (affichage)
852  {
853  case 1:
854  outStream << spectre.valGlobDBLin() << ';';
855  break;
856  case 2:
857  outStream << spectre.getValueReal(freq) << ';';
858  break;
859  case 0:
860  default:
861  outStream << spectre.valGlobDBA() << ';';
862  }
863  }
864 
865  outStream << '\n';
866  }
867  outputFile.close();
868  }
869 }
870 
871 void TYResultat::setPartialState(const bool& bPartial)
872 {
873  _bPartial = bPartial;
874  _backupSources.clear();
876 }
877 
879 {
880  LPTYSpectre puissance = new TYSpectre();
881 
882  std::map<TYElement*, int>::iterator it;
883  for (it = _sources.begin(); it != _sources.end(); it++)
884  {
885  TYElement* pElement = (*it).first;
886  TYUserSourcePonctuelle* pSource = dynamic_cast<TYUserSourcePonctuelle*>(pElement);
887  if (pSource != nullptr)
888  {
889  puissance = pSource->getRealPowerSpectrum();
890  }
891  else
892  {
893  TYAcousticVolumeNode* pVolNode = dynamic_cast<TYAcousticVolumeNode*>(pElement);
894  if (pVolNode != nullptr)
895  {
896  puissance = pVolNode->getRealPowerSpectrum();
897  }
898  else // Source lineique
899  {
900  TYAcousticLine* pLine = TYAcousticLine::safeDownCast(pElement);
901  if (pLine)
902  {
903  puissance = pLine->getRealPowerSpectrum();
904  }
905  }
906  }
907 
908  puissance->setType(SPECTRE_TYPE_LW);
909  _mapElementSpectre[pElement] = puissance;
910  }
911 }
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
std::vector< LPTYPointCalculGeoNode > TYTabPointCalculGeoNode
Collection de noeuds geometriques de type TYPointCalcul.
Representation graphique des resultats (fichier header)
outil IHM pour un resultat (fichier header)
TY_EXTENSION_INST(TYResultat)
TY_EXT_GRAPHIC_INST(TYResultat)
const std::vector< double > tabFreq
std::vector< LPTYSourcePonctuelleGeoNode > TYTabSourcePonctuelleGeoNode
Collection de noeuds geometriques de type TYSourcePonctuelle.
OTabFreq TYTabFreq
Collection des frequences.
Definition: TYSpectre.h:27
virtual void error(const char *message,...)
Definition: logging.cpp:127
static OMessageManager * get()
Definition: logging.cpp:108
virtual const char * getClassName() const
Definition: TYElement.h:248
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
OSpectreAbstract & subst(const OSpectreAbstract &spectre) const
Arithmetic subtraction of two spectrums in one-third Octave.
Definition: spectre.cpp:321
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
Definition: spectre.cpp:691
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
Definition: spectre.cpp:679
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:153
void setValid(const bool &valid=true)
Definition: spectre.h:142
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:595
bool isValid() const
Check the spectrum validity. Invalidity is caused by: corrupted data, impossible calculation.
Definition: spectre.h:134
OSpectreAbstract & sumdB(const OSpectreAbstract &spectre) const
Energetic sum of two spectrums.
Definition: spectre.cpp:176
double getValueReal(double freq)
Definition: spectre.cpp:974
T * getRealPointer()
Definition: smartptr.h:291
T * _pObj
The real pointer, must derived IRefCount.
Definition: smartptr.h:307
Spectrum class.
Definition: Spectre.h:25
virtual LPTYSpectre getRealPowerSpectrum()
virtual LPTYSpectre getRealPowerSpectrum()
Calculation program.
Definition: TYCalcul.h:50
LPTYSpectre getSpectre(const TYUUID &id_pt)
Definition: TYCalcul.cpp:1224
TYElement * getParent() const
Definition: TYElement.h:706
static void setLogInstances(bool log)
Definition: TYElement.h:831
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:366
QString _name
Nom courant de l'element.
Definition: TYElement.h:965
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:263
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:542
const TYUUID & getID() const
Definition: TYElement.cpp:176
virtual QString getName() const
Definition: TYElement.h:691
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:379
virtual void setIsAcousticModified(bool isModified)
Definition: TYElement.cpp:248
static TYElement * getInstance(TYUUID uuid)
Definition: TYElement.cpp:158
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
Definition: TYPointCalcul.h:33
Classe qui Permet de centraliser les resultats d'un calcul acoustique.
Definition: TYResultat.h:48
std::vector< LPTYElement > getSources()
return the list of all sources (business sources)
Definition: TYResultat.cpp:348
void buildMatrix()
Construit la matrice resultat a partir des sources et recepteurs entres.
Definition: TYResultat.cpp:427
std::map< TYElement *, LPTYSpectre > _mapElementSpectre
Les spectres de puissance associe a chaque source.
Definition: TYResultat.h:382
void addSource(TYElement *pSource)
Ajoute une source.
Definition: TYResultat.cpp:330
LPTYPointCalcul getRecepteur(const int &indexRecepteur)
Retourne le recepteur corresponadnt a l'indice passe.
Definition: TYResultat.cpp:546
virtual ~TYResultat()
Destructeur. Le destructeur de la classe TYResultat .
Definition: TYResultat.cpp:48
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYResultat.cpp:91
void buildSources(const TYTabSourcePonctuelleGeoNode &sources)
Construit la liste des sources.
Definition: TYResultat.cpp:338
bool remRecepteur(TYPointCalcul *pRecepteur)
Supprime un recepteur du tableau et indique s'il faut reconstruire la matrice.
Definition: TYResultat.cpp:405
void setPartialState(const bool &bPartial)
Get/Set du parametre de conservation de la matrice brut _bPartial.
Definition: TYResultat.cpp:871
size_t getNbOfRecepteurs() const
Retourne le nombre de recepteurs.
Definition: TYResultat.h:122
tympan::SpectrumMatrix _matrix
La matrice de resultat.
Definition: TYResultat.h:368
bool _bPartial
Sauvegarde de la matrice brute.
Definition: TYResultat.h:371
void saveValue(const QString &filename, const int &affichage, double freq=100)
Sauvegarde des valeurs dans un fichier affichage : false -> dBA et true -> dBLin.
Definition: TYResultat.cpp:707
bool operator==(const TYResultat &other) const
Operateur ==.
Definition: TYResultat.cpp:64
void buildMapSourceSpectre()
Build and store powerSpectrum of all sources in calcul.
Definition: TYResultat.cpp:878
LPTYElement getSource(const int &indexSource)
Retourne la source correspondant a l'indice passe.
Definition: TYResultat.cpp:504
void saveSpectre(const QString &filename, TYCalcul *pSubstCalcul=NULL)
Sauvegarde des spectres dans un fichier.
Definition: TYResultat.cpp:567
void purge()
Reinitialise la matrice resultat.
Definition: TYResultat.cpp:317
OSpectre getEmergence(OSpectre &spectre, OSpectre &substSpectre)
Renvoit la difference entre 2 resultats de calcul (spectre)
Definition: TYResultat.cpp:669
bool setSpectre(TYElement *pRecepteur, TYElement *pSource, OSpectre &Spectre)
Assigne un spectre a un couple S-R.
Definition: TYResultat.cpp:432
bool addRecepteur(TYElement *pRecepteur)
Ajoute un recepteur et indique s'il faut reconstruire la matrice.
Definition: TYResultat.cpp:384
TYResultat()
Constructeur. Le constructeur de la classe TYResultat.
Definition: TYResultat.cpp:36
TYMapElementIndex _recepteurs
Les recepteurs contenus dans la matrice resultat.
Definition: TYResultat.h:379
bool operator!=(const TYResultat &other) const
Operateur !=.
Definition: TYResultat.cpp:81
LPTYElement getElementSource(const int &indexSource)
Retourne la source elementaire correspondant a l'indice passe.
Definition: TYResultat.cpp:525
tympan::SpectrumMatrix _backupMatrix
Definition: TYResultat.h:372
OSpectre getAmbiant(OSpectre &spectre, OSpectre &substSpectre)
Renvoi du bruit ambiant.
Definition: TYResultat.cpp:680
TYMapElementIndex _backupSources
Definition: TYResultat.h:373
TYMapElementTabSources _mapEmetteurSources
Tableau associatif "emetteur"/liste des sources de l'emetteur.
Definition: TYResultat.h:385
void remSpectres(TYPointCalcul *pRecepteur)
Efface les spectres d'un recepteur donne.
Definition: TYResultat.cpp:497
void buildRecepteurs(const TYTabPointCalculGeoNode &sources)
Construit la liste des sources.
Definition: TYResultat.cpp:374
TYMapElementIndex _sources
Les sources contenues dans la matrice resultat.
Definition: TYResultat.h:376
bool _hideLW
Show / hide power spectrum in result matrix.
Definition: TYResultat.h:388
void saveParamValue(QTextStream &ofs, TYCalcul *pCalcul)
Definition: TYResultat.cpp:657
virtual std::string toString() const
Definition: TYResultat.cpp:86
std::vector< LPTYElement > getReceptors()
return the list of all sources (business sources)
Definition: TYResultat.cpp:361
TYResultat & operator=(const TYResultat &other)
Operateur =.
Definition: TYResultat.cpp:53
OTabSpectre getSpectres(TYPointCalcul *pRecepteur)
Retourne les spectres pour un recepteur donne.
Definition: TYResultat.cpp:485
OSpectre getSpectre(TYElement *pRecepteur, TYElement *pSource)
Retourne un spectre pour un couple S-R.
Definition: TYResultat.cpp:458
const OSpectre & getElementSpectre(int indexRecepteur, int indexSource) const
Retourne le spectre de la matrice brute (avant condensation)pour un couple S-R (S = Source elementair...
Definition: TYResultat.cpp:480
size_t getNbOfSources() const
Retourne le nombre de sources.
Definition: TYResultat.h:102
virtual int fromXML(DOM_Element domElement)
Definition: TYResultat.cpp:167
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSpectre.cpp:164
static const TYTabFreq getTabFreqNorm(TYSpectreForm form=SPECTRE_FORM_TIERS)
Definition: TYSpectre.cpp:419
static int getElementAttributeToInt(DOM_Element parentElem, DOMString attName, bool *ok=NULL)
Definition: TYXMLTools.cpp:293
static bool getElementBoolValue(DOM_Element parentElem, DOMString nodeName, bool &nodeValue)
Definition: TYXMLTools.cpp:179
static QString getElementAttributeToString(DOM_Element parentElem, DOMString attName)
Definition: TYXMLTools.cpp:276
static void addElementBoolValue(DOM_Element &parentElem, DOMString nodeName, bool nodeValue)
Definition: TYXMLTools.cpp:77
Spectrum matrix N*M used to store results. N is the number of receptors. M is the number of sources.
const std::vector< Spectrum > & by_receptor(size_t receptor_idx) const
Return a vector of Spectrum for a receptor.
void clear()
Clear the matrix.
size_t nb_sources() const
Number of columns (sources) of the matrix.
void clearReceptor(size_t receptor_idx)
Clear the matrix for the a given receptor.
size_t nb_receptors() const
Number of rows (receptors) of the matrix.
std::string intToStr(int val)
Definition: macros.h:158
@ SPECTRE_FORM_TIERS
Definition: spectre.h:37
std::vector< OSpectre > OTabSpectre
Spectrums vector.
Definition: spectre.h:473
@ SPECTRE_TYPE_LW
Definition: spectre.h:30
@ SPECTRE_TYPE_LP
Definition: spectre.h:31
bool operator<(const SortElement &rhs)
Definition: TYResultat.cpp:651