]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Connectivity.hxx
Salome HOME
NRI : Update 1.1a and New organisation.
[modules/med.git] / src / MEDMEM / MEDMEM_Connectivity.hxx
1 #ifndef CONNECTIVITY_HXX
2 #define CONNECTIVITY_HXX
3
4 #include <vector>
5
6 #include "utilities.h"
7 #include "MEDMEM_Exception.hxx"
8 #include "MEDMEM_define.hxx"
9
10 using namespace MED_EN;
11
12 class MEDSKYLINEARRAY;
13 class CELLMODEL;
14 class FAMILY;
15
16 /*!
17         this class deals with all type of connectivity 
18         this a recursive class in order to store 
19         
20 */
21 class CONNECTIVITY // recursive class
22
23 {
24   /*
25     Class Attributs
26   */
27
28 protected:
29                                          /*! contains MED_CELL MED_FACE or MED_EDGE */
30   medEntityMesh           _entity ;     
31                                          /*! contains MED_NODAL or MED_DESCEND */
32   medConnectivity         _typeConnectivity ;
33                                          /*! count of differents cells types 
34                                             used by the mesh */  
35   med_int                 _numberOfTypes ; 
36                                         /*! array of all med_geometric_type used by MESH. */
37   medGeometryElement*     _geometricTypes ;
38
39                                         /*! map indexed by med_geometric_type 
40                                             which contains the different 
41                                             'CellModel' used by MESH. */
42   CELLMODEL *             _type ;       
43                                         /*! contains the dimension of the entity */
44   med_int                 _entityDimension ;
45
46                                         /*! needed by calculateReverseNodalConnectivity */
47   med_int                 _numberOfNodes ; 
48
49                                          /*! array of size _numberOfTypes+1 which 
50                                          gives for each cell type the first 
51                                          cell number in _nodal or _descending
52                                          array (depends on _typeConnectivity) 
53                                          To get cells count for one type, we 
54                                          must minus _count[i+1] and _count[i]
55                                          ( 0 <= i < _numberOfTypes ). 
56                                          Note that _count[_numberOfTypes] returns
57                                          total cells count + 1 */
58   med_int *               _count ;
59
60                                         /*! pointer on an array which stores the nodal connectivity */
61   MEDSKYLINEARRAY* _nodal ;
62                                         /*! pointer on an array which stores the descending connectivity */
63   MEDSKYLINEARRAY* _descending ;
64                                         /*! pointer on an array which stores the resverse nodal connectivity */
65   MEDSKYLINEARRAY* _reverseNodalConnectivity ;
66                                         /*! pointer on an array which stores the reverse descending connectivity */
67   MEDSKYLINEARRAY* _reverseDescendingConnectivity ;
68                                         /*! if face or edge, list of 2 cells or 
69                                             2 faces it belongs to.
70                                             If 2nd number equals 0, we have a 
71                                             boundary entity. We could use 
72                                             MEDSKYLINEARRAY, but we suppose we have
73                                             always only 2 (or 1) entities. */
74   MEDSKYLINEARRAY* _neighbourhood ;
75                                         /*! connectivity of sub cell if 
76                                             descendant connectivity is calculated */
77   CONNECTIVITY * _constituent ;         
78
79   /*
80     Class Methods
81   */
82
83 private:
84                                         /*! does nothing if already exists, else 
85                                             evaluates _nodal from _descending */
86   void  calculateNodalConnectivity() ;  
87                                         /*! does nothing if already exists, else
88                                             evaluates from _nodal */  
89   void calculateReverseNodalConnectivity() ; 
90                                         /*! does nothing if already exists, else
91                                             evaluates _descending from _nodal */ 
92   void calculateDescendingConnectivity() ; 
93                                         /*! does nothing if already exists, else
94                                             evaluates from _descending */
95   //  void calculateReverseDescendingConnectivity(CONNECTIVITY *myConnectivity) ;
96
97   med_int*      getReverseNodalConnectivity           ()               ;
98   med_int*      getReverseNodalConnectivityIndex      ()               ;
99   med_int*      getReverseDescendingConnectivity      ()               ;
100   med_int*      getReverseDescendingConnectivityIndex ()               ;
101
102                                         /*! does nothing if already exists, else
103                                             evaluates _neighbourhood from _descending */
104   void calculateNeighbourhood(CONNECTIVITY &myConnectivity) ;
105
106 public:
107
108   friend class MED_MESH_RDONLY_DRIVER;
109   friend class MED_MESH_WRONLY_DRIVER;
110
111   CONNECTIVITY(medEntityMesh Entity=MED_CELL);
112   CONNECTIVITY(int numberOfTypes, medEntityMesh Entity=MED_CELL);
113   CONNECTIVITY(CONNECTIVITY & m);
114   ~CONNECTIVITY();
115
116   inline bool   existConnectivity     (medConnectivity connectivityType, medEntityMesh Entity) const ;
117   void          calculateConnectivity (medConnectivity connectivityType, medEntityMesh Entity) ;
118   void          updateFamily(vector<FAMILY*> myFamilies) ;
119
120   inline medEntityMesh        getEntity               ()                     const;
121   inline med_int              getNumberOfTypes        (medEntityMesh Entity) const;
122   inline medGeometryElement * getGeometricTypes       (medEntityMesh Entity) const;
123   medGeometryElement          getElementType(medEntityMesh Entity,int Number) const ;
124   inline int *                getGlobalNumberingIndex (medEntityMesh Entity) const ;
125
126   med_int *     getConnectivity      (medConnectivity ConnectivityType, medEntityMesh Entity,
127                                       medGeometryElement Type) ;
128   med_int *     getConnectivityIndex (medConnectivity ConnectivityType,medEntityMesh Entity) ;
129  
130   CELLMODEL &   getType              (medGeometryElement Type) const; 
131   CELLMODEL *   getCellsTypes        (medEntityMesh Entity) const; 
132  
133   med_int       getNumberOfNodesInType    (medGeometryElement Type)                                    const; 
134   med_int       getNumberOfSubCellInType  (medGeometryElement Type)                                    const; 
135   med_int       getNumberOf               (medEntityMesh Entity, medGeometryElement Type)              const;
136   med_int*      getValue                  (medConnectivity TypeConnectivity, medGeometryElement Type) ; 
137   med_int*      getValueIndex             (medConnectivity TypeConnectivity) ;
138
139   inline med_int* getReverseConnectivity     (medConnectivity ConnectivityType, medEntityMesh Entity=MED_CELL) ;
140   inline med_int* getReverseConnectivityIndex(medConnectivity ConnectivityType, medEntityMesh Entity=MED_CELL) ;
141
142   med_int*      getNeighbourhood()                                 const;
143
144 } ;
145 /*----------------------*/
146 /* Methodes Inline      */
147 /*----------------------*/
148
149 /*! Returns the  medEntityMesh */
150 inline medEntityMesh CONNECTIVITY::getEntity() const 
151
152   return _entity; 
153 }
154
155 /*!  Returns the number of different <medGeometryElement> types existing in the specified entity.
156
157      Note : Not implemented for MED_ALL_ENTITIES. */
158 inline med_int CONNECTIVITY::getNumberOfTypes(medEntityMesh Entity) const
159 {
160   MESSAGE("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
161   if (_entity==Entity)
162     return _numberOfTypes; 
163   else if (_constituent!=NULL)
164     return _constituent->getNumberOfTypes(Entity) ;
165   else
166     return 0 ; // because it is the right information (no need exception !
167   //throw MEDEXCEPTION("Entity not defined !") ;
168 }
169
170 /*!  Returns an array of all <med geometry elements> types existing in the mesh for the given medEntityMesh.
171
172      Note : Not implemented for MED_ALL_ENTITIES.  */
173 inline medGeometryElement* CONNECTIVITY::getGeometricTypes(medEntityMesh Entity) const 
174 {
175   if (_entity==Entity)
176     return _geometricTypes;
177   else if (_constituent!=NULL)
178     return _constituent->getGeometricTypes(Entity) ;
179   else
180     throw MEDEXCEPTION("Entity not defined !") ;
181 }
182
183 /*! A DOCUMENTER */
184 inline int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) const 
185 {
186   if (_entity==Entity)
187     return _count;
188   else if (_constituent!=NULL)
189     return _constituent->getGlobalNumberingIndex(Entity) ;
190   else
191     throw MEDEXCEPTION("Entity not defined !") ;
192 }
193
194 /*!  Returns true if a connectivity exists on elements of type "Entity" */
195 inline bool CONNECTIVITY::existConnectivity(medConnectivity ConnectivityType, medEntityMesh Entity) const
196 {
197   if (_entity==Entity) { 
198     MESSAGE("existConnectivity : _entity==Entity="<<Entity);
199     if ((ConnectivityType==MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL))
200       return true ;
201     if ((ConnectivityType==MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
202       return true ;
203   } else if (_constituent!=NULL)
204     return _constituent->existConnectivity(ConnectivityType,Entity) ;
205   return false ;
206 }
207
208 /*! 
209 Return an array which contain CELLMODEL foreach element type present in connectivity for given medEntityMesh (similar as getGeometricTypes)
210
211 Throw an execption if the given entity is not defined or if the array is not defined.
212 */
213 inline CELLMODEL * CONNECTIVITY::getCellsTypes(medEntityMesh Entity) const
214 {
215   if (Entity == _entity)
216     if (_type!=NULL)
217       return _type ;
218     else
219       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : CELLMODEL array is not defined !");
220   else
221     if (_constituent != NULL)
222       return _constituent->getCellsTypes(Entity) ;
223     else
224       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
225 }
226
227 inline med_int* CONNECTIVITY::getReverseConnectivity(medConnectivity ConnectivityType, medEntityMesh Entity) 
228 {
229   if(_entity==Entity)
230     if (ConnectivityType==MED_NODAL)
231       return getReverseNodalConnectivity() ;
232     else if (ConnectivityType==MED_DESCENDING)
233       return getReverseDescendingConnectivity() ;
234     else
235       throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
236
237   // other entity :
238   if (NULL==_constituent)
239     calculateDescendingConnectivity() ;
240   return _constituent->getReverseConnectivity(ConnectivityType,Entity) ;
241 }
242
243 inline med_int* CONNECTIVITY::getReverseConnectivityIndex(medConnectivity ConnectivityType, medEntityMesh Entity) 
244 {
245   if(_entity==Entity)
246     if (ConnectivityType==MED_NODAL)
247       return getReverseNodalConnectivityIndex() ;
248     else if (ConnectivityType==MED_DESCENDING)
249       return getReverseDescendingConnectivityIndex() ;
250     else
251       throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
252   
253   // other entity :
254   if (NULL==_constituent)
255     calculateDescendingConnectivity() ;
256   return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity) ;
257 }
258
259 #endif /* CONNECTIVITY_HXX */
260