1 #ifndef CONNECTIVITY_HXX
2 #define CONNECTIVITY_HXX
7 #include "MEDMEM_Exception.hxx"
8 #include "MEDMEM_define.hxx"
10 using namespace MED_EN;
13 class MEDSKYLINEARRAY;
19 This class deals with all type of connectivity ./n
23 /* ------------------------------------------- */
25 /* ------------------------------------------- */
27 /* ---------------------- */
29 /* ---------------------- */
32 /*! contains MED_CELL MED_FACE or MED_EDGE */
33 medEntityMesh _entity;
34 /*! contains MED_NODAL or MED_DESCEND */
35 medConnectivity _typeConnectivity;
36 /*! count of differents cells types
38 med_int _numberOfTypes;
39 /*! array of all med_geometric_type used by MESH. */
40 medGeometryElement* _geometricTypes;
42 /*! map indexed by med_geometric_type
43 which contains the different
44 'CellModel' used by MESH. */
46 /*! contains the dimension of the entity */
47 med_int _entityDimension;
49 /*! needed by calculateReverseNodalConnectivity */
50 med_int _numberOfNodes;
52 /*! array of size _numberOfTypes+1 which
53 gives for each cell type the first
54 cell number in _nodal or _descending
55 array (depends on _typeConnectivity)
56 To get cells count for one type, we
57 must minus _count[i+1] and _count[i]
58 ( 0 <= i < _numberOfTypes ).
59 Note that _count[_numberOfTypes] returns
60 total cells count + 1 */
63 /*! pointer to an array which stores the nodal connectivity */
64 MEDSKYLINEARRAY* _nodal;
65 /*! pointer to an array which stores
66 the descending connectivity */
67 MEDSKYLINEARRAY* _descending;
68 /*! pointer to an array which stores
69 the reverse nodal connectivity */
70 MEDSKYLINEARRAY* _reverseNodalConnectivity;
71 /*! pointer to an array which stores
72 the reverse descending connectivity */
73 MEDSKYLINEARRAY* _reverseDescendingConnectivity;
74 /*! if face or edge, list of 2 cells or
75 2 faces it belongs to.
76 If 2nd number equals 0, we have a
77 boundary entity. We could use
78 MEDSKYLINEARRAY, but we suppose we have
79 always only 2 (or 1) entities. */
80 MEDSKYLINEARRAY* _neighbourhood;
81 /*! connectivity of sub cell if
82 descendant connectivity is calculated */
83 CONNECTIVITY * _constituent;
85 /* -------------------- */
87 /* -------------------- */
90 /*! private method :/n
91 does nothing if already exists, else
92 evaluates _nodal from _descending */
93 void calculateNodalConnectivity();
94 /*! private method :/n
95 does nothing if already exists, else
96 evaluates from _nodal */
97 void calculateReverseNodalConnectivity();
98 /*! private method :/n
99 does nothing if already exists, else
100 evaluates _descending from _nodal */
101 void calculateDescendingConnectivity();
102 /*! private method :/n
103 does nothing if already exists, else
104 evaluates from _descending */
105 // void calculateReverseDescendingConnectivity(CONNECTIVITY *myConnectivity);
107 const med_int* getReverseNodalConnectivity ();
108 const med_int* getReverseNodalConnectivityIndex ();
109 const med_int* getReverseDescendingConnectivity ();
110 const med_int* getReverseDescendingConnectivityIndex ();
112 /*! private method :/n
113 does nothing if already exists, else
114 evaluates _neighbourhood from _descending */
115 void calculateNeighbourhood(CONNECTIVITY &myConnectivity);
119 friend class MED_MESH_RDONLY_DRIVER;
120 friend class MED_MESH_WRONLY_DRIVER;
121 friend ostream & operator<<(ostream &os, CONNECTIVITY &connectivity);
123 // in order to fill CONNECTIVITY of MESH
126 CONNECTIVITY (medEntityMesh Entity=MED_CELL);
127 CONNECTIVITY (int numberOfTypes, medEntityMesh Entity=MED_CELL);
128 CONNECTIVITY (const CONNECTIVITY & m);
129 virtual ~CONNECTIVITY ();
131 void setConstituent (CONNECTIVITY * Constituent)
132 throw (MEDEXCEPTION);
134 void setGeometricTypes (const medGeometryElement * Types,
135 const medEntityMesh Entity)
136 throw (MEDEXCEPTION);
138 void setCount (const int * Count, const medEntityMesh Entity)
139 throw (MEDEXCEPTION);
141 void setNodal (const int * Connectivity,
142 const medEntityMesh Entity,
143 const medGeometryElement Type)
144 throw (MEDEXCEPTION);
146 inline void setNumberOfNodes(med_int NumberOfNodes);
148 inline void setEntityDimension(med_int EntityDimension);
150 inline bool existConnectivity (medConnectivity connectivityType, medEntityMesh Entity) const;
152 virtual void calculateConnectivity (medConnectivity connectivityType, medEntityMesh Entity);
154 virtual void updateFamily (vector<FAMILY*> myFamilies);
155 virtual void updateGroup (vector<GROUP*> myFamilies);
157 inline medEntityMesh getEntity () const;
158 inline med_int getNumberOfTypes (medEntityMesh Entity) const;
159 inline const medGeometryElement * getGeometricTypes (medEntityMesh Entity) const
160 throw (MEDEXCEPTION);
161 medGeometryElement getElementType (medEntityMesh Entity,
163 virtual inline const int * getGlobalNumberingIndex (medEntityMesh Entity) const
164 throw (MEDEXCEPTION);
166 virtual const med_int * getConnectivity (medConnectivity ConnectivityType,
167 medEntityMesh Entity,
168 medGeometryElement Type);
169 virtual const med_int * getConnectivityIndex (medConnectivity ConnectivityType,
170 medEntityMesh Entity);
172 const CELLMODEL & getType (medGeometryElement Type) const;
173 const CELLMODEL * getCellsTypes (medEntityMesh Entity) const
174 throw (MEDEXCEPTION);
176 med_int getNumberOfNodesInType (medGeometryElement Type) const;
177 med_int getNumberOfSubCellInType (medGeometryElement Type) const;
178 virtual med_int getNumberOf (medEntityMesh Entity,
179 medGeometryElement Type) const;
180 virtual const med_int* getValue (medConnectivity TypeConnectivity,
181 medGeometryElement Type);
182 virtual const med_int* getValueIndex (medConnectivity TypeConnectivity);
184 virtual inline const med_int* getReverseConnectivity (medConnectivity ConnectivityType,
185 medEntityMesh Entity=MED_CELL)
186 throw (MEDEXCEPTION);
187 virtual inline const med_int* getReverseConnectivityIndex (medConnectivity ConnectivityType,
188 medEntityMesh Entity=MED_CELL)
189 throw (MEDEXCEPTION);
191 const med_int* getNeighbourhood() const;
195 /*----------------------*/
196 /* Methodes Inline */
197 /*----------------------*/
198 using namespace MEDMEM;
200 /*! Returns the medEntityMesh */
201 //--------------------------------------------------//
202 inline medEntityMesh CONNECTIVITY::getEntity() const
203 //--------------------------------------------------//
208 /*! Returns the number of different %medGeometryElement types
209 existing in the specified entity. /n
210 Note : Not implemented for MED_ALL_ENTITIES. */
211 //-----------------------------------------------------------------------//
212 inline med_int CONNECTIVITY::getNumberOfTypes(medEntityMesh Entity) const
213 //-----------------------------------------------------------------------//
215 MESSAGE("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
217 return _numberOfTypes;
218 else if (_constituent!=NULL)
219 return _constituent->getNumberOfTypes(Entity);
220 else if (_constituent == NULL)
222 MESSAGE("CONNECTIVITY::getNumberOfTypes : _constituent == NULL");
225 (const_cast <CONNECTIVITY *> (this))->calculateDescendingConnectivity();
227 catch (MEDEXCEPTION & ex)
232 SCRUTE(_entityDimension);
234 if (_entityDimension != 2 && _entityDimension != 3) return 0;
238 _constituent->calculateConnectivity(MED_NODAL,Entity);
240 catch (MEDEXCEPTION & ex)
245 return _constituent->getNumberOfTypes(Entity);
248 return 0; // because it is the right information (no exception needed)!
251 /*! Returns an array of all %medGeometryElement types existing in the mesh
252 for the given %medEntityMesh.
253 Note : Not implemented for MED_ALL_ENTITIES.
254 Throws an exception if Entity is unknown */
255 //------------------------------------------------------------------------------------------//
256 inline const medGeometryElement* CONNECTIVITY::getGeometricTypes(medEntityMesh Entity) const
258 //------------------------------------------------------------------------------------------//
261 return _geometricTypes;
262 else if (_constituent!=NULL)
263 return _constituent->getGeometricTypes(Entity);
265 throw MEDEXCEPTION("CONNECTIVITY::getGeometricTypes : Entity not defined !");
268 /*! Returns an array containing the accumulated number of entities sorted by the geometric type./n
272 In case of a CONNECTIVITY containing 3*MED_TRIA3 et 2*MED_QUAD4 : /n
273 int * count = getGlobalNumberingIndex(MED_CELL)/n
274 count[0] is always set to 1/n
275 count[1] is set to 1+3=4/n
276 count[2] is set to 4+2=6 = total number of cells + 1/n
278 Note : Not implemented for MED_ALL_ENTITIES. /n
279 Note : The geometric type order is given by the typedef enum medGeometryElement.
282 //----------------------------------------------------------------------------------//
283 inline const int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) const
285 //----------------------------------------------------------------------------------//
289 else if (_constituent!=NULL)
290 return _constituent->getGlobalNumberingIndex(Entity);
292 throw MEDEXCEPTION("CONNECTIVITY::getGlobalNumberingIndex : Entity not defined !");
295 /*! Returns true if a connectivity exists on elements of type "Entity" */
296 //-----------------------------------------------------------------------------//
297 inline bool CONNECTIVITY::existConnectivity( medConnectivity ConnectivityType,
298 medEntityMesh Entity) const
299 //-----------------------------------------------------------------------------//
301 if (_entity==Entity) {
302 MESSAGE("existConnectivity : _entity==Entity="<<Entity);
303 if ((ConnectivityType==MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL))
305 if ((ConnectivityType==MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
307 } else if (_constituent!=NULL)
308 return _constituent->existConnectivity(ConnectivityType,Entity);
313 Returns an array containing CELLMODEL foreach element type present
314 in connectivity for given medEntityMesh (similar as getGeometricTypes)./n
315 Throw an execption if the given entity is not defined or if the array is not defined.
317 //-----------------------------------------------------------------------------//
318 inline const CELLMODEL * CONNECTIVITY::getCellsTypes(medEntityMesh Entity) const
320 //-----------------------------------------------------------------------------//
322 if (Entity == _entity)
326 throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) :"
327 " CELLMODEL array is not defined !");
329 if (_constituent != NULL)
330 return _constituent->getCellsTypes(Entity);
332 throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
336 //------------------------------------------------------------------------------------------//
337 inline const med_int* CONNECTIVITY::getReverseConnectivity( medConnectivity ConnectivityType,
338 medEntityMesh Entity)
340 //------------------------------------------------------------------------------------------//
343 if (ConnectivityType==MED_NODAL)
344 return getReverseNodalConnectivity();
345 else if (ConnectivityType==MED_DESCENDING)
346 return getReverseDescendingConnectivity();
348 throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
351 if (NULL==_constituent)
352 calculateDescendingConnectivity();
353 return _constituent->getReverseConnectivity(ConnectivityType,Entity);
357 //-----------------------------------------------------------------------------------------------//
358 inline const med_int* CONNECTIVITY::getReverseConnectivityIndex(medConnectivity ConnectivityType,
359 medEntityMesh Entity)
361 //-----------------------------------------------------------------------------------------------//
364 if (ConnectivityType==MED_NODAL)
365 return getReverseNodalConnectivityIndex();
366 else if (ConnectivityType==MED_DESCENDING)
367 return getReverseDescendingConnectivityIndex();
369 throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
372 if (NULL==_constituent)
373 calculateDescendingConnectivity();
374 return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity);
378 inline void CONNECTIVITY::setNumberOfNodes(med_int NumberOfNodes)
380 _numberOfNodes=NumberOfNodes;
383 inline void CONNECTIVITY::setEntityDimension(med_int EntityDimension)
385 _entityDimension=EntityDimension;
388 #endif /* CONNECTIVITY_HXX */