1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MEDMEM_Connectivity.hxx
27 #ifndef CONNECTIVITY_HXX
28 #define CONNECTIVITY_HXX
32 #include "utilities.h"
33 #include "MEDMEM_Exception.hxx"
34 #include "MEDMEM_define.hxx"
36 using namespace MED_EN;
38 class MEDSKYLINEARRAY;
43 This class deals with all type of connectivity ./n
47 /* ------------------------------------------- */
49 /* ------------------------------------------- */
51 /* ---------------------- */
53 /* ---------------------- */
56 /*! contains MED_CELL MED_FACE or MED_EDGE */
57 medEntityMesh _entity;
58 /*! contains MED_NODAL or MED_DESCEND */
59 medConnectivity _typeConnectivity;
60 /*! count of differents cells types
62 med_int _numberOfTypes;
63 /*! array of all med_geometric_type used by MESH. */
64 medGeometryElement* _geometricTypes;
66 /*! map indexed by med_geometric_type
67 which contains the different
68 'CellModel' used by MESH. */
70 /*! contains the dimension of the entity */
71 med_int _entityDimension;
73 /*! needed by calculateReverseNodalConnectivity */
74 med_int _numberOfNodes;
76 /*! array of size _numberOfTypes+1 which
77 gives for each cell type the first
78 cell number in _nodal or _descending
79 array (depends on _typeConnectivity)
80 To get cells count for one type, we
81 must minus _count[i+1] and _count[i]
82 ( 0 <= i < _numberOfTypes ).
83 Note that _count[_numberOfTypes] returns
84 total cells count + 1 */
87 /*! pointer to an array which stores the nodal connectivity */
88 MEDSKYLINEARRAY* _nodal;
89 /*! pointer to an array which stores
90 the descending connectivity */
91 MEDSKYLINEARRAY* _descending;
92 /*! pointer to an array which stores
93 the reverse nodal connectivity */
94 MEDSKYLINEARRAY* _reverseNodalConnectivity;
95 /*! pointer to an array which stores
96 the reverse descending connectivity */
97 MEDSKYLINEARRAY* _reverseDescendingConnectivity;
98 /*! if face or edge, list of 2 cells or
99 2 faces it belongs to.
100 If 2nd number equals 0, we have a
101 boundary entity. We could use
102 MEDSKYLINEARRAY, but we suppose we have
103 always only 2 (or 1) entities. */
104 MEDSKYLINEARRAY* _neighbourhood;
105 /*! connectivity of sub cell if
106 descendant connectivity is calculated */
107 CONNECTIVITY * _constituent;
109 /* -------------------- */
111 /* -------------------- */
114 /*! private method :/n
115 does nothing if already exists, else
116 evaluates _nodal from _descending */
117 void calculateNodalConnectivity();
118 /*! private method :/n
119 does nothing if already exists, else
120 evaluates from _nodal */
121 void calculateReverseNodalConnectivity();
122 /*! private method :/n
123 does nothing if already exists, else
124 evaluates _descending from _nodal */
125 void calculateDescendingConnectivity();
126 /*! private method :/n
127 does nothing if already exists, else
128 evaluates from _descending */
129 // void calculateReverseDescendingConnectivity(CONNECTIVITY *myConnectivity);
131 const med_int* getReverseNodalConnectivity ();
132 const med_int* getReverseNodalConnectivityIndex ();
133 const med_int* getReverseDescendingConnectivity ();
134 const med_int* getReverseDescendingConnectivityIndex ();
136 /*! private method :/n
137 does nothing if already exists, else
138 evaluates _neighbourhood from _descending */
139 void calculateNeighbourhood(CONNECTIVITY &myConnectivity);
143 friend class MED_MESH_RDONLY_DRIVER;
144 friend class MED_MESH_WRONLY_DRIVER;
146 // in order to fill CONNECTIVITY of MESH
149 CONNECTIVITY (medEntityMesh Entity=MED_CELL);
150 CONNECTIVITY (int numberOfTypes, medEntityMesh Entity=MED_CELL);
151 CONNECTIVITY (const CONNECTIVITY & m);
154 void setConstituent (CONNECTIVITY * Constituent)
155 throw (MEDEXCEPTION);
157 void setGeometricTypes (const medGeometryElement * Types,
158 const medEntityMesh Entity)
159 throw (MEDEXCEPTION);
161 void setCount (const int * Count, const medEntityMesh Entity)
162 throw (MEDEXCEPTION);
164 void setNodal (const int * Connectivity,
165 const medEntityMesh Entity,
166 const medGeometryElement Type)
167 throw (MEDEXCEPTION);
169 inline bool existConnectivity (medConnectivity connectivityType, medEntityMesh Entity) const;
171 void calculateConnectivity (medConnectivity connectivityType, medEntityMesh Entity);
173 void updateFamily (vector<FAMILY*> myFamilies);
175 inline medEntityMesh getEntity () const;
176 inline med_int getNumberOfTypes (medEntityMesh Entity) const;
177 inline const medGeometryElement * getGeometricTypes (medEntityMesh Entity) const
178 throw (MEDEXCEPTION);
179 medGeometryElement getElementType (medEntityMesh Entity,
181 inline const int * getGlobalNumberingIndex (medEntityMesh Entity) const
182 throw (MEDEXCEPTION);
184 const med_int * getConnectivity (medConnectivity ConnectivityType,
185 medEntityMesh Entity,
186 medGeometryElement Type);
187 const med_int * getConnectivityIndex (medConnectivity ConnectivityType,
188 medEntityMesh Entity);
190 const CELLMODEL & getType (medGeometryElement Type) const;
191 const CELLMODEL * getCellsTypes (medEntityMesh Entity) const
192 throw (MEDEXCEPTION);
194 med_int getNumberOfNodesInType (medGeometryElement Type) const;
195 med_int getNumberOfSubCellInType (medGeometryElement Type) const;
196 med_int getNumberOf (medEntityMesh Entity,
197 medGeometryElement Type) const;
198 const med_int* getValue (medConnectivity TypeConnectivity,
199 medGeometryElement Type);
200 const med_int* getValueIndex (medConnectivity TypeConnectivity);
202 inline const med_int* getReverseConnectivity (medConnectivity ConnectivityType,
203 medEntityMesh Entity=MED_CELL)
204 throw (MEDEXCEPTION);
205 inline const med_int* getReverseConnectivityIndex (medConnectivity ConnectivityType,
206 medEntityMesh Entity=MED_CELL)
207 throw (MEDEXCEPTION);
209 const med_int* getNeighbourhood() const;
212 /*----------------------*/
213 /* Methodes Inline */
214 /*----------------------*/
216 /*! Returns the medEntityMesh */
217 //--------------------------------------------------//
218 inline medEntityMesh CONNECTIVITY::getEntity() const
219 //--------------------------------------------------//
224 /*! Returns the number of different <medGeometryElement> types
225 existing in the specified entity. /n
226 Note : Not implemented for MED_ALL_ENTITIES. */
227 //-----------------------------------------------------------------------//
228 inline med_int CONNECTIVITY::getNumberOfTypes(medEntityMesh Entity) const
229 //-----------------------------------------------------------------------//
231 MESSAGE("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
233 return _numberOfTypes;
234 else if (_constituent!=NULL)
235 return _constituent->getNumberOfTypes(Entity);
237 return 0; // because it is the right information (no exception needed)!
240 /*! Returns an array of all <med geometry elements> types existing in the mesh
241 for the given medEntityMesh./n
242 Note : Not implemented for MED_ALL_ENTITIES. /n
243 Throws an exception if Entity is unknown */
244 //------------------------------------------------------------------------------------------//
245 inline const medGeometryElement* CONNECTIVITY::getGeometricTypes(medEntityMesh Entity) const
247 //------------------------------------------------------------------------------------------//
250 return _geometricTypes;
251 else if (_constituent!=NULL)
252 return _constituent->getGeometricTypes(Entity);
254 throw MEDEXCEPTION("Entity not defined !");
258 //----------------------------------------------------------------------------------//
259 inline const int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) const
261 //----------------------------------------------------------------------------------//
265 else if (_constituent!=NULL)
266 return _constituent->getGlobalNumberingIndex(Entity);
268 throw MEDEXCEPTION("Entity not defined !");
271 /*! Returns true if a connectivity exists on elements of type "Entity" */
272 //-----------------------------------------------------------------------------//
273 inline bool CONNECTIVITY::existConnectivity( medConnectivity ConnectivityType,
274 medEntityMesh Entity) const
275 //-----------------------------------------------------------------------------//
277 if (_entity==Entity) {
278 MESSAGE("existConnectivity : _entity==Entity="<<Entity);
279 if ((ConnectivityType==MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL))
281 if ((ConnectivityType==MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
283 } else if (_constituent!=NULL)
284 return _constituent->existConnectivity(ConnectivityType,Entity);
289 Returns an array containing CELLMODEL foreach element type present
290 in connectivity for given medEntityMesh (similar as getGeometricTypes)./n
291 Throw an execption if the given entity is not defined or if the array is not defined.
293 //-----------------------------------------------------------------------------//
294 inline const CELLMODEL * CONNECTIVITY::getCellsTypes(medEntityMesh Entity) const
296 //-----------------------------------------------------------------------------//
298 if (Entity == _entity)
302 throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) :
303 CELLMODEL array is not defined !");
305 if (_constituent != NULL)
306 return _constituent->getCellsTypes(Entity);
308 throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
312 //------------------------------------------------------------------------------------------//
313 inline const med_int* CONNECTIVITY::getReverseConnectivity( medConnectivity ConnectivityType,
314 medEntityMesh Entity)
316 //------------------------------------------------------------------------------------------//
319 if (ConnectivityType==MED_NODAL)
320 return getReverseNodalConnectivity();
321 else if (ConnectivityType==MED_DESCENDING)
322 return getReverseDescendingConnectivity();
324 throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
327 if (NULL==_constituent)
328 calculateDescendingConnectivity();
329 return _constituent->getReverseConnectivity(ConnectivityType,Entity);
333 //-----------------------------------------------------------------------------------------------//
334 inline const med_int* CONNECTIVITY::getReverseConnectivityIndex(medConnectivity ConnectivityType,
335 medEntityMesh Entity)
337 //-----------------------------------------------------------------------------------------------//
340 if (ConnectivityType==MED_NODAL)
341 return getReverseNodalConnectivityIndex();
342 else if (ConnectivityType==MED_DESCENDING)
343 return getReverseDescendingConnectivityIndex();
345 throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
348 if (NULL==_constituent)
349 calculateDescendingConnectivity();
350 return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity);
353 #endif /* CONNECTIVITY_HXX */