]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Connectivity.hxx
Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / MEDMEM_Connectivity.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_Connectivity.hxx
25 //  Module : MED
26
27 #ifndef CONNECTIVITY_HXX
28 #define CONNECTIVITY_HXX
29
30 #include <vector>
31
32 #include "utilities.h"
33 #include "MEDMEM_Exception.hxx"
34 #include "MEDMEM_define.hxx"
35
36 using namespace MED_EN;
37
38 class MEDSKYLINEARRAY;
39 class CELLMODEL;
40 class FAMILY;
41
42 /*!
43         This class deals with all type of connectivity ./n
44         it a recursive class. 
45 */
46
47 /* ------------------------------------------- */
48 class CONNECTIVITY
49 /* ------------------------------------------- */
50 {
51   /* ---------------------- */
52   /*    Class Attributs     */
53   /* ---------------------- */
54
55 protected:
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 
61                                             used by the mesh */  
62   med_int                 _numberOfTypes; 
63                                         /*! array of all med_geometric_type used by MESH. */
64   medGeometryElement*     _geometricTypes;
65
66                                         /*! map indexed by med_geometric_type 
67                                             which contains the different 
68                                             'CellModel' used by MESH. */
69   CELLMODEL *             _type;       
70                                         /*! contains the dimension of the entity */
71   med_int                 _entityDimension;
72
73                                         /*! needed by calculateReverseNodalConnectivity */
74   med_int                 _numberOfNodes;
75
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 */
85   med_int *               _count;
86
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;  
108
109   /* -------------------- */
110   /*    Class Methods     */
111   /* -------------------- */
112
113 private:
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);
130
131   const med_int*      getReverseNodalConnectivity           ();
132   const med_int*      getReverseNodalConnectivityIndex      ();
133   const med_int*      getReverseDescendingConnectivity      ();
134   const med_int*      getReverseDescendingConnectivityIndex ();
135
136                                         /*! private method :/n
137                                             does nothing if already exists, else
138                                             evaluates _neighbourhood from _descending */
139   void calculateNeighbourhood(CONNECTIVITY &myConnectivity);
140
141 public:
142
143   friend class MED_MESH_RDONLY_DRIVER;
144   friend class MED_MESH_WRONLY_DRIVER;
145
146   // in order to fill CONNECTIVITY of MESH
147   friend class GRID;
148
149   CONNECTIVITY  (medEntityMesh Entity=MED_CELL);
150   CONNECTIVITY  (int numberOfTypes, medEntityMesh Entity=MED_CELL);
151   CONNECTIVITY  (const CONNECTIVITY & m);
152   ~CONNECTIVITY ();
153
154   void setConstituent (CONNECTIVITY * Constituent)
155                                         throw (MEDEXCEPTION);
156
157   void setGeometricTypes (const medGeometryElement * Types,
158                            const medEntityMesh Entity)
159                                         throw (MEDEXCEPTION);
160
161   void setCount (const int * Count, const medEntityMesh Entity)
162                                         throw (MEDEXCEPTION);
163
164   void setNodal (const int * Connectivity,
165                  const medEntityMesh Entity,
166                  const medGeometryElement Type)
167                                         throw (MEDEXCEPTION);
168
169   inline bool   existConnectivity     (medConnectivity connectivityType, medEntityMesh Entity) const;
170
171   void          calculateConnectivity (medConnectivity connectivityType, medEntityMesh Entity);
172
173   void          updateFamily (vector<FAMILY*> myFamilies);
174
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,
180                                                              int Number)           const;
181   inline const int *                getGlobalNumberingIndex (medEntityMesh Entity) const
182                                                              throw (MEDEXCEPTION);
183
184   const med_int *     getConnectivity      (medConnectivity ConnectivityType, 
185                                             medEntityMesh Entity,
186                                             medGeometryElement Type);
187   const med_int *     getConnectivityIndex (medConnectivity ConnectivityType,
188                                             medEntityMesh Entity);
189  
190   const CELLMODEL &   getType              (medGeometryElement Type) const; 
191   const CELLMODEL *   getCellsTypes        (medEntityMesh Entity)    const 
192                                             throw (MEDEXCEPTION);
193  
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);
201
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);
208
209   const med_int*      getNeighbourhood() const;
210
211 };
212 /*----------------------*/
213 /* Methodes Inline      */
214 /*----------------------*/
215
216 /*! Returns the  medEntityMesh */
217 //--------------------------------------------------//
218 inline medEntityMesh CONNECTIVITY::getEntity() const 
219 //--------------------------------------------------//
220
221         return _entity; 
222 }
223
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 //-----------------------------------------------------------------------//
230 {
231   MESSAGE("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
232   if (_entity==Entity)
233         return _numberOfTypes; 
234   else if (_constituent!=NULL)
235         return _constituent->getNumberOfTypes(Entity);
236   else
237         return 0; // because it is the right information (no exception needed)!
238 }
239
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 
246                                                 throw (MEDEXCEPTION)
247 //------------------------------------------------------------------------------------------//
248 {
249   if (_entity==Entity)
250         return _geometricTypes;
251   else if (_constituent!=NULL)
252         return _constituent->getGeometricTypes(Entity);
253   else
254         throw MEDEXCEPTION("Entity not defined !");
255 }
256
257 /*! A DOCUMENTER */
258 //----------------------------------------------------------------------------------//
259 inline const int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) const 
260                                                 throw (MEDEXCEPTION)
261 //----------------------------------------------------------------------------------//
262 {
263   if (_entity==Entity)
264         return _count;
265   else if (_constituent!=NULL)
266         return _constituent->getGlobalNumberingIndex(Entity);
267   else
268         throw MEDEXCEPTION("Entity not defined !");
269 }
270
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 //-----------------------------------------------------------------------------//
276 {
277   if (_entity==Entity) { 
278     MESSAGE("existConnectivity : _entity==Entity="<<Entity);
279     if ((ConnectivityType==MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL))
280       return true;
281     if ((ConnectivityType==MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
282       return true;
283   } else if (_constituent!=NULL)
284     return _constituent->existConnectivity(ConnectivityType,Entity);
285   return false;
286 }
287
288 /*! 
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.
292 */
293 //-----------------------------------------------------------------------------//
294 inline const CELLMODEL * CONNECTIVITY::getCellsTypes(medEntityMesh Entity) const
295                                                 throw (MEDEXCEPTION)
296 //-----------------------------------------------------------------------------//
297 {
298   if (Entity == _entity)
299     if (_type!=NULL)
300       return _type;
301     else
302       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) :
303                            CELLMODEL array is not defined !");
304   else
305     if (_constituent != NULL)
306       return _constituent->getCellsTypes(Entity);
307     else
308       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
309 }
310
311 /*! A DOCUMENTER */
312 //------------------------------------------------------------------------------------------//
313 inline const med_int* CONNECTIVITY::getReverseConnectivity( medConnectivity ConnectivityType, 
314                                                             medEntityMesh Entity) 
315                                                             throw (MEDEXCEPTION)
316 //------------------------------------------------------------------------------------------//
317 {
318   if(_entity==Entity)
319     if (ConnectivityType==MED_NODAL)
320       return getReverseNodalConnectivity();
321     else if (ConnectivityType==MED_DESCENDING)
322       return getReverseDescendingConnectivity();
323     else
324       throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
325
326   // other entity :
327   if (NULL==_constituent)
328     calculateDescendingConnectivity();
329   return _constituent->getReverseConnectivity(ConnectivityType,Entity);
330 }
331
332 /*! A DOCUMENTER */
333 //-----------------------------------------------------------------------------------------------//
334 inline const med_int* CONNECTIVITY::getReverseConnectivityIndex(medConnectivity ConnectivityType, 
335                                                                 medEntityMesh Entity) 
336                                                                 throw (MEDEXCEPTION)
337 //-----------------------------------------------------------------------------------------------//
338 {
339   if(_entity==Entity)
340     if (ConnectivityType==MED_NODAL)
341       return getReverseNodalConnectivityIndex();
342     else if (ConnectivityType==MED_DESCENDING)
343       return getReverseDescendingConnectivityIndex();
344     else
345       throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
346   
347   // other entity :
348   if (NULL==_constituent)
349     calculateDescendingConnectivity();
350   return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity);
351 }
352
353 #endif /* CONNECTIVITY_HXX */
354