2 Meshing a 2D geometry with polygons
3 -----------------------------------
8 In this example we propose to build a mesh on a 2D geometry. We first create triangles in the center of the geometry and then hexagons around them. The result will be saved in a med file, and then visualized with the SMESH module of Salome.
10 .. image:: images/Mesh_polygons2D.jpg
13 Beginning of implementation
14 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 To implement this exercice we use the python language script and import the MEDCoupling and MEDLoader parts of the MED module::
18 from MEDCoupling import *
19 from MEDLoader import *
23 Then we must instantiate a meshing object::
25 mesh=MEDCouplingUMesh.New()
26 mesh.setMeshDimension(2)
27 mesh.allocateCells(numberOfCells)
28 mesh.setName("MaFleur")
31 You must define 2 variables for space dimension and total number of nodes::
38 You must define the coordinates of the nodes of the central hexagon::
40 X = [1.,0.5,-0.5,-1.,-0.5,0.5]
41 Y = [0.,sqrt(3.)/2.,sqrt(3.)/2.,0.,-sqrt(3.)/2.,-sqrt(3.)/2.]
43 Definition of nodes coordinates
44 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46 Define the coordinates of the origin and the nodes of the 2D central polygon::
50 coordinates.append(0.)
51 coordinates.append(0.)
55 coordinates.append(X[i])
56 coordinates.append(Y[i])
58 Define the coordinates of the extra nodes of the hexagons around the central hexagon::
67 myCoords=DataArrayDouble.New()
68 myCoords.setValues(coordinates,numberOfNodes,2)
69 mesh.setCoords(myCoords)
72 Definition of triangles connectivity
73 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 For each triangle of the mesh, you have to give its connectivity: the list of the nodes which belong to the triangles::
79 connectivity.append(0)
80 connectivity.append(...)
81 connectivity.append(...)
83 mesh.insertNextCell(NORM_TRI3,3,connectivity[3*i:3*(i+1)])
87 Definition of hexagons connectivity
88 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90 For each hexagon of the mesh, you have to give its connectivity: the list of the nodes which belong to the hexagons::
95 connectivity.append(...)
97 mesh.insertNextCell(NORM_POLYGON,6,connectivity[6*i:6*(i+1)])
99 mesh.checkConsistencyLight()
101 Saving the mesh in a med file
102 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104 You have to create a med file with the MED driver::
106 medFileName = "MEDCoupling_Fleur.med"
107 MEDLoader.WriteUMesh(medFileName,mesh,True)
109 Visualize the mesh with SMESH module of Salome
110 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112 Launch Salome platform, then select SMESH module and import your MED file. First You can see the number of elements of your mesh. For that, select your mesh in the object browser, set select Mesh menu and "Advanced Mesh Info" option. Verify the number of triangles and the number of hexagons. To visualize your mesh: click right bottom on your mesh and select "Show" option.
117 :ref:`python_testMEDCoupling2D_solution`