Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYResultat.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 <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.setRealNumberNotation(QTextStream::FixedNotation);
578 
579  int nbSources = static_cast<int>(getNbOfSources());
580  int nbRecepteurs = static_cast<int>(getNbOfRecepteurs());
581 
582  int nbSpectre = nbSources;
583 
584  std::vector<OSpectre> tabSpectre;
585  tabSpectre.reserve(nbSpectre);
586 
588  for (int col = 0; col < nbRecepteurs; ++col)
589  {
590  // On s'assure que le tableau est vide
591  tabSpectre.clear();
592 
593  // On decale d'une case (affichage des frequences)
594  outStream << ";";
595 
596  // Entete pour synthese au point
597  outStream << "Synthese-" << getRecepteur(col)->getName().toLatin1().data() << ";";
598 
599  // On recupere le spectre au point
600  LPTYPointCalcul pPtCalc = getRecepteur(col);
601  OSpectre spectre =
602  *pCalcul->getSpectre(pPtCalc->getID()).getRealPointer(); //*pPtCalc->getSpectre(pCalcul);
603  if (pSubstCalcul != NULL)
604  {
605  OSpectre otherSpectum = *pSubstCalcul->getSpectre(pPtCalc->getID()).getRealPointer();
606  spectre = getEmergence(spectre, otherSpectum); //*pPtCalc->getSpectre(pSubstCalcul));
607  }
608  spectre.setType(SPECTRE_TYPE_LP);
609  spectre.toDB();
610  tabSpectre.push_back(spectre);
611 
612  // Puis on boucle sur les contributions par source
613  for (int row = 0; row < nbSources; ++row)
614  {
615  outStream << getSource(row)->getName().toLatin1().data() << "/"
616  << getRecepteur(col)->getName().toLatin1().data() << ";";
617 
618  // On profite de la boucle pour remplir le tableau
619  OSpectre spectre = getSpectre(col, row);
620  spectre.setType(SPECTRE_TYPE_LP);
621  spectre = spectre.toDB();
622 
623  tabSpectre.push_back(spectre);
624  }
625 
626  // On fait ensuite une boucle pour chaque frequence sur chaque tableau
627  for (int i = 0; i < 31; ++i)
628  {
629  outStream << "\n";
630  outStream << tabFreq[i] << ";";
631 
632  for (unsigned int j = 0; j < tabSpectre.size(); j++)
633  {
634  outStream << tabSpectre[j].getTabValReel()[i] << ";";
635  }
636  }
637 
638  outStream << "\n";
639  }
640 
641  outputFile.close();
642  }
643 }
644 
646 {
647  int indice;
648  float value;
649  bool operator<(const SortElement& rhs)
650  {
651  return value > rhs.value;
652  }
653 };
654 
655 void TYResultat::saveParamValue(QTextStream& str, TYCalcul* pCalcul)
656 {
657  if (pCalcul != NULL)
658  {
659  str << "Calcul" << ';';
660  str << '\n';
661  str << pCalcul->getName() << ';';
662  str << '\n';
663  str << '\n';
664  }
665 }
666 
668 {
669  if (!substSpectre.isValid())
670  {
671  return substSpectre;
672  }
673 
674  // Emergence = (Bruit particulier (+) Bruit de fond) - Bruit de Fond
675  return getAmbiant(spectre, substSpectre).subst(substSpectre);
676 }
677 
679 {
680  return spectre.sumdB(substSpectre);
681 }
682 
683 double TYResultat::getEmergence(const double& val1, const double& val2)
684 {
685  const double& BdF = val2; // Bruit de fond (pour la lisibilite)
686  const double& bP = val1; // Bruit particulier (pour la lisibilite)
687  double bruitAmbiant = getAmbiant(bP, BdF);
688 
689  return bruitAmbiant - BdF;
690 }
691 
692 double TYResultat::getAmbiant(const double& val1, const double& val2)
693 {
694  const double& BdF = val2; // Bruit de fond (pour la lisibilite)
695  const double& bP = val1; // Bruit particulier (pour la lisibilite)
696  return 10.0 * ::log10(::pow(10.0, (bP / 10.0)) + ::pow(10.0, (BdF / 10.0)));
697 }
698 
699 void TYResultat::saveValue(const QString& filename, const int& affichage, double freq /*=100*/)
700 {
701  QFile outputFile(filename);
702  if (outputFile.open(QFile::WriteOnly))
703  {
704  QTextStream outStream(&outputFile);
705  outStream.setRealNumberPrecision(2);
706  outStream.setRealNumberNotation(QTextStream::FixedNotation);
707 
708  unsigned int nbSources = static_cast<int>(getNbOfSources());
709  unsigned int nbRecepteurs = static_cast<int>(getNbOfRecepteurs());
710 
711  // CLM-NT33 - Ajout des parametres du calcul
713  saveParamValue(outStream, pCalcul);
714 
715  switch (affichage)
716  {
717  case 1:
718  outStream << "dBZ" << ';';
719  break;
720  case 2:
721  outStream << "dB(" << freq << "Hz)" << ';';
722  break;
723  case 0:
724  default:
725  outStream << "dBA" << ';';
726  }
727 
728  outStream << "LW" << ';';
729 
730  // Sauvegarde des valeurs
731  int col = 0;
732  for (col = 0; col < nbRecepteurs; ++col)
733  {
734  if (getRecepteur(col) == NULL)
735  {
736  continue;
737  }
738  outStream << getRecepteur(col)->getName().toLatin1().data() << ';';
739  }
740 
741  // Saut de ligne
742  outStream << '\n';
743 
744  // Ligne de synthese
745  outStream << "Synthese" << ';' << ';';
746  for (col = 0; col < nbRecepteurs; ++col)
747  {
748  LPTYPointCalcul pPtCalc = getRecepteur(col);
749  LPTYSpectre spectre = pCalcul->getSpectre(pPtCalc->getID());
750 
751  spectre->setType(SPECTRE_TYPE_LP);
752  spectre->toDB();
753 
754  switch (affichage)
755  {
756  case 1:
757  outStream << spectre->valGlobDBLin() << ';';
758  break;
759  case 2:
760  outStream << spectre->getValueReal(freq) << ';';
761  break;
762  case 0:
763  default:
764  outStream << spectre->valGlobDBA() << ';';
765  }
766  }
767 
768  // Saut de ligne
769  outStream << '\n';
770 
771  // On fait un tri decroissant selon les valeurs LW
772  std::list<SortElement> sortArray;
773  for (int row = 0; row < nbSources; ++row)
774  {
775  LPTYSpectre puissance = 0;
776  LPTYElement pElement = getSource(row);
777  TYUserSourcePonctuelle* pSource = dynamic_cast<TYUserSourcePonctuelle*>(pElement._pObj);
778  if (pSource != nullptr)
779  {
780  puissance = pSource->getRealPowerSpectrum();
781  }
782  else
783  {
784  TYAcousticVolumeNode* pVolNode = dynamic_cast<TYAcousticVolumeNode*>(pElement._pObj);
785  if (pVolNode != nullptr)
786  {
787  puissance = pVolNode->getRealPowerSpectrum();
788  }
789  else
790  {
791  puissance = TYAcousticLine::safeDownCast(pElement)->getRealPowerSpectrum();
792  }
793  }
794 
795  // Spectre de puissance
796  OSpectre spectre = *puissance;
797  spectre.setType(SPECTRE_TYPE_LW);
798 
799  SortElement pair;
800  pair.indice = row;
801 
802  switch (affichage)
803  {
804  case 1:
805  pair.value = spectre.valGlobDBLin();
806  break;
807  case 2:
808  pair.value = spectre.getValueReal(freq);
809  break;
810  case 0:
811  default:
812  pair.value = spectre.valGlobDBA();
813  }
814 
815  sortArray.push_back(pair);
816  }
817  sortArray.sort();
818 
819  // On traite chaque source avec chaque recepteur
820  for (std::list<SortElement>::iterator it = sortArray.begin(); it != sortArray.end(); ++it)
821  {
822  outStream << getSource(it->indice)->getName().toLatin1().data() << ';';
823  outStream << it->value << ';';
824  for (col = 0; col < nbRecepteurs; ++col)
825  {
826  OSpectre spectre = getSpectre(col, it->indice);
827  spectre.setType(SPECTRE_TYPE_LP);
828  spectre = spectre.toDB();
829 
830  switch (affichage)
831  {
832  case 1:
833  outStream << spectre.valGlobDBLin() << ';';
834  break;
835  case 2:
836  outStream << spectre.getValueReal(freq) << ';';
837  break;
838  case 0:
839  default:
840  outStream << spectre.valGlobDBA() << ';';
841  }
842  }
843 
844  outStream << '\n';
845  }
846  outputFile.close();
847  }
848 }
849 
850 void TYResultat::setPartialState(const bool& bPartial)
851 {
852  _bPartial = bPartial;
853  _backupSources.clear();
855 }
856 
858 {
859  LPTYSpectre puissance = new TYSpectre();
860 
861  std::map<TYElement*, int>::iterator it;
862  for (it = _sources.begin(); it != _sources.end(); it++)
863  {
864  TYElement* pElement = (*it).first;
865  TYUserSourcePonctuelle* pSource = dynamic_cast<TYUserSourcePonctuelle*>(pElement);
866  if (pSource != nullptr)
867  {
868  puissance = pSource->getRealPowerSpectrum();
869  }
870  else
871  {
872  TYAcousticVolumeNode* pVolNode = dynamic_cast<TYAcousticVolumeNode*>(pElement);
873  if (pVolNode != nullptr)
874  {
875  puissance = pVolNode->getRealPowerSpectrum();
876  }
877  else // Source lineique
878  {
879  TYAcousticLine* pLine = TYAcousticLine::safeDownCast(pElement);
880  if (pLine)
881  {
882  puissance = pLine->getRealPowerSpectrum();
883  }
884  }
885  }
886 
887  puissance->setType(SPECTRE_TYPE_LW);
888  _mapElementSpectre[pElement] = puissance;
889  }
890 }
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:249
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:316
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
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:152
void setValid(const bool &valid=true)
Definition: spectre.h:141
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:590
bool isValid() const
Check the spectrum validity. Invalidity is caused by: corrupted data, impossible calculation.
Definition: spectre.h:133
OSpectreAbstract & sumdB(const OSpectreAbstract &spectre) const
Energetic sum of two spectrums.
Definition: spectre.cpp:171
double getValueReal(double freq)
Definition: spectre.cpp:959
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:1223
TYElement * getParent() const
Definition: TYElement.h:699
static void setLogInstances(bool log)
Definition: TYElement.h:832
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:368
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
const TYUUID & getID() const
Definition: TYElement.cpp:176
virtual QString getName() const
Definition: TYElement.h:684
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
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:850
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:699
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:857
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:667
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:678
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:655
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:472
@ SPECTRE_TYPE_LW
Definition: spectre.h:30
@ SPECTRE_TYPE_LP
Definition: spectre.h:31
bool operator<(const SortElement &rhs)
Definition: TYResultat.cpp:649