1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : MEDMEM_Grid.hxx
8 // Author : Edward AGAPOV (eap)
12 #ifndef MEDMEM_Grid_HeaderFile
13 #define MEDMEM_Grid_HeaderFile
15 #include "MEDMEM_Mesh.hxx"
17 // class containing structured mesh data
19 class GRID: public MESH
22 //-----------------------//
24 //-----------------------//
26 // 1. grid type: MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED
27 med_grid_type _gridType;
29 // 2. node coordinates
30 // For MED_BODY_FITTED MESH::_coordinate is used
32 // 2.1. i component array: X for MED_CARTESIAN, R for MED_POLAR
35 // 2.2. j component array: Y for MED_CARTESIAN, Theta for MED_POLAR
38 // 2.3. k component array: Z for both MED_CARTESIAN and MED_POLAR
42 // 3. flags to know that _coordinates and _connectivity of MESH are filled
43 bool _is_coordinates_filled;
44 bool _is_connectivity_filled;
46 //-----------------------//
48 //-----------------------//
50 CONNECTIVITY * makeConnectivity (const medEntityMesh Entity,
51 const medGeometryElement Geometry,
55 // creates nodal connectivity
58 // Suppose a READ Driver to do the following except filling _[ijk]Array's
59 // 1) fill MESH fields:
63 // * _numberOfNodesFamilies, _numberOfCellsFamilies, ect
64 // * _familyNode, _familyCell, etc
65 // * _numberOfNodesGroups, _numberOfCellsGroups, etc
66 // * _groupNode, _groupCell, etc
68 // 2) create MESH::_coordinate without setting _coordinate->_coordinate and set:
69 // * _coordinate->_coordinateSystem
70 // * _coordinate->_coordinateName
71 // * _coordinate->_coordinateUnit
75 //-----------------------//
77 //-----------------------//
80 GRID(const med_grid_type type);
82 GRID( driverTypes driverType, const string & fileName="",const string & meshName="");
83 GRID & operator=(const GRID &m);
87 void fillCoordinates();
88 void fillConnectivity();
89 // fill _coordinates and _connectivity of MESH if not yet done
91 inline void makeUnstructured();
92 // fill both coordinates and connectivity of MESH
94 void fillMeshAfterRead();
95 // fill some fields (_numberOfNodes, etc.) after reading
97 void writeUnstructured(int index=0, const string & driverName = "");
98 // write a Grid as an Unstructured mesh
100 // API Methods returning fields of MESH that are filled while reading.
101 // So they need not to be redefined
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);
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
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) ;
144 // Specific GRID methods
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)
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
163 // 0 <= X < (getArrayLength( X_Axis )-1)
164 // 0 <= X < getArrayLength( NOT_X_Axis )
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
174 // 0 <= X < (getArrayLength( NOT_X_Axis )-1)
175 // 0 <= X < getArrayLength( X_Axis )
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
189 inline med_grid_type getGridType() const;
190 // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED
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
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)];
203 inline void setGridType(med_grid_type gridType);
205 friend class MED_MESH_RDONLY_DRIVER;
206 friend class MED_MESH_WRONLY_DRIVER;
211 //----------------------------------//
212 // Inline Methods Implementation
213 //----------------------------------//
215 inline med_grid_type GRID::getGridType() const
219 //=======================================================================
220 //function : getNodeNumber
222 //=======================================================================
224 inline int GRID::getNodeNumber(const int i, const int j, const int k)
226 return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k;
229 //=======================================================================
230 //function : getCellNumber
232 //=======================================================================
234 inline int GRID::getCellNumber(const int i, const int j, const int k)
236 return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k;
239 //=======================================================================
240 //function : makeUnstructured
241 //purpose : fill coordinates and connectivity of MESH
242 //=======================================================================
244 inline void GRID::makeUnstructured()
250 //=======================================================================
251 //function : setGridType
252 //purpose : set the _gridType field od the class GRID
253 //=======================================================================
255 inline void GRID::setGridType(med_grid_type gridType)
257 _gridType = gridType;