Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[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 <list>
10 #include <vector>
11 #include <string>
12 #include <list>
13
14 #include "MEDMEM_Utilities.hxx"
15 #include "MEDMEM_STRING.hxx"
16 #include "MEDMEM_Exception.hxx"
17 #include "MEDMEM_define.hxx"
18 #include "MEDMEM_SkyLineArray.hxx"
19 #include "MEDMEM_RCBase.hxx"
20
21 /*!
22
23   This class describe a support of elements on an entity of the mesh.
24
25   It contains the list of meshes elements for an entity (MED_NODE,
26   MED_CELL, MED_FACE or MED_EDGE).
27
28 */
29
30 namespace MEDMEM {
31 class MESH ;
32
33 class SUPPORT : public RCBASE
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   MED_EN::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   MED_EN::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 _index[_numberOfType]-1 wich contain number of
125     entities of each geometric type. We use global numbering.\n
126     Defined only if _isOnAllElts is false.
127     \endif
128   */
129   mutable MEDSKYLINEARRAY * _number;
130
131 public:
132   SUPPORT();
133   SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
134   SUPPORT(const SUPPORT & m);
135   virtual ~SUPPORT();
136   friend ostream & operator<<(ostream &os,const SUPPORT &my);
137
138   SUPPORT& operator=(const SUPPORT &support);
139   bool operator == (const SUPPORT &support) const;
140   bool deepCompare(const SUPPORT &support) const;
141   // function to set all value when SUPPORT was created by MedMedDriver without all MESH information !!! Change with new API !
142   void update();
143
144   inline void setName(string Name);
145   inline void setDescription(string Description);
146   void setMesh(MESH *Mesh);
147   inline void setAll(bool All);
148   inline void setEntity(MED_EN::medEntityMesh Entity);
149   inline void setNumberOfGeometricType(int NumberOfGeometricType);
150   inline void setGeometricType(const MED_EN::medGeometryElement *GeometricType);
151   inline void setNumberOfGaussPoint(const int *NumberOfGaussPoint);
152   inline void setNumberOfElements(const int *NumberOfElements);
153   inline void setTotalNumberOfElements(int TotalNumberOfElements);
154   inline void setNumber(MEDSKYLINEARRAY * Number);
155   inline void setNumber(const int * index, const int* value, bool shallowCopy=false);
156
157   inline string getName() const;
158   inline string getDescription() const;
159   virtual inline MESH * getMesh() const;
160   inline MED_EN::medEntityMesh getEntity() const;
161
162   inline bool   isOnAllElements() const;
163   inline int    getNumberOfTypes() const;
164   inline const MED_EN::medGeometryElement* getTypes() const ;
165   inline const int *  getNumberOfGaussPoint() const throw (MEDEXCEPTION);
166   inline int          getNumberOfGaussPoint(MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION);
167   inline int    getNumberOfElements(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
168   virtual inline MEDSKYLINEARRAY *  getnumber() const throw (MEDEXCEPTION);
169   virtual inline const int *  getNumber(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
170   virtual inline const int *  getNumberIndex() const throw (MEDEXCEPTION);
171
172   void blending(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
173
174   void setpartial(string Description, int NumberOfGeometricType,
175                   int TotalNumberOfEntity, MED_EN::medGeometryElement *GeometricType,
176                   int *NumberOfEntity, int *NumberValue);
177
178   void getBoundaryElements() throw (MEDEXCEPTION);
179   void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew, int limitNbClassicPoly, const int *renumberingFromOldToNewPoly=0);
180   void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
181   bool belongsTo(const SUPPORT& other, bool deepCompare=false) const;
182   SUPPORT *getComplement() const;
183   SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION) ;
184   SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION);
185   void fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION);
186   void fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION);
187   void clearDataOnNumbers();
188   //A.G. Addings for RC
189   virtual void addReference() const;
190   virtual void removeReference() const;
191 protected:
192   static list<int> *sub(int start,int end,const int *idsToSuppress,int lgthIdsToSuppress);
193   static list<int> *sub(const int *ids,int lgthIds,const int *idsToSuppress,int lgthIdsToSuppress);
194 };
195
196 // _____________________
197 // Methodes Inline
198 // _____________________
199
200 /*!
201   This method returns the number of all elements of the type GeometricType.
202
203   If isOnAllElements is false, it returns the number of elements in the
204   support else it returns number of elements in the whole mesh.
205
206   Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
207   in entity of support.
208
209   Note : If SUPPORT is defined on MED_NODE, use MED_ALL_ELEMENTS as
210          medGeometryElement GeometricType and it will returns the number
211          of nodes in the support (or in the whole mesh).
212 */
213 //-----------------------------------------------------------------------------
214 inline int SUPPORT::getNumberOfElements(MED_EN::medGeometryElement GeometricType) const
215   throw (MEDEXCEPTION)
216 //-----------------------------------------------------------------------------
217 {
218   if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
219     return _totalNumberOfElements;
220   for (int i=0;i<_numberOfGeometricType;i++)
221     if (_geometricType[i]==GeometricType)
222       return _numberOfElements[i];
223   throw MEDEXCEPTION("Support::getNumberOfElements : Geometric type not found !") ;
224 }
225
226 //---------------------------------------------------------------------
227 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const
228   throw (MEDEXCEPTION)
229 //---------------------------------------------------------------------
230 {
231   if (_number==NULL)
232     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
233   return _number ;
234 }
235
236 /*!
237   If isOnAllElements is false, returns an array which contains
238   all number of given medGeometryElement.
239
240   Numbering is global, ie numbers are bounded by 1 and
241   MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and
242   MESH::getNumberOfElement(entity,geomElement).
243
244   Note : If SUPPORT is defined on MED_NODE, use MED_NONE
245   medGeometryElement type.
246 */
247 //---------------------------------------------------------------------
248 inline const int * SUPPORT::getNumber(MED_EN::medGeometryElement GeometricType) const
249   throw (MEDEXCEPTION)
250 //---------------------------------------------------------------------
251 {
252   if (_isOnAllElts)
253     throw MEDEXCEPTION("Support::getNumber : Not defined, support is on all entity !") ;
254   if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
255     return _number->getValue() ;
256   for (int i=0;i<_numberOfGeometricType;i++)
257     if (_geometricType[i]==GeometricType)
258       return _number->getI(i+1) ;
259   throw MEDEXCEPTION("Support::getNumber : GeometricType not found !") ;
260 }
261
262 /*!
263   If isOnAllElements is false, returns index of element number.
264   Use it with getNumber(MED_ALL_ELEMENTS).
265
266   Note : See getConnectivityIndex for details.
267 */
268 //-------------------------------------------
269 inline const int * SUPPORT::getNumberIndex() const
270 //-------------------------------------------
271   throw (MEDEXCEPTION)
272 {
273   if (_isOnAllElts)
274     throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
275   return _number->getIndex() ;
276 }
277
278 /*! A DOCUMENTER */
279 //-------------------------------------------------
280 inline const int * SUPPORT::getNumberOfGaussPoint() const
281   throw (MEDEXCEPTION)
282 //-------------------------------------------------
283 {
284   if (_numberOfGaussPoint!=NULL)
285     return _numberOfGaussPoint ;
286   else
287     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
288 }
289
290 /*!
291   Returns number of Gauss points for this medGeometryElement.
292
293   Note :
294   - Not defined if SUPPORT is on MED_NODE.
295   - Not defined for MED_ALL_ELEMENTS medGeometryElement type.
296 */
297 //-----------------------------------------------------------------------------
298 inline int SUPPORT::getNumberOfGaussPoint(MED_EN::medGeometryElement geomElement) const
299   throw (MEDEXCEPTION)
300 //-----------------------------------------------------------------------------
301 {
302   if (_numberOfGaussPoint!=NULL) {
303     for (int i=0;i<_numberOfGeometricType;i++)
304       if (_geometricType[i]==geomElement)
305         return _numberOfGaussPoint[i] ;
306     throw MEDEXCEPTION("Support::getGlobalNumber : GeometricType not found !") ;
307   } else
308     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
309 }
310
311 /*! set the attribute _name to Name */
312 //--------------------------------------
313 inline void SUPPORT::setName(string Name)
314 //--------------------------------------
315 {
316   _name=Name;
317 }
318
319 /*! set the attribute _description to Description */
320 //--------------------------------------------------
321 inline void SUPPORT::setDescription(string Description)
322 //--------------------------------------------------
323 {
324   _description=Description;
325 }
326
327 /*! set the attribute _isOnAllElts to All */
328 //------------------------------------------
329 inline void SUPPORT::setAll(bool All)
330 //------------------------------------------
331 {
332   _isOnAllElts=All;
333 }
334
335 /*! set the attribute _entity to Entity */
336 //------------------------------------------
337 inline void SUPPORT::setEntity(MED_EN::medEntityMesh Entity)
338 {
339   _entity=Entity;
340 }
341
342 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
343 //---------------------------------------------------------------------
344 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
345 //---------------------------------------------------------------------
346 {
347   _numberOfGeometricType=NumberOfGeometricType;
348   if (_geometricType!=NULL) {
349     delete[] _geometricType ;
350     _geometricType = NULL ;
351   }
352   if (_numberOfElements!=NULL) {
353     delete[] _numberOfElements ;
354     _numberOfElements = NULL ;
355   }
356   if (_numberOfGaussPoint!=NULL) {
357     delete[] _numberOfGaussPoint ;
358     _numberOfGaussPoint = NULL ;
359   }
360 }
361
362 /*! set the attribute _geometricType to geometricType */
363 //---------------------------------------------------------------------
364 inline void SUPPORT::setGeometricType(const MED_EN::medGeometryElement *GeometricType)
365 //---------------------------------------------------------------------
366 {
367   if (NULL == _geometricType)
368     _geometricType=new MED_EN::medGeometryElement[_numberOfGeometricType];
369   for (int i=0;i<_numberOfGeometricType;i++)
370     _geometricType[i] = GeometricType[i];
371 }
372
373 /*! set the attribute _numberOfGaussPoint to NumberOfGaussPoint */
374 //-----------------------------------------------------------------
375 inline void SUPPORT::setNumberOfGaussPoint(const int *NumberOfGaussPoint)
376 //-----------------------------------------------------------------
377 {
378   if (NULL == _numberOfGaussPoint)
379     _numberOfGaussPoint=new int[_numberOfGeometricType];
380   for (int i=0;i<_numberOfGeometricType;i++)
381     _numberOfGaussPoint[i] = NumberOfGaussPoint[i];
382 }
383
384 /*!
385   Set the attribute _numberOfElements to NumberOfElements and
386   calculate the total number of elements.
387 */
388 //----------------------------------------------------------
389 inline void SUPPORT::setNumberOfElements(const int *NumberOfElements)
390 //----------------------------------------------------------
391 {
392   if (NULL == _numberOfElements)
393     _numberOfElements=new int[_numberOfGeometricType];
394   memcpy(_numberOfElements,NumberOfElements,sizeof(int)*_numberOfGeometricType);
395   _totalNumberOfElements = 0 ;
396   for (int i=0;i<_numberOfGeometricType;i++)
397     _totalNumberOfElements+=_numberOfElements[i];
398 }
399
400 /*! set the attribute _totalNumberOfElements to TotalNumberOfElements */
401 //--------------------------------------------------------------------
402 inline void SUPPORT::setTotalNumberOfElements(int TotalNumberOfElements)
403 //--------------------------------------------------------------------
404 {
405   _totalNumberOfElements=TotalNumberOfElements;
406 }
407
408 /*! set the attribute _number to Number */
409 //---------------------------------------------------
410 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
411 //---------------------------------------------------
412 {
413   if (_number != NULL) delete _number ;
414   _number=Number;
415 }
416
417 /*! set the attribute _number with index and value arrays */
418 //---------------------------------------------------
419 inline void SUPPORT::setNumber(const int * index, const int* value, bool shallowCopy)
420 //---------------------------------------------------
421 {
422   if (_number != NULL) delete _number ;
423   _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
424 }
425
426 /*! returns the name of the support. */
427 //------------------------------------
428 inline string SUPPORT::getName() const
429 //------------------------------------
430 {
431   return _name;
432 }
433
434
435 /*! returns the description of the support. */
436 //--------------------------------------------
437 inline string SUPPORT::getDescription() const
438 //--------------------------------------------
439 {
440   return _description;
441 }
442
443 /*! returns a reference to the mesh */
444 //------------------------------------
445 inline MESH * SUPPORT::getMesh() const
446 //------------------------------------
447 {
448   return _mesh;
449 }
450
451 /*!
452   Returns true if all elements of this entity are
453   concerned, false otherwise.
454   If true, you must use mesh reference (getMesh) to get more information.
455 */
456 //------------------------------------------
457 inline bool SUPPORT::isOnAllElements() const
458 //------------------------------------------
459 {
460   return _isOnAllElts;
461 }
462
463 /*!
464   Returns number of geometric Types
465   defines in the support
466 */
467 //------------------------------------------
468 inline int SUPPORT::getNumberOfTypes() const
469 //------------------------------------------
470 {
471   //    if ((_isOnAllElts)&(_entity != MED_NODE))
472   //      return _mesh->getNumberOfTypes(_entity) ;
473   //    else
474   return _numberOfGeometricType ;
475 }
476
477 /*!
478   Returns the %medEntityMesh's type used by the support.
479   Note : A support deals only with one entity's type
480   (for example : MED_FACE or MED_NODE)
481 */
482 //---------------------------------------------
483 inline MED_EN::medEntityMesh SUPPORT::getEntity() const
484 //---------------------------------------------
485 {
486   return _entity;
487 }
488
489 /*!
490   If isOnAllElements is false, returns an array of %medGeometryElement
491   types used by the support.
492 */
493 //---------------------------------------------------
494 inline const MED_EN::medGeometryElement * SUPPORT::getTypes() const
495 //---------------------------------------------------
496 {
497   return _geometricType;
498 }
499
500 }//End namespace MEDMEM
501
502
503 #endif /* SUPPORT_HXX */