Salome HOME
update from the MedMemory V1.0.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
17 #include "MEDMEM_SkyLineArray.hxx"
18 //#include "MEDMEM_Mesh.hxx"
19
20 using namespace MED_EN;
21
22 class MESH ;
23
24 /*!
25
26   This class describe a support of elements on an entity of the mesh.
27
28   It contains the list of meshes elements for an entity (MED_NODE, 
29   MED_CELL, MED_FACE or MED_EDGE).
30
31 */
32
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 // Methodes Inline
199 // _____________________
200
201 /*!
202   This method returns the number of all elements of the type GeometricType.
203
204   If isOnAllElements is false, it returns the number of elements in the
205   support else it returns number of elements in the whole mesh.
206
207   Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
208   in entity of support.
209
210   Note : If SUPPORT is defined on MED_NODE, use MED_ALL_ELEMENTS as
211          medGeometryElement GeometricType and it will returns the number
212          of nodes in the support (or in the whole mesh).
213 */
214 //-----------------------------------------------------------------------------
215 inline int SUPPORT::getNumberOfElements(medGeometryElement GeometricType) const
216   throw (MEDEXCEPTION)
217 //-----------------------------------------------------------------------------
218 {
219   if (GeometricType==MED_ALL_ELEMENTS)
220     return _totalNumberOfElements;
221   for (int i=0;i<_numberOfGeometricType;i++)
222     if (_geometricType[i]==GeometricType)
223       return _numberOfElements[i];
224   throw MEDEXCEPTION("Support::getNumberOfElements : Geometric type not found !") ;
225 }
226
227 //---------------------------------------------------------------------
228 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const
229   throw (MEDEXCEPTION)
230 //---------------------------------------------------------------------
231 {
232   if (_number==NULL)
233     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
234   return _number ;
235 }
236
237 /*!
238   If isOnAllElements is false, returns an array which contains
239   all number of given medGeometryElement.
240
241   Numbering is global, ie numbers are bounded by 1 and
242   MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and
243   MESH::getNumberOfElement(entity,geomElement).
244
245   Note : If SUPPORT is defined on MED_NODE, use MED_NONE
246   medGeometryElement type.
247 */
248 //---------------------------------------------------------------------
249 inline const int * SUPPORT::getNumber(medGeometryElement GeometricType) const
250   throw (MEDEXCEPTION)
251 //---------------------------------------------------------------------
252 {
253   const char * LOC = "Support::getNumber : " ;
254   if (_isOnAllElts)
255     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ;
256   if (GeometricType==MED_ALL_ELEMENTS)
257     return _number->getValue() ;
258   for (int i=0;i<_numberOfGeometricType;i++)
259     if (_geometricType[i]==GeometricType)
260       return _number->getI(i+1) ;
261   throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ;
262 }
263
264 /*!
265   If isOnAllElements is false, returns index of element number.
266   Use it with getNumber(MED_ALL_ELEMENTS).
267
268   Note : See getConnectivityIndex for details.
269 */
270 //-------------------------------------------
271 inline const int * SUPPORT::getNumberIndex() const
272 //-------------------------------------------
273   throw (MEDEXCEPTION)
274 {
275   if (_isOnAllElts)
276     throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
277   return _number->getIndex() ;
278 }
279
280 /*! A DOCUMENTER */
281 //-------------------------------------------------
282 inline const int * SUPPORT::getNumberOfGaussPoint() const
283   throw (MEDEXCEPTION)
284 //-------------------------------------------------
285 {
286   if (_numberOfGaussPoint!=NULL)
287     return _numberOfGaussPoint ;
288   else
289     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
290 }
291
292 /*!
293   Returns number of Gauss points for this medGeometryElement.
294
295   Note :
296   - Not defined if SUPPORT is on MED_NODE.
297   - Not defined for MED_ALL_ELEMENTS medGeometryElement type.
298 */
299 //-----------------------------------------------------------------------------
300 inline int SUPPORT::getNumberOfGaussPoint(medGeometryElement geomElement) const
301   throw (MEDEXCEPTION)
302 //-----------------------------------------------------------------------------
303 {
304   if (_numberOfGaussPoint!=NULL) {
305     for (int i=0;i<_numberOfGeometricType;i++)
306       if (_geometricType[i]==geomElement)
307         return _numberOfGaussPoint[i] ;
308     throw MEDEXCEPTION("Support::getGlobalNumber : GeometricType not found !") ;
309   } else
310     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
311 }
312 //  inline int SUPPORT::getNumberLength() const
313 //  throw (MEDEXCEPTION)
314 //  {
315 //      if (_isOnAllElts)
316 //        throw MEDEXCEPTION("Support::getNumberLength : Not defined, support is on all entity !") ;
317 //        return _number->getLength() ;
318 //  }
319
320 /*! set the attribute _name to Name */
321 //--------------------------------------
322 inline void SUPPORT::setName(string Name)
323 //--------------------------------------
324 {
325   _name=Name;
326 }
327
328 /*! set the attribute _description to Description */
329 //--------------------------------------------------
330 inline void SUPPORT::setDescription(string Description)
331 //--------------------------------------------------
332 {
333   _description=Description;
334 }
335
336 /*! set the reference _mesh to Mesh */
337 //--------------------------------------
338 inline void SUPPORT::setMesh(MESH *Mesh)
339 //--------------------------------------
340 {
341   _mesh=Mesh;
342 }
343
344 /*! set the attribute _isOnAllElts to All */
345 //------------------------------------------
346 inline void SUPPORT::setAll(bool All)
347 //------------------------------------------
348 {
349   _isOnAllElts=All;
350 }
351
352 /*! set the attribute _entity to Entity */
353 //------------------------------------------
354 inline void SUPPORT::setEntity(medEntityMesh Entity)
355 {
356   _entity=Entity;
357 //   if ( Entity == MED_NODE) {
358 //     _numberOfGeometricType=1 ;
359 //     if (_geometricType == (medGeometryElement *) NULL)
360 //       _geometricType=new medGeometryElement[1] ;
361 //     else 
362 //       {
363 //      // delete previous ???
364 //      delete [] _geometricType;
365 //      _geometricType=new medGeometryElement[1] ;
366 //       }
367 //     _geometricType[0]=MED_NONE ;
368 //   }
369 }
370
371 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
372 //---------------------------------------------------------------------
373 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
374 //---------------------------------------------------------------------
375 {
376   _numberOfGeometricType=NumberOfGeometricType;
377   if (_geometricType!=NULL) {
378     delete[] _geometricType ;
379     _geometricType = NULL ;
380   }
381   if (_numberOfElements!=NULL) {
382     delete[] _numberOfElements ;
383     _numberOfElements = NULL ;
384   }
385   if (_numberOfGaussPoint!=NULL) {
386     delete[] _numberOfGaussPoint ;
387     _numberOfGaussPoint = NULL ;
388   }
389 }
390
391 /*! set the attribute _geometricType to geometricType */
392 //---------------------------------------------------------------------
393 inline void SUPPORT::setGeometricType(const medGeometryElement *GeometricType)
394 //---------------------------------------------------------------------
395 {
396   if (NULL == _geometricType)
397     _geometricType=new medGeometryElement[_numberOfGeometricType];
398   for (int i=0;i<_numberOfGeometricType;i++)
399     _geometricType[i] = GeometricType[i];
400   //  _geometricType=GeometricType;
401 }
402
403 /*! set the attribute _numberOfGaussPoint to NumberOfGaussPoint */
404 //-----------------------------------------------------------------
405 inline void SUPPORT::setNumberOfGaussPoint(const int *NumberOfGaussPoint)
406 //-----------------------------------------------------------------
407 {
408   if (NULL == _numberOfGaussPoint)
409     _numberOfGaussPoint=new int[_numberOfGeometricType];
410   for (int i=0;i<_numberOfGeometricType;i++)
411     _numberOfGaussPoint[i] = NumberOfGaussPoint[i];
412   //  _numberOfGaussPoint = NumberOfGaussPoint ;
413 }
414
415 /*! set the attribute _geometricTypeNumber to GeometricTypeNumber */
416 //-------------------------------------------------------------------
417 //inline void SUPPORT::setGeometricTypeNumber(int *GeometricTypeNumber)
418 //-------------------------------------------------------------------
419 //{
420 //  _geometricTypeNumber=GeometricTypeNumber;
421 //}
422
423 /*!
424   Set the attribute _numberOfElements to NumberOfElements and 
425   calculate the total number of elements.
426 */
427 //----------------------------------------------------------
428 inline void SUPPORT::setNumberOfElements(const int *NumberOfElements)
429 //----------------------------------------------------------
430 {
431   if (NULL == _numberOfElements)
432     _numberOfElements=new int[_numberOfGeometricType];
433   memcpy(_numberOfElements,NumberOfElements,sizeof(int)*_numberOfGeometricType);
434   _totalNumberOfElements = 0 ;
435   for (int i=0;i<_numberOfGeometricType;i++)
436     _totalNumberOfElements+=_numberOfElements[i];
437 }
438
439 /*! set the attribute _totalNumberOfElements to TotalNumberOfElements */
440 //--------------------------------------------------------------------
441 inline void SUPPORT::setTotalNumberOfElements(int TotalNumberOfElements)
442 //--------------------------------------------------------------------
443 {
444   _totalNumberOfElements=TotalNumberOfElements;
445 }
446
447 /*! set the attribute _number to Number */
448 //---------------------------------------------------
449 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
450 //---------------------------------------------------
451 {
452   if (_number != NULL) delete _number ;
453   _number=Number;
454 }
455
456 /*! set the attribute _number with index and value arrays */
457 //---------------------------------------------------
458 inline void SUPPORT::setNumber(const int * index, const int* value)
459 //---------------------------------------------------
460 {
461   if (_number != NULL) delete _number ;
462   _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value);
463 }
464
465 /*! returns the name of the support. */
466 //------------------------------------
467 inline string SUPPORT::getName() const
468 //------------------------------------
469 {
470   return _name;
471 }
472
473
474 /*! returns the description of the support. */
475 //--------------------------------------------
476 inline string SUPPORT::getDescription() const
477 //--------------------------------------------
478 {
479   return _description;
480 }
481
482 /*! returns a reference to the mesh */
483 //------------------------------------
484 inline MESH * SUPPORT::getMesh() const
485 //------------------------------------
486 {
487   return _mesh;
488 }
489
490 /*!
491   Returns true if all elements of this entity are
492   concerned, false otherwise.
493   If true, you must use mesh reference (getMesh) to get more information.
494 */
495 //------------------------------------------
496 inline bool SUPPORT::isOnAllElements() const
497 //------------------------------------------
498 {
499   return _isOnAllElts;
500 }
501
502 /*!
503   Returns number of geometric Types
504   defines in the support
505 */
506 //------------------------------------------
507 inline int SUPPORT::getNumberOfTypes() const
508 //------------------------------------------
509 {
510   //    if ((_isOnAllElts)&(_entity != MED_NODE))
511   //      return _mesh->getNumberOfTypes(_entity) ;
512   //    else
513   return _numberOfGeometricType ;
514 }
515
516 /*!
517   Returns the medEntityMesh's type used by the support.
518   Note : A support deals only with one entity's type
519   (for example : MED_FACE or MED_NODE)
520 */
521 //---------------------------------------------
522 inline medEntityMesh SUPPORT::getEntity() const
523 //---------------------------------------------
524 {
525   return _entity;
526 }
527
528 /*!
529   If isOnAllElements is false, returns an array of <medGeometryElement>
530   types used by the support.
531
532   <medEntityMesh> is given by getEntity.
533 */
534 //---------------------------------------------------
535 inline const medGeometryElement * SUPPORT::getTypes() const
536 //---------------------------------------------------
537 {
538   //    if ((_isOnAllElts)&(_entity != MED_NODE))
539   //      return _mesh->getTypes(_entity) ;
540   //    else
541   return _geometricType;
542 }
543
544 //---------------------------------------------------
545 //inline int * SUPPORT::getGeometricTypeNumber() const
546 //---------------------------------------------------
547 //  {
548 //    const char * LOC = "SUPPORT::getGeometricTypeNumber() : ";
549 //    if (_isOnAllElts)
550 //      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined (is on all elements) !"));
551 //    if (_geometricTypeNumber==NULL)
552 //      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined !"));
553 //    return _geometricTypeNumber;
554 //  }
555
556
557 #endif /* SUPPORT_HXX */