]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Mesh.hxx
Salome HOME
NRI : Merge from V1_2.
[modules/med.git] / src / MEDMEM / MEDMEM_Mesh.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_Mesh.hxx
25 //  Module : MED
26
27 #ifndef MESH_HXX
28 #define MESH_HXX
29
30 #include <string>
31 #include <vector>
32
33 #include "utilities.h"
34 #include "MEDMEM_STRING.hxx"
35 #include "MEDMEM_Exception.hxx"
36 #include "MEDMEM_define.hxx"
37
38 //#include "MEDMEM_Support.hxx"
39 #include "MEDMEM_Coordinate.hxx"
40 #include "MEDMEM_Connectivity.hxx"
41
42 // Add your own driver header (step 2)
43 #include "MEDMEM_MedMeshDriver.hxx"
44 #include "MEDMEM_MedMedDriver.hxx"
45 #include "MEDMEM_GibiMeshDriver.hxx"
46
47 class CELLMODEL;
48 class FAMILY;
49 class GROUP;
50 class SUPPORT;
51
52 template <class T> class FIELD;
53
54 //class GENDRIVER ;
55 //class MED_MESH_RDONLY_DRIVER ;
56 //class MED_MESH_WRONLY_DRIVER ;
57
58 using namespace MED_EN;
59
60 /*! This class contains all the informations related with a MESH :
61   - COORDINATES
62   - CONNECTIVITIES
63   - FAMILIES OF NODES
64   - FAMILIES OF CELLS
65   - FAMILIES OF FACES
66   - FAMILIES OF EDGES
67
68   NOTE: A Family is only on one type of entity (MED_CELL, MED_FACE, MED_EDGE, MED_NODE).
69   You can't have a family on MED_CELL and MED_FACE
70
71 */
72
73 class MESH
74 {
75
76
77 public :
78
79   // ------- Drivers Management Part
80 protected:
81
82   //-----------------------//
83   class INSTANCE
84   //-----------------------//
85   {
86   public:
87     virtual GENDRIVER * run(const string & fileName, MESH * ptrMesh) const = 0 ;
88   } ;
89
90   //-------------------------------------------------------//
91   template <class T> class INSTANCE_DE : public INSTANCE
92   //-------------------------------------------------------//
93   {
94   public :
95     GENDRIVER * run(const string & fileName, MESH * ptrMesh) const
96     { return new T(fileName,ptrMesh) ; }
97   } ;
98
99   // Add a similar line for your personnal driver (step 3)
100   static INSTANCE_DE<MED_MESH_RDWR_DRIVER>  inst_med ;
101   static INSTANCE_DE<GIBI_MESH_RDWR_DRIVER> inst_gibi ;
102   //static INSTANCE_DE<VTK_DRIVER>   inst_vtk   ;
103   static const INSTANCE * const instances[] ;
104
105   // ------ End of Drivers Management Part
106
107
108   //-----------------------//
109   //   Attributes
110   //-----------------------//
111
112 protected :
113
114   string        _name; // A POSITIONNER EN FCT DES IOS ?
115
116   COORDINATE *   _coordinate;
117   CONNECTIVITY * _connectivity;
118
119   int           _spaceDimension;
120   int           _meshDimension ;
121   int           _numberOfNodes    ;
122
123   int             _numberOfNodesFamilies;  //INUTILE ? -> _familyNode.size()
124   vector<FAMILY*> _familyNode ;  // array of size _numberOfNodesFamilies;
125   int             _numberOfCellsFamilies;
126   vector<FAMILY*> _familyCell ;  // array of size _numberOfCellsFamilies;
127   int             _numberOfFacesFamilies;
128   vector<FAMILY*> _familyFace ;  // array of size _numberOfFacesFamilies;
129   int             _numberOfEdgesFamilies;
130   vector<FAMILY*> _familyEdge ;  // array of size _numberOfEdgesFamilies;
131
132   int            _numberOfNodesGroups; //INUTILE ?
133   vector<GROUP*> _groupNode;    // array of size _numberOfNodesGroups;
134   int            _numberOfCellsGroups; //INUTILE ?
135   vector<GROUP*> _groupCell;    // array of size _numberOfCellsGroups;
136   int            _numberOfFacesGroups; //INUTILE ?
137   vector<GROUP*> _groupFace;    // array of size _numberOfFacesGroups;
138   int            _numberOfEdgesGroups; //INUTILE ?
139   vector<GROUP*> _groupEdge;    // array of size _numberOfEdgesGroups;
140   // list of all Group
141
142   vector<GENDRIVER *> _drivers; // Storage of the drivers currently in use
143
144   bool           _isAGrid;      // am I a GRID or not
145
146   //-----------------------//
147   //   Methods
148   //-----------------------//
149
150   inline void checkGridFillCoords() const;
151   inline void checkGridFillConnectivity() const;
152   // if this->_isAGrid, assure that _coordinate and _connectivity are filled
153
154 public :
155
156   // Add your personnal driver line (step 2)
157   friend class MED_MESH_RDONLY_DRIVER;
158   friend class MED_MESH_WRONLY_DRIVER;
159   friend class MED_MED_DRIVER;
160
161   friend class MED_MED_RDONLY_DRIVER;
162   friend class MED_MED_WRONLY_DRIVER;
163   friend class MED_MED_RDWR_DRIVER;
164
165   friend class GIBI_MESH_RDONLY_DRIVER;
166   friend class GIBI_MESH_WRONLY_DRIVER;
167   friend class GIBI_MESH_RDWR_DRIVER;
168
169   void init();
170   MESH();
171   MESH(MESH &m);
172   MESH & operator=(const MESH &m);
173   MESH( driverTypes driverType, const string & fileName="",
174         const string & meshName="");
175   ~MESH();
176   friend ostream & operator<<(ostream &os, MESH &my) ;
177
178   int  addDriver(driverTypes driverType,
179                  const string & fileName  ="Default File Name.med",
180                  const string & driverName="Default Mesh Name");
181   int  addDriver(GENDRIVER & driver);
182   void rmDriver(int index=0);
183
184   void read(int index=0);
185   inline void read(const MED_MED_DRIVER & genDriver);
186   inline void write(int index=0, const string & driverName = "");
187   inline void write(const MED_MED_DRIVER & genDriver);
188
189   //  void calculateReverseConnectivity();
190   //  void createFaces();       //Faces creation => full constituent informations
191   //  void buildConstituent() ; // calculate descendent connectivity + face-cell connectivity
192
193
194   inline void         setName(string name);
195
196   inline string       getName() const;
197   inline int          getSpaceDimension() const ;
198   inline int          getMeshDimension() const ;
199   inline bool         getIsAGrid();
200
201   inline int          getNumberOfNodes() const ;
202   inline const COORDINATE * getCoordinateptr() const ;
203   inline string       getCoordinatesSystem() const ;
204   inline const double *     getCoordinates(medModeSwitch Mode) const ;
205   inline const double       getCoordinate(int Number,int Axis) const ;
206   inline const string *     getCoordinatesNames() const ;
207   inline const string *     getCoordinatesUnits() const ;
208   //  inline int *        getNodesNumbers();
209
210   inline int          getNumberOfTypes(medEntityMesh Entity) const ;
211   inline const medGeometryElement *  getTypes(medEntityMesh Entity) const ;
212   inline const CELLMODEL *  getCellsTypes(medEntityMesh Entity) const ;
213   inline const int *        getGlobalNumberingIndex(medEntityMesh Entity) const ;
214   inline int          getNumberOfElements(medEntityMesh Entity,medGeometryElement Type) const ;
215   inline bool         existConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity) const ;
216   inline medGeometryElement getElementType(medEntityMesh Entity,int Number) const ;
217   inline void         calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity) ;
218   inline const int *        getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity, medGeometryElement Type) const ;
219   inline const int *        getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity) const ;
220   int                 getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity) const ;
221   inline const int *        getReverseConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity=MED_CELL) const ;
222   inline const int *        getReverseConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity=MED_CELL) const ;
223
224   inline int          getNumberOfFamilies(medEntityMesh Entity) const ;
225   inline const vector<FAMILY*> getFamilies(medEntityMesh Entity) const ;
226   inline const FAMILY*      getFamily(medEntityMesh Entity,int i) const ;
227   inline int          getNumberOfGroups(medEntityMesh Entity) const ;
228   inline const vector<GROUP*> getGroups(medEntityMesh Entity) const ;
229   inline const GROUP*      getGroup(medEntityMesh Entity,int i) const ;
230   inline const CONNECTIVITY* getConnectivityptr() const ;
231   SUPPORT * getBoundaryElements(medEntityMesh Entity) throw (MEDEXCEPTION) ;
232   //SUPPORT * getBoundaryElements(medEntityMesh Entity) const throw (MEDEXCEPTION) ; // problème avec le maillage dans le support : le pointeur n'est pas const, mais sa valeur oui. A voir !!! PG
233
234   SUPPORT * getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION) ;
235
236   //  Node DonneBarycentre(const Cell &m) const;
237   FIELD<double>* getVolume(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 3D elements
238   FIELD<double>* getArea(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 2D elements
239   FIELD<double>* getLength(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 1D elements
240   FIELD<double>* getNormal(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 2D elements
241   FIELD<double>* getBarycenter(const SUPPORT * Support) const throw (MEDEXCEPTION) ;
242   //  FIELD<int>* getNeighbourhood(SUPPORT * Support) const throw (MEDEXCEPTION) ; // Il faut preciser !
243 };
244
245 // ---------------------------------------
246 //              Methodes Inline
247 // ---------------------------------------
248
249 inline const CONNECTIVITY* MESH::getConnectivityptr() const
250 {
251   return _connectivity;
252 }
253
254 // inline void MESH::read(int index/*=0*/)
255 // {
256 //   const char * LOC = "MESH::read(int index=0) : ";
257 //   BEGIN_OF(LOC);
258
259 //   if (_drivers[index]) {
260 //     _drivers[index]->open();
261 //     _drivers[index]->read();
262 //     _drivers[index]->close();
263 //   }
264 //   else
265 //     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
266 //                                      << "The index given is invalid, index must be between  0 and |"
267 //                                      << _drivers.size()
268 //                                      )
269 //                           );
270 //   END_OF(LOC);
271 // }
272
273 /*! Write all the content of the MESH using driver referenced by the handler <index>*/
274 inline void MESH::write(int index/*=0*/, const string & driverName/* = ""*/)
275 {
276   const char * LOC = "MESH::write(int index=0, const string & driverName = \"\") : ";
277   BEGIN_OF(LOC);
278
279   if ( _drivers[index] ) {
280     _drivers[index]->open();
281     if (driverName != "") _drivers[index]->setMeshName(driverName);
282     _drivers[index]->write();
283     _drivers[index]->close();
284   }
285   else
286     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
287                                      << "The index given is invalid, index must be between  0 and |"
288                                      << _drivers.size()
289                                      )
290                           );
291   END_OF(LOC);
292 }
293
294 // This method is MED specific : don't use it
295 // must be private.
296 inline void MESH::write(const MED_MED_DRIVER & genDriver)
297 {
298   const char * LOC = "MESH::write(const MED_MED_DRIVER & genDriver): ";
299   BEGIN_OF(LOC);
300
301   for (int index=0; index < _drivers.size(); index++ )
302     if ( *_drivers[index] == genDriver ) {
303       _drivers[index]->open();
304       _drivers[index]->write();
305       _drivers[index]->close();
306       // ? FINALEMENT PAS BESOIN DE L'EXCEPTION ?
307     }
308
309   END_OF(LOC);
310
311 }
312
313 // This method is MED specific : don't use it
314 // must be private.
315 inline void MESH::read(const MED_MED_DRIVER & genDriver)
316 {
317   const char * LOC = "MESH::read(const MED_MED_DRIVER & genDriver): ";
318   BEGIN_OF(LOC);
319
320   for (int index=0; index < _drivers.size(); index++ )
321     if ( *_drivers[index] == genDriver ) {
322       _drivers[index]->open();
323       _drivers[index]->read();
324       _drivers[index]->close();
325       // ? FINALEMENT PAS BESOIN DE L'EXCEPTION ?
326     }
327
328   END_OF(LOC);
329
330 }
331
332 // This method is MED specific : don't use it 
333 // must be private. 
334 inline void MESH::read(const MED_MED_DRIVER & genDriver) 
335
336   const char * LOC = "MESH::read(const MED_MED_DRIVER & genDriver): ";
337   BEGIN_OF(LOC);
338
339   for (int index=0; index < _drivers.size(); index++ )
340     if ( *_drivers[index] == genDriver ) { 
341       _drivers[index]->open();   
342       _drivers[index]->read(); 
343       _drivers[index]->close();
344       // ? FINALEMENT PAS BESOIN DE L'EXCEPTION ?
345     }
346   
347   END_OF(LOC);
348   
349
350
351 /*! Set the MESH name */
352 inline void MESH::setName(string name)
353 {
354   _name=name ; //NOM interne à la classe
355 }
356
357 /*! Get the MESH name */
358 inline string MESH::getName() const
359 {
360   return _name ;
361 }
362
363 /*! Get the dimension of the space */
364 inline int MESH::getSpaceDimension() const
365 {
366   return _spaceDimension;
367 }
368
369 /*! Get the dimension of the MESH */
370 inline int MESH::getMeshDimension() const
371 {
372   return _meshDimension;
373 }
374
375 /*! Get the number of nodes used in the MESH */
376 inline int MESH::getNumberOfNodes() const
377 {
378   return _numberOfNodes;
379 }
380
381 /*! Get the COORDINATES object. Use it only if you need COORDINATES informations not provided by the MESH class.*/
382 inline const COORDINATE * MESH::getCoordinateptr() const
383 {
384   checkGridFillCoords();
385   return _coordinate;
386 }
387
388 /*! Get the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
389 inline string MESH::getCoordinatesSystem() const
390 {
391   return _coordinate->getCoordinatesSystem();
392 }
393
394 /*! Get the whole coordinates array in a given interlacing mode. The interlacing mode are :
395   - MED_NO_INTERLACE   :  X1 X2 Y1 Y2 Z1 Z2
396   - MED_FULL_INTERLACE :  X1 Y1 Z1 X2 Y2 Z2
397  */
398 inline const double * MESH::getCoordinates(medModeSwitch Mode) const
399 {
400   checkGridFillCoords();
401   return _coordinate->getCoordinates(Mode);
402 }
403
404 /*! Get the coordinate n° number on axis n°axis*/
405 inline const double MESH::getCoordinate(int number, int axis) const
406 {
407   checkGridFillCoords();
408   return _coordinate->getCoordinate(number,axis);
409 }
410
411 /*! Get the coordinate names array ("x       ","y       ","z       ")
412   of size n*MED_TAILLE_PNOM
413 */
414 inline const string * MESH::getCoordinatesNames() const
415 {
416   return _coordinate->getCoordinatesNames();
417 }
418
419 /*! Get the coordinate unit names array ("cm       ","cm       ","cm       ")
420   of size n*MED_TAILLE_PNOM
421 */
422 inline const string * MESH::getCoordinatesUnits() const
423 {
424   return _coordinate->getCoordinatesUnits();
425 }
426 //  int * MESH::getNodesNumbers() const
427 //  {
428 //    return nodesNumbers;
429 //  }
430
431 /*! Get the number of different geometric types for a given entity type.
432
433     For exemple getNumberOfTypes(MED_CELL) would return 3 is the MESH
434     have some MED_TETRA4, MED_PYRA5 and MED_HEXA6 in it.
435
436     medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_NODE, MED_ALL_ENTITIES
437
438     If entity is not defined, return 0.
439
440     If there is no connectivity, return an exception.
441 */
442 inline int MESH::getNumberOfTypes(medEntityMesh entity) const
443 {
444   MESSAGE("MESH::getNumberOfTypes(medEntityMesh entity) : "<<entity);
445   if (entity == MED_NODE)
446     return 1 ;
447   checkGridFillConnectivity();
448   if (_connectivity != NULL)
449     return _connectivity->getNumberOfTypes(entity) ;
450   throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
451 }
452
453 /*!
454   Get the list of geometric types used by a given entity.
455   medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_ALL_ENTITIES
456
457   REM : Don't use MED_NODE
458
459   If entity is not defined, return an exception.
460 */
461 inline const medGeometryElement * MESH::getTypes(medEntityMesh entity) const
462 {
463   if (entity == MED_NODE)
464     throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : No medGeometryElement with MED_NODE entity !"));
465   // return un tableau de taille 1 contenant MED_NONE, comme les supports pour etre coherent avec getNumberOfTypes ???? PG
466
467   checkGridFillConnectivity();
468   if (_connectivity != NULL)
469     return _connectivity->getGeometricTypes(entity) ;
470   throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : Connectivity not defined !"));
471 }
472
473 /*!
474   Get the whole list of CELLMODEL used by cells of given type (medEntityMesh).
475
476   REMARK : Don't use MED_NODE as medEntityMesh
477 */
478 inline const CELLMODEL * MESH::getCellsTypes(medEntityMesh Entity) const
479 {
480   checkGridFillConnectivity();
481   if (_connectivity != NULL)
482     return _connectivity->getCellsTypes(Entity) ;
483   throw MEDEXCEPTION(LOCALIZED("MESH::getCellsTypes( medEntityMesh ) : Connectivity not defined !"));
484 }
485
486 /*! Return an array of size NumbreOfTypes+1 which contains, for each
487     geometric type of the given entity, the first global element number
488     of this type.
489
490     For exemple, if we have a mesh with 5 triangles and 4 quadrangle :
491     - size of GlobalNumberingIndex is 3
492     - GlobalNumberingIndex[0]=1 (the first type)
493     - GlobalNumberingIndex[1]=6 (the second type)
494     - GlobalNumberingIndex[2]=10
495 */
496 inline const int * MESH::getGlobalNumberingIndex(medEntityMesh entity) const
497 {
498   checkGridFillConnectivity();
499   if (_connectivity != NULL)
500     return _connectivity->getGlobalNumberingIndex(entity);
501   throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
502 }
503 /*!
504   Return the number of element of given geometric type of given entity. Return 0 if query is not defined.
505
506   Example :
507   - getNumberOfElements(MED_NODE,MED_NONE) : number of node
508   - getNumberOfElements(MED_NODE,MED_TRIA3) : return 0 (not defined)
509   - getNumberOfElements(MED_FACE,MED_TRIA3) : return number of triangles
510   elements defined in face entity (0 if not defined)
511   - getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) : return total number
512   of elements defined in cell entity
513  */
514 inline int MESH::getNumberOfElements(medEntityMesh entity, medGeometryElement Type) const
515 {
516   const char * LOC = "MESH::getNumberOfElements(medEntityMesh,medGeometryElement) : " ;
517   if (entity==MED_NODE)
518     if ((Type==MED_NONE)|(Type==MED_ALL_ELEMENTS))
519       return _numberOfNodes ;
520     else
521       return 0 ;
522   //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"wrong medGeometryElement with MED_NODE"));
523   else
524     {
525       checkGridFillConnectivity();
526       if (_connectivity != (CONNECTIVITY*)NULL)
527         return _connectivity->getNumberOf(entity,Type) ;
528       else
529         return 0 ;
530       //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"connectivity not defined !"));
531     }
532 }
533 /*!
534   Return true if the wanted connectivity exist, else return false
535   (to use before a getSomething method).
536  */
537 inline bool MESH::existConnectivity(medConnectivity connectivityType, medEntityMesh entity) const
538 {
539   checkGridFillConnectivity();
540   if (_connectivity==(CONNECTIVITY*)NULL)
541     throw MEDEXCEPTION("MESH::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !");
542   return _connectivity->existConnectivity(connectivityType,entity) ;
543 }
544 /*!
545   Return the geometric type of global element Number of entity Entity.
546
547   Throw an exception if Entity is not defined or Number are wrong (too big).
548  */
549 inline medGeometryElement MESH::getElementType(medEntityMesh Entity,int Number) const
550 {
551   checkGridFillConnectivity();
552   if (_connectivity==(CONNECTIVITY*)NULL)
553     throw MEDEXCEPTION("MESH::getElementType(medEntityMesh,int) : no connectivity defined !");
554   return _connectivity->getElementType(Entity,Number) ;
555 }
556 /*!
557   Calculate the ask connectivity. Return an exception if this could not be
558   done. Do nothing if connectivity already exist.
559  */
560
561 inline void MESH::calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity)
562 {
563   checkGridFillConnectivity();
564   if (Mode==MED_FULL_INTERLACE)
565     _connectivity->calculateConnectivity(ConnectivityType,entity) ;
566   else
567     throw MEDEXCEPTION(LOCALIZED("MESH::calculateConnectivity : only for MED_FULL_INTERLACE mode"));
568 }
569 /*!
570   Return the required connectivity in the right mode for the given
571   geometric type of the given entity.
572
573   To get connectivity for all geometric type, use Mode=MED_FULL_INTERLACE
574   and Type=MED_ALL_ELEMENTS.
575   You must also get the corresponding index array.
576  */
577 inline const int * MESH::getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity, medGeometryElement Type) const
578 {
579   checkGridFillConnectivity();
580   if (Mode==MED_FULL_INTERLACE)
581     return _connectivity->getConnectivity(ConnectivityType,entity,Type) ;
582   throw MEDEXCEPTION(LOCALIZED("MESH::getConnectivity : only for MED_FULL_INTERLACE mode"));
583 }
584 /*!
585   Return the required index array for a connectivity received in
586   MED_FULL_ENTERLACE mode and MED_ALL_ELEMENTS type.
587
588   This array allow to find connectivity of each elements.
589
590   Example : Connectivity of i^{th} elements (1<=i<=NumberOfElement) begin
591   at index ConnectivityIndex[i-1] and end at index ConnectivityIndex[i]-1
592   in Connectivity array (Connectivity[ConnectivityIndex[i-1]-1] is the
593   first value)
594  */
595 inline const int * MESH::getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh entity) const
596 {
597   checkGridFillConnectivity();
598   return _connectivity->getConnectivityIndex(ConnectivityType, entity) ;
599 }
600 /*!
601   Return the reverse connectivity required by ConnectivityType :
602   - If ConnectivityType=MED_NODAL : return connectivity node-cell
603   - If ConnectivityType=MED_DESCENDING : return connectivity face-cell
604
605   You must get ReverseConnectivityIndex array to use it.
606  */
607 inline const int * MESH::getReverseConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const
608 {
609   checkGridFillConnectivity();
610   if (NULL==_connectivity)
611     throw MEDEXCEPTION("MESH::getReverseConnectivity : no connectivity defined in MESH !");
612
613   return _connectivity->getReverseConnectivity(ConnectivityType,Entity) ;
614 }
615 /*!
616   Return the index array required by ConnectivityType.
617
618   This array allow to find reverse connectivity of each elements.
619
620   Example : Reverse connectivity of i^{th} elements (1<=i<=NumberOfElement)
621   begin at index ReverseConnectivityIndex[i-1] and end at index
622   ReverseConnectivityIndex[i]-1
623   in ReverseConnectivity array (
624   ReverseConnectivity[ReverseConnectivityIndex[i-1]-1]
625   is the first value)
626  */
627 inline const int * MESH::getReverseConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const
628 {
629   checkGridFillConnectivity();
630   if (NULL==_connectivity)
631     throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : no connectivity defined in MESH !");
632
633   return _connectivity->getReverseConnectivityIndex(ConnectivityType,Entity) ;
634 }
635
636
637 inline int MESH::getNumberOfFamilies (medEntityMesh entity) const
638 {
639   switch (entity) {
640   case MED_NODE :
641     return _numberOfNodesFamilies ;
642   case MED_CELL :
643     return _numberOfCellsFamilies ;
644   case MED_FACE :
645     return _numberOfFacesFamilies ;
646   case MED_EDGE :
647     return _numberOfEdgesFamilies ;
648   default :
649     throw MEDEXCEPTION("MESH::getNumberOfFamilies : Unknown entity");
650   }
651 }
652 inline int MESH::getNumberOfGroups (medEntityMesh entity) const
653 {
654   switch (entity) {
655   case MED_NODE :
656     return _numberOfNodesGroups ;
657   case MED_CELL :
658     return _numberOfCellsGroups ;
659   case MED_FACE :
660     return _numberOfFacesGroups ;
661   case MED_EDGE :
662     return _numberOfEdgesGroups ;
663   default :
664     throw MEDEXCEPTION("MESH::getNumberOfGroups : Unknown entity");
665   }
666 }
667 const vector<FAMILY*> MESH::getFamilies(medEntityMesh entity) const
668 {
669   switch (entity) {
670   case MED_NODE :
671     return _familyNode ;
672   case MED_CELL :
673     return _familyCell ;
674   case MED_FACE :
675     return _familyFace ;
676   case MED_EDGE :
677     return _familyEdge ;
678   default :
679     throw MEDEXCEPTION("MESH::getFamilies : Unknown entity");
680   }
681 }
682
683 const vector<GROUP*> MESH::getGroups(medEntityMesh entity) const
684 {
685   switch (entity) {
686   case MED_NODE :
687     return _groupNode ;
688   case MED_CELL :
689     return _groupCell ;
690   case MED_FACE :
691     return _groupFace ;
692   case MED_EDGE :
693     return _groupEdge ;
694   default :
695     throw MEDEXCEPTION("MESH::getGroups : Unknown entity");
696   }
697 }
698
699 const FAMILY* MESH::getFamily(medEntityMesh entity, int i) const
700 {
701   if (i<=0)
702     throw MEDEXCEPTION("MESH::getFamily(i) : argument i must be > 0");
703   int NumberOfFamilies = 0 ;
704   vector<FAMILY*> Family ;
705   switch (entity) {
706   case MED_NODE : {
707     NumberOfFamilies = _numberOfNodesFamilies ;
708     Family = _familyNode ;
709     break ;
710   }
711   case MED_CELL : {
712     NumberOfFamilies = _numberOfCellsFamilies ;
713     Family = _familyCell ;
714     break ;
715   }
716   case MED_FACE : {
717     NumberOfFamilies = _numberOfFacesFamilies ;
718     Family = _familyFace ;
719     break ;
720   }
721   case MED_EDGE : {
722     NumberOfFamilies = _numberOfEdgesFamilies ;
723     Family = _familyEdge ;
724     break ;
725   }
726   default :
727     throw MEDEXCEPTION("MESH::getFamilies : Unknown entity");
728   }
729   if (i>NumberOfFamilies)
730     throw MEDEXCEPTION("MESH::getFamily(entity,i) : argument i must be <= _numberOfFamilies");
731   return Family[i-1];
732 }
733
734 const GROUP* MESH::getGroup(medEntityMesh entity, int i) const
735 {
736   const char * LOC = "MESH::getGroup(medEntityMesh entity, int i) : " ;
737   if (i<=0)
738     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"argument i must be > 0"));
739   int NumberOfGroups = 0 ;
740   vector<GROUP*> Group ;
741   switch (entity) {
742   case MED_NODE : {
743     NumberOfGroups = _numberOfNodesGroups ;
744     Group = _groupNode ;
745     break ;
746   }
747   case MED_CELL : {
748     NumberOfGroups = _numberOfCellsGroups ;
749     Group = _groupCell ;
750     break ;
751   }
752   case MED_FACE : {
753     NumberOfGroups = _numberOfFacesGroups ;
754     Group = _groupFace ;
755     break ;
756   }
757   case MED_EDGE : {
758     NumberOfGroups = _numberOfEdgesGroups ;
759     Group = _groupEdge ;
760     break ;
761   }
762   default :
763     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Unknown entity"));
764   }
765   if (i>NumberOfGroups)
766     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"argument i="<<i<<" must be <= _numberOfGroups="<<NumberOfGroups));
767   return Group[i-1];
768 }
769
770
771 //    int * get_() {
772 //      return  ;
773 //    }
774
775 //inline void MESH::write(const string & driverName)  {
776 //  write(0,driverName);
777 //}
778
779 inline bool MESH::getIsAGrid()
780 {
781   return _isAGrid;
782 }
783
784 #endif /* MESH_HXX */