]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Connectivity.hxx
Salome HOME
Initialisation module MED_SRC de la base MED
[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                                         /*! does nothing if already exists, else
97                                             evaluates _neighbourhood from _descending */
98   void calculateNeighbourhood(CONNECTIVITY &myConnectivity) ;
99
100 public:
101
102   friend class MED_MESH_RDONLY_DRIVER;
103   friend class MED_MESH_WRONLY_DRIVER;
104
105   CONNECTIVITY(medEntityMesh Entity=MED_CELL);
106   CONNECTIVITY(int numberOfTypes, medEntityMesh Entity=MED_CELL);
107   ~CONNECTIVITY();
108
109   inline bool   existConnectivity     (medConnectivity connectivityType, medEntityMesh Entity) const ;
110   void          calculateConnectivity (medConnectivity connectivityType, medEntityMesh Entity) ;
111   void          updateFamily(vector<FAMILY*> myFamilies) ;
112
113   inline medEntityMesh        getEntity               ()                     const;
114   inline med_int              getNumberOfTypes        (medEntityMesh Entity) const;
115   inline medGeometryElement * getGeometricTypes       (medEntityMesh Entity) const;
116   medGeometryElement          getElementType(medEntityMesh Entity,int Number) const ;
117   inline int *                getGlobalNumberingIndex (medEntityMesh Entity) const ;
118
119   med_int *     getConnectivity      (medConnectivity ConnectivityType, medEntityMesh Entity,
120                                       medGeometryElement Type) ;
121   med_int *     getConnectivityIndex (medConnectivity ConnectivityType,medEntityMesh Entity) ;
122  
123   CELLMODEL &   getType              (medGeometryElement Type) const; 
124   CELLMODEL *   getCellsTypes        (medEntityMesh Entity) const; 
125  
126   med_int       getNumberOfNodesInType    (medGeometryElement Type)                                    const; 
127   med_int       getNumberOfSubCellInType  (medGeometryElement Type)                                    const; 
128   med_int       getNumberOf               (medEntityMesh Entity, medGeometryElement Type)               const;
129   med_int*      getValue                  (medConnectivity TypeConnectivity, medGeometryElement Type) ; 
130   med_int*      getValueIndex             (medConnectivity TypeConnectivity) ;
131   med_int*      getReverseNodalConnectivity           ()               ;
132   med_int*      getReverseNodalConnectivityIndex      ()               ;
133   med_int*      getReverseDescendingConnectivity      ()               ;
134   med_int*      getReverseDescendingConnectivityIndex ()               ;
135   med_int*      getNeighbourhood()                                 const;
136
137 } ;
138 /*----------------------*/
139 /* Methodes Inline      */
140 /*----------------------*/
141
142 /*! Returns the  medEntityMesh */
143 inline medEntityMesh CONNECTIVITY::getEntity() const 
144
145   return _entity; 
146 }
147
148 /*!  Returns the number of different <medGeometryElement> types existing in the specified entity.
149
150      Note : Not implemented for MED_ALL_ENTITIES. */
151 inline med_int CONNECTIVITY::getNumberOfTypes(medEntityMesh Entity) const
152 {
153   MESSAGE("CONNECTIVITY::getNumberOfTypes : Entity = "<<Entity<<", _entity = "<<_entity);
154   if (_entity==Entity)
155     return _numberOfTypes; 
156   else if (_constituent!=NULL)
157     return _constituent->getNumberOfTypes(Entity) ;
158   else
159     return 0 ; // because it is the right information (no need exception !
160   //throw MEDEXCEPTION("Entity not defined !") ;
161 }
162
163 /*!  Returns an array of all <med geometry elements> types existing in the mesh for the given medEntityMesh.
164
165      Note : Not implemented for MED_ALL_ENTITIES.  */
166 inline medGeometryElement* CONNECTIVITY::getGeometricTypes(medEntityMesh Entity) const 
167 {
168   if (_entity==Entity)
169     return _geometricTypes;
170   else if (_constituent!=NULL)
171     return _constituent->getGeometricTypes(Entity) ;
172   else
173     throw MEDEXCEPTION("Entity not defined !") ;
174 }
175
176 /*! A DOCUMENTER */
177 inline int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) const 
178 {
179   if (_entity==Entity)
180     return _count;
181   else if (_constituent!=NULL)
182     return _constituent->getGlobalNumberingIndex(Entity) ;
183   else
184     throw MEDEXCEPTION("Entity not defined !") ;
185 }
186
187 /*!  Returns true if a connectivity exists on elements of type "Entity" */
188 inline bool CONNECTIVITY::existConnectivity(medConnectivity ConnectivityType, medEntityMesh Entity) const
189 {
190   if (_entity==Entity) { 
191     MESSAGE("existConnectivity : _entity==Entity="<<Entity);
192     if ((ConnectivityType==MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL))
193       return true ;
194     if ((ConnectivityType==MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL))
195       return true ;
196   } else if (_constituent!=NULL)
197     return _constituent->existConnectivity(ConnectivityType,Entity) ;
198   return false ;
199 }
200
201 /*! 
202 Return an array which contain CELLMODEL foreach element type present in connectivity for given medEntityMesh (similar as getGeometricTypes)
203
204 Throw an execption if the given entity is not defined or if the array is not defined.
205 */
206 inline CELLMODEL * CONNECTIVITY::getCellsTypes(medEntityMesh Entity) const
207 {
208   if (Entity == _entity)
209     if (_type!=NULL)
210       return _type ;
211     else
212       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : CELLMODEL array is not defined !");
213   else
214     if (_constituent != NULL)
215       return _constituent->getCellsTypes(Entity) ;
216     else
217       throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : Not found Entity !");
218 }
219
220 #endif /* CONNECTIVITY_HXX */
221