]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Support.hxx
Salome HOME
NRI : Merge from V1_2.
[modules/med.git] / src / MEDMEM / MEDMEM_Support.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_Support.hxx
25 //  Module : MED
26
27 /*
28   File Support.hxx
29   $Header$
30 */
31
32 #ifndef SUPPORT_HXX
33 #define SUPPORT_HXX
34
35 #include <vector>
36 #include <string>
37
38 #include "utilities.h"
39 #include "MEDMEM_STRING.hxx"
40 #include "MEDMEM_Exception.hxx"
41 #include "MEDMEM_define.hxx"
42
43 #include "MEDMEM_SkyLineArray.hxx"
44 //#include "MEDMEM_Mesh.hxx"
45
46 using namespace MED_EN;
47
48 class MESH ;
49
50 /*!
51
52   This class describe a support of elements on an entity of the mesh.
53
54   It contains the list of meshes elements for an entity (MED_NODE, 
55   MED_CELL, MED_FACE or MED_EDGE).
56
57 */
58
59 class SUPPORT
60 {
61 protected:
62   /*!
63     \if developper
64     Support name.
65     \endif
66   */
67   string                   _name;
68
69   /*!
70     \if developper
71     Description of the support (optional).
72     \endif
73   */
74   string                   _description;
75
76   /*!
77     \if developper
78     Reference to the mesh on which the support is defined.
79     \endif
80   */
81   MESH *                   _mesh;
82
83   /*!
84     \if developper
85     Type of entity on which the support is defined
86     (only one for each support).
87     \endif
88   */
89   medEntityMesh            _entity ;
90
91   /*!
92     \if developper
93     Number of geometric type defined in the support.
94     \endif
95   */
96   int                      _numberOfGeometricType;
97
98   /*!
99     \if developper
100     Array of all geometric type defined in the support.
101     \endif
102   */
103   medGeometryElement *     _geometricType;
104
105   /*!
106     \if developper
107     Array of size _numberOfGeometricType which contains
108     for each type the number of gauss point
109     (not yet implemented).
110     \endif
111   */
112   int *                    _numberOfGaussPoint ;
113
114    /*
115     \if developper
116     Array of size _numberOfGeometricType
117     which contains number of geometric
118     entity type in Mesh
119     (to get corresponding CellModel).
120     \endif
121   */
122   //int *                    _geometricTypeNumber;
123
124   /*!
125     \if developper
126     If true, we consider all entities of type _entity.
127     \endif
128   */
129   bool                     _isOnAllElts; 
130
131   /*!
132     \if developper
133     Index array of size _numberOfGeometricType wich contains
134     for each geometric type, the number of elements of this type.
135     \endif
136   */
137   int *                    _numberOfElements;
138
139   /*!
140     \if developper
141     Sum of each _numberOfElements component.
142     \endif
143   */
144   int                      _totalNumberOfElements;
145
146   // the two following arrays are defined only if _isOnAllElts is false :
147
148   /*
149     \if developper
150     array of size _numberOfType+1 wich contains for
151     each geometric type, index in _number._value
152     (if _all is true, we must ask _mesh to get
153     information). _typeIndex[i+1]-_typeIndex[i]
154     represents count of entities of ith geometric
155     type. _typeIndex[_numberOfType] contains total
156     entities count. If _numberOf[i]=0,
157     _typeIndex[i+1]=_typeIndex[i]
158     defined only if _isOnAllElts is false
159     \endif
160   */
161   //  int *      _typeIndex;
162
163   /*!
164     \if developper
165     Array of size _index[_numberOfType]-1 wich contain number of
166     entities of each geometric type. We use global numbering.\n
167     Defined only if _isOnAllElts is false.
168     \endif
169   */
170   MEDSKYLINEARRAY * _number;
171
172 public:
173   SUPPORT();
174   SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL);
175   SUPPORT(const SUPPORT & m);
176   ~SUPPORT();
177   friend ostream & operator<<(ostream &os,const SUPPORT &my);
178
179   // function to set all value when SUPPORT was created by MedMedDriver without all MESH information !!! Change with new API !
180   void update();
181
182   inline void setName(string Name);
183   inline void setDescription(string Description);
184   inline void setMesh(MESH *Mesh);
185   inline void setAll(bool All);
186   inline void setEntity(medEntityMesh Entity);
187   inline void setNumberOfGeometricType(int NumberOfGeometricType);
188   inline void setGeometricType(const medGeometryElement *GeometricType);
189   inline void setNumberOfGaussPoint(const int *NumberOfGaussPoint);
190   //  inline void setGeometricTypeNumber(int *GeometricTypeNumber);
191   inline void setNumberOfElements(const int *NumberOfElements);
192   inline void setTotalNumberOfElements(int TotalNumberOfElements);
193   inline void setNumber(MEDSKYLINEARRAY * Number);
194   inline void setNumber(const int * index, const int* value);
195
196   inline string getName() const;
197   inline string getDescription() const;
198   inline MESH * getMesh() const;
199   inline medEntityMesh getEntity() const;
200
201   inline bool   isOnAllElements() const;
202   inline int    getNumberOfTypes() const;
203   inline const medGeometryElement* getTypes() const ;
204   inline const int *  getNumberOfGaussPoint() const throw (MEDEXCEPTION);
205   inline int          getNumberOfGaussPoint(medGeometryElement geomElement) const throw (MEDEXCEPTION);
206   //inline int *  getGeometricTypeNumber() const;
207   //inline int    getTotalNumberOfElement() const;
208   inline int    getNumberOfElements(medGeometryElement GeometricType) const throw (MEDEXCEPTION);
209   inline MEDSKYLINEARRAY *  getnumber() const throw (MEDEXCEPTION);
210   inline const int *  getNumber(medGeometryElement GeometricType) const throw (MEDEXCEPTION);
211   inline const int *  getNumberIndex() const throw (MEDEXCEPTION);
212
213   void blending(SUPPORT * mySupport);
214
215   void setpartial(string Description, int NumberOfGeometricType,
216                   int TotalNumberOfEntity, medGeometryElement *GeometricType,
217                   int *NumberOfEntity, int *NumberValue);
218
219   void getBoundaryElements() throw (MEDEXCEPTION);
220 };
221 // _____________________
222 // Methodes Inline
223 // _____________________
224
225 /*!
226   If isOnAllElements is false, returns number of elements in the
227   support else returns number of nodes.
228
229   Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
230   in entity of support.
231
232   Note : If SUPPORT is defined on MED_NODE, use MED_NONE
233   medGeometryElement type.
234 */
235 //-----------------------------------------------------------------------------
236 inline int SUPPORT::getNumberOfElements(medGeometryElement GeometricType) const
237   throw (MEDEXCEPTION)
238 //-----------------------------------------------------------------------------
239 {
240   if (GeometricType==MED_ALL_ELEMENTS)
241     return _totalNumberOfElements;
242   for (int i=0;i<_numberOfGeometricType;i++)
243     if (_geometricType[i]==GeometricType)
244       return _numberOfElements[i];
245   throw MEDEXCEPTION("Support::getNumberOfElements : Geometric type not found !") ;
246 }
247
248 //---------------------------------------------------------------------
249 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const
250   throw (MEDEXCEPTION)
251 //---------------------------------------------------------------------
252 {
253   if (_number==NULL)
254     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
255   return _number ;
256 }
257
258 /*!
259   If isOnAllElements is false, returns an array which contains
260   all number of given medGeometryElement.
261
262   Numbering is global, ie numbers are bounded by 1 and
263   MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and
264   MESH::getNumberOfElement(entity,geomElement).
265
266   Note : If SUPPORT is defined on MED_NODE, use MED_NONE
267   medGeometryElement type.
268 */
269 //---------------------------------------------------------------------
270 inline const int * SUPPORT::getNumber(medGeometryElement GeometricType) const
271   throw (MEDEXCEPTION)
272 //---------------------------------------------------------------------
273 {
274   const char * LOC = "Support::getNumber : " ;
275   if (_isOnAllElts)
276     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ;
277   if (GeometricType==MED_ALL_ELEMENTS)
278     return _number->getValue() ;
279   for (int i=0;i<_numberOfGeometricType;i++)
280     if (_geometricType[i]==GeometricType)
281       return _number->getI(i+1) ;
282   throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ;
283 }
284
285 /*!
286   If isOnAllElements is false, returns index of element number.
287   Use it with getNumber(MED_ALL_ELEMENTS).
288
289   Note : See getConnectivityIndex for details.
290 */
291 //-------------------------------------------
292 inline const int * SUPPORT::getNumberIndex() const
293 //-------------------------------------------
294   throw (MEDEXCEPTION)
295 {
296   if (_isOnAllElts)
297     throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
298   return _number->getIndex() ;
299 }
300
301 /*! A DOCUMENTER */
302 //-------------------------------------------------
303 inline const int * SUPPORT::getNumberOfGaussPoint() const
304   throw (MEDEXCEPTION)
305 //-------------------------------------------------
306 {
307   if (_numberOfGaussPoint!=NULL)
308     return _numberOfGaussPoint ;
309   else
310     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
311 }
312
313 /*!
314   Returns number of Gauss points for this medGeometryElement.
315
316   Note :
317   - Not defined if SUPPORT is on MED_NODE.
318   - Not defined for MED_ALL_ELEMENTS medGeometryElement type.
319 */
320 //-----------------------------------------------------------------------------
321 inline int SUPPORT::getNumberOfGaussPoint(medGeometryElement geomElement) const
322   throw (MEDEXCEPTION)
323 //-----------------------------------------------------------------------------
324 {
325   if (_numberOfGaussPoint!=NULL) {
326     for (int i=0;i<_numberOfGeometricType;i++)
327       if (_geometricType[i]==geomElement)
328         return _numberOfGaussPoint[i] ;
329     throw MEDEXCEPTION("Support::getGlobalNumber : GeometricType not found !") ;
330   } else
331     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
332 }
333 //  inline int SUPPORT::getNumberLength() const
334 //  throw (MEDEXCEPTION)
335 //  {
336 //      if (_isOnAllElts)
337 //        throw MEDEXCEPTION("Support::getNumberLength : Not defined, support is on all entity !") ;
338 //        return _number->getLength() ;
339 //  }
340
341 /*! set the attribute _name to Name */
342 //--------------------------------------
343 inline void SUPPORT::setName(string Name)
344 //--------------------------------------
345 {
346   _name=Name;
347 }
348
349 /*! set the attribute _description to Description */
350 //--------------------------------------------------
351 inline void SUPPORT::setDescription(string Description)
352 //--------------------------------------------------
353 {
354   _description=Description;
355 }
356
357 /*! set the reference _mesh to Mesh */
358 //--------------------------------------
359 inline void SUPPORT::setMesh(MESH *Mesh)
360 //--------------------------------------
361 {
362   _mesh=Mesh;
363 }
364
365 /*! set the attribute _isOnAllElts to All */
366 //------------------------------------------
367 inline void SUPPORT::setAll(bool All)
368 //------------------------------------------
369 {
370   _isOnAllElts=All;
371 }
372
373 /*! set the attribute _entity to Entity */
374 //------------------------------------------
375 inline void SUPPORT::setEntity(medEntityMesh Entity)
376 {
377   _entity=Entity;
378 //   if ( Entity == MED_NODE) {
379 //     _numberOfGeometricType=1 ;
380 //     if (_geometricType == (medGeometryElement *) NULL)
381 //       _geometricType=new medGeometryElement[1] ;
382 //     else 
383 //       {
384 //      // delete previous ???
385 //      delete [] _geometricType;
386 //      _geometricType=new medGeometryElement[1] ;
387 //       }
388 //     _geometricType[0]=MED_NONE ;
389 //   }
390 }
391
392 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
393 //---------------------------------------------------------------------
394 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
395 //---------------------------------------------------------------------
396 {
397   _numberOfGeometricType=NumberOfGeometricType;
398   if (_geometricType!=NULL) {
399     delete[] _geometricType ;
400     _geometricType = NULL ;
401   }
402   if (_numberOfElements!=NULL) {
403     delete[] _numberOfElements ;
404     _numberOfElements = NULL ;
405   }
406   if (_numberOfGaussPoint!=NULL) {
407     delete[] _numberOfGaussPoint ;
408     _numberOfGaussPoint = NULL ;
409   }
410 }
411
412 /*! set the attribute _geometricType to geometricType */
413 //---------------------------------------------------------------------
414 inline void SUPPORT::setGeometricType(const medGeometryElement *GeometricType)
415 //---------------------------------------------------------------------
416 {
417   if (NULL == _geometricType)
418     _geometricType=new medGeometryElement[_numberOfGeometricType];
419   for (int i=0;i<_numberOfGeometricType;i++)
420     _geometricType[i] = GeometricType[i];
421   //  _geometricType=GeometricType;
422 }
423
424 /*! set the attribute _numberOfGaussPoint to NumberOfGaussPoint */
425 //-----------------------------------------------------------------
426 inline void SUPPORT::setNumberOfGaussPoint(const int *NumberOfGaussPoint)
427 //-----------------------------------------------------------------
428 {
429   if (NULL == _numberOfGaussPoint)
430     _numberOfGaussPoint=new int[_numberOfGeometricType];
431   for (int i=0;i<_numberOfGeometricType;i++)
432     _numberOfGaussPoint[i] = NumberOfGaussPoint[i];
433   //  _numberOfGaussPoint = NumberOfGaussPoint ;
434 }
435
436 /*! set the attribute _geometricTypeNumber to GeometricTypeNumber */
437 //-------------------------------------------------------------------
438 //inline void SUPPORT::setGeometricTypeNumber(int *GeometricTypeNumber)
439 //-------------------------------------------------------------------
440 //{
441 //  _geometricTypeNumber=GeometricTypeNumber;
442 //}
443
444 /*!
445   Set the attribute _numberOfElements to NumberOfElements and 
446   calculate the total number of elements.
447 */
448 //----------------------------------------------------------
449 inline void SUPPORT::setNumberOfElements(const int *NumberOfElements)
450 //----------------------------------------------------------
451 {
452   if (NULL == _numberOfElements)
453     _numberOfElements=new int[_numberOfGeometricType];
454   memcpy(_numberOfElements,NumberOfElements,sizeof(int)*_numberOfGeometricType);
455   _totalNumberOfElements = 0 ;
456   for (int i=0;i<_numberOfGeometricType;i++)
457     _totalNumberOfElements+=_numberOfElements[i];
458 }
459
460 /*! set the attribute _totalNumberOfElements to TotalNumberOfElements */
461 //--------------------------------------------------------------------
462 inline void SUPPORT::setTotalNumberOfElements(int TotalNumberOfElements)
463 //--------------------------------------------------------------------
464 {
465   _totalNumberOfElements=TotalNumberOfElements;
466 }
467
468 /*! set the attribute _number to Number */
469 //---------------------------------------------------
470 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
471 //---------------------------------------------------
472 {
473   if (_number != NULL) delete _number ;
474   _number=Number;
475 }
476
477 /*! set the attribute _number with index and value arrays */
478 //---------------------------------------------------
479 inline void SUPPORT::setNumber(const int * index, const int* value)
480 //---------------------------------------------------
481 {
482   if (_number != NULL) delete _number ;
483   _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value);
484 }
485
486 /*! returns the name of the support. */
487 //------------------------------------
488 inline string SUPPORT::getName() const
489 //------------------------------------
490 {
491   return _name;
492 }
493
494
495 /*! returns the description of the support. */
496 //--------------------------------------------
497 inline string SUPPORT::getDescription() const
498 //--------------------------------------------
499 {
500   return _description;
501 }
502
503 /*! returns a reference to the mesh */
504 //------------------------------------
505 inline MESH * SUPPORT::getMesh() const
506 //------------------------------------
507 {
508   return _mesh;
509 }
510
511 /*!
512   Returns true if all elements of this entity are
513   concerned, false otherwise.
514   If true, you must use mesh reference (getMesh) to get more information.
515 */
516 //------------------------------------------
517 inline bool SUPPORT::isOnAllElements() const
518 //------------------------------------------
519 {
520   return _isOnAllElts;
521 }
522
523 /*!
524   Returns number of geometric Types
525   defines in the support
526 */
527 //------------------------------------------
528 inline int SUPPORT::getNumberOfTypes() const
529 //------------------------------------------
530 {
531   //    if ((_isOnAllElts)&(_entity != MED_NODE))
532   //      return _mesh->getNumberOfTypes(_entity) ;
533   //    else
534   return _numberOfGeometricType ;
535 }
536
537 /*!
538   Returns the medEntityMesh's type used by the support.
539   Note : A support deals only with one entity's type
540   (for example : MED_FACE or MED_NODE)
541 */
542 //---------------------------------------------
543 inline medEntityMesh SUPPORT::getEntity() const
544 //---------------------------------------------
545 {
546   return _entity;
547 }
548
549 /*!
550   If isOnAllElements is false, returns an array of <medGeometryElement>
551   types used by the support.
552
553   <medEntityMesh> is given by getEntity.
554 */
555 //---------------------------------------------------
556 inline const medGeometryElement * SUPPORT::getTypes() const
557 //---------------------------------------------------
558 {
559   //    if ((_isOnAllElts)&(_entity != MED_NODE))
560   //      return _mesh->getTypes(_entity) ;
561   //    else
562   return _geometricType;
563 }
564
565 //---------------------------------------------------
566 //inline int * SUPPORT::getGeometricTypeNumber() const
567 //---------------------------------------------------
568 //  {
569 //    const char * LOC = "SUPPORT::getGeometricTypeNumber() : ";
570 //    if (_isOnAllElts)
571 //      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined (is on all elements) !"));
572 //    if (_geometricTypeNumber==NULL)
573 //      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined !"));
574 //    return _geometricTypeNumber;
575 //  }
576
577
578 #endif /* SUPPORT_HXX */