Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEM / MEDMEM_Grid.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File      : MEDMEM_Grid.hxx
24 // Created   : Wed Dec 18 08:35:26 2002
25 // Descr     : class containing structured mesh data
26 // Author    : Edward AGAPOV (eap)
27 // Project   : SALOME Pro
28 // Module    : MED 
29 //
30 #ifndef MEDMEM_Grid_HeaderFile
31 #define MEDMEM_Grid_HeaderFile
32
33 #include <MEDMEM.hxx>
34
35 #include "MEDMEM_Mesh.hxx"
36
37 // class containing structured mesh data
38
39 namespace MEDMEM {
40 class MEDMEM_EXPORT GRID: public GMESH
41 {
42  protected:
43   //-----------------------//
44   //   Fields
45   //-----------------------//
46   
47   // 1. grid type: MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED
48   MED_EN::med_grid_type     _gridType;
49   
50   // 2. node coordinates for MED_BODY_FITTED and coordinate names, units etc.
51   COORDINATE*       _coordinate;
52
53   // 2.1. i component array: X for MED_CARTESIAN, R for MED_POLAR
54   int               _iArrayLength;
55   double*           _iArray;
56   // 2.2. j component array: Y for MED_CARTESIAN, Theta for MED_POLAR
57   int               _jArrayLength;
58   double*           _jArray;
59   // 2.3. k component array: Z for both MED_CARTESIAN and MED_POLAR
60   int               _kArrayLength;
61   double*           _kArray;
62
63   // 3. is _gridType a true value or just a default one
64   bool              _is_default_gridType;
65
66   // Suppose a READ Driver to do the following except filling _[ijk]Array's
67   // 1) fill GMESH fields:
68   //    * _name
69   //    * _spaceDimension
70   //    * _numberOfNodesFamilies, _numberOfCellsFamilies, ect
71   //    * _familyNode, _familyCell, etc
72   //    * _numberOfNodesGroups, _numberOfCellsGroups, etc
73   //    * _groupNode, _groupCell, etc
74   //    * _
75   // 2) create _coordinate without setting _coordinate->_coordinate and set: 
76   //    * _coordinate->_coordinateSystem
77   //    * _coordinate->_coordinateName
78   //    * _coordinate->_coordinateUnit
79  protected:
80   virtual bool isEmpty() const;
81
82
83  public:
84   //-----------------------//
85   //   Public Methods
86   //-----------------------//
87
88   GRID();
89   GRID(const MED_EN::med_grid_type type);
90   GRID(const GRID &m);
91   GRID( driverTypes driverType, const string & fileName,const string & meshName);
92   GRID(const std::vector<std::vector<double> >& xyz_array,
93        const std::vector<std::string>&          coord_name,
94        const std::vector<std::string>&          coord_unit,
95        const MED_EN::med_grid_type              type=MED_EN::MED_CARTESIAN);
96   GRID & operator=(const GRID &m);
97   virtual ~GRID();
98   virtual void init();
99   virtual bool deepCompare(const GMESH& other) const;
100   virtual void printMySelf(std::ostream &os) const;
101
102   virtual const MESH *        convertInMESH() const;
103
104   virtual int                 getMeshDimension() const;
105   virtual bool                getIsAGrid() const;
106   virtual int                 getNumberOfNodes() const;
107
108   virtual std::string         getCoordinatesSystem() const;
109   virtual const std::string * getCoordinatesNames() const;
110   virtual const std::string * getCoordinatesUnits() const;
111
112   virtual int                 getNumberOfTypes(MED_EN::medEntityMesh Entity) const;
113   virtual int                 getNumberOfElements(MED_EN::medEntityMesh      Entity,
114                                                   MED_EN::medGeometryElement Type) const;
115   virtual const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
116   virtual MED_EN::medGeometryElement getElementType(MED_EN::medEntityMesh Entity,
117                                                     int                   Number) const;
118
119   virtual SUPPORT *                  getBoundaryElements(MED_EN::medEntityMesh Entity) const
120                                                 throw (MEDEXCEPTION);
121   virtual SUPPORT *                  getSkin(const SUPPORT * Support3D)
122                                                 throw (MEDEXCEPTION);
123   virtual SUPPORT *buildSupportOnNodeFromElementList(const std::list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
124   virtual void     fillSupportOnNodeFromElementList(const std::list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION);
125
126   virtual FIELD<double>* getVolume (const SUPPORT * Support, bool isAbs = true) const
127                                 throw (MEDEXCEPTION);
128                                 // Support must be on 3D elements
129   virtual FIELD<double>* getArea (const SUPPORT * Support) const
130                                 throw (MEDEXCEPTION);
131                                 // Support must be on 2D elements
132   virtual FIELD<double>* getLength (const SUPPORT * Support) const
133                                 throw (MEDEXCEPTION);
134                                 // Support must be on 1D elements
135   virtual FIELD<double>* getNormal (const SUPPORT * Support) const
136                                 throw (MEDEXCEPTION);
137                                 // Support must be on 2D elements
138   virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const
139                                 throw (MEDEXCEPTION);
140   
141   virtual vector< vector<double> >   getBoundingBox() const;
142
143
144   // Specific GRID methods
145   //-----------------------//
146
147   inline int getNodeNumber(const int i, const int j=0, const int k=0) const;
148   // return a NODE number by its position in the grid.
149   // WARNING: be carefull, there is no check that i,j,k are within a good range
150   // A good range is: 0 <= X < getArrayLength( X_Axis )
151
152   inline int getCellNumber(const int i, const int j=0, const int k=0) const ;
153   // return a CELL number by its position in the grid.
154   // WARNING: be carefull, there is no check that i,j,k are within a good range
155   // A good range is: 0 <= X < (getArrayLength( X_Axis )-1)
156
157   int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ;
158   // return an EDGE number by its position in the grid.
159   // Axis [1,2,3] means one of directions: along i, j or k.
160   // It selects an edge of ones having same (i,j,k):
161   //  * an EDGE going along given Axis.
162   // Exception for Axis out of range or when there is no edges in the grid (1D)
163   // WARNING: be carefull, there is no check that i,j,k are within a good range
164   // A good range is:
165   // 0 <= X < (getArrayLength( X_Axis )-1)
166   // 0 <= X < getArrayLength( NOT_X_Axis )
167
168   int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ;
169   // return a FACE number by its position in the grid.
170   // Axis [1,2,3] means one of directions: along i, j or k.
171   // It selects a face of ones having same (i,j,k):
172   //  * a FACE which is normal to given Axis
173   // Exception for Axis out of range or when there is no faces in the grid (1,2D)
174   // WARNING: be carefull, there is no check that i,j,k are within a good range
175   // A good range is:
176   // 0 <= X < (getArrayLength( NOT_X_Axis )-1)
177   // 0 <= X < getArrayLength( X_Axis )
178   
179
180   void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
181   void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
182   void getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
183   void getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
184   // return position (i,j,k) of an entity #Number
185   // Axis: [1,2,3], see get*Number for details
186   // Exception for Number out of range
187
188
189   //  Access to fields
190   //-----------------------//
191
192   inline MED_EN::med_grid_type getGridType() const;
193   // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED
194
195   int getArrayLength( const int Axis ) const throw (MEDEXCEPTION);
196   // return array length. Axis = [1,2,3] meaning [i,j,k],
197   // exception if Axis out of [1-3] range
198
199   const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION) ;
200   // return i-th array component. Axis = [1,2,3] meaning [i,j,k],
201   // exception if Axis out of [1 - 3] range
202   // exception if i is out of range [0 - (getArrayLength(Axis)-1)];
203
204   inline void setGridType(MED_EN::med_grid_type gridType);
205
206
207   friend class MED_MESH_RDONLY_DRIVER;
208   friend class MED_MESH_WRONLY_DRIVER;
209   friend class ENSIGHT_MESH_RDONLY_DRIVER;
210 };
211
212
213   //----------------------------------//
214   //   Inline Methods Implementation
215   //----------------------------------//
216
217 inline MED_EN::med_grid_type GRID::getGridType() const
218 {
219   return _gridType;
220 }
221 //=======================================================================
222 //function : getNodeNumber
223 //purpose  : 
224 //=======================================================================
225
226 inline int GRID::getNodeNumber(const int i, const int j, const int k) const
227 {
228   return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k;
229 }
230
231 //=======================================================================
232 //function : getCellNumber
233 //purpose  : 
234 //=======================================================================
235
236 inline int GRID::getCellNumber(const int i, const int j, const int k) const
237 {
238   return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k;
239 }
240
241 //=======================================================================
242 //function : setGridType
243 //purpose : set the _gridType field od the class GRID
244 //=======================================================================
245
246 inline void GRID::setGridType(MED_EN::med_grid_type gridType)
247 {
248   _gridType = gridType;
249 }
250
251 }
252
253 #endif