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