Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticSurface.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 
19 #if TY_USE_IHM
21 #endif
22 #include "TYAcousticSurface.h"
23 
25 
27 {
29 
31  _pSrcSurf->setParent(this);
32 
35 
36  _isSub = false;
37 }
38 
40 {
41  *this = other;
42 }
43 
45 
47 {
48  if (this != &other)
49  {
50  TYElement::operator=(other);
53  _pSrcSurf = other._pSrcSurf;
55  _isSub = other._isSub;
56  }
57  return *this;
58 }
59 
61 {
62  if (this != &other)
63  {
64  if (TYElement::operator!=(other))
65  {
66  return false;
67  }
68  if (TYColorInterface::operator!=(other))
69  {
70  return false;
71  }
72  if (TYAcousticInterface::operator!=(other))
73  {
74  return false;
75  }
76  if (_pSrcSurf != other._pSrcSurf)
77  {
78  return false;
79  }
80  if (_pBoundingRect != other._pBoundingRect)
81  {
82  return false;
83  }
84  if (_isSub != other._isSub)
85  {
86  return false;
87  }
88  }
89  return true;
90 }
91 
93 {
94  return !operator==(other);
95 }
96 
97 bool TYAcousticSurface::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
98 {
99  if (!TYElement::deepCopy(pOther, copyId))
100  {
101  return false;
102  }
103 
104  TYAcousticSurface* pOtherAccSurf = (TYAcousticSurface*)pOther;
105 
106  TYColorInterface::deepCopy((TYColorInterface*)pOtherAccSurf, copyId);
107 
108  TYAcousticInterface::deepCopy(pOtherAccSurf, copyId);
109 
110  _pSrcSurf->deepCopy(pOtherAccSurf->_pSrcSurf, copyId);
111  _pBoundingRect->deepCopy(pOtherAccSurf->_pBoundingRect, copyId);
112 
113  _isSub = pOtherAccSurf->_isSub;
114 
115  return true;
116 }
117 
118 std::string TYAcousticSurface::toString() const
119 {
120  return "TYAcousticSurface";
121 }
122 
124 {
125  DOM_Element domNewElem = TYElement::toXML(domElement);
126  TYColorInterface::toXML(domNewElem);
127  TYAcousticInterface::toXML(domNewElem);
128 
129  TYXMLTools::addElementBoolValue(domNewElem, "isSub", _isSub);
130 
131  _pBoundingRect->toXML(domNewElem);
132  _pSrcSurf->toXML(domNewElem);
133 
134  return domNewElem;
135 }
136 
138 {
139  TYElement::fromXML(domElement);
140  TYColorInterface::fromXML(domElement);
141  TYAcousticInterface::fromXML(domElement);
142  TYUUID currentId = this->getID();
143  if (TYElement::testId(currentId, this))
144  {
145  this->regenerateID();
146  }
147  bool isSubOk = false;
148  DOM_Element elemCur;
149  QDomNodeList childs = domElement.childNodes();
150  for (unsigned int i = 0; i < childs.length(); i++)
151  {
152  elemCur = childs.item(i).toElement();
153  TYXMLTools::getElementBoolValue(elemCur, "isSub", _isSub, isSubOk);
154 
155  _pSrcSurf->callFromXMLIfEqual(elemCur);
156 
158  }
159 
160  return 1;
161 }
162 
164 {
166 
167  if (_pParent)
168  {
169  _pParent->setIsAcousticModified(isModified);
170  }
171 }
172 
173 void TYAcousticSurface::setDensiteSrcsH(double densite, bool recursif /*=true*/)
174 {
175  TYAcousticInterface::setDensiteSrcsH(densite, recursif);
176  _pSrcSurf->setDensiteSrcsH(densite);
177 }
178 
179 void TYAcousticSurface::setDensiteSrcsV(double densite, bool recursif /*=true*/)
180 {
181  TYAcousticInterface::setDensiteSrcsV(densite, recursif);
182  _pSrcSurf->setDensiteSrcsV(densite);
183 }
184 
186 {
189 
190  for (unsigned int i = 0; i < tab.size(); i++)
191  {
192  tabRet.push_back(new TYSourcePonctuelleGeoNode((LPTYElement)tab[i]));
193  }
194 
195  return tabRet;
196 }
197 
199 {
200  return TYSourcePonctuelle();
201 }
202 
204 {
206 }
207 
209 {
211 
212  setIsAcousticModified(true);
213 }
214 
216 {
217  setIsAcousticModified(true);
218 
220 }
221 
223 
225 {
226  _pSrcSurf->remAllSrc();
227 }
228 
230 {
231  double surface = this->surface();
232 
233  const TYTabSourcePonctuelleGeoNode& tabSrcs = this->getSrcs();
234  size_t nbSrcs = tabSrcs.size();
235 
237  s.setType(SPECTRE_TYPE_LW);
238 
239  if (this->getUseAtt() && this->_pAtt != NULL) // Si un attenuateur est defini, on l'applique
240  {
241  s = s.div(_pAtt->getSpectreAtt().toGPhy());
242  }
243 
244  double surfSource = surface / nbSrcs;
245 
246  s = s.mult(getCurrentSpectre().toGPhy().mult(surfSource / surface));
247 
248  for (size_t i = 0; i < nbSrcs; i++)
249  {
250  // Affectation du spectre a la source i pour le regime j
251  TYSourcePonctuelle::safeDownCast(tabSrcs[i]->getElement())->setSpectre(new TYSpectre(s));
252  }
253 
254  return true;
255 }
256 
257 bool TYAcousticSurface::updateAcoustic(const bool& force) // force = false
258 {
259  return true;
260 }
261 
263 {
264  // XXX This is a dummy default implementation
265  return _pBoundingRect->surface();
266 }
267 
269 {
270  // XXX This is a dummy default implementation
271  return _pBoundingRect->normal();
272 }
273 
275 {
276  // XXX This is a dummy default implementation
277  return _pBoundingRect->plan();
278 }
279 
281 {
282  // XXX This is a dummy default implementation
283  return _pBoundingRect->getContour(n);
284 }
285 
287 {
288  // XXX This is a dummy default implementation
289  return _pBoundingRect->getOContour(n);
290 }
291 
293 {
294  // XXX This is a dummy default implementation
295  return _pBoundingRect->intersects(pSurf, seg);
296 }
297 
299 {
300  // XXX This is a dummy default implementation
301  return _pBoundingRect->intersects(seg, pt);
302 }
303 
305 {
306  // XXX This is a dummy default implementation
307  return _pBoundingRect->intersects(pt);
308 }
309 
311 {
312  LPTYMateriauConstruction pMat = NULL;
313 
314  TYElement* pParent = getParent();
315 
316  // Tant qu'il y a un parent
317  while (pParent)
318  {
319  // Tentative de cast du parent en AcousticVolume
321 
322  // Si le parent est effectivement un AcousticVolume
323  if (pAccVol)
324  {
325  pMat = pAccVol->getMateriau();
326  break;
327  }
328 
329  // Parent du parent...
330  pParent = pParent->getParent();
331  }
332 
333  return pMat;
334 }
335 
336 TYSpectre TYAcousticSurface::setGlobalLW(const TYSpectre& spectre, const double& surfGlobale,
337  const int& regime /*=-1*/)
338 {
339  TYSpectre LWv;
340 
341  // 2 cas
343  {
344  if (surfGlobale == 0)
345  {
347  }
348  else
349  {
350  LWv = spectre.toGPhy()
351  .mult(surface() / surfGlobale)
352  .toDB(); // Spectre pondere de la surface de la face
353  }
354 
355  setRegime(LWv, regime, false);
356  }
357 
358  return getCurrentSpectre().toGPhy();
359 }
360 
362 {
363  // Si la surface n'est pas rayonnante on renvoi un spectre vide
364  if (!_isRayonnant)
365  {
366  return new TYSpectre();
367  }
368 
369  // on prend en compte l'eventuel attenuateur
370  if (_useAtt && (_pAtt != NULL))
371  {
373  return new TYSpectre(temp);
374  }
375 
376  return new TYSpectre(_pCurrentSpectre);
377 }
378 
379 void TYAcousticSurface::setIsRayonnant(bool rayonnant, bool recursif)
380 {
382 
383  if (_isSub && rayonnant)
384  {
385  // Si une face rayonne son parent rayonne
387  if (pSurfNode)
388  {
389  pSurfNode->setIsRayonnant(rayonnant, recursif);
390  }
391  }
392 }
393 
394 void TYAcousticSurface::exportCSV(std::ofstream& ofs)
395 {
396  // Export du nom de l'objet
397  ofs << getName().toLatin1().data() << '\n';
398 
399  // Export du type de l'objet
400  ofs << toString() << '\n';
402 }
NxReal s
Definition: NxVec3.cpp:317
QDomElement DOM_Element
Definition: QT2DOM.h:30
outil IHM pour une surface acoustique (fichier header)
TY_EXTENSION_INST(TYAcousticSurface)
class OGenID TYUUID
Definition: TYDefines.h:59
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
std::deque< OPoint3D > TYTabPoint3D
Collection de OPoint3D.
Definition: TYDefines.h:403
std::vector< LPTYSourcePonctuelle > TYTabLPSourcePonctuelle
Collection de pointeurs de TYSourcePonctuelle.
Definition: TYDefines.h:355
TYGeometryNode TYSourcePonctuelleGeoNode
Noeud geometrique de type TYSourcePonctuelle.
std::vector< LPTYSourcePonctuelleGeoNode > TYTabSourcePonctuelleGeoNode
Collection de noeuds geometriques de type TYSourcePonctuelle.
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:31
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:249
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
Class to define a segment.
Definition: 3d.h:1089
OSpectreAbstract & subst(const OSpectreAbstract &spectre) const
Arithmetic subtraction of two spectrums in one-third Octave.
Definition: spectre.cpp:316
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
Definition: spectre.cpp:634
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:590
OSpectreAbstract & mult(const OSpectreAbstract &spectre) const
Multiplication of two spectrums.
Definition: spectre.cpp:243
The 3D vector class.
Definition: 3d.h:298
bool _useAtt
Indique l'utilisation d'un attenuateur pour l'etat courant.
virtual void setDensiteSrcsH(double densite, bool recursif=true)
LPTYAttenuateur _pAtt
Attenuateur de l'etat courant.
int _typeDistribution
Indique le type de distribution a utiliser. pour l'etat courant.
TYSpectre & getCurrentSpectre()
virtual void setDensiteSrcsV(double densite, bool recursif=true)
DOM_Element toXML(DOM_Element &domElement)
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
TYAcousticInterface & operator=(const TYAcousticInterface &other)
virtual void setRegime(TYSpectre &Spectre, int regime=-1, bool recursif=false)
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
virtual void setCurRegime(int regimeNumber)
int fromXML(DOM_Element domElement)
void deepCopy(const TYAcousticInterface *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual void propagateRegime()
virtual void propagateAtt(LPTYAttenuateur pAtt)
bool _isRayonnant
Etat courant de l'element (rayonnant ou non rayonnant)
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
virtual void setDensiteSrcsV(double densite, bool recursif=true)
TYAcousticSurface & operator=(const TYAcousticSurface &other)
Operateur =.
virtual void remAllSrcs()
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
bool _isSub
Indicateur qui precise si la surface est un sous-element d'une face (fenetre ou bouche d'aeration).
virtual void setCurRegime(int regime)
virtual double surface() const
bool operator==(const TYAcousticSurface &other) const
Operateur ==.
virtual TYTabPoint3D getOContour(int n=-1) const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual void propagateAtt(LPTYAttenuateur pAtt)
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual void distriSrcs()
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)
LPTYRectangle _pBoundingRect
Rectangle englobant.
virtual std::string toString() const
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual LPTYSpectre getRealPowerSpectrum()
virtual LPTYMateriauConstruction getMateriau() const
virtual void propagateRegime()
virtual bool setSrcsLw()
virtual void setIsAcousticModified(bool isModified)
virtual TYTabPoint getContour(int n=-1) const
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
Get/set de l'etat rayonnant ou pas.
virtual OPlan plan() const
virtual TYSourcePonctuelle srcPonctEquiv() const
virtual DOM_Element toXML(DOM_Element &domElement)
virtual OVector3D normal() const
LPTYSourceSurfacic _pSrcSurf
Source surfacique.
bool operator!=(const TYAcousticSurface &other) const
Operateur !=.
virtual int fromXML(DOM_Element domElement)
virtual bool updateAcoustic(const bool &force=false)
TYMateriauConstruction * getMateriau() const
TYSpectre & getSpectreAtt()
Definition: TYAttenuateur.h:99
int fromXML(DOM_Element domElement)
TYColorInterface & operator=(const TYColorInterface &other)
void deepCopy(const TYColorInterface *pOther, bool copyId=true, bool pUseCopyTag=false)
DOM_Element toXML(DOM_Element &domElement)
TYElement * getParent() const
Definition: TYElement.h:699
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYElement.cpp:307
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
static bool testId(const TYUUID &id, const TYElement *pElem)
Definition: TYElement.cpp:216
void regenerateID()
Definition: TYElement.cpp:243
const TYUUID & getID() const
Definition: TYElement.cpp:176
virtual QString getName() const
Definition: TYElement.h:684
TYElement * _pParent
Reference sur l'element parent.
Definition: TYElement.h:969
void setParent(TYElement *pParent)
Definition: TYElement.h:692
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
virtual void setIsAcousticModified(bool isModified)
Definition: TYElement.cpp:248
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
virtual DOM_Element toXML(DOM_Element &domElement)
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
virtual OPlan plan() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual TYTabPoint getContour(int n=-1) const
virtual OVector3D normal() const
virtual TYTabPoint3D getOContour(int n=-1) const
virtual double surface() const
void setDensiteSrcsH(const double &densite)
void setDensiteSrcsV(const double &densite)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual DOM_Element toXML(DOM_Element &domElement)
TYTabLPSourcePonctuelle & getSrcs()
static TYSpectre getEmptyLinSpectre(const double &valInit=1.0E-20)
Cree un spectre en lin.
Definition: TYSpectre.cpp:451
static bool getElementBoolValue(DOM_Element parentElem, DOMString nodeName, bool &nodeValue)
Definition: TYXMLTools.cpp:179
static void addElementBoolValue(DOM_Element &parentElem, DOMString nodeName, bool nodeValue)
Definition: TYXMLTools.cpp:77
@ SPECTRE_TYPE_LW
Definition: spectre.h:30