Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticCylinder.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"
19 #if TY_USE_IHM
23 #endif
24 #include "TYAcousticCylinder.h"
25 
28 
30 {
32 
33  // Couleur par default
34  float r = 255.0f, g = 67.0f, b = 133.0f;
35 
36 #if TY_USE_IHM
37  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "TYAcousticCylinderGraphicColorR"))
38  {
39  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "TYAcousticCylinderGraphicColor", r, g, b);
40  }
41  else
42  {
43  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "TYAcousticCylinderGraphicColor", r, g, b);
44  }
45 
46 #endif // TY_USE_IHM
47 
48  OColor color;
49  color.r = r / 255;
50  color.g = g / 255;
51  color.b = b / 255;
52 
53  setColor(color);
54 
56  _pEnveloppe->setParent(this);
57 
59  *_pCircTop->getShape() =
60  TYRectangle(TYPoint(-1, 1, 0.5), TYPoint(1, 1, 0.5), TYPoint(1, -1, 0.5), TYPoint(-1, -1, 0.5));
61  _pCircTop->setParent(this);
62 
65  TYRectangle(TYPoint(-1, -1, -0.5), TYPoint(1, -1, -0.5), TYPoint(1, 1, -0.5), TYPoint(-1, 1, -0.5));
66  _pCircBottom->setParent(this);
67 
72 }
73 
75 {
76  *this = other;
77 }
78 
80 
82 {
83  if (this != &other)
84  {
86  _pEnveloppe = other._pEnveloppe;
87  _pCircTop = other._pCircTop;
88  _pCircBottom = other._pCircBottom;
89  }
90 
95 
96  return *this;
97 }
98 
100 {
101  if (this != &other)
102  {
103  if (TYAcousticVolume::operator!=(other))
104  {
105  return false;
106  }
107  if (_pEnveloppe != other._pEnveloppe)
108  {
109  return false;
110  }
111  if (_pCircTop != other._pCircTop)
112  {
113  return false;
114  }
115  if (_pCircBottom != other._pCircBottom)
116  {
117  return false;
118  }
119  }
120  return true;
121 }
122 
124 {
125  return !operator==(other);
126 }
127 
128 bool TYAcousticCylinder::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
129 {
130  if (!TYAcousticVolume::deepCopy(pOther, copyId))
131  {
132  return false;
133  }
134 
135  TYAcousticCylinder* pOtherCyl = (TYAcousticCylinder*)pOther;
136 
137  _pEnveloppe->deepCopy(pOtherCyl->_pEnveloppe, copyId);
138  _pEnveloppe->setParent(this);
139  _pCircTop->deepCopy(pOtherCyl->_pCircTop, copyId);
140  _pCircTop->setParent(this);
141  _pCircBottom->deepCopy(pOtherCyl->_pCircBottom, copyId);
142  _pCircBottom->setParent(this);
143 
144  _volEnglob = volEnglob();
148 
149  return true;
150 }
151 
152 std::string TYAcousticCylinder::toString() const
153 {
154  return "TYAcousticCylinder";
155 }
156 
158 {
159  DOM_Element domNewElem = TYAcousticVolume::toXML(domElement);
160 
161  _pEnveloppe->toXML(domNewElem);
162  _pCircTop->toXML(domNewElem);
163  _pCircBottom->toXML(domNewElem);
164 
165  return domNewElem;
166 }
167 
169 {
170  TYAcousticVolume::fromXML(domElement);
171 
172  bool circTopFound = false;
173  bool circBottomFound = false;
174  bool enveloppeFound = false;
175 
176  DOM_Element elemCur;
177 
178  QDomNodeList childs = domElement.childNodes();
179  for (unsigned int i = 0; i < childs.length(); i++)
180  {
181  elemCur = childs.item(i).toElement();
182 
183  if (!enveloppeFound)
184  {
185  enveloppeFound = _pEnveloppe->callFromXMLIfEqual(elemCur);
186  }
187 
188  if (!circTopFound)
189  {
190  circTopFound = _pCircTop->callFromXMLIfEqual(elemCur);
191  }
192  else if (!circBottomFound)
193  {
194  circBottomFound = _pCircBottom->callFromXMLIfEqual(elemCur);
195  }
196  }
197 
198  if (!enveloppeFound) // Lecture d'un fichier TYMPAN 3.2
199  {
202 
203  // On ajoute autant de regime a l'enveloppe qu'il y a de regime a la machine.
204  // On prend la machine comme reference car il y a un probleme sur le modele chinon
205  // un cylindre possede 11 regimes alors que la machine n'en possede que 2.
207  size_t nbRegMachine = pMachine->getNbRegimes();
208 
209  size_t j = 0;
210  for (j = 0; j < nbRegMachine - 1; j++) // (-1) car l'enveloppe possede deja au moins un regime
211  {
213  }
214 
215  // On "construit" les regimes
216  bool statusFrom = true;
217  bool statusTo = true;
218  for (j = 0; j < _pEnveloppe->getNbRegimes(); j++)
219  {
220  TYRegime& regimeFrom = this->getRegimeNb(static_cast<int>(j), statusFrom);
221  TYRegime& regimeTo = _pEnveloppe->getRegimeNb(static_cast<int>(j), statusTo);
222 
223  if (!statusFrom || !statusTo)
224  {
225  break;
226  }
227 
228  regimeTo.deepCopy(&regimeFrom, false);
229  }
230 
232  _pEnveloppe->loadRegime(-1); // On met l'etat de l'enveloppe par rapport au regime courant
233  }
234 
235  _volEnglob = volEnglob();
239 
240  return 1;
241 }
242 
243 void TYAcousticCylinder::getChilds(LPTYElementArray& childs, bool recursif /*=true*/)
244 {
245  TYAcousticVolume::getChilds(childs, recursif);
246 
247  childs.push_back(_pCircTop);
248  childs.push_back(_pCircBottom);
249  childs.push_back(_pEnveloppe);
250 
251  if (recursif)
252  {
253  _pCircTop->getChilds(childs, recursif);
254  _pCircBottom->getChilds(childs, recursif);
255  _pEnveloppe->getChilds(childs, recursif);
256  }
257 }
258 
259 void TYAcousticCylinder::setRegime(TYSpectre& Spectre, int regime /*=-1*/, bool recursif /*=false*/)
260 {
261  if (recursif)
262  {
263  _pEnveloppe->setRegime(Spectre, regime, recursif);
264  _pCircTop->setRegime(Spectre, regime, recursif);
265  _pCircBottom->setRegime(Spectre, regime, recursif);
266  }
267 
268  TYAcousticInterface::setRegime(Spectre, regime, recursif);
269 }
270 
272 {
273  _pEnveloppe->remRegime(regime);
274  _pCircTop->remRegime(regime);
275  _pCircBottom->remRegime(regime);
276 
277  return TYAcousticVolume::remRegime(regime);
278 }
279 
281 {
282  _pEnveloppe->loadRegime(regimeNb);
283  _pCircTop->loadRegime(regimeNb);
284  _pCircBottom->loadRegime(regimeNb);
285 
287 }
288 
290 {
291  _pEnveloppe->setCurRegime(regime);
292  _pCircTop->setCurRegime(regime);
293  _pCircBottom->setCurRegime(regime);
294 
296 
297  setIsAcousticModified(true);
298 }
299 
301 {
302  _pEnveloppe->propagateAtt(pAtt);
303  _pCircTop->propagateAtt(pAtt);
304  _pCircBottom->propagateAtt(pAtt);
305 
307 }
308 /*
309 int TYAcousticCylinder::addRegime(const TYRegime& regime)
310 {
311  _pEnveloppe->addRegime();
312  _pCircTop->addRegime();
313  _pCircBottom->addRegime();
314 
315  return TYAcousticInterface::addRegime(regime);
316 }
317 */
319 {
321  _pCircTop->addRegime();
323 
325 }
326 
328 {
329  TYTabSourcePonctuelleGeoNode tab, tabTmp;
330 
331  tabTmp = _pCircBottom->getSrcs();
332  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
333 
334  tabTmp = _pCircTop->getSrcs();
335  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
336 
337  tabTmp = _pEnveloppe->getSrcs();
338  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
339 
340  return tab;
341 }
342 
344 {
345  return TYSourcePonctuelle();
346 }
347 
348 void TYAcousticCylinder::setDensiteSrcsH(double densite, bool recursif /*= true*/)
349 {
350  TYAcousticVolume::setDensiteSrcsH(densite, recursif);
351 
352  if (recursif)
353  {
354  // Cercle bottom
356 
357  // Cercle top
359 
360  // Enveloppe (src surf)
362  }
363 }
364 
365 void TYAcousticCylinder::setDensiteSrcsV(double densite, bool recursif /*=true*/)
366 {
367  TYAcousticVolume::setDensiteSrcsV(densite, recursif);
368 
369  if (recursif)
370  {
371  // Cercle bottom
373 
374  // Cercle top
376 
377  // Enveloppe (src surf)
379  }
380 }
381 
383 {
384  // Suppression des sources existantes
388 }
389 
391 {
392  if (_isRayonnant == false)
393  {
394  // Pas de calcul
395  return;
396  }
397 
398  // Cercle bottom
400  {
402  }
403 
404  // Cercle top
405  if (_pCircTop->getIsRayonnant())
406  {
408  }
409 
410  // Enveloppe (src surf)
411  if (!_pEnveloppe->getIsRayonnant() || (_pEnveloppe->getDensiteSrcsH() == 0) ||
412  (_pEnveloppe->getDensiteSrcsV() == 0))
413  {
414  return;
415  }
416 
417  // On travaille directement sur la source surfacique de l'enveloppe
419 
420  // Distance angulaire (sur la circonference de chaque cercle
421  // concentrique)
422  const double distAngle = pSrcSurf->getDensiteSrcsH();
423  int nbSrcs = ROUND(M_PI * getDiameter() / distAngle);
424  nbSrcs = nbSrcs < 4 ? 4 : nbSrcs; // Au moins 4 sources sur la circonference (champ rayonne homogene)
425  const double anglePortion = M_2PI / nbSrcs;
426 
427  // Distance sur la hauteur
428  double distHauteur = pSrcSurf->getDensiteSrcsV();
429 
430  const double hauteurCyl = getHauteur();
431 
432  int nbCercle = (int)(hauteurCyl / distHauteur);
433  if (nbCercle == 0)
434  {
435  nbCercle = 1;
436  distHauteur = hauteurCyl / 2.0;
437  }
438 
439  // Si la hauteur residuelle est inferieure a la demi distance entre les cercles, on retire un cercle
440  const double HResiduel = (hauteurCyl - (distHauteur * nbCercle)) / 2.0;
441  if ((nbCercle > 1) && (HResiduel < (distHauteur / 2.0)))
442  {
443  nbCercle--;
444  }
445 
446  // Position du premier cercle en partant du bas
447  double base = (hauteurCyl - (nbCercle - 1) * distHauteur) / 2.0;
448 
449  // nombre d'iterations ((M_2PI / distAngle) + (hauteurCyl / distHauteur));
450 
451  OPoint3D pt;
452  double angle = 0.0;
453  double hauteur = base;
454  double rayon = (getDiameter() / 2.0) + _offsetSources; // decalage des sources pour le lancer de rayons
455  const double hauteurOffset = _pCircBottom->getCenter()._z;
456  OPoint3D center = _pCircBottom->getCenter();
457 
458  // To define directivity
459  double specificSize = this->getDiameter();
461 
462  // Calcul de la portion d'angle pour le cercle
463  if (anglePortion > 0.0)
464  {
465  // Parcours sur la hauteur
466  for (int i = 0; i < nbCercle; i++)
467  {
468  // Init angle
469  angle = 0.0;
470 
471  // Pour chaque portion d'angle
472  while ((angle < M_2PI))
473  {
474 
475  // Point correspondant
476  pt._x = cos(angle) * rayon;
477  pt._y = sin(angle) * rayon;
478  pt._z = hauteurOffset + hauteur;
479 
480  // Pour trouver la normale
481  center._z = pt._z;
482  OVector3D faceNormal(center, pt);
483  faceNormal.normalize();
484 
485  // Creation d'une source ponctuelle
487  pSrc->setDirectivity(new TYComputedDirectivity(faceNormal, type, specificSize));
488 
489  // Definition de sa position
490  *pSrc->getPos() = pt;
491 
492  // Definition des sources comme sources a directivite calculee
493  pSrc->setTypeRaynt(CALCULATED);
494 
495  // Ajout de la src ponct a la src surf
496  pSrcSurf->addSrc(pSrc);
497 
498  // Attribution du parent
499  // pSrc->setParent(_pEnveloppe);
500 
501  // Increment de la portion (sens horaire)
502  angle += anglePortion;
503  }
504 
505  // Increment de la hauteur
506  hauteur += distHauteur;
507  }
508  }
509 }
510 
512 {
514  {
516  }
517  if (_pCircTop->getIsRayonnant())
518  {
519  _pCircTop->setSrcsLw();
520  }
522  {
524  }
525 
526  return true;
527 }
528 
530 {
531  // Pi.R^2.h
532  double rayon = getDiameter() / 2.0;
533  return (M_PI * rayon * rayon * getHauteur());
534 }
535 
537 {
538  // 2.Pi.R.(R+h)
539  double rayon = getDiameter() / 2.0;
540  return (2 * M_PI * rayon * (rayon + getHauteur()));
541 }
542 
544 {
545  double res = 0.0;
546 
548  {
549  res += _pCircBottom->surface();
550  }
551  if (_pCircTop->getIsRayonnant())
552  {
553  res += _pCircTop->surface();
554  }
556  {
557  res += _pEnveloppe->surface();
558  }
559 
560  return res;
561 }
562 
564 {
565  double res = 0.0;
566 
568  {
569  res += _pCircBottom->surface();
570  }
571  if (_pCircTop->getIsRayonnant())
572  {
573  res += _pCircTop->surface();
574  }
576  {
577  res += _pEnveloppe->surface();
578  }
579 
580  return res;
581 }
582 
584 {
585  TYTabVector tab;
586 
587  tab.push_back(_pCircBottom->getShape()->normal());
588  tab.push_back(_pCircTop->getShape()->normal());
589 
590  TYTabRectangle tabRect = getEnveloppe();
591  for (unsigned int i = 0; i < tabRect.size(); i++)
592  {
593  tab.push_back(tabRect[i].normal());
594  }
595 
596  return tab;
597 }
598 
600 {
601  TYTabPoint tab;
602 
603  TYTabRectangle tabRect = getEnveloppe();
604  tab.reserve(tabRect.size() * 4);
605 
606  // Chaque rectangle
607  for (unsigned int i = 0; i < tabRect.size(); i++)
608  {
609  // Chaque point du rectangle
610  for (int j = 0; j < 4; j++)
611  {
612  // Ajout du sommet au tableau
613  tab.push_back(tabRect[i]._pts[j]);
614  }
615  }
616 
617  return tab;
618 }
619 
621 {
622  TYTabLPPolygon tab;
623 
624  TYTabRectangle enveloppe = getEnveloppe();
625  for (unsigned int i = 0; i < enveloppe.size(); i++)
626  {
627  tab.push_back(enveloppe[i].toPolygon());
628  }
629 
630  tab.push_back(_pCircBottom->getBoundingRect()->toPolygon());
631  tab.push_back(_pCircTop->getBoundingRect()->toPolygon());
632 
633  return tab;
634 }
635 
637 {
639 }
640 
642 {
643  return getCenter();
644 }
645 
647 {
648  return TYVolumeInterface::intersects(seg, ptList);
649 }
650 
652 {
653  int res = INTERS_NULLE;
654 
655  // Test de la position du point par rapport au vol englob
656  if (_volEnglob.isInside(pt) == INTERS_NULLE)
657  {
658  return res;
659  }
660 
661  // Le point doit verifier X^2+Y^2 < R^2 pour Z a l'interieur
662  // du cylindre (Le cylindre ne doit pas etre un cône...)
663  // La verification de l'appartenance au cone infini est
664  // suffisante car on a deja teste si le point est compris
665  // entre les plan haut et bas du cylindre (boîte englobante)
666 
667  // Obtention de la matrice de changement de repere
669  repere._origin = getCenter();
670 
671  // On passe dans le repere du cylindre pour travailler en 2D
672  OPoint3D ptCopy = repere.asMatrix() * pt;
673 
674  // Test X^2 + Y^2 <= R^2
675  double rayon = getDiameter() / 2.0;
676  if ((ptCopy._x * ptCopy._x) + (ptCopy._y * ptCopy._y) <= (rayon * rayon))
677  {
678  // Le point est a l'interieur du cylindre
679  res = INTERS_OUI;
680  }
681 
682  return res;
683 }
684 
686 {
688 
689  // Circ top
690  tab.push_back(new TYAcousticSurfaceGeoNode((LPTYElement&)_pCircTop));
691  // Circ bottom
692  tab.push_back(new TYAcousticSurfaceGeoNode((LPTYElement&)_pCircBottom));
693 
694  // Enveloppe
695  // Resolution pour l'enveloppe
696  int resolution = TYDEFAULTRESOLUTIONIONCIRCLE;
697 
698 #if TY_USE_IHM
699  // static const char prefName[] = "ResolutionCircle";
700 
701  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "ResolutionCircle"))
702  {
703  resolution = TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "ResolutionCircle");
704  }
705  else
706  {
707  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "ResolutionCircle", resolution);
708  }
709 #endif // TY_USE_IHM
710 
711  TYTabRectangle enveloppe = getEnveloppe(resolution);
712  TYAcousticRectangle* pEnvElt = NULL;
713 
714  for (unsigned int i = 0; i < enveloppe.size(); i++)
715  {
716  // Element de l'enveloppe
717  pEnvElt = new TYAcousticRectangle();
718  pEnvElt->setParent(this);
720 
721  // Geometrie
722  *pEnvElt->getShape() = enveloppe[i];
723 
724  // Acoustique
725  // pEnvElt->setSrcSurf(_pEnveloppe->getSrcSurf());
726 
727  // Ajout
728  tab.push_back(new TYAcousticSurfaceGeoNode(pEnvElt));
729  }
730 
731  return tab;
732 }
733 
735 {
736  bool ret = false;
737 
738  if (((TYAcousticSurface*)_pCircBottom._pObj == pAccSurf) ||
739  ((TYAcousticSurface*)_pCircTop._pObj == pAccSurf))
740  {
741  // Pas de changement de repere pour ces surfaces
742  ret = true;
743  }
744 
745  return ret;
746 }
747 
749 {
750  return _pCircBottom->getDiameter();
751 }
752 
753 void TYAcousticCylinder::setDiameter(double diameter)
754 {
755  _pCircBottom->setDiameter(diameter);
756  _pCircTop->setDiameter(diameter);
757 
758  _volEnglob = volEnglob();
759  if (_pParent)
760  {
761  TYAcousticVolumeNode::safeDownCast(_pParent)->updateVolEnglob();
762  } // Informe le parent de se mettre a jour
763 
765 
767 
768  // Recalcul de la surface de l'enveloppe affectee au rectangle associe a l'acousticsurface
770 
771  setIsGeometryModified(true);
772 }
773 
775 {
777 }
778 
779 void TYAcousticCylinder::setHauteur(double hauteur)
780 {
781  // On ajuste la position du cylindre
782  float oldZ = getHauteur();
783 
784  // Modification de la position pour tenir compte des nouvelles dimensions
786  if (pParent)
787  {
788  LPTYAcousticVolumeGeoNode pGeoNode = pParent->findAcousticVol(this);
789  if (pGeoNode)
790  {
791  ORepere3D repere = pGeoNode->getORepere3D();
792  TYPoint org = repere._origin;
793  // On retire l'ancienne hauteur
794  org._z -= oldZ / 2;
795  // On ajoute la nouvelle hauteur
796  org._z += hauteur / 2;
797  repere._origin = org;
798  pGeoNode->setRepere(repere);
799  }
800  }
801 
802  // On attribue +hauteur/2 au cercle du dessus
803  // et -hauteur/2 au cercle du dessous
804  // On calcul en fait des facteurs en fonction de la taille actuelle
805  // Les vecteurs obtenus font abstraction de la position du cylindre
806 
807  // Cercle top
808  OVector3D vecTop(getCenter(), _pCircTop->getCenter());
809  vecTop = vecTop * (((hauteur / 2.0) / vecTop.norme()) - 1.0);
810 
811  // Cercle bottom
812  OVector3D vecBottom(getCenter(), _pCircBottom->getCenter());
813  vecBottom = vecBottom * (((hauteur / 2.0) / vecBottom.norme()) - 1.0);
814 
815  // Pour chaque point
816  for (int i = 0; i < 4; i++)
817  {
818  // On applique le vecteur facteur
819  _pCircTop->getShape()->_pts[i] = OVector3D(_pCircTop->getShape()->_pts[i]) + vecTop;
820  _pCircBottom->getShape()->_pts[i] = OVector3D(_pCircBottom->getShape()->_pts[i]) + vecBottom;
821  }
822 
823  _volEnglob = volEnglob();
824  if (_pParent)
825  {
826  TYAcousticVolumeNode::safeDownCast(_pParent)->updateVolEnglob();
827  } // Informe le parent de se mettre a jour
828 
831 
832  // Recalcul de la surface de l'enveloppe affectee au rectangle associe a l'acousticsurface
834 
835  setIsGeometryModified(true);
836 }
837 
839 {
840  TYTabRectangle tab;
841 
842  if (n == -1)
843  {
844  // Prise en compte de la precision
845  n = ROUND((getDiameter() / 2.0) / TYPRECISIONCIRCLE);
846 
847  // On veut au moins tous les Pi/2 (90deg)
848  n = ROUND(n / 4 * 4);
849  }
850 
851  if (n < 3)
852  {
853  return tab;
854  }
855 
856  // Obtention des contours des cercles top et bottom
857  // (Le nombre de points generes doit etre le meme)
858  TYTabPoint tabPtBottom = _pCircBottom->getContour(n);
859  TYTabPoint tabPtTop = _pCircTop->getContour(n);
860 
861  // On genere une face pour chaque couple de points top bottom
862  for (int i = 0; i < n; i++)
863  {
864  TYRectangle rect(tabPtTop[(i + 1) % n], tabPtTop[i], tabPtBottom[(n - i) % n],
865  tabPtBottom[n - i - 1]);
866  tab.push_back(rect);
867  }
868 
869  return tab;
870 }
871 
873 {
874  // Le centre du cylindre est la mi-hauteur entre les centres des 2 cercles
876  return (OVector3D(_pCircBottom->getCenter()) + (vec * 0.5));
877 }
878 
879 bool TYAcousticCylinder::updateAcoustic(const bool& force) // force = false
880 {
881  /*
882  NB : On travaille sur un regime donne.
883  */
884 
885  bool ret = true;
886 
887  // Si le volume n'est pas rayonnant, inutile de tenter de distribuer
888  // la puissance, mais ce n'est pas une raison pour bloquer le calcul
889  if (!_isRayonnant)
890  {
891  return true;
892  }
893 
894  // 1/ Recuperer la surface totale
895  double surfTotale = this->activeSurface();
896 
897  OSpectre LWc = OSpectre::getEmptyLinSpectre(); // Spectre cumule de l'ensemble des elements
898  OSpectre LWg = getCurrentSpectre().toGPhy(); // Spectre global du regime courant
899  OSpectre LWv; // Spectre de puissance de la face courante
900 
901  LWc.setType(SPECTRE_TYPE_LW); // LWc represente une puissance
902 
903  if (_pCircTop->getIsRayonnant())
904  {
905  LWv = _pCircTop->setGlobalLW(LWg, surfTotale);
906  LWc = LWc.sum(LWv);
907  }
908  else
909  {
910  TYSpectre aTYSpectre;
911  _pCircTop->setRegime(aTYSpectre);
912  }
913 
915  {
916  LWv = _pCircBottom->setGlobalLW(LWg, surfTotale);
917  LWc = LWc.sum(LWv);
918  }
919  else
920  {
921  TYSpectre aTYSpectre;
922  _pCircBottom->setRegime(aTYSpectre);
923  }
924 
926  {
927  LWv = _pEnveloppe->setGlobalLW(LWg, surfTotale);
928  LWc = LWc.sum(LWv);
929  }
930  else
931  {
932  TYSpectre aSpectre;
933  _pEnveloppe->setRegime(aSpectre);
934  }
935 
937  {
938  // Il faut s'assurer que la somme des puissances des volumes egale la puissance de la machine
939  double residu = ABS(10 * log10(LWg.sigma()) - 10 * log10(LWc.sigma()));
940 
941  // Si l'ecart est inferieur a 1 dB on accepte
942  ret = residu < 1 ? true : false;
943  }
945  {
948 
949  if (_pCircTop->getIsRayonnant())
950  {
951  LWc = LWc.sum(_pCircTop->getCurrentSpectre().toGPhy());
952  }
954  {
955  LWc = LWc.sum(_pCircBottom->getCurrentSpectre().toGPhy());
956  }
958  {
959  LWc = LWc.sum(_pEnveloppe->getCurrentSpectre().toGPhy());
960  }
961 
962  TYSpectre temp = LWc.toDB();
963  setRegime(temp, -1, false); // Pas de problemes, la puissance peut etre modifiee
964  ret = true;
965  }
966 
967  if (_pParent && _pParent->isA("TYBatiment"))
968  {
969  // Dans le cas des machine, cette operation est pilotee par TYAcousticVolumeNode
970  distriSrcs();
971  setSrcsLw();
972  }
973 
974  return ret;
975 }
976 
978 {
979  TYTabLPAcousticSurface tabSubFaces;
980 
981  // On balaye toutes les faces
983  for (unsigned int j = 0; j < tabFaces.size(); j++)
984  {
985  if (TYAcousticSurface::safeDownCast(tabFaces[j]->getElement())->getIsSub())
986  {
987  tabSubFaces.push_back(TYAcousticSurface::safeDownCast(tabFaces[j]->getElement()));
988  }
989  }
990 
991  return tabSubFaces;
992 }
993 
994 void TYAcousticCylinder::setIsRayonnant(bool rayonnant /*= true*/, bool recursif /*=true*/)
995 {
996  TYAcousticVolume::setIsRayonnant(rayonnant, recursif);
997 }
998 
1000 {
1001  _nextRegime = next;
1002 
1003  // Surface du dessus
1004  _pCircTop->setNextRegimeNb(next);
1007  // Enveloppe
1009 }
1010 
1012 {
1014 
1015  // Surface du dessus
1019  // Enveloppe
1021 }
1022 
1024 {
1025  double sizeRectangle = sqrt(getDiameter() * M_PI * getHauteur()); // = 2.pi.r.h
1026  _pEnveloppe->getBoundingRect()->setDimension(sizeRectangle, sizeRectangle);
1027 }
1028 
1029 void TYAcousticCylinder::exportCSV(std::ofstream& ofs)
1030 {
1031  // Export du nom de l'objet
1032  ofs << getName().toLatin1().data() << '\n';
1033 
1034  // Export du type de l'objet
1035  ofs << toString() << '\n';
1036 
1037  // Export des donnees acoustiques
1039 
1040  _pCircTop->exportCSV(ofs);
1041  _pCircBottom->exportCSV(ofs);
1042  _pEnveloppe->exportCSV(ofs);
1043 }
#define M_2PI
2Pi.
Definition: 3d.h:55
int ROUND(double a)
Compute the rounded value of a number.
Definition: 3d.h:192
#define INTERS_OUI
The intersection exists.
Definition: 3d.h:33
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
#define INTERS_NULLE
No intersection.
Definition: 3d.h:35
QColor getColor
QDomElement DOM_Element
Definition: QT2DOM.h:30
Representation graphique d'un cylindre accoustique (fichier header)
outil IHM pour un cylindre acoustique (fichier header)
TY_EXTENSION_INST(TYAcousticCylinder)
TY_EXT_GRAPHIC_INST(TYAcousticCylinder)
TYGeometryNode TYAcousticSurfaceGeoNode
Noeud geometrique de type TYAcousticSurface.
std::vector< LPTYAcousticSurface > TYTabLPAcousticSurface
Tableau de TYAcousticSurfaces.
std::vector< LPTYAcousticSurfaceGeoNode > TYTabAcousticSurfaceGeoNode
Collection de noeuds geometriques de type TYAcousticSurface.
std::vector< TYRectangle > TYTabRectangle
Collection de TYRectangle.
Definition: TYDefines.h:346
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
#define TYDEFAULTRESOLUTIONIONCIRCLE
Resolution par defaut pour la representation des cercles par des segments.
Definition: TYDefines.h:415
#define TYPRECISIONCIRCLE
Precision pour la representation des cercles par des segments.
Definition: TYDefines.h:412
std::vector< OVector3D > TYTabVector
Collection de OVector3D.
Definition: TYDefines.h:398
std::vector< LPTYPolygon > TYTabLPPolygon
Collection de pointeurs de TYPolygon.
Definition: TYDefines.h:349
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:344
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
const char * name
std::vector< LPTYSourcePonctuelleGeoNode > TYTabSourcePonctuelleGeoNode
Collection de noeuds geometriques de type TYSourcePonctuelle.
@ CALCULATED
Definition: color.h:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
The 4x4 matrix class.
Definition: 3d.h:625
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:248
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
bool isA(const char *className) const
Definition: TYElement.cpp:65
3D frame with a point and 3 vectors.
Definition: 3d.h:1263
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
OMatrix asMatrix() const
return the transformation matrix from unity to this pose such as this = transform * unity
Definition: 3d.cpp:1462
Class to define a segment.
Definition: 3d.h:1141
OSpectreAbstract & sum(const OSpectreAbstract &spectre) const
Arithmetic sum of two spectrums in one-third Octave.
Definition: spectre.cpp:224
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
Definition: spectre.cpp:642
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:153
double sigma()
Sum the values of the spectrum.
Definition: spectre.cpp:558
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:595
static OSpectre getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
Definition: spectre.cpp:1130
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
void normalize()
Normalizes this vector.
Definition: 3d.cpp:225
T * _pObj
The real pointer, must derived IRefCount.
Definition: smartptr.h:307
Spectrum class.
Definition: Spectre.h:25
TYRectangle * getShape()
virtual double surface() const
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
void setDiameter(double diameter)
TYPoint getCenter() const
virtual void distriSrcs()
virtual DOM_Element toXML(DOM_Element &domElement)
virtual TYTabPoint getContour(int n=-1) const
double getDiameter() const
virtual bool setSrcsLw()
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual TYTabPoint sommets() const
bool operator==(const TYAcousticCylinder &other) const
Operateur ==.
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
TYTabLPAcousticSurface getSubFace()
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual int isInside(const TYPoint &pt) const
virtual std::string toString() const
LPTYAcousticCircle _pCircBottom
Surface de dessous.
bool operator!=(const TYAcousticCylinder &other) const
Operateur !=.
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual TYPoint getCenter() const
virtual double surface() const
virtual bool remRegime(int regime)
virtual void setCurRegime(int regime)
virtual TYTabVector normals() const
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
virtual int intersects(const OSegment3D &seg, TYTabPoint &ptList) const
virtual TYSourcePonctuelle srcPonctEquiv() const
void setHauteur(double hauteur)
virtual TYPoint centreGravite() const
virtual int fromXML(DOM_Element domElement)
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual void setRegime(TYSpectre &Spectre, int regime=-1, bool recursif=false)
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
LPTYAcousticSurface _pEnveloppe
Enveloppe.
virtual void propagateAtt(LPTYAttenuateur pAtt)
virtual TYTabLPPolygon faces() const
void setDiameter(double diameter)
virtual void loadRegime(int regimeNb=-1)
virtual void setNextRegimeNb(const int &next)
virtual TYTabRectangle getEnveloppe(int n=-1) const
virtual double volume() const
virtual double activeSurface() const
bool updateAcoustic(const bool &force=false)
double getDiameter() const
virtual DOM_Element toXML(DOM_Element &domElement)
virtual bool findAcousticSurface(const TYAcousticSurface *pAccSurf, OMatrix *pMatrix=0)
virtual void setRegimeName(const QString &name)
virtual TYTabAcousticSurfaceGeoNode acousticFaces()
LPTYAcousticCircle _pCircTop
Surface de dessus.
virtual TYBox volEnglob() const
TYAcousticCylinder & operator=(const TYAcousticCylinder &other)
Operateur =.
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
double _densiteSrcsV
Densite verticale de sources.
double getDensiteSrcsH() const
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual void setNextRegimeNb(const int &next)
TYRegime & getRegimeNb(const int &nb, bool &status)
size_t getNbRegimes() const
double getDensiteSrcsV() const
int _typeDistribution
Indique le type de distribution a utiliser. pour l'etat courant.
double _offsetSources
Offset de decalage des sources ponctuelles sur les surfaces.
virtual void loadRegime(int regimeNb=-1)
TYSpectre & getCurrentSpectre()
virtual int addRegime(const TYRegime &regime)
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
virtual void setRegime(TYSpectre &Spectre, int regime=-1, bool recursif=false)
virtual void setCurRegime(int regimeNumber)
int _nextRegime
Numero d'ordre du regime suivant.
double _densiteSrcsH
Densite horizontale de sources.
virtual bool remRegime(int regime)
virtual void setRegimeName(const QString &name)
bool _isRayonnant
Etat courant de l'element (rayonnant ou non rayonnant)
TYRectangle * getShape()
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual void remAllSrcs()
virtual void setCurRegime(int regime)
virtual double surface() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual void propagateAtt(LPTYAttenuateur pAtt)
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
TYSpectre setGlobalLW(const TYSpectre &spectre, const double &surfGlobale, const int &regime=-1)
LPTYSourceSurfacic getSrcSurf()
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual bool setSrcsLw()
TYRectangle * getBoundingRect()
virtual DOM_Element toXML(DOM_Element &domElement)
LPTYAcousticVolumeGeoNode findAcousticVol(const LPTYAcousticVolume pAccVol)
TYAcousticVolume & operator=(const TYAcousticVolume &other)
Operateur =.
virtual DOM_Element toXML(DOM_Element &domElement)
virtual int fromXML(DOM_Element domElement)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual void propagateAtt(LPTYAttenuateur pAtt)
virtual void setIsAcousticModified(bool isModified)
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
Definition: TYBox.h:34
int isInside(const TYPoint &pt) const
Definition: TYBox.cpp:236
virtual void setColor(const OColor &color)
TYElement * getParent() const
Definition: TYElement.h:706
virtual bool isInCurrentCalcul()
Definition: TYElement.h:539
QString _name
Nom courant de l'element.
Definition: TYElement.h:965
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:542
virtual QString getName() const
Definition: TYElement.h:691
TYElement * _pParent
Reference sur l'element parent.
Definition: TYElement.h:968
virtual void setInCurrentCalcul(bool state, bool recurschild=true, bool recursparent=true)
Definition: TYElement.cpp:408
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:530
void setParent(TYElement *pParent)
Definition: TYElement.h:699
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
const ORepere3D & getORepere3D() const
void setRepere(const ORepere3D &repere)
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
ORepere3D getORepere3D() const
void setDimension(float lon, float haut)
TYPoint _pts[4]
Sommets.
Definition: TYRectangle.h:274
TYPolygon * toPolygon() const
virtual OVector3D normal() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYRegime.cpp:99
void setDirectivity(TYDirectivity *directivity_)
: Get/Set directivity to source
void setTypeRaynt(TYTypeRaynt type)
double getDensiteSrcsH() const
bool addSrc(LPTYSourcePonctuelle pSrcPonct)
double getDensiteSrcsV() const
virtual int intersects(const OSegment3D &seg, TYTabPoint &ptList) const
virtual TYBox volEnglob() const
void calculRayonSphere(const TYBox &volEnglob)
virtual void calculCentreGravite()
#define M_PI
Pi.
Definition: color.cpp:25
@ SPECTRE_TYPE_LW
Definition: spectre.h:30