]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Support.hxx
Salome HOME
correct a small bug appearing when using the gcc 3.2.1.
[modules/med.git] / src / MEDMEM / MEDMEM_Support.hxx
1 /*
2   File Support.hxx
3   $Header$
4 */
5
6 #ifndef SUPPORT_HXX
7 #define SUPPORT_HXX
8
9 #include <vector>
10 #include <string>
11
12 #include "utilities.h"
13 #include "MEDMEM_STRING.hxx"
14 #include "MEDMEM_Exception.hxx"
15 #include "MEDMEM_define.hxx"
16 #include "MEDMEM_SkyLineArray.hxx"
17
18 using namespace MED_EN;
19 using namespace MEDMEM;
20
21
22 /*!
23
24   This class describe a support of elements on an entity of the mesh.
25
26   It contains the list of meshes elements for an entity (MED_NODE, 
27   MED_CELL, MED_FACE or MED_EDGE).
28
29 */
30
31 namespace MEDMEM {
32 class MESH ;
33 class SUPPORT
34 {
35 protected:
36   /*!
37     \if developper
38     Support name.
39     \endif
40   */
41   string                   _name;
42
43   /*!
44     \if developper
45     Description of the support (optional).
46     \endif
47   */
48   string                   _description;
49
50   /*!
51     \if developper
52     Reference to the mesh on which the support is defined.
53     \endif
54   */
55   mutable MESH *                   _mesh;
56
57   /*!
58     \if developper
59     Type of entity on which the support is defined
60     (only one for each support).
61     \endif
62   */
63   medEntityMesh            _entity ;
64
65   /*!
66     \if developper
67     Number of geometric type defined in the support.
68     \endif
69   */
70   int                      _numberOfGeometricType;
71
72   /*!
73     \if developper
74     Array of all geometric type defined in the support.
75     \endif
76   */
77   medGeometryElement *     _geometricType;
78
79   /*!
80     \if developper
81     Array of size _numberOfGeometricType which contains
82     for each type the number of gauss point
83     (not yet implemented).
84     \endif
85   */
86   mutable int *                    _numberOfGaussPoint ;
87
88    /*
89     \if developper
90     Array of size _numberOfGeometricType
91     which contains number of geometric
92     entity type in Mesh
93     (to get corresponding CellModel).
94     \endif
95   */
96   //int *                    _geometricTypeNumber;
97
98   /*!
99     \if developper
100     If true, we consider all entities of type _entity.
101     \endif
102   */
103   bool                     _isOnAllElts; 
104
105   /*!
106     \if developper
107     Index array of size _numberOfGeometricType wich contains
108     for each geometric type, the number of elements of this type.
109     \endif
110   */
111   int *                    _numberOfElements;
112
113   /*!
114     \if developper
115     Sum of each _numberOfElements component.
116     \endif
117   */
118   int                      _totalNumberOfElements;
119
120   // the two following arrays are defined only if _isOnAllElts is false :
121
122   /*
123     \if developper
124     array of size _numberOfType+1 wich contains for
125     each geometric type, index in _number._value
126     (if _all is true, we must ask _mesh to get
127     information). _typeIndex[i+1]-_typeIndex[i]
128     represents count of entities of ith geometric
129     type. _typeIndex[_numberOfType] contains total
130     entities count. If _numberOf[i]=0,
131     _typeIndex[i+1]=_typeIndex[i]
132     defined only if _isOnAllElts is false
133     \endif
134   */
135   //  int *      _typeIndex;
136
137   /*!
138     \if developper
139     Array of size _index[_numberOfType]-1 wich contain number of
140     entities of each geometric type. We use global numbering.\n
141     Defined only if _isOnAllElts is false.
142     \endif
143   */
144   mutable MEDSKYLINEARRAY * _number;
145
146 public:
147   SUPPORT();
148   SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL);
149   SUPPORT(const SUPPORT & m);
150   virtual ~SUPPORT();
151   friend ostream & operator<<(ostream &os,const SUPPORT &my);
152
153   // function to set all value when SUPPORT was created by MedMedDriver without all MESH information !!! Change with new API !
154   void update();
155
156   inline void setName(string Name);
157   inline void setDescription(string Description);
158   inline void setMesh(MESH *Mesh);
159   inline void setAll(bool All);
160   inline void setEntity(medEntityMesh Entity);
161   inline void setNumberOfGeometricType(int NumberOfGeometricType);
162   inline void setGeometricType(const medGeometryElement *GeometricType);
163   inline void setNumberOfGaussPoint(const int *NumberOfGaussPoint);
164   //  inline void setGeometricTypeNumber(int *GeometricTypeNumber);
165   inline void setNumberOfElements(const int *NumberOfElements);
166   inline void setTotalNumberOfElements(int TotalNumberOfElements);
167   inline void setNumber(MEDSKYLINEARRAY * Number);
168   inline void setNumber(const int * index, const int* value);
169
170   inline string getName() const;
171   inline string getDescription() const;
172   virtual inline MESH * getMesh() const;
173   inline medEntityMesh getEntity() const;
174
175   inline bool   isOnAllElements() const;
176   inline int    getNumberOfTypes() const;
177   inline const medGeometryElement* getTypes() const ;
178   inline const int *  getNumberOfGaussPoint() const throw (MEDEXCEPTION);
179   inline int          getNumberOfGaussPoint(medGeometryElement geomElement) const throw (MEDEXCEPTION);
180   //inline int *  getGeometricTypeNumber() const;
181   //inline int    getTotalNumberOfElement() const;
182   inline int    getNumberOfElements(medGeometryElement GeometricType) const throw (MEDEXCEPTION);
183   virtual inline MEDSKYLINEARRAY *  getnumber() const throw (MEDEXCEPTION);
184   virtual inline const int *  getNumber(medGeometryElement GeometricType) const throw (MEDEXCEPTION);
185   virtual inline const int *  getNumberIndex() const throw (MEDEXCEPTION);
186
187   void blending(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
188
189   void setpartial(string Description, int NumberOfGeometricType,
190                   int TotalNumberOfEntity, medGeometryElement *GeometricType,
191                   int *NumberOfEntity, int *NumberValue);
192
193   void getBoundaryElements() throw (MEDEXCEPTION);
194
195   void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
196 };
197 };
198 // _____________________
199 // Methodes Inline
200 // _____________________
201
202 using namespace MEDMEM;
203 /*!
204   This method returns the number of all elements of the type GeometricType.
205
206   If isOnAllElements is false, it returns the number of elements in the
207   support else it returns number of elements in the whole mesh.
208
209   Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
210   in entity of support.
211
212   Note : If SUPPORT is defined on MED_NODE, use MED_ALL_ELEMENTS as
213          medGeometryElement GeometricType and it will returns the number
214          of nodes in the support (or in the whole mesh).
215 */
216 //-----------------------------------------------------------------------------
217 inline int SUPPORT::getNumberOfElements(medGeometryElement GeometricType) const
218   throw (MEDEXCEPTION)
219 //-----------------------------------------------------------------------------
220 {
221   if (GeometricType==MED_ALL_ELEMENTS)
222     return _totalNumberOfElements;
223   for (int i=0;i<_numberOfGeometricType;i++)
224     if (_geometricType[i]==GeometricType)
225       return _numberOfElements[i];
226   throw MEDEXCEPTION("Support::getNumberOfElements : Geometric type not found !") ;
227 }
228
229 //---------------------------------------------------------------------
230 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const
231   throw (MEDEXCEPTION)
232 //---------------------------------------------------------------------
233 {
234   if (_number==NULL)
235     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
236   return _number ;
237 }
238
239 /*!
240   If isOnAllElements is false, returns an array which contains
241   all number of given medGeometryElement.
242
243   Numbering is global, ie numbers are bounded by 1 and
244   MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and
245   MESH::getNumberOfElement(entity,geomElement).
246
247   Note : If SUPPORT is defined on MED_NODE, use MED_NONE
248   medGeometryElement type.
249 */
250 //---------------------------------------------------------------------
251 inline const int * SUPPORT::getNumber(medGeometryElement GeometricType) const
252   throw (MEDEXCEPTION)
253 //---------------------------------------------------------------------
254 {
255   const char * LOC = "Support::getNumber : " ;
256   if (_isOnAllElts)
257     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ;
258   if (GeometricType==MED_ALL_ELEMENTS)
259     return _number->getValue() ;
260   for (int i=0;i<_numberOfGeometricType;i++)
261     if (_geometricType[i]==GeometricType)
262       return _number->getI(i+1) ;
263   throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ;
264 }
265
266 /*!
267   If isOnAllElements is false, returns index of element number.
268   Use it with getNumber(MED_ALL_ELEMENTS).
269
270   Note : See getConnectivityIndex for details.
271 */
272 //-------------------------------------------
273 inline const int * SUPPORT::getNumberIndex() const
274 //-------------------------------------------
275   throw (MEDEXCEPTION)
276 {
277   if (_isOnAllElts)
278     throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
279   return _number->getIndex() ;
280 }
281
282 /*! A DOCUMENTER */
283 //-------------------------------------------------
284 inline const int * SUPPORT::getNumberOfGaussPoint() const
285   throw (MEDEXCEPTION)
286 //-------------------------------------------------
287 {
288   if (_numberOfGaussPoint!=NULL)
289     return _numberOfGaussPoint ;
290   else
291     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
292 }
293
294 /*!
295   Returns number of Gauss points for this medGeometryElement.
296
297   Note :
298   - Not defined if SUPPORT is on MED_NODE.
299   - Not defined for MED_ALL_ELEMENTS medGeometryElement type.
300 */
301 //-----------------------------------------------------------------------------
302 inline int SUPPORT::getNumberOfGaussPoint(medGeometryElement geomElement) const
303   throw (MEDEXCEPTION)
304 //-----------------------------------------------------------------------------
305 {
306   if (_numberOfGaussPoint!=NULL) {
307     for (int i=0;i<_numberOfGeometricType;i++)
308       if (_geometricType[i]==geomElement)
309         return _numberOfGaussPoint[i] ;
310     throw MEDEXCEPTION("Support::getGlobalNumber : GeometricType not found !") ;
311   } else
312     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
313 }
314 //  inline int SUPPORT::getNumberLength() const
315 //  throw (MEDEXCEPTION)
316 //  {
317 //      if (_isOnAllElts)
318 //        throw MEDEXCEPTION("Support::getNumberLength : Not defined, support is on all entity !") ;
319 //        return _number->getLength() ;
320 //  }
321
322 /*! set the attribute _name to Name */
323 //--------------------------------------
324 inline void SUPPORT::setName(string Name)
325 //--------------------------------------
326 {
327   _name=Name;
328 }
329
330 /*! set the attribute _description to Description */
331 //--------------------------------------------------
332 inline void SUPPORT::setDescription(string Description)
333 //--------------------------------------------------
334 {
335   _description=Description;
336 }
337
338 /*! set the reference _mesh to Mesh */
339 //--------------------------------------
340 inline void SUPPORT::setMesh(MESH *Mesh)
341 //--------------------------------------
342 {
343   _mesh=Mesh;
344 }
345
346 /*! set the attribute _isOnAllElts to All */
347 //------------------------------------------
348 inline void SUPPORT::setAll(bool All)
349 //------------------------------------------
350 {
351   _isOnAllElts=All;
352 }
353
354 /*! set the attribute _entity to Entity */
355 //------------------------------------------
356 inline void SUPPORT::setEntity(medEntityMesh Entity)
357 {
358   _entity=Entity;
359 //   if ( Entity == MED_NODE) {
360 //     _numberOfGeometricType=1 ;
361 //     if (_geometricType == (medGeometryElement *) NULL)
362 //       _geometricType=new medGeometryElement[1] ;
363 //     else 
364 //       {
365 //      // delete previous ???
366 //      delete [] _geometricType;
367 //      _geometricType=new medGeometryElement[1] ;
368 //       }
369 //     _geometricType[0]=MED_NONE ;
370 //   }
371 }
372
373 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
374 //---------------------------------------------------------------------
375 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
376 //---------------------------------------------------------------------
377 {
378   _numberOfGeometricType=NumberOfGeometricType;
379   if (_geometricType!=NULL) {
380     delete[] _geometricType ;
381     _geometricType = NULL ;
382   }
383   if (_numberOfElements!=NULL) {
384     delete[] _numberOfElements ;
385     _numberOfElements = NULL ;
386   }
387   if (_numberOfGaussPoint!=NULL) {
388     delete[] _numberOfGaussPoint ;
389     _numberOfGaussPoint = NULL ;
390   }
391 }
392
393 /*! set the attribute _geometricType to geometricType */
394 //---------------------------------------------------------------------
395 inline void SUPPORT::setGeometricType(const medGeometryElement *GeometricType)
396 //---------------------------------------------------------------------
397 {
398   if (NULL == _geometricType)
399     _geometricType=new medGeometryElement[_numberOfGeometricType];
400   for (int i=0;i<_numberOfGeometricType;i++)
401     _geometricType[i] = GeometricType[i];
402   //  _geometricType=GeometricType;
403 }
404
405 /*! set the attribute _numberOfGaussPoint to NumberOfGaussPoint */
406 //-----------------------------------------------------------------
407 inline void SUPPORT::setNumberOfGaussPoint(const int *NumberOfGaussPoint)
408 //-----------------------------------------------------------------
409 {
410   if (NULL == _numberOfGaussPoint)
411     _numberOfGaussPoint=new int[_numberOfGeometricType];
412   for (int i=0;i<_numberOfGeometricType;i++)
413     _numberOfGaussPoint[i] = NumberOfGaussPoint[i];
414   //  _numberOfGaussPoint = NumberOfGaussPoint ;
415 }
416
417 /*! set the attribute _geometricTypeNumber to GeometricTypeNumber */
418 //-------------------------------------------------------------------
419 //inline void SUPPORT::setGeometricTypeNumber(int *GeometricTypeNumber)
420 //-------------------------------------------------------------------
421 //{
422 //  _geometricTypeNumber=GeometricTypeNumber;
423 //}
424
425 /*!
426   Set the attribute _numberOfElements to NumberOfElements and 
427   calculate the total number of elements.
428 */
429 //----------------------------------------------------------
430 inline void SUPPORT::setNumberOfElements(const int *NumberOfElements)
431 //----------------------------------------------------------
432 {
433   if (NULL == _numberOfElements)
434     _numberOfElements=new int[_numberOfGeometricType];
435   memcpy(_numberOfElements,NumberOfElements,sizeof(int)*_numberOfGeometricType);
436   _totalNumberOfElements = 0 ;
437   for (int i=0;i<_numberOfGeometricType;i++)
438     _totalNumberOfElements+=_numberOfElements[i];
439 }
440
441 /*! set the attribute _totalNumberOfElements to TotalNumberOfElements */
442 //--------------------------------------------------------------------
443 inline void SUPPORT::setTotalNumberOfElements(int TotalNumberOfElements)
444 //--------------------------------------------------------------------
445 {
446   _totalNumberOfElements=TotalNumberOfElements;
447 }
448
449 /*! set the attribute _number to Number */
450 //---------------------------------------------------
451 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
452 //---------------------------------------------------
453 {
454   if (_number != NULL) delete _number ;
455   _number=Number;
456 }
457
458 /*! set the attribute _number with index and value arrays */
459 //---------------------------------------------------
460 inline void SUPPORT::setNumber(const int * index, const int* value)
461 //---------------------------------------------------
462 {
463   if (_number != NULL) delete _number ;
464   _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value);
465 }
466
467 /*! returns the name of the support. */
468 //------------------------------------
469 inline string SUPPORT::getName() const
470 //------------------------------------
471 {
472   return _name;
473 }
474
475
476 /*! returns the description of the support. */
477 //--------------------------------------------
478 inline string SUPPORT::getDescription() const
479 //--------------------------------------------
480 {
481   return _description;
482 }
483
484 /*! returns a reference to the mesh */
485 //------------------------------------
486 inline MESH * SUPPORT::getMesh() const
487 //------------------------------------
488 {
489   return _mesh;
490 }
491
492 /*!
493   Returns true if all elements of this entity are
494   concerned, false otherwise.
495   If true, you must use mesh reference (getMesh) to get more information.
496 */
497 //------------------------------------------
498 inline bool SUPPORT::isOnAllElements() const
499 //------------------------------------------
500 {
501   return _isOnAllElts;
502 }
503
504 /*!
505   Returns number of geometric Types
506   defines in the support
507 */
508 //------------------------------------------
509 inline int SUPPORT::getNumberOfTypes() const
510 //------------------------------------------
511 {
512   //    if ((_isOnAllElts)&(_entity != MED_NODE))
513   //      return _mesh->getNumberOfTypes(_entity) ;
514   //    else
515   return _numberOfGeometricType ;
516 }
517
518 /*!
519   Returns the medEntityMesh's type used by the support.
520   Note : A support deals only with one entity's type
521   (for example : MED_FACE or MED_NODE)
522 */
523 //---------------------------------------------
524 inline medEntityMesh SUPPORT::getEntity() const
525 //---------------------------------------------
526 {
527   return _entity;
528 }
529
530 /*!
531   If isOnAllElements is false, returns an array of <medGeometryElement>
532   types used by the support.
533
534   <medEntityMesh> is given by getEntity.
535 */
536 //---------------------------------------------------
537 inline const medGeometryElement * SUPPORT::getTypes() const
538 //---------------------------------------------------
539 {
540   //    if ((_isOnAllElts)&(_entity != MED_NODE))
541   //      return _mesh->getTypes(_entity) ;
542   //    else
543   return _geometricType;
544 }
545
546 //---------------------------------------------------
547 //inline int * SUPPORT::getGeometricTypeNumber() const
548 //---------------------------------------------------
549 //  {
550 //    const char * LOC = "SUPPORT::getGeometricTypeNumber() : ";
551 //    if (_isOnAllElts)
552 //      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined (is on all elements) !"));
553 //    if (_geometricTypeNumber==NULL)
554 //      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined !"));
555 //    return _geometricTypeNumber;
556 //  }
557
558
559 #endif /* SUPPORT_HXX */