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