Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MEDMEM / MEDMEM_Grid.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : MEDMEM_Grid.hxx
8 //  Author : Edward AGAPOV (eap)
9 //  Module : MED
10 //  $Header$
11
12 #ifndef MEDMEM_Grid_HeaderFile
13 #define MEDMEM_Grid_HeaderFile
14
15 #include "MEDMEM_Mesh.hxx"
16
17 // class containing structured mesh data
18
19 class GRID: public MESH
20 {
21  protected:
22   //-----------------------//
23   //   Fields
24   //-----------------------//
25   
26   // 1. grid type: MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED
27   med_grid_type     _gridType;
28   
29   // 2. node coordinates
30   // For MED_BODY_FITTED MESH::_coordinate is used
31   
32   // 2.1. i component array: X for MED_CARTESIAN, R for MED_POLAR
33   int               _iArrayLength;
34   double*           _iArray;
35   // 2.2. j component array: Y for MED_CARTESIAN, Theta for MED_POLAR
36   int               _jArrayLength;
37   double*           _jArray;
38   // 2.3. k component array: Z for both MED_CARTESIAN and MED_POLAR
39   int               _kArrayLength;
40   double*           _kArray;
41
42   // 3. flags to know that _coordinates and _connectivity of MESH are filled
43   bool              _is_coordinates_filled;
44   bool              _is_connectivity_filled;
45
46   //-----------------------//
47   //   Protected Methods
48   //-----------------------//
49
50   CONNECTIVITY * makeConnectivity (const medEntityMesh      Entity,
51                                    const medGeometryElement Geometry,
52                                    const int                NbEntities,
53                                    const int                NbNodes,
54                                    int *                    NodeNumbers);
55   // creates nodal connectivity
56
57   
58   // Suppose a READ Driver to do the following except filling _[ijk]Array's
59   // 1) fill MESH fields:
60   //    * _name
61   //    * _spaceDimension
62   //    * _meshDimension
63   //    * _numberOfNodesFamilies, _numberOfCellsFamilies, ect
64   //    * _familyNode, _familyCell, etc
65   //    * _numberOfNodesGroups, _numberOfCellsGroups, etc
66   //    * _groupNode, _groupCell, etc
67   //    * _
68   // 2) create MESH::_coordinate without setting _coordinate->_coordinate and set: 
69   //    * _coordinate->_coordinateSystem
70   //    * _coordinate->_coordinateName
71   //    * _coordinate->_coordinateUnit
72   
73
74  public:
75   //-----------------------//
76   //   Methods
77   //-----------------------//
78
79   GRID();
80   GRID(const med_grid_type type);
81   GRID(const GRID &m);
82   GRID( driverTypes driverType, const string & fileName="",const string & meshName="");
83   GRID & operator=(const GRID &m);
84   virtual ~GRID();
85   virtual void init();
86
87   void fillCoordinates();
88   void fillConnectivity();
89   // fill _coordinates and _connectivity of MESH if not yet done
90
91   inline void makeUnstructured();
92   // fill both coordinates and connectivity of MESH
93
94   void fillMeshAfterRead();
95   // fill some fields (_numberOfNodes, etc.) after reading
96
97   void writeUnstructured(int index=0, const string & driverName = "");
98   // write a Grid as an Unstructured mesh
99
100   //   API Methods returning fields of MESH that are filled while reading.
101   //   So they need not to be redefined
102
103 //   string                getName() const;
104 //   int                   getSpaceDimension();
105 //   int                   getMeshDimension();
106 //   string                getCoordinatesSystem();
107 //   int                   getNumberOfNodes();
108 //   string *              getCoordinatesNames();
109 //   string *              getCoordinatesUnits();
110 //   int                   getNumberOfFamilies(medEntityMesh Entity);
111 //   vector<FAMILY*>       getFamilies(medEntityMesh Entity);
112 //   FAMILY*               getFamily(medEntityMesh Entity,int i);
113 //   int                   getNumberOfGroups(medEntityMesh Entity);
114 //   vector<GROUP*>        getGroups(medEntityMesh Entity);
115 //   GROUP*                getGroup(medEntityMesh Entity,int i);
116
117
118 // Since a MESH itself knows if it is a GRID, it calls fillConnectivity()
119 // or fillCoordinates() whenever needed. So no redifinition of the following methods
120
121 //   const double *        getCoordinates(medModeSwitch Mode);
122 //   COORDINATE *          getCoordinateptr();
123 //   const double          getCoordinate(int Number,int Axis);
124 //   int                   getNumberOfTypes(medEntityMesh Entity);
125 //   medGeometryElement *  getTypes(medEntityMesh Entity);
126 //   CELLMODEL *           getCellsTypes(medEntityMesh Entity);
127 //   medGeometryElement    getElementType(medEntityMesh Entity,int Number) ;
128 //   int                   getNumberOfElements(medEntityMesh Entity,medGeometryElement Type);
129 //   int                   getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity) ;
130 //   int *                 getGlobalNumberingIndex(medEntityMesh Entity);
131 //   int *                 getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity, medGeometryElement Type);
132 //   int *                 getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity);
133 //   int *                 getReverseConnectivity(medConnectivity ConnectivityType);
134 //   int *                 getReverseConnectivityIndex(medConnectivity ConnectivityType);
135 //   bool                  existConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity);
136 //   void                  calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity);
137 //   FIELD<double>*        getVolume(const SUPPORT * Support) throw (MEDEXCEPTION) ;
138 //   FIELD<double>*        getArea(const SUPPORT * Support) throw (MEDEXCEPTION) ;
139 //   FIELD<double>*        getLength(const SUPPORT * Support) throw (MEDEXCEPTION) ;
140 //   FIELD<double>*        getNormal(const SUPPORT * Support) throw (MEDEXCEPTION) ;
141 //   FIELD<double>*        getBarycenter(const SUPPORT * Support) throw (MEDEXCEPTION) ;
142
143
144   // Specific GRID methods
145
146   inline int getNodeNumber(const int i, const int j=0, const int k=0);
147   // return a NODE number by its position in the grid.
148   // WARNING: be carefull, there is no check that i,j,k are within a good range
149   // A good range is: 0 <= X < getArrayLength( X_Axis )
150   inline int getCellNumber(const int i, const int j=0, const int k=0) ;
151   // return a CELL number by its position in the grid.
152   // WARNING: be carefull, there is no check that i,j,k are within a good range
153   // A good range is: 0 <= X < (getArrayLength( X_Axis )-1)
154
155   int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) throw (MEDEXCEPTION) ;
156   // return an EDGE number by its position in the grid.
157   // Axis [1,2,3] means one of directions: along i, j or k.
158   // It selects an edge of ones having same (i,j,k):
159   //  * an EDGE going along given Axis.
160   // Exception for Axis out of range or when there is no edges in the grid (1D)
161   // WARNING: be carefull, there is no check that i,j,k are within a good range
162   // A good range is:
163   // 0 <= X < (getArrayLength( X_Axis )-1)
164   // 0 <= X < getArrayLength( NOT_X_Axis )
165
166   int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) throw (MEDEXCEPTION) ;
167   // return a FACE number by its position in the grid.
168   // Axis [1,2,3] means one of directions: along i, j or k.
169   // It selects a face of ones having same (i,j,k):
170   //  * a FACE which is normal to given Axis
171   // Exception for Axis out of range or when there is no faces in the grid (1,2D)
172   // WARNING: be carefull, there is no check that i,j,k are within a good range
173   // A good range is:
174   // 0 <= X < (getArrayLength( NOT_X_Axis )-1)
175   // 0 <= X < getArrayLength( X_Axis )
176   
177
178   void getNodePosition(const int Number, int& i, int& j, int& k) throw (MEDEXCEPTION) ;
179   void getCellPosition(const int Number, int& i, int& j, int& k) throw (MEDEXCEPTION) ;
180   void getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) throw (MEDEXCEPTION) ;
181   void getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) throw (MEDEXCEPTION) ;
182   // return position (i,j,k) of an entity #Number
183   // Axis: [1,2,3], see get*Number for details
184   // Exception for Number out of range
185
186
187   //  Access to fields
188
189   inline med_grid_type getGridType() const;
190   // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED
191
192   int getArrayLength( const int Axis ) throw (MEDEXCEPTION);
193   // return array length. Axis = [1,2,3] meaning [i,j,k],
194   // exception if Axis out of [1-3] range
195
196   const double getArrayValue (const int Axis, const int i) throw (MEDEXCEPTION) ;
197   // return i-th array component. Axis = [1,2,3] meaning [i,j,k],
198   // exception if Axis out of [1 - 3] range
199   // exception if i is out of range [0 - (getArrayLength(Axis)-1)];
200
201   //  Setting fields
202
203   inline void setGridType(med_grid_type gridType);
204
205   friend class MED_MESH_RDONLY_DRIVER;
206   friend class MED_MESH_WRONLY_DRIVER;
207
208 };
209
210
211   //----------------------------------//
212   //   Inline Methods Implementation
213   //----------------------------------//
214
215 inline med_grid_type GRID::getGridType() const
216 {
217   return _gridType;
218 }
219 //=======================================================================
220 //function : getNodeNumber
221 //purpose  : 
222 //=======================================================================
223
224 inline int GRID::getNodeNumber(const int i, const int j, const int k)
225 {
226   return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k;
227 }
228
229 //=======================================================================
230 //function : getCellNumber
231 //purpose  : 
232 //=======================================================================
233
234 inline int GRID::getCellNumber(const int i, const int j, const int k)
235 {
236   return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k;
237 }
238
239 //=======================================================================
240 //function : makeUnstructured
241 //purpose : fill coordinates and connectivity of MESH
242 //=======================================================================
243
244 inline void GRID::makeUnstructured()
245 {
246   fillCoordinates();
247   fillConnectivity();
248 }
249
250 //=======================================================================
251 //function : setGridType
252 //purpose : set the _gridType field od the class GRID
253 //=======================================================================
254
255 inline void GRID::setGridType(med_grid_type gridType)
256 {
257   _gridType = gridType;
258 }
259
260 #endif