1 #ifndef CONNECTIVITY_HXX
2 #define CONNECTIVITY_HXX
7 #include "MEDMEM_Exception.hxx"
8 #include "MEDMEM_define.hxx"
9 #include "MEDMEM_PolyhedronArray.hxx"
12 class MEDSKYLINEARRAY;
18 This class deals with all type of connectivity .\n
22 /* ------------------------------------------- */
24 /* ------------------------------------------- */
26 /* ---------------------- */
28 /* ---------------------- */
31 /*! contains MED_CELL MED_FACE or MED_EDGE */
32 MED_EN::medEntityMesh _entity;
33 /*! contains MED_NODAL or MED_DESCEND */
34 MED_EN::medConnectivity _typeConnectivity;
35 /*! count of differents cells types
38 /*! array of all med_geometric_type used by MESH. */
39 MED_EN::medGeometryElement* _geometricTypes;
41 /*! map indexed by med_geometric_type
42 which contains the different
43 'CellModel' used by MESH. */
45 /*! contains the dimension of the entity */
48 /*! needed by calculateReverseNodalConnectivity */
51 /*! array of size _numberOfTypes+1 which
52 gives for each cell type the first
53 cell number in _nodal or _descending
54 array (depends on _typeConnectivity)
55 To get cells count for one type, we
56 must minus _count[i+1] and _count[i]
57 ( 0 <= i < _numberOfTypes ).
58 Note that _count[_numberOfTypes] returns
59 total cells count + 1 */
62 /*! pointer to an array which stores the nodal connectivity */
63 MEDSKYLINEARRAY* _nodal;
64 /*! pointer to an array which stores the nodal connectivity only for polygons */
65 MEDSKYLINEARRAY* _polygonsNodal;
66 /*! pointer to an array which stores the nodal connectivity only for polyhedron */
67 POLYHEDRONARRAY* _polyhedronNodal;
68 /*! pointer to an array which stores
69 the descending connectivity */
70 MEDSKYLINEARRAY* _descending;
71 /*! pointer to an array which stores the descending connectivity only for polygons */
72 MEDSKYLINEARRAY* _polygonsDescending;
73 /*! pointer to an array which stores the descending connectivity only for polyhedron */
74 MEDSKYLINEARRAY* _polyhedronDescending;
75 /*! pointer to an array which stores
76 the reverse nodal connectivity */
77 MEDSKYLINEARRAY* _reverseNodalConnectivity;
78 /*! pointer to an array which stores
79 the reverse descending connectivity */
80 MEDSKYLINEARRAY* _reverseDescendingConnectivity;
81 /*! if face or edge, list of 2 cells or
82 2 faces it belongs to.
83 If 2nd number equals 0, we have a
84 boundary entity. We could use
85 MEDSKYLINEARRAY, but we suppose we have
86 always only 2 (or 1) entities. */
87 MEDSKYLINEARRAY* _neighbourhood;
88 /*! connectivity of sub cell if
89 descendant connectivity is calculated */
90 CONNECTIVITY * _constituent;
92 /* -------------------- */
94 /* -------------------- */
97 /*! private method :\n
98 does nothing if already exists, else
99 evaluates _nodal from _descending */
100 void calculateNodalConnectivity();
101 /*! private method :\n
102 does nothing if already exists, else
103 evaluates from _nodal */
104 void calculateReverseNodalConnectivity();
105 /*! private method :\n
106 does nothing if already exists, else
107 evaluates _descending from _nodal */
108 void calculateDescendingConnectivity();
109 /*! private method :\n
110 does nothing if already exists, else
111 evaluates from _descending */
112 // void calculateReverseDescendingConnectivity(CONNECTIVITY *myConnectivity);
114 const int* getReverseNodalConnectivity ();
115 const int* getReverseNodalConnectivityIndex ();
116 const int* getReverseDescendingConnectivity ();
117 const int* getReverseDescendingConnectivityIndex ();
119 /*! private method :\n
120 does nothing if already exists, else
121 evaluates _neighbourhood from _descending */
122 void calculateNeighbourhood(CONNECTIVITY &myConnectivity);
124 int getIndexOfEndClassicElementInReverseNodal(const int *reverseNodalValue, const int *reverseNodalIndex, int rk) const;
128 friend class IMED_MESH_RDONLY_DRIVER;
129 friend class MED_MESH_RDONLY_DRIVER21;
130 friend class IMED_MESH_WRONLY_DRIVER;
131 friend class MED_MESH_WRONLY_DRIVER21;
132 friend class MED_MESH_RDONLY_DRIVER22;
133 friend class MED_MESH_WRONLY_DRIVER22;
136 friend ostream & operator<<(ostream &os, CONNECTIVITY &connectivity);
138 // in order to fill CONNECTIVITY of MESH
141 CONNECTIVITY (MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
142 CONNECTIVITY (int numberOfTypes, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
143 CONNECTIVITY (const CONNECTIVITY & m);
144 virtual ~CONNECTIVITY ();
146 void setConstituent (CONNECTIVITY * Constituent)
147 throw (MEDEXCEPTION);
149 void setGeometricTypes (const MED_EN::medGeometryElement * Types,
150 const MED_EN::medEntityMesh Entity)
151 throw (MEDEXCEPTION);
153 void setCount (const int * Count, const MED_EN::medEntityMesh Entity)
154 throw (MEDEXCEPTION);
156 void setNodal (const int * Connectivity,
157 const MED_EN::medEntityMesh Entity,
158 const MED_EN::medGeometryElement Type)
159 throw (MEDEXCEPTION);
161 inline void setNumberOfNodes(int NumberOfNodes);
163 inline int getEntityDimension() const;
165 inline void setEntityDimension(int EntityDimension);
167 void setPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
168 MED_EN::medEntityMesh Entity,
169 const int* PolygonsConnectivity,
170 const int* PolygonsConnectivityIndex,
171 int ConnectivitySize, int NumberOfPolygons);
173 void setPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType,
174 const int* PolyhedronConnectivity,
175 const int* PolyhedronIndex, int ConnectivitySize,
176 int NumberOfPolyhedron,
177 const int* PolyhedronFacesIndex= (int*) NULL,
178 int NumberOfFaces=0);
180 inline bool existConnectivity (MED_EN::medConnectivity connectivityType, MED_EN::medEntityMesh Entity) const;
182 inline bool existPolygonsConnectivity(MED_EN::medConnectivity connectivityType,
183 MED_EN::medEntityMesh Entity) const;
185 inline bool existPolyhedronConnectivity(MED_EN::medConnectivity connectivityType,
186 MED_EN::medEntityMesh Entity) const;
188 virtual void calculateConnectivity (MED_EN::medConnectivity connectivityType, MED_EN::medEntityMesh Entity);
190 virtual void updateFamily (const vector<FAMILY*>& myFamilies);
192 inline MED_EN::medEntityMesh getEntity () const;
193 inline int getNumberOfTypes (MED_EN::medEntityMesh Entity) const;
194 int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const;
195 const int * getConnectivityOfAnElementWithPoly(MED_EN::medConnectivity ConnectivityType,
196 MED_EN::medEntityMesh Entity,
197 int Number, int &lgth);
198 int getNumberOfPolyType() const;
199 int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const;
200 int getNumberOfElementOfPolyType(MED_EN::medEntityMesh Entity) const;
201 inline const MED_EN::medGeometryElement * getGeometricTypes (MED_EN::medEntityMesh Entity) const
202 throw (MEDEXCEPTION);
203 MED_EN::medGeometryElement * getGeometricTypesWithPoly (MED_EN::medEntityMesh Entity) const
204 throw (MEDEXCEPTION);
205 MED_EN::medGeometryElement getElementType (MED_EN::medEntityMesh Entity,
207 MED_EN::medGeometryElement getElementTypeWithPoly (MED_EN::medEntityMesh Entity,
209 inline MED_EN::medGeometryElement getPolyTypeRelativeTo() const;
210 virtual inline const int * getGlobalNumberingIndex (MED_EN::medEntityMesh Entity) const
211 throw (MEDEXCEPTION);
213 virtual const int * getConnectivity (MED_EN::medConnectivity ConnectivityType,
214 MED_EN::medEntityMesh Entity,
215 MED_EN::medGeometryElement Type);
216 virtual int getConnectivityLength (MED_EN::medConnectivity ConnectivityType,
217 MED_EN::medEntityMesh Entity,
218 MED_EN::medGeometryElement Type);
220 virtual const int * getConnectivityIndex (MED_EN::medConnectivity ConnectivityType,
221 MED_EN::medEntityMesh Entity);
223 const int* getPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
224 MED_EN::medEntityMesh Entity);
225 const int* getPolygonsConnectivityIndex(MED_EN::medConnectivity ConnectivityType,
226 MED_EN::medEntityMesh Entity);
227 int getNumberOfPolygons() const;
228 const int* getPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType) const;
229 const int* getPolyhedronFacesIndex() const;
230 const int* getPolyhedronIndex(MED_EN::medConnectivity ConnectivityType) const;
231 int getNumberOfPolyhedronFaces() const;
232 int getNumberOfPolyhedron() const;
233 int *getNodesOfPolyhedron(int polyhedronId, int& lgthOfTab) const;
234 int **getNodesPerFaceOfPolyhedron(int polyhedronId, int& nbOfFaces, int* & nbOfNodesPerFaces) const;
235 const CELLMODEL & getType (MED_EN::medGeometryElement Type) const;
236 const CELLMODEL * getCellsTypes (MED_EN::medEntityMesh Entity) const
237 throw (MEDEXCEPTION);
239 int getNumberOfNodesInType (MED_EN::medGeometryElement Type) const;
240 int getNumberOfSubCellInType (MED_EN::medGeometryElement Type) const;
241 virtual int getNumberOf (MED_EN::medEntityMesh Entity,
242 MED_EN::medGeometryElement Type) const;
243 virtual const int* getValue (MED_EN::medConnectivity TypeConnectivity,
244 MED_EN::medGeometryElement Type);
245 virtual const int* getValueIndex (MED_EN::medConnectivity TypeConnectivity);
247 virtual inline const int* getReverseConnectivity (MED_EN::medConnectivity ConnectivityType,
248 MED_EN::medEntityMesh Entity=MED_EN::MED_CELL)
249 throw (MEDEXCEPTION);
250 virtual inline const int* getReverseConnectivityIndex (MED_EN::medConnectivity ConnectivityType,
251 MED_EN::medEntityMesh Entity=MED_EN::MED_CELL)
252 throw (MEDEXCEPTION);
254 const int* getNeighbourhood() const;
255 void invertConnectivityForAFace(int faceId, const int *nodalConnForFace, bool polygonFace=false);
256 bool deepCompare(const CONNECTIVITY& other) const;
258 /*----------------------*/
259 /* Methodes Inline */
260 /*----------------------*/
262 /*! Returns the medEntityMesh */
263 //--------------------------------------------------//
264 inline MED_EN::medEntityMesh CONNECTIVITY::getEntity() const
265 //--------------------------------------------------//
270 /*! Returns the number of different %medGeometryElement types
271 existing in the specified entity. \n
272 Note : Not implemented for MED_ALL_ENTITIES. */
273 //-----------------------------------------------------------------------//
274 inline int CONNECTIVITY::getNumberOfTypes(MED_EN::medEntityMesh Entity) const
275 //-----------------------------------------------------------------------//
277 MESSAGE("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
279 return _numberOfTypes;
280 else if (_constituent!=NULL)
281 return _constituent->getNumberOfTypes(Entity);
282 else if (_constituent == NULL)
284 MESSAGE("CONNECTIVITY::getNumberOfTypes : _constituent == NULL");
287 (const_cast <CONNECTIVITY *> (this))->calculateDescendingConnectivity();
289 catch (MEDEXCEPTION & ex)
294 SCRUTE(_entityDimension);
296 if (_entityDimension != 2 && _entityDimension != 3) return 0;
300 _constituent->calculateConnectivity(MED_EN::MED_NODAL,Entity);
302 catch (MEDEXCEPTION & ex)
307 return _constituent->getNumberOfTypes(Entity);
310 return 0; // because it is the right information (no exception needed)!
313 /*! Returns an array of all %medGeometryElement types existing in the mesh
314 for the given %medEntityMesh.
315 Note : Not implemented for MED_ALL_ENTITIES.
316 Throws an exception if Entity is unknown */
317 //------------------------------------------------------------------------------------------//
318 inline const MED_EN::medGeometryElement* CONNECTIVITY::getGeometricTypes(MED_EN::medEntityMesh Entity) const
320 //------------------------------------------------------------------------------------------//
323 return _geometricTypes;
324 else if (_constituent!=NULL)
325 return _constituent->getGeometricTypes(Entity);
327 throw MEDEXCEPTION("CONNECTIVITY::getGeometricTypes : Entity not defined !");
330 /*! Returns an array containing the accumulated number of entities sorted by the geometric type.\n
334 In case of a CONNECTIVITY containing 3*MED_TRIA3 et 2*MED_QUAD4 : \n
335 int * count = getGlobalNumberingIndex(MED_CELL)\n
336 count[0] is always set to 1\n
337 count[1] is set to 1+3=4\n
338 count[2] is set to 4+2=6 = total number of cells + 1\n
340 Note : Not implemented for MED_ALL_ENTITIES. \n
341 Note : The geometric type order is given by the typedef enum medGeometryElement.
344 //----------------------------------------------------------------------------------//
345 inline const int * CONNECTIVITY::getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const
347 //----------------------------------------------------------------------------------//
351 else if (_constituent!=NULL)
352 return _constituent->getGlobalNumberingIndex(Entity);
354 throw MEDEXCEPTION("CONNECTIVITY::getGlobalNumberingIndex : Entity not defined !");
357 /*! Returns true if a connectivity exists on elements of type "Entity" */
358 //-----------------------------------------------------------------------------//
359 inline bool CONNECTIVITY::existConnectivity( MED_EN::medConnectivity ConnectivityType,
360 MED_EN::medEntityMesh Entity) const
361 //-----------------------------------------------------------------------------//
363 if (_entity==Entity) {
364 if ((ConnectivityType==MED_EN::MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL))
366 if ((ConnectivityType==MED_EN::MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
368 } else if (_constituent!=NULL)
369 return _constituent->existConnectivity(ConnectivityType,Entity);
373 /*! Returns true if a polygons connectivity exists on elements of type "Entity" */
374 //-----------------------------------------------------------------------------//
375 inline bool CONNECTIVITY::existPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
376 MED_EN::medEntityMesh Entity) const
377 //-----------------------------------------------------------------------------//
379 if (_entity == Entity)
381 MESSAGE("existPolygonsConnectivity : _entity == Entity = "<<Entity);
382 if (ConnectivityType == MED_EN::MED_NODAL && _polygonsNodal != (MEDSKYLINEARRAY*) NULL)
384 if (ConnectivityType == MED_EN::MED_DESCENDING && _polygonsDescending != (MEDSKYLINEARRAY*) NULL)
387 else if (_constituent != (CONNECTIVITY*) NULL)
388 return _constituent->existPolygonsConnectivity(ConnectivityType,Entity);
392 /*! Returns true if a polyhedron connectivity exists on elements of type "Entity" */
393 //-----------------------------------------------------------------------------//
394 inline bool CONNECTIVITY::existPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType,
395 MED_EN::medEntityMesh Entity) const
396 //-----------------------------------------------------------------------------//
398 if (_entity == Entity)
400 MESSAGE("existPolyhedronConnectivity : _entity == Entity = "<<Entity);
401 if (ConnectivityType == MED_EN::MED_NODAL && _polyhedronNodal != (POLYHEDRONARRAY*) NULL)
403 if (ConnectivityType == MED_EN::MED_DESCENDING && _polyhedronDescending != (MEDSKYLINEARRAY*) NULL)
406 else if (_constituent != (CONNECTIVITY*) NULL)
407 return _constituent->existPolyhedronConnectivity(ConnectivityType,Entity);
412 Returns an array containing CELLMODEL foreach element type present
413 in connectivity for given medEntityMesh (similar as getGeometricTypes).\n
414 Throw an execption if the given entity is not defined or if the array is not defined.
416 //-----------------------------------------------------------------------------//
417 inline const CELLMODEL * CONNECTIVITY::getCellsTypes(MED_EN::medEntityMesh Entity) const
419 //-----------------------------------------------------------------------------//
421 if (Entity == _entity)
425 throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) :"
426 " CELLMODEL array is not defined !");
428 if (_constituent != NULL)
429 return _constituent->getCellsTypes(Entity);
431 throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
435 //------------------------------------------------------------------------------------------//
436 inline const int* CONNECTIVITY::getReverseConnectivity( MED_EN::medConnectivity ConnectivityType,
437 MED_EN::medEntityMesh Entity)
439 //------------------------------------------------------------------------------------------//
442 if (ConnectivityType==MED_EN::MED_NODAL)
443 return getReverseNodalConnectivity();
444 else if (ConnectivityType==MED_EN::MED_DESCENDING)
445 return getReverseDescendingConnectivity();
447 throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
450 if (NULL==_constituent)
451 calculateDescendingConnectivity();
452 return _constituent->getReverseConnectivity(ConnectivityType,Entity);
456 //-----------------------------------------------------------------------------------------------//
457 inline const int* CONNECTIVITY::getReverseConnectivityIndex(MED_EN::medConnectivity ConnectivityType,
458 MED_EN::medEntityMesh Entity)
460 //-----------------------------------------------------------------------------------------------//
463 if (ConnectivityType==MED_EN::MED_NODAL)
464 return getReverseNodalConnectivityIndex();
465 else if (ConnectivityType==MED_EN::MED_DESCENDING)
466 return getReverseDescendingConnectivityIndex();
468 throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
471 if (NULL==_constituent)
472 calculateDescendingConnectivity();
473 return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity);
477 inline void CONNECTIVITY::setNumberOfNodes(int NumberOfNodes)
479 _numberOfNodes=NumberOfNodes;
482 inline void CONNECTIVITY::setEntityDimension(int EntityDimension)
484 _entityDimension=EntityDimension;
487 int CONNECTIVITY::getEntityDimension() const
489 return _entityDimension;
492 MED_EN::medGeometryElement CONNECTIVITY::getPolyTypeRelativeTo() const
494 if(_entity==MED_EN::MED_CELL && _entityDimension==3)
495 return MED_EN::MED_POLYHEDRA;
496 else if((_entity==MED_EN::MED_CELL && _entityDimension==2) || (_entity==MED_EN::MED_FACE && _entityDimension==2))
497 return MED_EN::MED_POLYGON;
499 throw MEDEXCEPTION("getPolyTypeRelativeTo : ");
502 }//End namespace MEDMEM
504 #endif /* CONNECTIVITY_HXX */