]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Support.hxx
Salome HOME
Initialisation module MED_SRC de la base MED
[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_Exception.hxx"
14 #include "MEDMEM_define.hxx"
15
16 #include "MEDMEM_SkyLineArray.hxx"
17 #include "MEDMEM_Mesh.hxx"
18
19 using namespace MED_EN;
20
21 class MESH ;
22
23 class SUPPORT 
24 {
25 protected:
26                                                  /*! name of the support */
27   string                   _name;
28                                                  /*! description of the support (optionnal) */
29   string                   _description;
30                                                  /*! reference to the mesh on which the support is defined */
31   MESH *                   _mesh;
32                                                  /*! type of entity on which the support is defined 
33                                                      (only one for each support) */
34   medEntityMesh            _entity ;
35                                                  /*! number of geometric type defined in the support */
36   int                      _numberOfGeometricType;
37                                                  /*! array of all geometric type defined in the support */
38   medGeometryElement *     _geometricType;
39                                                  /*! array of size _numberOfGeometricType which contains 
40                                                      for each type the number of gauss point 
41                                                      (not yet implemented) */
42   int *                    _numberOfGaussPoint ; 
43                                                  /*! array of size _numberOfGeometricType 
44                                                      which contains number of geometric
45                                                      entity type in Mesh 
46                                                      (to get corresponding CellModel)*/
47   int *                    _geometricTypeNumber; 
48                                                  /*! If true, we consider all entities of type _entity */
49   bool                     _isOnAllElts;        
50                                                  /*! array of size _numberOfGeometricType wich contains
51                                                      for each geometric type, count of entities. 
52                                                      (if _isOnAllElts is true, we could get same 
53                                                      information from _mesh) */
54   int *                    _numberOfEntities;   
55                                                  /*! sum of each _numberOfEntities component (if 
56                                                      _isOnAllElts is true, we could get same 
57                                                      information from _mesh) */
58   int                      _totalNumberOfEntities;    
59
60   // the two following arrays are defined only if _isOnAllElts is false :
61
62                              /* array of size _numberOfType+1 wich contains for 
63                                  each geometric type, index in _number._value 
64                                  (if _all is true, we must ask _mesh to get 
65                                  information). _typeIndex[i+1]-_typeIndex[i] 
66                                  represents count of entities of ith geometric 
67                                  type. _typeIndex[_numberOfType] contains total 
68                                  entities count. If _numberOf[i]=0, 
69                                  _typeIndex[i+1]=_typeIndex[i] 
70                                  defined only if _isOnAllElts is false*/
71   //  int *      _typeIndex; 
72                              /*! array of size _index[_numberOfType] wich contain number of 
73                                  entities of each geometric type. We use global numbering.
74                                  defined only if _isOnAllElts is false*/
75   MEDSKYLINEARRAY * _number;   
76
77 public:
78   SUPPORT(); 
79   SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL); 
80   ~SUPPORT();
81   friend ostream & operator<<(ostream &os,const SUPPORT &my);
82   
83   // function to set all value when SUPPORT was created by MedMedDriver without all MESH information !!! Change with new API !
84   void update();
85   
86   inline void setName(string Name);
87   inline void setDescription(string Description); 
88   inline void setMesh(MESH *Mesh);               
89   inline void setAll(bool All);                          
90   inline void setEntity(medEntityMesh Entity); 
91   inline void setNumberOfGeometricType(int NumberOfGeometricType); 
92   inline void setGeometricType(medGeometryElement *GeometricType); 
93   inline void setNumberOfGaussPoint(int *NumberOfGaussPoint);
94   inline void setGeometricTypeNumber(int *GeometricTypeNumber); 
95   inline void setNumberOfEntities(int *NumberOfEntities); 
96   inline void setTotalNumberOfEntities(int TotalNumberOfEntities); 
97   inline void setNumber(MEDSKYLINEARRAY * Number); 
98   
99   inline string getName() const; 
100   inline string getDescription() const; 
101   inline MESH * getMesh() const; 
102   inline medEntityMesh getEntity() const;
103
104   inline bool   isOnAllElements() const; 
105   inline int    getNumberOfTypes() const;
106   inline medGeometryElement* getTypes() const ;
107   inline int *  getNumberOfGaussPoint() const throw (MEDEXCEPTION);
108   inline int    getNumberOfGaussPoint(medGeometryElement geomElement) const throw (MEDEXCEPTION);
109   inline int *  getGeometricTypeNumber() const; 
110   //  inline int    getNumberOfTotalEntity() const;
111   inline int    getNumberOfElements(medGeometryElement GeometricType) const throw (MEDEXCEPTION);
112   inline MEDSKYLINEARRAY *  getnumber() const throw (MEDEXCEPTION);
113   inline int *  getNumber(medGeometryElement GeometricType) const throw (MEDEXCEPTION);
114   inline int *  getNumberIndex() const throw (MEDEXCEPTION);
115
116   void blending(SUPPORT * mySupport);
117
118   /*
119     This function allows the user to set a support not on all entities Entity,
120     it should be used after an initialisation with the constructor
121     SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL) and
122     after the call to the function setAll(false).
123     It allocates and initialises all the attributs of the class SUPPORT.
124   */
125
126   void setpartial(string Description, int NumberOfGeometricType,
127                   int TotalNumberOfEntity, medGeometryElement *GeometricType,
128                   int *NumberOfEntity, int *NumberValue);
129 };
130 // _____________________
131 // Methodes Inline
132 // _____________________
133
134 /*!  If isOnAllElements is false, returns number of elements in the
135      support else returns number of nodes.
136
137       Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
138       in entity of support.
139
140       Note : If SUPPORT is defined on MED_NODE, use MED_NONE
141       medGeometryElement type.  */
142 //-----------------------------------------------------------------------------
143 inline int SUPPORT::getNumberOfElements(medGeometryElement GeometricType) const
144 throw (MEDEXCEPTION) 
145 //-----------------------------------------------------------------------------
146 {
147   if (_isOnAllElts){ 
148     return _mesh->getNumberOfElements(_entity,GeometricType);
149   } else {
150     if (GeometricType==MED_ALL_ELEMENTS)
151       return _totalNumberOfEntities;
152     for (int i=0;i<_numberOfGeometricType;i++)
153       if (_geometricType[i]==GeometricType)
154         return _numberOfEntities[i] ;
155     throw MEDEXCEPTION("Support::getNumberOfElements : Type not found !") ;
156   }
157 }
158 //  inline int SUPPORT::getNumberOf(medGeometryElement GeometricType) const 
159 //  throw (MEDEXCEPTION) 
160 //  {
161 //      if (GeometricType==MED_ALL_ELEMENTS)
162 //          return _totalNumberOfEntities ; 
163 //      for (int i=0;i<_numberOfGeometricType;i++)
164 //          if (_geometricType[i]==GeometricType)
165 //      return _numberOfEntities[i] ;
166 //      throw MEDEXCEPTION("Support::getNumberOf: GeometricType not found !");
167 //  }
168
169 //  inline int SUPPORT::getNumberOfTotalEntity() const 
170 //  { 
171 //    return _totalNumberOfEntities ; 
172 //  }
173
174 //---------------------------------------------------------------------
175 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const 
176   throw (MEDEXCEPTION) 
177 //---------------------------------------------------------------------
178 {
179   if (_number==NULL) 
180     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
181   return _number ;
182 }
183
184 /*!   If isOnAllElements is false, returns an array which contains
185       all number of given medGeometryElement.
186
187       Numbering is global, ie numbers are bounded by 1 and
188       MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and
189       MESH::getNumberOfElement(entity,geomElement).
190
191       Note : If SUPPORT is defined on MED_NODE, use MED_NONE
192       medGeometryElement type. */
193 //---------------------------------------------------------------------
194 inline int * SUPPORT::getNumber(medGeometryElement GeometricType) const 
195   throw (MEDEXCEPTION) 
196 //---------------------------------------------------------------------
197 {
198   const char * LOC = "Support::getNumber : " ;
199   if (_isOnAllElts) 
200     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ;
201   if (GeometricType==MED_ALL_ELEMENTS)
202     return _number->getValue() ; 
203   for (int i=0;i<_numberOfGeometricType;i++)
204     if (_geometricType[i]==GeometricType)
205       return _number->getI(i+1) ;
206   throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ;
207 }
208
209 /*!  If isOnAllElements is false, returns index of element number.
210       Use it with getNumber(MED_ALL_ELEMENTS).
211
212       Note : See getConnectivityIndex for details.  */
213 //-------------------------------------------
214 inline int * SUPPORT::getNumberIndex() const 
215 //-------------------------------------------
216 throw (MEDEXCEPTION) 
217 {
218     if (_isOnAllElts) 
219       throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
220       return _number->getIndex() ;
221 }
222
223 /*! A DOCUMENTER */
224 //-------------------------------------------------
225 inline int * SUPPORT::getNumberOfGaussPoint() const 
226 throw (MEDEXCEPTION) 
227 //-------------------------------------------------
228 {
229   if (_numberOfGaussPoint!=NULL)
230     return _numberOfGaussPoint ;
231   else
232     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
233 }
234
235 /*!  Returns number of Gauss points for this medGeometryElement.
236
237       Note :
238       - Not defined if SUPPORT is on MED_NODE.
239       - Not defined for MED_ALL_ELEMENTS medGeometryElement type.  */
240 //-----------------------------------------------------------------------------
241 inline int SUPPORT::getNumberOfGaussPoint(medGeometryElement geomElement) const 
242 throw (MEDEXCEPTION) 
243 //-----------------------------------------------------------------------------
244 {
245   if (_numberOfGaussPoint!=NULL) {
246     for (int i=0;i<_numberOfGeometricType;i++)
247       if (_geometricType[i]==geomElement)
248         return _numberOfGaussPoint[i] ;
249     throw MEDEXCEPTION("Support::getGlobalNumber : GeometricType not found !") ;
250   } else
251     throw MEDEXCEPTION("Support::getNumberOfGaussPoint : Not defined !") ;
252 }
253 //  inline int SUPPORT::getNumberLength() const 
254 //  throw (MEDEXCEPTION) 
255 //  {
256 //      if (_isOnAllElts) 
257 //        throw MEDEXCEPTION("Support::getNumberLength : Not defined, support is on all entity !") ;
258 //        return _number->getLength() ;
259 //  }
260
261 /*! set the attribute _name to Name   */
262 //--------------------------------------
263 inline void SUPPORT::setName(string Name)
264 //--------------------------------------
265
266   _name=Name; 
267 }
268
269 /*! set the attribute _description to Description */
270 //--------------------------------------------------
271 inline void SUPPORT::setDescription(string Description)
272 //--------------------------------------------------
273
274   _description=Description; 
275 }
276
277 /*! set the reference _mesh to Mesh   */
278 //--------------------------------------
279 inline void SUPPORT::setMesh(MESH *Mesh)
280 //--------------------------------------
281
282   _mesh=Mesh; 
283 }
284
285 /*! set the attribute _isOnAllElts to All */
286 //------------------------------------------
287 inline void SUPPORT::setAll(bool All)
288 //------------------------------------------
289
290   _isOnAllElts=All; 
291 }
292
293 /*! set the attribute _entity to Entity */
294 //------------------------------------------
295 inline void SUPPORT::setEntity(medEntityMesh Entity)
296
297   _entity=Entity; 
298   if ( Entity == MED_NODE) {
299     _numberOfGeometricType=1 ;
300     _geometricType=new medGeometryElement[1] ; // delete previous ???
301     _geometricType[0]=MED_NONE ;
302   }
303 }
304
305 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
306 //---------------------------------------------------------------------
307 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
308 //---------------------------------------------------------------------
309
310   _numberOfGeometricType=NumberOfGeometricType; 
311 }
312
313 /*! set the attribute _geometricType to geometricType                */
314 //---------------------------------------------------------------------
315 inline void SUPPORT::setGeometricType(medGeometryElement *GeometricType)
316 //---------------------------------------------------------------------
317
318   _geometricType=GeometricType; 
319 }
320
321 /*! set the attribute _numberOfGaussPoint to NumberOfGaussPoint  */
322 //-----------------------------------------------------------------
323 inline void SUPPORT::setNumberOfGaussPoint(int *NumberOfGaussPoint)
324 //-----------------------------------------------------------------
325 {
326   _numberOfGaussPoint = NumberOfGaussPoint ;
327 }
328
329 /*! set the attribute _geometricTypeNumber to GeometricTypeNumber  */
330 //-------------------------------------------------------------------
331 inline void SUPPORT::setGeometricTypeNumber(int *GeometricTypeNumber)
332 //-------------------------------------------------------------------
333
334   _geometricTypeNumber=GeometricTypeNumber; 
335 }
336
337 /*! set the attribute _numberOfEntities to NumberOfEntities */
338 //----------------------------------------------------------
339 inline void SUPPORT::setNumberOfEntities(int *NumberOfEntities)
340 //----------------------------------------------------------
341
342   _numberOfEntities=NumberOfEntities; 
343 }
344
345 /*! set the attribute _totalNumberOfEntities to TotalNumberOfEntities */
346 //--------------------------------------------------------------------
347 inline void SUPPORT::setTotalNumberOfEntities(int TotalNumberOfEntities)
348 //--------------------------------------------------------------------
349
350   _totalNumberOfEntities=TotalNumberOfEntities; 
351 }
352
353 /*! set the attribute _number to Number           */
354 //---------------------------------------------------
355 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
356 //---------------------------------------------------
357
358   _number=Number; 
359 }
360
361 /*! returns the name of the support. */
362 //------------------------------------
363 inline string SUPPORT::getName() const 
364 //------------------------------------
365
366   return _name; 
367 }
368
369
370 /*! returns the description of the support. */
371 //--------------------------------------------
372 inline string SUPPORT::getDescription() const 
373 //--------------------------------------------
374
375   return _description; 
376 }
377
378 /*! returns a refernce to the mesh  */
379 //------------------------------------
380 inline MESH * SUPPORT::getMesh() const 
381 //------------------------------------
382
383   return _mesh; 
384 }
385
386 /*!  Returns true if all elements of this entity are
387      concerned, false otherwise.
388      If true, you must use mesh reference (getMesh) to get more information.*/
389 //------------------------------------------
390 inline bool SUPPORT::isOnAllElements() const 
391 //------------------------------------------
392
393   return _isOnAllElts; 
394 }
395
396 /*!  Returns number of geometric Types
397      defines in the support              */ 
398 //------------------------------------------
399 inline int SUPPORT::getNumberOfTypes() const 
400 //------------------------------------------
401
402   if ((_isOnAllElts)&(_entity != MED_NODE))
403     return _mesh->getNumberOfTypes(_entity) ;
404   else
405     return _numberOfGeometricType ; 
406 }
407
408 /*!  Returns the medEntityMesh's type used by the support.
409      Note : A support deals only with one entity's type
410      (for example : MED_FACE or MED_NODE)*/
411 //---------------------------------------------
412 inline medEntityMesh SUPPORT::getEntity() const 
413 //---------------------------------------------
414
415   return _entity; 
416 }
417
418 /*!  If isOnAllElements is false, returns an array of <medGeometryElement>
419      types used by the support.
420
421      <medEntityMesh> is given by getEntity.  */
422 //---------------------------------------------------
423 inline medGeometryElement * SUPPORT::getTypes() const 
424 //---------------------------------------------------
425 {
426   if ((_isOnAllElts)&(_entity != MED_NODE))
427     return _mesh->getTypes(_entity) ;
428   else
429     return _geometricType; 
430 }
431
432 //---------------------------------------------------
433 inline int * SUPPORT::getGeometricTypeNumber() const
434 //---------------------------------------------------
435 {
436   const char * LOC = "SUPPORT::getGeometricTypeNumber() : ";
437   if (_isOnAllElts)
438     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined (is on all elements) !"));
439   if (_geometricTypeNumber==NULL)
440     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined !"));
441   return _geometricTypeNumber; 
442 }
443
444     
445 #endif /* SUPPORT_HXX */