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