4 * Created on: 22 janv. 2012
11 #include "MEDCouplingUMesh.hxx"
12 #include "MEDCouplingIMesh.hxx"
13 #include "MEDCouplingFieldDouble.hxx"
16 * Mesh class is defined by
17 * - case 1: file name of mesh med file (general unstructured)
18 * - case 2: 1D cartesian, xmin and xmax and number of cells
19 * - case 3: 2D cartesian, xmin, xmax, ymin and ymax and numbers of cells in x direction and y direction
20 * - case 4: 3D cartesian, xmin, xmax, ymin, ymax, zmin and zmax and numbers of cells in x direction, y direction and z direction
21 * - case 5: 2D regular triangular mesh
22 * - case 6: 3D regular hexahedral mesh
23 * - case 7: 1D unstructured
29 class MEDCouplingMesh;
30 class MEDCouplingIMesh;
31 class MEDCouplingUMesh;
32 class DataArrayIdType;
36 class DataArrayIdType;
39 #include "NormalizedGeometricTypes"
59 public: //----------------------------------------------------------------
61 * \brief default constructor
66 * \brief constructor with data to load a general unstructured mesh
67 * @param filename name of mesh file
68 * @param meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
70 Mesh ( const std::string filename, int meshLevel=0 ) ;
73 * \brief constructor with data for a regular 1D grid
74 * @param xmin : minimum x
75 * @param xmax : maximum x
76 * @param nx : Number of cells in x direction
78 Mesh( double xmin, double xmax, int nx, std::string meshName="MESH1D_Regular_Grid" ) ;
81 * \brief constructor with data for an unstructured 1D mesh
82 * @param points : abscissas of the mesh nodes
84 Mesh( std::vector<double> points, std::string meshName="MESH1D_unstructured" ) ;
87 * \brief constructor with data for a regular 2D grid
88 * @param xmin : minimum x
89 * @param xmax : maximum x
90 * @param ymin : minimum y
91 * @param ymax : maximum y
92 * @param nx : Number of cells in x direction
93 * @param ny : Number of cells in y direction
94 * @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
96 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") ;
99 * \brief constructor with data for a regular 3D grid
100 * @param xmin : minimum x
101 * @param xmax : maximum x
102 * @param ymin : minimum y
103 * @param ymax : maximum y
104 * @param zmin : minimum z
105 * @param zmax : maximum z
106 * @param nx : Number of cells in x direction
107 * @param ny : Number of cells in y direction
108 * @param nz : Number of cells in z direction
109 * @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
111 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") ;
113 Mesh( const MEDCoupling::MEDCouplingIMesh* mesh ) ;
114 Mesh( const MEDCoupling::MEDCouplingUMesh* mesh ) ;
117 * \brief constructor with data
118 * @param filename : file name of mesh med file
119 * @param meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
121 void readMeshMed( const std::string filename, int meshLevel=0 ) ;
124 * \brief constructor by copy
125 * @param mesh : The Mesh object to be copied
127 Mesh ( const Mesh & mesh ) ;
135 * \brief return mesh name
138 std::string getName( void ) const ;
141 * \brief return Space dimension
144 int getSpaceDimension( void ) const ;
147 * \brief Mesh dimension
150 int getMeshDimension( void ) const ;
153 * \brief return The nodes in this mesh
156 Node* getNodes ( void ) const ;
159 * \brief return The cells in this mesh
162 Cell* getCells ( void ) const ;
165 * \brief return the faces in this mesh
168 Face* getFaces ( void ) const ;
171 * \brief return the number of nodes in this mesh
172 * @return _numberOfNodes
174 int getNumberOfNodes ( void ) const ;
177 * \brief return the number of faces in this mesh
178 * @return _numberOfFaces
180 int getNumberOfFaces ( void ) const ;
183 * \brief return the number of cells in this mesh
184 * @return _numberOfCells
186 int getNumberOfCells ( void ) const ;
189 * \brief return the number of edges in this mesh
190 * @return _numberOfEdges
192 int getNumberOfEdges ( void ) const ;
195 * \brief return the cell i in this mesh
198 Cell& getCell ( int i ) const ;
201 * return The face i in this mesh
204 Face& getFace ( int i ) const ;
207 * \brief return The node i in this mesh
210 Node& getNode ( int i ) const ;
213 * \brief return number of cell in x direction (structured mesh)
216 int getNx( void ) const ;
219 * \brief return number of cell in y direction (structured mesh)
222 int getNy( void ) const ;
225 * \brief return number of cell in z direction (structured mesh)
228 int getNz( void ) const ;
230 double getXMin( void ) const ;
232 double getXMax( void ) const ;
234 double getYMin( void ) const ;
236 double getYMax( void ) const ;
238 double getZMin( void ) const ;
240 double getZMax( void ) const ;
242 std::vector<double> getDXYZ() const ;// for structured meshes
244 std::vector<mcIdType> getCellGridStructure() const;// for structured meshes
247 * \brief surcharge operator =
248 * @param mesh : The Mesh object to be copied
250 const Mesh& operator= ( const Mesh& mesh ) ;
253 * \brief return the mesh MEDCoupling
256 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> getMEDCouplingMesh ( void ) const ;
259 * \brief computes the skin surrounding the mesh
261 Mesh getBoundaryMesh ( void ) const ;
264 * \brief return the list of face group names
265 * return _faceGroupNames
267 std::vector<std::string> getNameOfFaceGroups( void ) const ;
270 * \brief return the list of node group names
271 * return _nodeGroupNames
273 std::vector<std::string> getNameOfNodeGroups( void ) const ;
276 * \brief return the list of face groups
277 * @return _faceGroups
279 std::vector<MEDCoupling::MEDCouplingUMesh *> getFaceGroups( void ) const ;
282 * \brief return the list of node groups
283 * @return _nodeGroups
285 std::vector<MEDCoupling::DataArrayIdType *> getNodeGroups( void ) const ;
288 * Functions to extract boundary nodes and faces Ids
291 * \brief return the list of boundary faces Ids
292 * @return _boundaryFaceIds
294 std::vector< int > getBoundaryFaceIds() const;
296 * \brief list of boundary nodes Ids
297 * @return _boundaryNodeIds
299 std::vector< int > getBoundaryNodeIds() const;
301 * Functions to extract group nodes and faces ids
304 * @return list of face group Ids
306 std::vector< int > getGroupFaceIds(std::string groupName) const;
308 * @return list of node group Ids
310 std::vector< int > getGroupNodeIds(std::string groupName) const;
313 * \brief write mesh in the VTK format
315 void writeVTK ( const std::string fileName ) const ;
318 * \brief write mesh in the MED format
320 void writeMED ( const std::string fileName ) const ;
322 void setGroupAtPlan(double value, int direction, double eps, std::string groupName) ;
324 void setGroupAtFaceByCoords(double x, double y, double z, double eps, std::string groupName) ;
326 void setFaceGroupByIds(std::vector< int > faceIds, std::string groupName) ;
328 void setNodeGroupByIds(std::vector< int > nodeIds, std::string groupName) ;
331 * Functions to manage periodic boundary condition in square/cubic geometries
333 void setPeriodicFaces(bool check_groups= false, bool use_central_inversion=false) ;
334 int getIndexFacePeriodic(int indexFace, bool check_groups= false, bool use_central_inversion=false);
335 void setBoundaryNodesFromFaces();
336 std::map<int,int> getIndexFacePeriodic( void ) const;
337 bool isIndexFacePeriodicSet() const ;
339 bool isBorderNode(int nodeid) const ;
340 bool isBorderFace(int faceid) const ;
342 bool isTriangular() const ;
343 bool isTetrahedral() const ;
344 bool isQuadrangular() const ;
345 bool isHexahedral() const ;
346 bool isStructured() const ;
348 // epsilon used in mesh comparisons
349 double getComparisonEpsilon() const {return _epsilon;};
350 void setComparisonEpsilon(double epsilon){ _epsilon=epsilon;};
351 // Quick comparison of two meshes to see if they are identical with high probability (three cells are compared)
352 void checkFastEquivalWith( Mesh m) const { return getMEDCouplingMesh()->checkFastEquivalWith(m.getMEDCouplingMesh(),1e-6);};
353 // Deep comparison of two meshes to see if they are identical Except for their names and units
354 bool isEqualWithoutConsideringStr( Mesh m) const { return getMEDCouplingMesh()->isEqualWithoutConsideringStr(m.getMEDCouplingMesh(),1e-6);};
356 std::vector< std::string > getElementTypesNames() const ;
358 * \brief Compute the minimum value over all cells of the ratio cell perimeter/cell vaolume
360 double minRatioVolSurf() const;
363 * \brief Compute the maximum number of neighbours around an element (cells around a cell or nodes around a node)
365 int getMaxNbNeighbours(EntityType type) const;
367 private: //----------------------------------------------------------------
369 MEDCoupling::MEDCouplingUMesh* setMesh( void ) ;
371 void setGroups( const MEDCoupling::MEDFileUMesh* medmesh, MEDCoupling::MEDCouplingUMesh* mu) ;
376 * \brief Space dimension
381 * \brief Mesh dimension
386 * Structured mesh parameters
403 std::vector<mcIdType> _nxyz;
405 std::vector<double> _dxyz;
407 * The nodes in this mesh.
412 * The number of nodes in this mesh.
417 * The faces in this mesh.
422 * The numbers of faces in this mesh.
427 * The cells in this mesh.
432 * The number of cells in this mesh.
437 * The number of edges in this mesh.
439 int _numberOfEdges;//Useful to deduce the number of non zero coefficients in the finite element matrix
442 * The names of face groups.
444 std::vector<std::string> _faceGroupNames;
447 * The names of node groups.
449 std::vector<std::string> _nodeGroupNames;
452 * The list of face groups.
454 std::vector<MEDCoupling::MEDCouplingUMesh *> _faceGroups;
456 * The list of node groups.
458 std::vector<MEDCoupling::DataArrayIdType *> _nodeGroups;
460 * The mesh MEDCoupling
462 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> _mesh;
464 std::vector< INTERP_KERNEL::NormalizedCellType > _eltsTypes;//List of cell types contained in the mesh
465 std::vector< std::string > _eltsTypesNames;//List of cell types contained in the mesh
466 std::vector< INTERP_KERNEL::NormalizedCellType > getElementTypes() const;
469 * Tools to manage periodic boundary conditions in square/cube geometries
471 bool _indexFacePeriodicSet;
472 std::map<int,int> _indexFacePeriodicMap;
474 /* List of boundary faces*/
475 std::vector< int > _boundaryFaceIds;
476 /* List of boundary nodes*/
477 std::vector< int > _boundaryNodeIds;
479 const MEDCoupling::MEDCouplingUMesh * _boundaryMesh;
484 #endif /* MESH_HXX_ */