1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
30 #ifndef MEDMEM_Grid_HeaderFile
31 #define MEDMEM_Grid_HeaderFile
35 #include "MEDMEM_Mesh.hxx"
37 // class containing structured mesh data
40 class MEDMEM_EXPORT GRID: public GMESH
43 //-----------------------//
45 //-----------------------//
47 // 1. grid type: MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED
48 MED_EN::med_grid_type _gridType;
50 // 2. node coordinates for MED_BODY_FITTED and coordinate names, units etc.
51 COORDINATE* _coordinate;
53 // 2.1. i component array: X for MED_CARTESIAN, R for MED_POLAR
56 // 2.2. j component array: Y for MED_CARTESIAN, Theta for MED_POLAR
59 // 2.3. k component array: Z for both MED_CARTESIAN and MED_POLAR
63 // 3. is _gridType a true value or just a default one
64 bool _is_default_gridType;
66 // Suppose a READ Driver to do the following except filling _[ijk]Array's
67 // 1) fill GMESH fields:
70 // * _numberOfNodesFamilies, _numberOfCellsFamilies, ect
71 // * _familyNode, _familyCell, etc
72 // * _numberOfNodesGroups, _numberOfCellsGroups, etc
73 // * _groupNode, _groupCell, etc
75 // 2) create _coordinate without setting _coordinate->_coordinate and set:
76 // * _coordinate->_coordinateSystem
77 // * _coordinate->_coordinateName
78 // * _coordinate->_coordinateUnit
80 virtual bool isEmpty() const;
84 //-----------------------//
86 //-----------------------//
89 GRID(const MED_EN::med_grid_type type);
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);
99 virtual bool deepCompare(const GMESH& other) const;
100 virtual void printMySelf(std::ostream &os) const;
102 virtual const MESH * convertInMESH() const;
104 virtual int getMeshDimension() const;
105 virtual bool getIsAGrid() const;
106 virtual int getNumberOfNodes() const;
108 virtual std::string getCoordinatesSystem() const;
109 virtual const std::string * getCoordinatesNames() const;
110 virtual const std::string * getCoordinatesUnits() const;
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,
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);
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);
141 virtual vector< vector<double> > getBoundingBox() const;
144 // Specific GRID methods
145 //-----------------------//
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 )
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)
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
165 // 0 <= X < (getArrayLength( X_Axis )-1)
166 // 0 <= X < getArrayLength( NOT_X_Axis )
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
176 // 0 <= X < (getArrayLength( NOT_X_Axis )-1)
177 // 0 <= X < getArrayLength( X_Axis )
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
190 //-----------------------//
192 inline MED_EN::med_grid_type getGridType() const;
193 // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED
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
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)];
204 inline void setGridType(MED_EN::med_grid_type gridType);
207 friend class MED_MESH_RDONLY_DRIVER;
208 friend class MED_MESH_WRONLY_DRIVER;
209 friend class ENSIGHT_MESH_RDONLY_DRIVER;
213 //----------------------------------//
214 // Inline Methods Implementation
215 //----------------------------------//
217 inline MED_EN::med_grid_type GRID::getGridType() const
221 //=======================================================================
222 //function : getNodeNumber
224 //=======================================================================
226 inline int GRID::getNodeNumber(const int i, const int j, const int k) const
228 return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k;
231 //=======================================================================
232 //function : getCellNumber
234 //=======================================================================
236 inline int GRID::getCellNumber(const int i, const int j, const int k) const
238 return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k;
241 //=======================================================================
242 //function : setGridType
243 //purpose : set the _gridType field od the class GRID
244 //=======================================================================
246 inline void GRID::setGridType(MED_EN::med_grid_type gridType)
248 _gridType = gridType;