Salome HOME
Merge branch 'V8_5_asterstudy'
[modules/smesh.git] / doc / salome / examples / modifying_meshes_ex10.py
1 # Add Polyhedron
2
3
4 import salome
5 salome.salome_init()
6
7 from salome.smesh import smeshBuilder
8 smesh =  smeshBuilder.New(salome.myStudy)
9
10 import math
11
12 # create an empty mesh structure
13 mesh = smesh.Mesh()  
14
15 # Create nodes for 12-hedron with pentagonal faces
16 al = 2 * math.pi / 5.0
17 cosal = math.cos(al)
18 aa = 13
19 rr = aa / (2.0 * math.sin(al/2.0))
20 dr = 2.0 * rr * cosal
21 r1 = rr + dr
22 dh = rr * math.sqrt(2.0 * (1.0 - cosal * (1.0 + 2.0 * cosal)))
23 hh = 2.0 * dh - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh
24
25 dd = [] # top
26 cc = [] # below top
27 bb = [] # above bottom
28 aa = [] # bottom
29
30 for i in range(5):
31     cos_bot = math.cos(i*al)
32     sin_bot = math.sin(i*al)
33
34     cos_top = math.cos(i*al + al/2.0)
35     sin_top = math.sin(i*al + al/2.0)
36
37     nd = mesh.AddNode(rr * cos_top, rr * sin_top, hh     ) # top
38     nc = mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # below top
39     nb = mesh.AddNode(r1 * cos_bot, r1 * sin_bot,      dh) # above bottom
40     na = mesh.AddNode(rr * cos_bot, rr * sin_bot,       0) # bottom
41     dd.append(nd) # top
42     cc.append(nc) # below top
43     bb.append(nb) # above bottom
44     aa.append(na) # bottom
45     pass
46
47 # Create a polyhedral volume (12-hedron with pentagonal faces)
48 mesh.AddPolyhedralVolume([dd[0], dd[1], dd[2], dd[3], dd[4],  # top
49                           dd[0], cc[0], bb[1], cc[1], dd[1],  # -
50                           dd[1], cc[1], bb[2], cc[2], dd[2],  # -
51                           dd[2], cc[2], bb[3], cc[3], dd[3],  # - below top
52                           dd[3], cc[3], bb[4], cc[4], dd[4],  # -
53                           dd[4], cc[4], bb[0], cc[0], dd[0],  # -
54                           aa[4], bb[4], cc[4], bb[0], aa[0],  # .
55                           aa[3], bb[3], cc[3], bb[4], aa[4],  # .
56                           aa[2], bb[2], cc[2], bb[3], aa[3],  # . above bottom
57                           aa[1], bb[1], cc[1], bb[2], aa[2],  # .
58                           aa[0], bb[0], cc[0], bb[1], aa[1],  # .
59                           aa[0], aa[1], aa[2], aa[3], aa[4]], # bottom
60                          [5,5,5,5,5,5,5,5,5,5,5,5])
61
62 if salome.sg.hasDesktop():
63     salome.sg.updateObjBrowser(True)