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