Salome HOME
initial project version
[tools/solverlab.git] / CDMATH / mesh / inc / Mesh.hxx
1 /*
2  * mesh.hxx
3  *
4  *  Created on: 22 janv. 2012
5  *      Authors: CDMAT
6  */
7
8 #ifndef MESH_HXX_
9 #define MESH_HXX_
10
11 /**
12  * Mesh class is defined by
13  * - case 1: file name of mesh med file (general unstructured)
14  * - case 2: 1D cartesian, xmin and xmax and number of cells
15  * - case 3: 2D cartesian, xmin, xmax, ymin and ymax and numbers of cells in x direction and y direction
16  * - case 4: 3D cartesian, xmin, xmax, ymin, ymax, zmin and zmax and numbers of cells in x direction, y direction and z direction
17  * - case 5: 2D regular triangular mesh
18  * - case 6: 3D regular hexahedral mesh
19  * - case 7: 1D unstructured
20  */
21
22 namespace MEDCoupling
23 {
24 class MEDFileUMesh;
25 class MEDCouplingMesh;
26 class MEDCouplingIMesh;
27 class MEDCouplingUMesh;
28 class DataArrayInt32;
29 }
30 namespace ParaMEDMEM
31 {
32 class DataArrayInt;
33 }
34 #include <MCAuto.hxx>
35 #include "NormalizedGeometricTypes"
36
37 class Node;
38 class Cell;
39 class Face;
40
41 typedef enum
42   {
43     CELLS = 0,
44     NODES = 1,
45     FACES = 2,
46   } EntityType;
47
48 #include <vector>
49 #include <string>
50 #include <map>
51
52 class Mesh
53 {
54
55 public: //----------------------------------------------------------------
56         /**
57          * \brief default constructor
58          */
59         Mesh ( void ) ;
60
61         /**
62          * \brief constructor with data to load a general unstructured mesh
63          * @param filename name of mesh file
64          * @param meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
65          */
66         Mesh ( const std::string filename, int meshLevel=0 ) ;
67
68         /**
69          * \brief constructor with data for a regular 1D grid 
70          * @param xmin : minimum x
71          * @param xmax : maximum x
72          * @param nx : Number of cells in x direction
73          */
74         Mesh( double xmin, double xmax, int nx, std::string meshName="MESH1D_Regular_Grid" ) ;
75
76         /**
77          * \brief constructor with data for an unstructured 1D mesh
78          * @param points : abscissas of the mesh nodes
79          */
80         Mesh( std::vector<double> points, std::string meshName="MESH1D_unstructured" ) ;
81
82         /**
83          * \brief constructor with data for a regular 2D grid 
84          * @param xmin : minimum x
85          * @param xmax : maximum x
86          * @param ymin : minimum y
87          * @param ymax : maximum y
88          * @param nx : Number of cells in x direction
89          * @param ny : Number of cells in y direction
90      * @param split_to_triangles_policy : each rectangle will be split into 2 triangles with orientation of the cut depending if value is 0 or 1
91          */
92         Mesh( double xmin, double xmax, int nx, double ymin, double ymax, int ny, int split_to_triangles_policy=-1, std::string meshName="MESH2D_Regular_Rectangle_Grid") ;
93
94         /**
95          * \brief constructor with data for a regular 3D grid 
96          * @param xmin : minimum x
97          * @param xmax : maximum x
98          * @param ymin : minimum y
99          * @param ymax : maximum y
100          * @param zmin : minimum z
101          * @param zmax : maximum z
102          * @param nx : Number of cells in x direction
103          * @param ny : Number of cells in y direction
104          * @param nz : Number of cells in z direction
105      * @param split_to_tetrahedra_policy : each cuboid will be split into 5 tetrahedra if value is INTERP_KERNEL::PLANAR_FACE_5 or 6 tetrahedra if the value is INTERP_KERNEL::PLANAR_FACE_6
106          */
107         Mesh( double xmin, double xmax, int nx, double ymin, double ymax, int ny, double zmin, double zmax, int nz, int split_to_tetrahedra_policy=-1, std::string meshName="MESH3D_Regular_Cuboid_Grid") ;
108
109         Mesh( const MEDCoupling::MEDCouplingIMesh* mesh ) ;
110         Mesh( const MEDCoupling::MEDCouplingUMesh* mesh ) ;
111
112         /**
113          * \brief constructor with data
114          * @param filename : file name of mesh med file
115          * @param meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
116          */
117         void readMeshMed( const std::string filename, int meshLevel=0 ) ;
118
119         /**
120          * \brief constructor by copy
121          * @param mesh : The Mesh object to be copied
122          */
123         Mesh ( const Mesh & mesh ) ;
124
125         /**
126          * \brief destructor
127          */
128         ~Mesh( void ) ;
129
130         /**
131          * \brief return mesh name
132          * @return _name
133          */
134         std::string getName( void ) const ;
135
136         /**
137          * \brief return Space dimension
138          * @return _spaceDim
139          */
140         int getSpaceDimension( void ) const ;
141
142         /**
143          * \brief Mesh dimension
144          * @return _meshDim
145          */
146         int getMeshDimension( void ) const ;
147
148         /**
149          * \brief return The nodes in this mesh
150          * @return _nodes
151          */
152         Node* getNodes ( void ) const ;
153
154         /**
155          * \brief return The cells in this mesh
156          * @return _vertices
157          */
158         Cell* getCells ( void ) const ;
159
160         /**
161          * \brief return the faces in this mesh
162          * @return _vertices
163          */
164         Face* getFaces ( void ) const ;
165
166         /**
167          * \brief return the number of nodes in this mesh
168          * @return _numberOfNodes
169          */
170         int getNumberOfNodes ( void )  const ;
171
172         /**
173          * \brief return the number of faces in this mesh
174          * @return _numberOfFaces
175          */
176         int getNumberOfFaces ( void )  const ;
177
178         /**
179          * \brief return the number of cells in this mesh
180          * @return _numberOfCells
181          */
182         int getNumberOfCells ( void )  const ;
183
184         /**
185          * \brief return the number of edges in this mesh
186          * @return _numberOfEdges
187          */
188         int getNumberOfEdges ( void )  const ;
189
190         /**
191          * \brief return the cell i in this mesh
192          * @return _cells[i]
193          */
194         Cell& getCell ( int i )  const ;
195
196         /**
197          * return The face i in this mesh
198          * @return _faces[i]
199          */
200         Face& getFace ( int i )  const ;
201
202         /**
203          * \brief return The node i in this mesh
204          * @return _nodes[i]
205          */
206         Node& getNode ( int i )  const ;
207
208         /**
209          * \brief return number of cell in x direction (structured mesh)
210          * @return _nX
211          */
212         int getNx( void )  const ;
213
214         /**
215          * \brief return number of cell in y direction (structured mesh)
216          * @return _nY
217          */
218         int getNy( void )  const ;
219
220         /**
221          * \brief return number of cell in z direction (structured mesh)
222          * @return _nZ
223          */
224         int getNz( void )  const ;
225
226         double getXMin( void )  const ;
227
228         double getXMax( void )  const ;
229
230         double getYMin( void )  const ;
231
232         double getYMax( void )  const ;
233
234         double getZMin( void )  const ;
235
236         double getZMax( void )  const ;
237
238         std::vector<double> getDXYZ() const ;// for structured meshes
239
240         std::vector<int> getCellGridStructure() const;// for structured meshes
241
242         /**
243          * \brief surcharge operator =
244          * @param mesh : The Mesh object to be copied
245          */
246         const Mesh& operator= ( const Mesh& mesh ) ;
247
248         /**
249          * \brief return the mesh MEDCoupling
250          * @return _mesh
251          */
252         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> getMEDCouplingMesh ( void )  const ;
253
254         /**
255          * \brief computes the skin surrounding the mesh
256          */
257         Mesh getBoundaryMesh ( void )  const ;
258
259         /**
260          * \brief return the list of face group names
261          * return _faceGroupNames
262          */
263         std::vector<std::string> getNameOfFaceGroups( void )  const ;
264
265         /**
266          * \brief return the list of node group names
267          * return _nodeGroupNames
268          */
269         std::vector<std::string> getNameOfNodeGroups( void )  const ;
270
271         /**
272          * \brief return the list of face groups
273          * @return _faceGroups
274          */
275         std::vector<MEDCoupling::MEDCouplingUMesh *> getFaceGroups( void )  const ;
276
277         /**
278          * \brief return the list of node groups
279          * @return _nodeGroups
280          */
281         std::vector<MEDCoupling::DataArrayInt32 *> getNodeGroups( void )  const ;
282
283     /*
284      * Functions to extract boundary nodes and faces Ids
285      */
286      /**
287       *  \brief return the list of boundary faces Ids
288       *  @return _boundaryFaceIds
289       */
290     std::vector< int > getBoundaryFaceIds() const;
291     /**
292      * \brief list of boundary nodes Ids
293      * @return _boundaryNodeIds
294      */
295     std::vector< int > getBoundaryNodeIds() const;
296     /*
297      * Functions to extract group nodes and faces ids
298      */
299      /** 
300       * @return list of face group Ids
301       */
302     std::vector< int > getGroupFaceIds(std::string groupName) const;
303     /**
304      * @return list of node group Ids
305      * */
306     std::vector< int > getGroupNodeIds(std::string groupName) const;
307  
308         /**
309          * \brief write mesh in the VTK format
310          */
311         void writeVTK ( const std::string fileName ) const ;
312
313         /**
314          * \brief write mesh in the MED format
315          */
316         void writeMED ( const std::string fileName ) const ;
317
318         void setGroupAtPlan(double value, int direction, double eps, std::string groupName) ;
319
320         void setGroupAtFaceByCoords(double x, double y, double z, double eps, std::string groupName) ;
321
322         void setFaceGroupByIds(std::vector< int > faceIds, std::string groupName) ;
323
324         void setNodeGroupByIds(std::vector< int > nodeIds, std::string groupName) ;
325
326         /*
327      * Functions to manage periodic boundary condition in square/cubic geometries 
328      */
329     void setPeriodicFaces(bool check_groups= false, bool use_central_inversion=false) ;
330     int getIndexFacePeriodic(int indexFace, bool check_groups= false, bool use_central_inversion=false);
331     void setBoundaryNodesFromFaces();
332     std::map<int,int> getIndexFacePeriodic( void ) const;
333     bool isIndexFacePeriodicSet() const ;
334     
335         bool isBorderNode(int nodeid) const ;
336         bool isBorderFace(int faceid) const ;
337         
338         bool isTriangular() const ;
339         bool isTetrahedral() const ;
340         bool isQuadrangular() const ;
341         bool isHexahedral() const ;
342     bool isStructured() const ;
343     std::vector< std::string > getElementTypesNames() const ;
344         /**
345          * \brief Compute the minimum value over all cells of the ratio cell perimeter/cell vaolume
346          */
347     double minRatioVolSurf();
348     
349         /**
350          * \brief Compute the maximum number of neighbours around an element (cells around a cell or nodes around a node)
351          */
352     int getMaxNbNeighbours(EntityType type) const;
353     
354 private: //----------------------------------------------------------------
355
356         MEDCoupling::MEDCouplingUMesh*  setMesh( void ) ;
357
358         void setGroups( const MEDCoupling::MEDFileUMesh* medmesh, MEDCoupling::MEDCouplingUMesh*  mu) ;
359
360     std::string _name;
361     
362         /**
363          * \brief Space dimension
364          */
365         int _spaceDim ;
366
367         /**
368          * \brief Mesh dimension
369          */
370         int _meshDim ;
371     
372     /*
373      * Structured mesh parameters
374      */
375
376     bool _isStructured;
377     
378         double _xMin;
379
380         double _xMax;
381
382         double _yMin;
383
384         double _yMax;
385
386         double _zMin;
387
388         double _zMax;
389
390         std::vector<int> _nxyz;
391
392         std::vector<double> _dxyz;
393         /*
394          * The nodes in this mesh.
395          */
396         Node *_nodes;
397
398         /*
399          * The number of nodes in this mesh.
400          */
401         int _numberOfNodes;
402
403         /*
404          * The faces in this mesh.
405          */
406         Face *_faces;
407
408         /*
409          * The numbers of faces in this mesh.
410          */
411         int _numberOfFaces;
412
413         /*
414          * The cells in this mesh.
415          */
416         Cell *_cells;
417
418         /*
419          * The number of cells in this mesh.
420          */
421         int _numberOfCells;
422
423         /*
424          * The number of edges in this mesh.
425          */
426         int _numberOfEdges;//Useful to deduce the number of non zero coefficients in the finite element matrix 
427
428         /*
429          * The names of face groups.
430          */
431         std::vector<std::string> _faceGroupNames;
432
433         /*
434          * The names of node groups.
435          */
436         std::vector<std::string> _nodeGroupNames;
437
438         /*
439          * The list of face groups.
440          */
441         std::vector<MEDCoupling::MEDCouplingUMesh *> _faceGroups;
442         /*
443          * The list of node groups.
444          */
445         std::vector<MEDCoupling::DataArrayInt32 *> _nodeGroups;
446         /*
447          * The mesh MEDCoupling
448          */
449         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> _mesh;
450
451         std::vector< INTERP_KERNEL::NormalizedCellType > _eltsTypes;//List of cell types contained in the mesh
452         std::vector< std::string > _eltsTypesNames;//List of cell types contained in the mesh
453     std::vector< INTERP_KERNEL::NormalizedCellType > getElementTypes() const;    
454     
455     /*
456      * Tools to manage periodic boundary conditions in square/cube geometries
457      */
458      bool _indexFacePeriodicSet;
459      std::map<int,int> _indexFacePeriodicMap;
460     
461     /* List of boundary faces*/
462     std::vector< int > _boundaryFaceIds;
463     /* List of boundary nodes*/
464     std::vector< int > _boundaryNodeIds;
465     /* Boundary mesh */
466     const MEDCoupling::MEDCouplingUMesh * _boundaryMesh;
467 };
468
469 #endif /* MESH_HXX_ */