4 * Created on: 22 janv. 2012
14 #include "NormalizedGeometricTypes"
16 #include "MEDCouplingUMesh.hxx"
19 * Mesh class is defined by
20 * - case 1: file name of mesh med file (general unstructured)
21 * - case 2: 1D cartesian, xmin and xmax and number of cells
22 * - case 3: 2D cartesian, xmin, xmax, ymin and ymax and numbers of cells in x direction and y direction
23 * - case 4: 3D cartesian, xmin, xmax, ymin, ymax, zmin and zmax and numbers of cells in x direction, y direction and z direction
24 * - case 5: 2D regular triangular mesh
25 * - case 6: 3D regular hexahedral mesh
26 * - case 7: 1D unstructured
33 class MEDCouplingMesh;
34 class DataArrayIdType;
38 class DataArrayIdType;
58 public: //----------------------------------------------------------------
60 * \brief default constructor
65 * \brief constructor with data from a medcoupling mesh
66 * @param medcoupling mesh
68 Mesh( MEDCoupling::MCAuto<const MEDCoupling::MEDCouplingMesh> mesh ) ;
71 * \brief constructor with data to load a general unstructured mesh
72 * @param filename name of mesh file
73 * @param meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
75 Mesh ( const std::string filename, const std::string & meshName="" , int meshLevel=0) ;
78 * \brief constructor with data for a regular 1D grid
79 * @param xmin : minimum x
80 * @param xmax : maximum x
81 * @param nx : Number of cells in x direction
83 Mesh( double xmin, double xmax, int nx, std::string meshName="MESH1D_Regular_Grid" ) ;
86 * \brief constructor with data for an unstructured 1D mesh
87 * @param points : abscissas of the mesh nodes
89 Mesh( std::vector<double> points, std::string meshName="MESH1D_unstructured" ) ;
92 * \brief constructor with data for a regular 2D grid
93 * @param xmin : minimum x
94 * @param xmax : maximum x
95 * @param ymin : minimum y
96 * @param ymax : maximum y
97 * @param nx : Number of cells in x direction
98 * @param ny : Number of cells in y direction
99 * @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
101 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") ;
104 * \brief constructor with data for a regular 3D grid
105 * @param xmin : minimum x
106 * @param xmax : maximum x
107 * @param ymin : minimum y
108 * @param ymax : maximum y
109 * @param zmin : minimum z
110 * @param zmax : maximum z
111 * @param nx : Number of cells in x direction
112 * @param ny : Number of cells in y direction
113 * @param nz : Number of cells in z direction
114 * @param split_to_tetrahedra_policy : each cuboid will be split into 5 tetrahedra if value is 0 or 6 tetrahedra if the value is 1
116 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") ;
119 * \brief constructor with data
120 * @param filename : file name of mesh med file
121 * @param meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
123 void readMeshMed( const std::string filename, const std::string & meshName="" , int meshLevel=0) ;
126 * \brief constructor by copy
127 * @param mesh : The Mesh object to be copied
129 Mesh ( const Mesh & mesh ) ;
137 * \brief return mesh name
140 std::string getName( void ) const ;
143 * \brief return Space dimension
146 int getSpaceDimension( void ) const ;
149 * \brief return Mesh dimension
152 int getMeshDimension( void ) const ;
155 * \brief return the number of nodes in this mesh
156 * @return _numberOfNodes
158 int getNumberOfNodes ( void ) const ;
161 * \brief return the number of faces in this mesh
162 * @return _numberOfFaces
164 int getNumberOfFaces ( void ) const ;
167 * \brief return the number of cells in this mesh
168 * @return _numberOfCells
170 int getNumberOfCells ( void ) const ;
173 * \brief return the number of edges in this mesh
174 * @return _numberOfEdges
176 int getNumberOfEdges ( void ) const ;
179 * \brief return the cell i in this mesh
182 Cell& getCell ( int i ) const ;
185 * return The face i in this mesh
188 Face& getFace ( int i ) const ;
191 * \brief return The node i in this mesh
194 Node& getNode ( int i ) const ;
197 * \brief return number of cell in x direction (structured mesh)
200 int getNx( void ) const ;
203 * \brief return number of cell in y direction (structured mesh)
206 int getNy( void ) const ;
209 * \brief return number of cell in z direction (structured mesh)
212 int getNz( void ) const ;
214 double getXMin( void ) const ;
216 double getXMax( void ) const ;
218 double getYMin( void ) const ;
220 double getYMax( void ) const ;
222 double getZMin( void ) const ;
224 double getZMax( void ) const ;
226 std::vector<mcIdType> getCellGridStructure() const;// for structured meshes
229 * \brief overload operator =
230 * @param mesh : The Mesh object to be copied
232 const Mesh& operator= ( const Mesh& mesh ) ;
235 * \brief return the mesh MEDCoupling
238 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> getMEDCouplingMesh ( void ) const ;
241 * \brief return the skin surrounding the mesh
243 Mesh getBoundaryMesh ( void ) const ;
246 * \brief return a group surrounding the mesh
248 Mesh getBoundaryGroupMesh ( std::string groupName, int nth_group_match = 0 ) const ;
251 * \brief return the list of face group names
252 * @return _faceGroupNames
254 std::vector<std::string> getNameOfFaceGroups( void ) const ;
257 * \brief return the list of node group names
258 * @return _nodeGroupNames
260 std::vector<std::string> getNameOfNodeGroups( void ) const ;
263 * \brief return the list of face groups
264 * @return _faceGroups
266 std::vector<MEDCoupling::MEDCouplingUMesh *> getFaceGroups( void ) const ;
269 * \brief return the list of node groups
270 * @return _nodeGroups
272 std::vector<MEDCoupling::DataArrayIdType *> getNodeGroups( void ) const ;
275 * \brief Functions to extract boundary nodes and faces Ids
278 * \brief return the list of boundary faces Ids
279 * @return _boundaryFaceIds
281 std::vector< int > getBoundaryFaceIds() const;
283 * \brief list of boundary nodes Ids
284 * @return _boundaryNodeIds
286 std::vector< int > getBoundaryNodeIds() const;
288 * \brief Functions to extract group nodes and faces ids
291 * @return list of face group Ids
293 std::vector< int > getFaceGroupIds(std::string groupName, bool isBoundaryGroup=true) const;
295 * @return list of node group Ids
297 std::vector< int > getNodeGroupIds(std::string groupName, bool isBoundaryGroup=true) const;
300 * \brief write mesh in the VTK format
302 void writeVTK ( const std::string fileName ) const ;
305 * \brief write mesh in the MED format
307 void writeMED ( const std::string fileName, bool fromScratch = true ) const;
309 void setGroupAtPlan(double value, int direction, double eps, std::string groupName, bool isBoundaryGroup=true) ;
311 void setGroupAtFaceByCoords(double x, double y, double z, double eps, std::string groupName, bool isBoundaryGroup=true) ;
313 void setGroupAtNodeByCoords(double x, double y, double z, double eps, std::string groupName, bool isBoundaryGroup=true) ;
315 void setFaceGroupByIds(std::vector< int > faceIds, std::string groupName) ;
317 void setNodeGroupByIds(std::vector< int > nodeIds, std::string groupName) ;
320 * Functions to manage periodic boundary condition in square/cubic geometries
322 void setPeriodicFaces(bool check_groups= false, bool use_central_inversion=false) ;
323 int getIndexFacePeriodic(int indexFace, bool check_groups= false, bool use_central_inversion=false);
324 void setBoundaryNodesFromFaces();
325 std::map<int,int> getIndexFacePeriodic( void ) const;
326 bool isIndexFacePeriodicSet() const ;
328 bool isBorderNode(int nodeid) const ;
329 bool isBorderFace(int faceid) const ;
331 bool isTriangular() const ;
332 bool isTetrahedral() const ;
333 bool isQuadrangular() const ;
334 bool isHexahedral() const ;
335 bool isStructured() const ;
337 // epsilon used in mesh comparisons
338 double getComparisonEpsilon() const {return _epsilon;};
339 void setComparisonEpsilon(double epsilon){ _epsilon=epsilon;};
340 // Quick comparison of two meshes to see if they are identical with high probability (three cells are compared)
341 void checkFastEquivalWith( Mesh m) const { return getMEDCouplingMesh()->checkFastEquivalWith(m.getMEDCouplingMesh(),_epsilon);};
342 // Deep comparison of two meshes to see if they are identical Except for their names and units
343 bool isEqualWithoutConsideringStr( Mesh m) const { return getMEDCouplingMesh()->isEqualWithoutConsideringStr(m.getMEDCouplingMesh(),_epsilon);};
345 std::vector< std::string > getElementTypesNames() const ;
347 * \brief Compute the minimum value over all cells of the ratio cell perimeter/cell volume
349 double minRatioVolSurf() const;
352 * \brief Compute the maximum number of neighbours around an element (cells around a cell or nodes around a node)
354 int getMaxNbNeighbours(EntityType type) const;
357 * \brief Delete the medcoupling mesh to save memory space
359 void deleteMEDCouplingMesh();
362 * \brief Returns true iff an unstructured mesh has been loaded
364 bool meshNotDeleted() const {return _meshNotDeleted;}
366 private: //----------------------------------------------------------------
368 MEDCoupling::MEDCouplingUMesh* setMesh( void ) ;
369 void setFaceGroups( const MEDCoupling::MEDFileUMesh* medmesh, MEDCoupling::MEDCouplingUMesh* mu) ;//Read all face groups
370 void setNodeGroups( const MEDCoupling::MEDFileMesh* medmesh, MEDCoupling::MEDCouplingUMesh* mu) ;//Read all node groups
371 void addNewFaceGroup( const MEDCoupling::MEDCouplingUMesh *m);//adds one face group in the vectors _faceGroups, _faceGroupNames and _faceGroupIds
374 * \brief The MEDCoupling mesh
376 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> _mesh;// This is either a MEDCouplingUMesh or a MEDCouplingStructuredMesh
378 bool _meshNotDeleted;
383 * \brief Space dimension
388 * \brief Mesh dimension
393 * \brief Signal a structured mesh
397 * \brief Number of cells in each direction (Structured meshes)
399 std::vector<mcIdType> _nxyz;
402 * \brief The nodes in this mesh.
404 std::shared_ptr<Node> _nodes;
407 * \brief The number of nodes in this mesh.
412 * \brief The faces in this mesh.
414 std::shared_ptr<Face> _faces;
417 * \brief The numbers of faces in this mesh.
422 * \brief The cells in this mesh.
424 std::shared_ptr<Cell> _cells;
427 * \brief The number of cells in this mesh.
432 * \brief return The nodes in this mesh
435 std::shared_ptr<Node> getNodes ( void ) const ;
438 * \brief return The cells in this mesh
441 std::shared_ptr<Cell> getCells ( void ) const ;
444 * \brief return the faces in this mesh
447 std::shared_ptr<Face> getFaces ( void ) const ;
450 * \brief The number of edges in this mesh.
452 int _numberOfEdges;//Useful to deduce the number of non zero coefficients in a finite element matrix
455 * \brief The names of face groups.
457 std::vector<std::string> _faceGroupNames;
460 * \brief The names of node groups.
462 std::vector<std::string> _nodeGroupNames;
465 * \brief The list of face groups.
467 std::vector<MEDCoupling::MEDCouplingUMesh *> _faceGroups;
469 * \brief The list of node groups.
471 std::vector<MEDCoupling::DataArrayIdType *> _nodeGroups;
474 * \brief The list of face id in each face groups.
476 std::vector< std::vector<int> > _faceGroupsIds;
479 * \brief The list of node id in each node groups.
481 std::vector< std::vector<int> > _nodeGroupsIds;
484 * \brief Elements types (SEG2, TRI3, QUAD4, HEXA6 ...)
486 std::vector< INTERP_KERNEL::NormalizedCellType > _eltsTypes;//List of cell types contained in the mesh
487 std::vector< std::string > _eltsTypesNames;//List of cell types contained in the mesh
488 std::vector< INTERP_KERNEL::NormalizedCellType > getElementTypes() const;
491 * \brief Tools to manage periodic boundary conditions in square/cube geometries
493 bool _indexFacePeriodicSet;
494 std::map<int,int> _indexFacePeriodicMap;
496 /* List of boundary faces*/
497 std::vector< int > _boundaryFaceIds;
498 /* List of boundary nodes*/
499 std::vector< int > _boundaryNodeIds;
501 MEDCoupling::MEDCouplingUMesh * _boundaryMesh;
506 #endif /* MESH_HXX_ */