]> SALOME platform Git repositories - tools/medcoupling.git/blob - doc/tutorial/atestMEDCouplingPoly.rst
Salome HOME
Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/medcoupling
[tools/medcoupling.git] / doc / tutorial / atestMEDCouplingPoly.rst
1
2 .. _python_testMEDCoupling2D_solution:
3
4 2D polygons meshing
5 ~~~~~~~~~~~~~~~~~~~
6
7 ::
8
9         from MEDCoupling import *
10         from MEDLoader import *
11
12         from math import *
13
14         numberOfNodes = 25
15         numberOfCells = 12
16
17         print "1 ********************"
18         spaceDimension = 2
19
20         # Coordinates of central polygon
21         X = [1.,0.5,-0.5,-1.,-0.5,0.5]
22         Y = [0.,sqrt(3.)/2.,sqrt(3.)/2.,0.,-sqrt(3.)/2.,-sqrt(3.)/2.]
23
24         coordinates = []
25         # origin
26         coordinates.append(0.)
27         coordinates.append(0.)
28
29         # central polygon
30         for i in range(6):
31                 coordinates.append(X[i])
32                 coordinates.append(Y[i])
33
34         # Coordinates of second couron
35         xc = 1.5
36         yc = - sqrt(3.)/2.
37         d = sqrt(xc*xc+yc*yc)
38         a30 = pi/6.0
39         a60 = pi/3.0
40
41         for i in range(6):
42                 angle = a30+a60*i
43                 xtmp = d*cos(angle)
44                 ytmp = d*sin(angle)
45                 start = (i-1)%6
46                 coordinates.append(xtmp+X[(i-1)%6])
47                 coordinates.append(ytmp+Y[(i-1)%6])
48                 coordinates.append(xtmp+X[i%6])
49                 coordinates.append(ytmp+Y[i%6])
50                 coordinates.append(xtmp+X[(i+1)%6])
51                 coordinates.append(ytmp+Y[(i+1)%6])
52
53         print "2 ********************"
54         # Creation of mesh
55         mesh=MEDCouplingUMesh.New()
56         mesh.setMeshDimension(2)
57         mesh.allocateCells(numberOfCells)
58         mesh.setName("MaFleur")
59
60         myCoords=DataArrayDouble.New()
61         myCoords.setValues(coordinates,numberOfNodes,2)
62         mesh.setCoords(myCoords)
63
64         print "3 ********************"
65         # Connectivity of triangular meshing
66         connectivity = []
67         for i in range(6):
68                 connectivity.append(0)
69                 connectivity.append(i%6+1)
70                 connectivity.append((i+1)%6+1)
71         for i in range(6):
72                 mesh.insertNextCell(NORM_TRI3,3,connectivity[3*i:3*(i+1)])
73                 pass
74
75         print "4 ********************"
76         # Connectivity of hexagons
77         connectivity = []
78         for i in range(6):
79                 start = i%6+1
80                 connectivity.append(start)
81                 connectivity.append(start+2*(i+3))
82                 connectivity.append(start+2*(i+3)+1)
83                 connectivity.append(start+2*(i+3)+2)
84                 if i==5:
85                         connectivity.append(7)
86                 else:
87                         connectivity.append(start+2*(i+3)+3)
88                 connectivity.append((i+1)%6+1)
89         for i in range(6):
90                 mesh.insertNextCell(NORM_POLYGON,6,connectivity[6*i:6*(i+1)])
91                 pass
92
93         print "5 ********************"
94         mesh.checkConsistencyLight()
95
96         medFileName = "MEDCoupling_Fleur.med"
97         MEDLoader.WriteUMesh(medFileName,mesh,True)