]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Grid.hxx
Salome HOME
removing this useless file.
[modules/med.git] / src / MEDMEM / MEDMEM_Grid.hxx
1 // File      : MEDMEM_Grid.hxx
2 // Created   : Wed Dec 18 08:35:26 2002
3 // Descr     : class containing structured mesh data
4
5 // Author    : Edward AGAPOV (eap)
6 // Project   : SALOME Pro
7 // Module    : MED 
8 // Copyright : Open CASCADE
9 // $Header$
10
11 #ifndef MEDMEM_Grid_HeaderFile
12 #define MEDMEM_Grid_HeaderFile
13
14 #include "MEDMEM_Mesh.hxx"
15
16 // class containing structured mesh data
17
18 namespace MEDMEM {
19 class GRID: public MESH
20 {
21  protected:
22   //-----------------------//
23   //   Fields
24   //-----------------------//
25   
26   // 1. grid type: MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED
27 //   med_grid_type     _gridType;
28
29   // 1. grid type MED_GRILLE_CARTESIENNE, MED_GRILLE_POLAIRE,
30   //              MED_GRILLE_STANDARD
31   med_type_grille _gridType;
32
33   // 2. node coordinates
34   // For MED_BODY_FITTED MESH::_coordinate is used
35   
36   // 2.1. i component array: X for MED_CARTESIAN, R for MED_POLAR
37   int               _iArrayLength;
38   double*           _iArray;
39   // 2.2. j component array: Y for MED_CARTESIAN, Theta for MED_POLAR
40   int               _jArrayLength;
41   double*           _jArray;
42   // 2.3. k component array: Z for both MED_CARTESIAN and MED_POLAR
43   int               _kArrayLength;
44   double*           _kArray;
45
46   // 3. flags to know that _coordinates and _connectivity of MESH are filled
47   bool              _is_coordinates_filled;
48   bool              _is_connectivity_filled;
49
50   //-----------------------//
51   //   Protected Methods
52   //-----------------------//
53
54   CONNECTIVITY * makeConnectivity (const medEntityMesh Entity,
55                                    const medGeometryElement Geometry,
56                                    const int NbEntities, const int NbNodes,
57                                    int * NodeNumbers) const ;
58   // creates nodal connectivity
59
60   
61   // Suppose a READ Driver to do the following except filling _[ijk]Array's
62   // 1) fill MESH fields:
63   //    * _name
64   //    * _spaceDimension
65   //    * _meshDimension
66   //    * _numberOfNodesFamilies, _numberOfCellsFamilies, ect
67   //    * _familyNode, _familyCell, etc
68   //    * _numberOfNodesGroups, _numberOfCellsGroups, etc
69   //    * _groupNode, _groupCell, etc
70   //    * _
71   // 2) create MESH::_coordinate without setting _coordinate->_coordinate and set: 
72   //    * _coordinate->_coordinateSystem
73   //    * _coordinate->_coordinateName
74   //    * _coordinate->_coordinateUnit
75   
76
77  public:
78   //-----------------------//
79   //   Methods
80   //-----------------------//
81
82   GRID();
83 //   GRID(const med_grid_type type);
84   GRID(const med_type_grille type);
85   GRID(const GRID &m);
86   GRID( driverTypes driverType, const string & fileName="",const string & meshName="");
87   GRID & operator=(const GRID &m);
88   virtual ~GRID();
89   virtual void init();
90
91   void fillCoordinates() const ;
92   void fillConnectivity() const ;
93   // fill _coordinates and _connectivity of MESH if not yet done
94
95   inline void makeUnstructured();
96   // fill both coordinates and connectivity of MESH
97
98   void fillMeshAfterRead();
99   // fill some fields (_numberOfNodes, etc.) after reading
100
101   void writeUnstructured(int index=0, const string & driverName = "");
102   // write a Grid as an Unstructured mesh
103
104   void read(int index=0);
105
106   //   API Methods returning fields of MESH that are filled while reading.
107   //   So they need not to be redefined
108
109 //   string                getName() const;
110 //   int                   getSpaceDimension();
111 //   int                   getMeshDimension();
112 //   string                getCoordinatesSystem();
113 //   int                   getNumberOfNodes();
114 //   string *              getCoordinatesNames();
115 //   string *              getCoordinatesUnits();
116 //   int                   getNumberOfFamilies(medEntityMesh Entity);
117 //   vector<FAMILY*>       getFamilies(medEntityMesh Entity);
118 //   FAMILY*               getFamily(medEntityMesh Entity,int i);
119 //   int                   getNumberOfGroups(medEntityMesh Entity);
120 //   vector<GROUP*>        getGroups(medEntityMesh Entity);
121 //   GROUP*                getGroup(medEntityMesh Entity,int i);
122
123
124 // Since a MESH itself knows if it is a GRID, it calls fillConnectivity()
125 // or fillCoordinates() whenever needed. So no redifinition of the following methods
126
127 //   const double *        getCoordinates(medModeSwitch Mode);
128 //   COORDINATE *          getCoordinateptr();
129 //   const double          getCoordinate(int Number,int Axis);
130 //   int                   getNumberOfTypes(medEntityMesh Entity);
131 //   medGeometryElement *  getTypes(medEntityMesh Entity);
132 //   CELLMODEL *           getCellsTypes(medEntityMesh Entity);
133 //   medGeometryElement    getElementType(medEntityMesh Entity,int Number) ;
134 //   int                   getNumberOfElements(medEntityMesh Entity,medGeometryElement Type);
135 //   int                   getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity) ;
136 //   int *                 getGlobalNumberingIndex(medEntityMesh Entity);
137 //   int *                 getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity, medGeometryElement Type);
138 //   int *                 getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity);
139 //   int *                 getReverseConnectivity(medConnectivity ConnectivityType);
140 //   int *                 getReverseConnectivityIndex(medConnectivity ConnectivityType);
141 //   bool                  existConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity);
142 //   void                  calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity);
143 //   FIELD<double>*        getVolume(const SUPPORT * Support) throw (MEDEXCEPTION) ;
144 //   FIELD<double>*        getArea(const SUPPORT * Support) throw (MEDEXCEPTION) ;
145 //   FIELD<double>*        getLength(const SUPPORT * Support) throw (MEDEXCEPTION) ;
146 //   FIELD<double>*        getNormal(const SUPPORT * Support) throw (MEDEXCEPTION) ;
147 //   FIELD<double>*        getBarycenter(const SUPPORT * Support) throw (MEDEXCEPTION) ;
148
149
150   // Specific GRID methods
151
152   inline int getNodeNumber(const int i, const int j=0, const int k=0) const;
153   // return a NODE number by its position in the grid.
154   // WARNING: be carefull, there is no check that i,j,k are within a good range
155   // A good range is: 0 <= X < getArrayLength( X_Axis )
156   inline int getCellNumber(const int i, const int j=0, const int k=0) const ;
157   // return a CELL number by its position in the grid.
158   // WARNING: be carefull, there is no check that i,j,k are within a good range
159   // A good range is: 0 <= X < (getArrayLength( X_Axis )-1)
160
161   int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ;
162   // return an EDGE number by its position in the grid.
163   // Axis [1,2,3] means one of directions: along i, j or k.
164   // It selects an edge of ones having same (i,j,k):
165   //  * an EDGE going along given Axis.
166   // Exception for Axis out of range or when there is no edges in the grid (1D)
167   // WARNING: be carefull, there is no check that i,j,k are within a good range
168   // A good range is:
169   // 0 <= X < (getArrayLength( X_Axis )-1)
170   // 0 <= X < getArrayLength( NOT_X_Axis )
171
172   int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ;
173   // return a FACE number by its position in the grid.
174   // Axis [1,2,3] means one of directions: along i, j or k.
175   // It selects a face of ones having same (i,j,k):
176   //  * a FACE which is normal to given Axis
177   // Exception for Axis out of range or when there is no faces in the grid (1,2D)
178   // WARNING: be carefull, there is no check that i,j,k are within a good range
179   // A good range is:
180   // 0 <= X < (getArrayLength( NOT_X_Axis )-1)
181   // 0 <= X < getArrayLength( X_Axis )
182   
183
184   void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
185   void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
186   void getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
187   void getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
188   // return position (i,j,k) of an entity #Number
189   // Axis: [1,2,3], see get*Number for details
190   // Exception for Number out of range
191
192
193   //  Access to fields
194
195 //   inline med_grid_type getGridType() const;
196   // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED
197
198   inline med_type_grille getGridType() const;
199   // returns MED_GRILLE_CARTESIENNE, MED_GRILLE_POLAIRE, MED_GRILLE_STANDARD
200
201   int getArrayLength( const int Axis ) const throw (MEDEXCEPTION);
202   // return array length. Axis = [1,2,3] meaning [i,j,k],
203   // exception if Axis out of [1-3] range
204
205   const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION) ;
206   // return i-th array component. Axis = [1,2,3] meaning [i,j,k],
207   // exception if Axis out of [1 - 3] range
208   // exception if i is out of range [0 - (getArrayLength(Axis)-1)];
209
210   inline const COORDINATE * getCoordinateptr() const;
211
212   inline const double * getCoordinates(medModeSwitch Mode) const;
213
214   inline const double getCoordinate(int Number,int Axis) const;
215
216   inline int getNumberOfTypes(medEntityMesh Entity) const;
217
218   inline const medGeometryElement * getTypes(medEntityMesh Entity) const;
219
220   inline const CELLMODEL * getCellsTypes(medEntityMesh Entity) const;
221
222   const int * getGlobalNumberingIndex(medEntityMesh Entity) const;
223
224   inline int getNumberOfElements(medEntityMesh Entity,
225                                  medGeometryElement Type) const;
226
227   inline bool existConnectivity(medConnectivity ConnectivityType,
228                                 medEntityMesh Entity) const;
229
230   inline medGeometryElement getElementType(medEntityMesh Entity,
231                                            int Number) const;
232
233   inline void calculateConnectivity(medModeSwitch Mode,
234                                     medConnectivity ConnectivityType,
235                                     medEntityMesh Entity) const ;
236
237   inline const CONNECTIVITY* getConnectivityptr() const;
238
239   inline const int * getConnectivity(medModeSwitch Mode,
240                                      medConnectivity ConnectivityType,
241                                      medEntityMesh Entity, 
242                                      medGeometryElement Type) const;
243
244   inline const int * getConnectivityIndex(medConnectivity ConnectivityType,
245                                           medEntityMesh Entity) const;
246
247   inline const int * getReverseConnectivity(medConnectivity ConnectivityType,
248                                             medEntityMesh Entity=MED_CELL) const;
249
250   inline const int * getReverseConnectivityIndex(medConnectivity ConnectivityType,
251                                                  medEntityMesh Entity=MED_CELL) const;
252
253   //  Setting fields
254
255 //   inline void setGridType(med_grid_type gridType);
256   inline void setGridType(med_type_grille gridType);
257
258   friend class MED_MESH_RDONLY_DRIVER;
259   friend class MED_MESH_WRONLY_DRIVER;
260
261 };
262 };
263 using namespace MEDMEM;
264
265
266   //----------------------------------//
267   //   Inline Methods Implementation
268   //----------------------------------//
269
270 // inline med_grid_type GRID::getGridType() const
271 // {
272 //   return _gridType;
273 // }
274
275 inline med_type_grille GRID::getGridType() const
276 {
277   return _gridType;
278 }
279 //=======================================================================
280 //function : getNodeNumber
281 //purpose  : 
282 //=======================================================================
283
284 inline int GRID::getNodeNumber(const int i, const int j, const int k) const
285 {
286   return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k;
287 }
288
289 //=======================================================================
290 //function : getCellNumber
291 //purpose  : 
292 //=======================================================================
293
294 inline int GRID::getCellNumber(const int i, const int j, const int k) const
295 {
296   return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k;
297 }
298
299 //=======================================================================
300 //function : makeUnstructured
301 //purpose : fill coordinates and connectivity of MESH
302 //=======================================================================
303
304 inline void GRID::makeUnstructured()
305 {
306   fillCoordinates();
307   fillConnectivity();
308 }
309
310 //=======================================================================
311 //function : setGridType
312 //purpose : set the _gridType field od the class GRID
313 //=======================================================================
314
315 // inline void GRID::setGridType(med_grid_type gridType)
316 // {
317 //   _gridType = gridType;
318 // }
319
320 inline void GRID::setGridType(med_type_grille gridType)
321 {
322   _gridType = gridType;
323 }
324
325 /*! Get the COORDINATES object. Use it only if you need COORDINATES informations not provided by the GRID class via the MESH class.*/
326 inline const COORDINATE * GRID::getCoordinateptr() const
327 {
328   fillCoordinates();
329   return _coordinate;
330 }
331
332 /*! Get the whole coordinates array in a given interlacing mode. The interlacing mode are :
333   - MED_NO_INTERLACE   :  X1 X2 Y1 Y2 Z1 Z2
334   - MED_FULL_INTERLACE :  X1 Y1 Z1 X2 Y2 Z2
335  */
336 inline const double * GRID::getCoordinates(medModeSwitch Mode) const
337 {
338   fillCoordinates();
339   return _coordinate->getCoordinates(Mode);
340 }
341
342 /*! Get the coordinate n° number on axis n°axis*/
343 inline const double GRID::getCoordinate(int number, int axis) const
344 {
345   fillCoordinates();
346   return _coordinate->getCoordinate(number,axis);
347 }
348
349 /*! Get the number of different geometric types for a given entity type.
350
351     medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_NODE,
352     MED_ALL_ENTITIES
353
354     If entity is not defined, return 0.
355
356     If there is no connectivity, return an exception.
357 */
358 inline int GRID::getNumberOfTypes(medEntityMesh entity) const
359 {
360   MESSAGE("GRID::getNumberOfTypes(medEntityMesh entity) : "<<entity);
361   if (entity == MED_NODE)
362     return 1;
363
364   fillConnectivity();
365
366   if (_connectivity != NULL)
367     return _connectivity->getNumberOfTypes(entity);
368   throw MEDEXCEPTION(LOCALIZED("GRID::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
369 }
370
371 /*!
372   Get the list of geometric types used by a given entity.
373   medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_ALL_ENTITIES
374
375   REM : Don't use MED_NODE
376
377   If entity is not defined, return an exception.
378 */
379 inline const medGeometryElement * GRID::getTypes(medEntityMesh entity) const
380 {
381   if (entity == MED_NODE)
382     throw MEDEXCEPTION(LOCALIZED("GRID::getTypes( medEntityMesh ) : No medGeometryElement with MED_NODE entity !"));
383   // return un tableau de taille 1 contenant MED_NONE, comme les supports pour etre coherent avec getNumberOfTypes ???? PG
384
385   fillConnectivity();
386
387   if (_connectivity != NULL)
388     return _connectivity->getGeometricTypes(entity);
389   throw MEDEXCEPTION(LOCALIZED("GRID::getTypes( medEntityMesh ) : Connectivity not defined !"));
390 }
391
392 /*!
393   Get the whole list of CELLMODEL used by cells of given type (medEntityMesh).
394
395   REMARK : Don't use MED_NODE as medEntityMesh
396 */
397 inline const CELLMODEL * GRID::getCellsTypes(medEntityMesh Entity) const
398 {
399   fillConnectivity();
400
401   if (_connectivity != NULL)
402     return _connectivity->getCellsTypes(Entity);
403   throw MEDEXCEPTION(LOCALIZED("GRID::getCellsTypes( medEntityMesh ) : Connectivity not defined !"));
404 }
405
406 /*! Return an array of size NumbreOfTypes+1 which contains, for each
407     geometric type of the given entity, the first global element number
408     of this type.
409
410     For exemple, if we have a mesh with 5 triangles and 4 quadrangle :
411     - size of GlobalNumberingIndex is 3
412     - GlobalNumberingIndex[0]=1 (the first type)
413     - GlobalNumberingIndex[1]=6 (the second type)
414     - GlobalNumberingIndex[2]=10
415 */
416 inline const int * GRID::getGlobalNumberingIndex(medEntityMesh entity) const
417 {
418   fillConnectivity();
419
420   if (_connectivity != NULL)
421     return _connectivity->getGlobalNumberingIndex(entity);
422   throw MEDEXCEPTION(LOCALIZED("GRID::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
423 }
424
425 /*!
426   Return the number of element of given geometric type of given entity. Return 0 if query is not defined.
427
428   Example :
429   - getNumberOfElements(MED_NODE,MED_NONE) : number of node
430   - getNumberOfElements(MED_NODE,MED_TRIA3) : return 0 (not defined)
431   - getNumberOfElements(MED_FACE,MED_TRIA3) : return number of triangles
432   elements defined in face entity (0 if not defined)
433   - getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) : return total number
434   of elements defined in cell entity
435 */
436 inline int GRID::getNumberOfElements(medEntityMesh entity, medGeometryElement Type) const
437 {
438   //  const char * LOC = "MESH::getNumberOfElements(medEntityMesh,medGeometryElement) : ";
439   if (entity==MED_NODE)
440     if ((Type==MED_NONE)|(Type==MED_ALL_ELEMENTS))
441       return _numberOfNodes;
442     else
443       return 0;
444   //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"wrong medGeometryElement with MED_NODE"));
445   else
446     {
447       fillConnectivity();
448
449       if (_connectivity != (CONNECTIVITY*)NULL)
450         return _connectivity->getNumberOf(entity,Type);
451       else
452         return 0;
453       //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"connectivity not defined !"));
454     }
455 }
456
457 /*!
458   Return true if the wanted connectivity exist, else return false
459   (to use before a getSomething method).
460  */
461 inline bool GRID::existConnectivity(medConnectivity connectivityType, medEntityMesh entity) const
462 {
463   fillConnectivity();
464
465   if (_connectivity==(CONNECTIVITY*)NULL)
466     throw MEDEXCEPTION("GRID::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !");
467   return _connectivity->existConnectivity(connectivityType,entity);
468 }
469
470 /*!
471   Return the geometric type of global element Number of entity Entity.
472
473   Throw an exception if Entity is not defined or Number are wrong (too big).
474  */
475 inline medGeometryElement GRID::getElementType(medEntityMesh Entity,int Number) const
476 {
477   fillConnectivity();
478
479   if (_connectivity==(CONNECTIVITY*)NULL)
480     throw MEDEXCEPTION("GRID::getElementType(medEntityMesh,int) : no connectivity defined !");
481   return _connectivity->getElementType(Entity,Number);
482 }
483
484 /*!
485   Calculate the ask connectivity. Return an exception if this could not be
486   done. Do nothing if connectivity already exist.
487  */
488
489 inline void GRID::calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity) const
490 {
491   fillConnectivity();
492
493   if (Mode==MED_FULL_INTERLACE)
494     _connectivity->calculateConnectivity(ConnectivityType,entity);
495   else
496     throw MEDEXCEPTION(LOCALIZED("GRID::calculateConnectivity : only for MED_FULL_INTERLACE mode"));
497 }
498
499 inline const CONNECTIVITY* GRID::getConnectivityptr() const
500 {
501   fillConnectivity();
502
503   return _connectivity;
504 }
505
506 /*!
507   Return the required connectivity in the right mode for the given
508   geometric type of the given entity.
509
510   To get connectivity for all geometric type, use Mode=MED_FULL_INTERLACE
511   and Type=MED_ALL_ELEMENTS.
512   You must also get the corresponding index array.
513  */
514 inline const int * GRID::getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity, medGeometryElement Type) const
515 {
516   fillConnectivity();
517
518   if (Mode==MED_FULL_INTERLACE)
519     return _connectivity->getConnectivity(ConnectivityType,entity,Type);
520   throw MEDEXCEPTION(LOCALIZED("GRID::getConnectivity : only for MED_FULL_INTERLACE mode"));
521 }
522
523 /*!
524   Return the required index array for a connectivity received in
525   MED_FULL_ENTERLACE mode and MED_ALL_ELEMENTS type.
526
527   This array allow to find connectivity of each elements.
528
529   Example : Connectivity of i^{th} elements (1<=i<=NumberOfElement) begin
530   at index ConnectivityIndex[i-1] and end at index ConnectivityIndex[i]-1
531   in Connectivity array (Connectivity[ConnectivityIndex[i-1]-1] is the
532   first value)
533  */
534 inline const int * GRID::getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh entity) const
535 {
536   fillConnectivity();
537
538   return _connectivity->getConnectivityIndex(ConnectivityType, entity);
539 }
540
541 /*!
542   Return the reverse connectivity required by ConnectivityType :
543   - If ConnectivityType=MED_NODAL : return connectivity node-cell
544   - If ConnectivityType=MED_DESCENDING : return connectivity face-cell
545
546   You must get ReverseConnectivityIndex array to use it.
547  */
548 inline const int * GRID::getReverseConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const
549 {
550   fillConnectivity();
551
552   if (NULL==_connectivity)
553     throw MEDEXCEPTION("GRID::getReverseConnectivity : no connectivity defined in MESH !");
554
555   return _connectivity->getReverseConnectivity(ConnectivityType,Entity);
556 }
557
558 /*!
559   Return the index array required by ConnectivityType.
560
561   This array allow to find reverse connectivity of each elements.
562
563   Example : Reverse connectivity of i^{th} elements (1<=i<=NumberOfElement)
564   begin at index ReverseConnectivityIndex[i-1] and end at index
565   ReverseConnectivityIndex[i]-1
566   in ReverseConnectivity array (
567   ReverseConnectivity[ReverseConnectivityIndex[i-1]-1]
568   is the first value)
569  */
570 inline const int * GRID::getReverseConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const
571 {
572   fillConnectivity();
573
574   if (NULL==_connectivity)
575     throw MEDEXCEPTION("GRID::getReverseConnectivityIndex : no connectivity defined in MESH !");
576
577   return _connectivity->getReverseConnectivityIndex(ConnectivityType,Entity);
578 }
579
580 #endif