Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_Connectivity.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef CONNECTIVITY_HXX
23 #define CONNECTIVITY_HXX
24
25 #include <MEDMEM.hxx>
26
27 #include <vector>
28 #include <set>
29 #include <map>
30 #include "MEDMEM_Utilities.hxx"
31 #include "MEDMEM_Exception.hxx"
32 #include "MEDMEM_define.hxx"
33 #include "MEDMEM_PolyhedronArray.hxx"
34 #include "MEDMEM_CellModel.hxx"
35 #ifndef WNT
36 #include <ext/hash_map>
37 #else
38 #include <hash_map>
39 #endif
40
41 #ifndef WNT
42 using namespace __gnu_cxx;
43 #else
44 using namespace std;
45 using stdext::hash_map;
46 #endif
47
48 namespace MEDMEM {
49 class MEDSKYLINEARRAY;
50  class FAMILY;
51 class GROUP;
52   class CONNECTIVITY;
53   MEDMEM_EXPORT ostream & operator<<(ostream &os, CONNECTIVITY &my);
54
55 /*!
56         This class deals with all type of connectivity .\n
57         it a recursive class.
58 */
59
60 /* ------------------------------------------- */
61 class MEDMEM_EXPORT CONNECTIVITY
62 /* ------------------------------------------- */
63 {
64
65   class myHashFn
66         {
67         public:
68                 size_t operator()(const vector<int>& key) const
69                 {
70                         size_t sum=0;
71                         for (int i=0; i<(int)key.size(); i++)
72                                 sum+=key[i];
73                         return sum;
74                 }
75 #ifdef WNT
76     static const size_t bucket_size = 4;
77     static const size_t min_buckets = 8;
78                 bool operator()(const vector<int>& key1, const vector<int>& key2) const
79                 {
80       return ::size_t()(key1) < ::size_t()(key2);
81                 }
82 #endif          
83         };
84
85   typedef hash_map<vector<int>,int, myHashFn > CONNECTIVITY_HashMap;
86
87   /* ---------------------- */
88   /*    Class Attributs     */
89   /* ---------------------- */
90
91 protected:
92                                          /*! contains MED_CELL MED_FACE or MED_EDGE */
93   MED_EN::medEntityMesh           _entity;
94                                          /*! contains MED_NODAL or MED_DESCEND */
95   MED_EN::medConnectivity         _typeConnectivity;
96                                          /*! count of differents cells types
97                                             used by the mesh */
98   int                             _numberOfTypes;
99                                         /*! array of all med_geometric_type used by MESH. */
100   MED_EN::medGeometryElement*     _geometricTypes;
101
102                                         /*! map indexed by med_geometric_type
103                                             which contains the different
104                                             'CellModel' used by MESH. */
105   CELLMODEL *      _type;
106                                         /*! contains the dimension of the entity */
107   int              _entityDimension;
108
109                                         /*! needed by calculateReverseNodalConnectivity */
110   int              _numberOfNodes;
111
112                                          /*! array of size _numberOfTypes+1 which
113                                          gives for each cell type the first
114                                          cell number in _nodal or _descending
115                                          array (depends on _typeConnectivity)
116                                          To get cells count for one type, we
117                                          must minus _count[i+1] and _count[i]
118                                          ( 0 <= i < _numberOfTypes ).
119                                          Note that _count[_numberOfTypes] returns
120                                          total cells count + 1 */
121   int *            _count;
122
123                                         /*! pointer to an array which stores the nodal connectivity */
124   MEDSKYLINEARRAY* _nodal;
125                                         /*! pointer to an array which stores the nodal connectivity only for polygons */
126   MEDSKYLINEARRAY* _polygonsNodal;
127                                         /*! pointer to an array which stores the nodal connectivity only for polyhedron */
128   POLYHEDRONARRAY* _polyhedronNodal;
129                                         /*! pointer to an array which stores
130                                             the descending connectivity */
131   MEDSKYLINEARRAY* _descending;
132                                         /*!  pointer to an array which stores the descending connectivity only for polygons */
133   MEDSKYLINEARRAY* _polygonsDescending;
134                                         /*!  pointer to an array which stores the descending connectivity only for polyhedron */
135   MEDSKYLINEARRAY* _polyhedronDescending;
136                                         /*! pointer to an array which stores
137                                             the reverse nodal connectivity */
138   MEDSKYLINEARRAY* _reverseNodalConnectivity;
139                                         /*! pointer to an array which stores
140                                             the reverse descending connectivity */
141   MEDSKYLINEARRAY* _reverseDescendingConnectivity;
142                                         /*! if face or edge, list of 2 cells or
143                                             2 faces it belongs to.
144                                             If 2nd number equals 0, we have a
145                                             boundary entity. We could use
146                                             MEDSKYLINEARRAY, but we suppose we have
147                                             always only 2 (or 1) entities. */
148   MEDSKYLINEARRAY* _neighbourhood;
149                                         /*! connectivity of sub cell if
150                                             descendant connectivity is calculated */
151   CONNECTIVITY *   _constituent;
152                                         /*! is descending connectivity computed by 
153                                             calculatePartialDescendingConnectivity() */
154   bool             _isDescendingConnectivityPartial;
155
156   /* -------------------- */
157   /*    Class Methods     */
158   /* -------------------- */
159
160 private:
161                                         /*! private method :\n
162                                             does nothing if already exists, else
163                                             evaluates _nodal from _descending */
164   void  calculateNodalConnectivity();
165                                         /*! private method :\n
166                                             does nothing if already exists, else
167                                             evaluates from _nodal */
168   void calculateReverseNodalConnectivity();
169                                         /*! private method :\n
170                                             does nothing if already exists, else
171                                             evaluates _descending from _nodal */
172   void calculateDescendingConnectivity();
173
174   void calculatePartialDescendingConnectivity();
175   void addToDescendingConnectivity( const set<int>&    nodes,
176                                     multimap<int,int>& descending,
177                                     int                iglobal_cell ,
178                                     const CONNECTIVITY_HashMap & );
179         
180                                         /*! private method :\n
181                                             does nothing if already exists, else
182                                             evaluates from _descending */
183   //  void calculateReverseDescendingConnectivity(CONNECTIVITY *myConnectivity);
184
185   const int*      getReverseNodalConnectivity           ();
186   const int*      getReverseNodalConnectivityIndex      ();
187   const int*      getReverseDescendingConnectivity      ();
188   const int*      getReverseDescendingConnectivityIndex ();
189
190                                         /*! private method :\n
191                                             does nothing if already exists, else
192                                             evaluates _neighbourhood from _descending */
193   void calculateNeighbourhood(CONNECTIVITY &myConnectivity);
194
195   int getIndexOfEndClassicElementInReverseNodal(const int *reverseNodalValue, const int *reverseNodalIndex, int rk)  const;
196
197 public:
198
199   friend class IMED_MESH_RDONLY_DRIVER;
200   friend class MED_MESH_RDONLY_DRIVER21;
201   friend class IMED_MESH_WRONLY_DRIVER;
202   friend class MED_MESH_WRONLY_DRIVER21;
203   friend class MED_MESH_RDONLY_DRIVER22;
204   friend class MED_MESH_WRONLY_DRIVER22;
205
206
207   friend ostream & operator<<(ostream &os, CONNECTIVITY &connectivity);
208
209   // in order to fill CONNECTIVITY of MESH
210   friend class GRID;
211
212   CONNECTIVITY  (MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
213   CONNECTIVITY  (int numberOfTypes, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
214   CONNECTIVITY  (const CONNECTIVITY & m);
215   virtual ~CONNECTIVITY ();
216
217   void setConstituent (CONNECTIVITY * Constituent)
218                                         throw (MEDEXCEPTION);
219
220   void setGeometricTypes (const MED_EN::medGeometryElement * Types,
221                            const MED_EN::medEntityMesh Entity)
222                                         throw (MEDEXCEPTION);
223
224   void setCount (const int * Count, const MED_EN::medEntityMesh Entity)
225                                         throw (MEDEXCEPTION);
226
227   void setNodal (const int * Connectivity,
228                  const MED_EN::medEntityMesh Entity,
229                  const MED_EN::medGeometryElement Type)
230                                         throw (MEDEXCEPTION);
231
232   inline void setNumberOfNodes(int NumberOfNodes);
233         inline int getNumberOfNodes();
234   inline int getEntityDimension() const;
235
236   inline void setEntityDimension(int EntityDimension);
237
238   void setPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
239                                MED_EN::medEntityMesh Entity,
240                                const int* PolygonsConnectivity,
241                                const int* PolygonsConnectivityIndex,
242                                int ConnectivitySize, int NumberOfPolygons);
243
244   void setPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType,
245                                  const int* PolyhedronConnectivity,
246                                  const int* PolyhedronIndex, int ConnectivitySize,
247                                  int NumberOfPolyhedron,
248                                  const int* PolyhedronFacesIndex= (int*) NULL,
249                                  int NumberOfFaces=0);
250
251   inline bool    existConnectivity (MED_EN::medConnectivity connectivityType,
252                                     MED_EN::medEntityMesh   Entity) const;
253   bool   existConnectivityWithPoly (MED_EN::medConnectivity connectivityType,
254                                     MED_EN::medEntityMesh   Entity) const;
255
256   virtual bool existPolygonsConnectivity (MED_EN::medConnectivity connectivityType,
257                                           MED_EN::medEntityMesh   Entity) const;
258
259   virtual bool existPolyhedronConnectivity (MED_EN::medConnectivity connectivityType,
260                                             MED_EN::medEntityMesh   Entity) const;
261
262   virtual void calculateConnectivity (MED_EN::medConnectivity connectivityType,
263                                       MED_EN::medEntityMesh   Entity);
264
265   virtual void calculateFullDescendingConnectivity(MED_EN::medEntityMesh Entity);
266
267   virtual void updateFamily (const vector<FAMILY*>& myFamilies);
268
269   inline MED_EN::medEntityMesh         getEntity () const;
270
271   inline int                    getNumberOfTypes (MED_EN::medEntityMesh Entity) const;
272   int                   getNumberOfTypesWithPoly (MED_EN::medEntityMesh Entity) const;
273   const int * getConnectivityOfAnElementWithPoly (MED_EN::medConnectivity ConnectivityType,
274                                                   MED_EN::medEntityMesh Entity,
275                                                   int Number, int &lgth);
276
277   int getNumberOfPolyType()  const;
278   int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const;
279   int getNumberOfElementOfPolyType(MED_EN::medEntityMesh Entity)  const;
280
281   inline const MED_EN::medGeometryElement * getGeometricTypes (MED_EN::medEntityMesh Entity) const
282                                                              throw (MEDEXCEPTION);
283   MED_EN::medGeometryElement * getGeometricTypesWithPoly      (MED_EN::medEntityMesh Entity) const
284                                                              throw (MEDEXCEPTION);
285   MED_EN::medGeometryElement                getElementType          (MED_EN::medEntityMesh Entity,
286                                                              int Number)           const;
287   MED_EN::medGeometryElement                getElementTypeWithPoly          (MED_EN::medEntityMesh Entity,
288                                                              int Number)           const;
289   inline MED_EN::medGeometryElement                getPolyTypeRelativeTo() const;
290   virtual inline const int *                getGlobalNumberingIndex (MED_EN::medEntityMesh Entity) const
291                                                              throw (MEDEXCEPTION);
292
293   virtual const int *     getConnectivity      (MED_EN::medConnectivity ConnectivityType,
294                                                 MED_EN::medEntityMesh Entity,
295                                                 MED_EN::medGeometryElement Type);
296   virtual int getConnectivityLength        (MED_EN::medConnectivity ConnectivityType,
297                                             MED_EN::medEntityMesh Entity,
298                                             MED_EN::medGeometryElement Type);
299
300   virtual const int *     getConnectivityIndex (MED_EN::medConnectivity ConnectivityType,
301                                                 MED_EN::medEntityMesh Entity);
302
303   virtual const int* getPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
304                                              MED_EN::medEntityMesh Entity);
305   virtual const int* getPolygonsConnectivityIndex(MED_EN::medConnectivity ConnectivityType,
306                                                   MED_EN::medEntityMesh Entity);
307   virtual int getNumberOfPolygons(MED_EN::medEntityMesh Entity=MED_EN::MED_ALL_ENTITIES) const;
308   virtual const int* getPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType) const;
309   virtual const int* getPolyhedronFacesIndex() const;
310   virtual const int* getPolyhedronIndex(MED_EN::medConnectivity ConnectivityType) const;
311   virtual int getNumberOfPolyhedronFaces() const;
312   virtual int getNumberOfPolyhedron() const;
313   int *getNodesOfPolyhedron(int polyhedronId, int& lgthOfTab) const;
314   int **getNodesPerFaceOfPolyhedron(int polyhedronId, int& nbOfFaces, int* & nbOfNodesPerFaces) const;
315   const CELLMODEL &   getType              (MED_EN::medGeometryElement Type) const;
316   const CELLMODEL *   getCellsTypes        (MED_EN::medEntityMesh Entity)    const
317                                             throw (MEDEXCEPTION);
318   string * getCellTypeNames (MED_EN::medEntityMesh Entity) const
319     throw (MEDEXCEPTION);
320
321   int       getNumberOfNodesInType     (MED_EN::medGeometryElement Type) const;
322   int       getNumberOfSubCellInType   (MED_EN::medGeometryElement Type) const;
323   virtual int   getNumberOf                (MED_EN::medEntityMesh Entity,
324                                             MED_EN::medGeometryElement Type) const;
325   virtual const int*      getValue             (MED_EN::medConnectivity TypeConnectivity,
326                                             MED_EN::medGeometryElement Type);
327   virtual const int*      getValueIndex        (MED_EN::medConnectivity TypeConnectivity);
328
329   virtual inline const int* getReverseConnectivity (MED_EN::medConnectivity ConnectivityType,
330                                                 MED_EN::medEntityMesh Entity=MED_EN::MED_CELL)
331                                                 throw (MEDEXCEPTION);
332   virtual inline const int* getReverseConnectivityIndex (MED_EN::medConnectivity ConnectivityType,
333                                                      MED_EN::medEntityMesh Entity=MED_EN::MED_CELL)
334                                                      throw (MEDEXCEPTION);
335
336   const int*      getNeighbourhood() const;
337   void invertConnectivityForAFace(int faceId, const int *nodalConnForFace, bool polygonFace=false);
338   bool deepCompare(const CONNECTIVITY& other) const;
339
340
341 };
342 /*----------------------*/
343 /* Methodes Inline      */
344 /*----------------------*/
345
346 /*! Returns the  medEntityMesh */
347 //--------------------------------------------------//
348 inline MED_EN::medEntityMesh CONNECTIVITY::getEntity() const
349 //--------------------------------------------------//
350 {
351         return _entity;
352 }
353
354 /*!  Returns the number of different %medGeometryElement types
355      existing in the specified entity. \n
356      Note : Not implemented for MED_ALL_ENTITIES. */
357 //-----------------------------------------------------------------------//
358 inline int CONNECTIVITY::getNumberOfTypes(MED_EN::medEntityMesh Entity) const
359 //-----------------------------------------------------------------------//
360 {
361   MESSAGE_MED("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
362   if (_entity==Entity)
363     return _numberOfTypes;
364   else if (_constituent!=NULL)
365     return _constituent->getNumberOfTypes(Entity);
366   else if (_constituent == NULL)
367     {
368       MESSAGE_MED("CONNECTIVITY::getNumberOfTypes : _constituent == NULL");
369       try
370         {
371           (const_cast <CONNECTIVITY *> (this))->calculateDescendingConnectivity();
372         }
373       catch (MEDEXCEPTION &)
374         {
375           return 0 ;
376         }
377
378       SCRUTE_MED(_entityDimension);
379
380       if (_entityDimension != 2 && _entityDimension != 3) return 0;
381
382       try
383         {
384           _constituent->calculateConnectivity(MED_EN::MED_NODAL,Entity);
385         }
386       catch (MEDEXCEPTION &)
387         {
388           return 0 ;
389         }
390
391       return _constituent->getNumberOfTypes(Entity);
392     }
393   else
394         return 0; // because it is the right information (no exception needed)!
395 }
396
397 /*!  Returns an array of all %medGeometryElement types existing in the mesh
398      for the given %medEntityMesh.
399      Note : Not implemented for MED_ALL_ENTITIES.
400      Throws an exception if Entity is unknown */
401 //------------------------------------------------------------------------------------------//
402 inline const MED_EN::medGeometryElement* CONNECTIVITY::getGeometricTypes(MED_EN::medEntityMesh Entity) const
403                                                 throw (MEDEXCEPTION)
404 //------------------------------------------------------------------------------------------//
405 {
406   if (_entity==Entity)
407         return _geometricTypes;
408   else if (_constituent!=NULL)
409         return _constituent->getGeometricTypes(Entity);
410   else
411         throw MEDEXCEPTION("CONNECTIVITY::getGeometricTypes : Entity not defined !");
412 }
413
414 /*!   Returns an array containing the accumulated number of entities sorted by the geometric type.\n
415
416       Exemple :\n
417
418       In case of a CONNECTIVITY containing 3*MED_TRIA3 et 2*MED_QUAD4 : \n
419             int * count = getGlobalNumberingIndex(MED_CELL)\n
420       count[0] is always set to 1\n
421       count[1] is set to 1+3=4\n
422       count[2] is set to 4+2=6 = total number of cells + 1\n
423
424       Note : Not implemented for MED_ALL_ENTITIES. \n
425       Note : The geometric type order is given by the typedef enum medGeometryElement.
426
427 */
428 //----------------------------------------------------------------------------------//
429 inline const int * CONNECTIVITY::getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const
430                                                 throw (MEDEXCEPTION)
431 //----------------------------------------------------------------------------------//
432 {
433   if (_entity==Entity)
434         return _count;
435   else if (_constituent!=NULL)
436         return _constituent->getGlobalNumberingIndex(Entity);
437   else
438         throw MEDEXCEPTION("CONNECTIVITY::getGlobalNumberingIndex : Entity not defined !");
439 }
440
441 /*!  Returns true if a connectivity exists on elements of type "Entity" */
442 //-----------------------------------------------------------------------------//
443 inline bool CONNECTIVITY::existConnectivity( MED_EN::medConnectivity ConnectivityType,
444                                              MED_EN::medEntityMesh Entity) const
445 //-----------------------------------------------------------------------------//
446 {
447   if (_entity==Entity) {
448     if ((ConnectivityType == MED_EN::MED_NODAL) && (_nodal != (MEDSKYLINEARRAY*)NULL))
449       return true;
450     if ((ConnectivityType==MED_EN::MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
451       return true;
452   } else if (_constituent!=NULL)
453     return _constituent->existConnectivity(ConnectivityType,Entity);
454   return false;
455 }
456
457 /*! Returns true if a polygons connectivity exists on elements of type "Entity" */
458 //-----------------------------------------------------------------------------//
459 inline bool CONNECTIVITY::existPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
460                                                     MED_EN::medEntityMesh Entity) const
461 //-----------------------------------------------------------------------------//
462 {
463   if (_entity == Entity)
464     {
465       MESSAGE_MED("existPolygonsConnectivity : _entity == Entity = "<<Entity);
466       if (ConnectivityType == MED_EN::MED_NODAL && _polygonsNodal != (MEDSKYLINEARRAY*) NULL)
467         return true;
468       if (ConnectivityType == MED_EN::MED_DESCENDING && _polygonsDescending != (MEDSKYLINEARRAY*) NULL)
469         return true;
470     }
471   else if (_constituent != (CONNECTIVITY*) NULL)
472     return _constituent->existPolygonsConnectivity(ConnectivityType,Entity);
473   return false;
474 }
475
476 /*! Returns true if a polyhedron connectivity exists on elements of type "Entity" */
477 //-----------------------------------------------------------------------------//
478 inline bool CONNECTIVITY::existPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType,
479                                                       MED_EN::medEntityMesh Entity) const
480 //-----------------------------------------------------------------------------//
481 {
482   if (_entity == Entity)
483     {
484       MESSAGE_MED("existPolyhedronConnectivity : _entity == Entity = "<<Entity);
485       if (ConnectivityType == MED_EN::MED_NODAL && _polyhedronNodal != (POLYHEDRONARRAY*) NULL)
486         return true;
487       if (ConnectivityType == MED_EN::MED_DESCENDING && _polyhedronDescending != (MEDSKYLINEARRAY*) NULL)
488         return true;
489     }
490   else if (_constituent != (CONNECTIVITY*) NULL)
491     return _constituent->existPolyhedronConnectivity(ConnectivityType,Entity);
492   return false;
493 }
494
495 /*!
496 Returns an array containing CELLMODEL foreach element type present
497 in connectivity for given medEntityMesh (similar as getGeometricTypes).\n
498 Throw an execption if the given entity is not defined or if the array is not defined.
499 */
500 //-----------------------------------------------------------------------------//
501 inline const CELLMODEL * CONNECTIVITY::getCellsTypes(MED_EN::medEntityMesh Entity) const
502                                                 throw (MEDEXCEPTION)
503 //-----------------------------------------------------------------------------//
504 {
505   if (Entity == _entity)
506     if (_type!=NULL)
507       return _type;
508     else
509       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) :"
510                          " CELLMODEL array is not defined !");
511   else
512     if (_constituent != NULL)
513       return _constituent->getCellsTypes(Entity);
514     else
515       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
516 }
517 /*!
518 Returns an array (it should deleted after use) containing the whole list of
519 CELLMODEL Name foreach element type present in connectivity for given
520 medEntityMesh (similar as getGeometricTypes).\n
521 Throw an execption if the given entity is not defined or if the array is not
522 defined.
523
524 */
525 //-----------------------------------------------------------------------------//
526 inline string * CONNECTIVITY::getCellTypeNames(MED_EN::medEntityMesh Entity) const
527                                                 throw (MEDEXCEPTION)
528 //-----------------------------------------------------------------------------//
529 {
530   if (Entity == _entity)
531     if (_type!=NULL)
532       {
533         string * stringArray = new string[_numberOfTypes];
534
535         for (int i=0;i<_numberOfTypes;i++)
536           stringArray[i] = _type[i].getName();
537
538         return stringArray;
539       }
540     else
541       throw MEDEXCEPTION("CONNECTIVITY::getCellTypeNames(medEntityMesh) :"
542                          " CELLMODEL array is not defined !");
543   else
544     if (_constituent != NULL)
545       return _constituent->getCellTypeNames(Entity);
546     else
547       throw MEDEXCEPTION("CONNECTIVITY::getCellTypeNames(medEntityMesh) : Not found Entity !");
548 }
549
550
551
552
553
554
555 /*! A DOCUMENTER */
556 //------------------------------------------------------------------------------------------//
557 inline const int* CONNECTIVITY::getReverseConnectivity( MED_EN::medConnectivity ConnectivityType,
558                                                             MED_EN::medEntityMesh Entity)
559                                                             throw (MEDEXCEPTION)
560 //------------------------------------------------------------------------------------------//
561 {
562   if(_entity==Entity)
563     if (ConnectivityType==MED_EN::MED_NODAL)
564       return getReverseNodalConnectivity();
565     else if (ConnectivityType==MED_EN::MED_DESCENDING)
566       return getReverseDescendingConnectivity();
567     else
568       throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
569
570   // other entity :
571   if (NULL==_constituent)
572     calculateDescendingConnectivity();
573   return _constituent->getReverseConnectivity(ConnectivityType,Entity);
574 }
575
576 /*! A DOCUMENTER */
577 //-----------------------------------------------------------------------------------------------//
578 inline const int* CONNECTIVITY::getReverseConnectivityIndex(MED_EN::medConnectivity ConnectivityType,
579                                                                 MED_EN::medEntityMesh Entity)
580                                                                 throw (MEDEXCEPTION)
581 //-----------------------------------------------------------------------------------------------//
582 {
583   if(_entity==Entity)
584     if (ConnectivityType==MED_EN::MED_NODAL)
585       return getReverseNodalConnectivityIndex();
586     else if (ConnectivityType==MED_EN::MED_DESCENDING)
587       return getReverseDescendingConnectivityIndex();
588     else
589       throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
590
591   // other entity :
592   if (NULL==_constituent)
593     calculateDescendingConnectivity();
594   return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity);
595 }
596
597
598 inline void CONNECTIVITY::setNumberOfNodes(int NumberOfNodes)
599 {
600     _numberOfNodes=NumberOfNodes;
601 }
602
603 inline int CONNECTIVITY::getNumberOfNodes()
604 {
605         return _numberOfNodes;
606 }
607
608 inline void CONNECTIVITY::setEntityDimension(int EntityDimension)
609 {
610     _entityDimension=EntityDimension;
611 }
612
613 int CONNECTIVITY::getEntityDimension() const
614 {
615   return _entityDimension;
616 }
617
618 MED_EN::medGeometryElement CONNECTIVITY::getPolyTypeRelativeTo() const
619 {
620   if(_entity==MED_EN::MED_CELL && _entityDimension==3)
621     return MED_EN::MED_POLYHEDRA;
622   else if((_entity==MED_EN::MED_CELL && _entityDimension==2) || (_entity==MED_EN::MED_FACE && _entityDimension==2))
623     return MED_EN::MED_POLYGON;
624   else
625     throw MEDEXCEPTION("getPolyTypeRelativeTo : ");
626 }
627
628
629
630
631 }//End namespace MEDMEM
632
633 // namespace __gnu_cxx {
634 // template <> struct hash< std::vector<int> > {
635 //      size_t operator()(const std::vector<int>& input) {
636 //                      size_t sum=0;
637 //                      for (int i=0; i<input.size();i++)
638 //                              sum+=input[i];
639 //                      return sum;
640 //     }
641 // };
642 //}
643
644 #endif /* CONNECTIVITY_HXX */