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