Salome HOME
Fix for problem: SIGSEGV appears if to select group after opening "Edit Group" dialog...
[modules/smesh.git] / src / SMESH_SWIG / ex15_cyl2geometry.py
1 # CEA/LGLS 2004-2005, Francis KLOSS (OCC)
2 # =======================================
3
4 from geompy import *
5
6 import smesh
7
8 # Geometrie
9 # =========
10
11 # Construire avec des hexahedres une piece faite de 2 cylindres de diametre different
12 # et dont les axes se coupent orthogonalement, puis mailler.
13
14 # Valeurs
15 # -------
16
17 cx = 0
18 cy = 0
19 cz = 0
20
21 g_rayon   = 100.0
22 g_hauteur = 500
23
24 p_rayon   =  50.0
25 p_hauteur = 500
26
27 g_trim = 1000
28
29 # Gros cylindre
30 # -------------
31
32 cpd = []
33
34 g_base = MakeVertex(cx, cy, cz)
35 g_dir  = MakeVectorDXDYDZ(0, 0, 1)
36 t_hauteur = p_rayon+10.0
37
38 g_cyl = MakeCylinder(g_base, g_dir, g_rayon, g_hauteur)
39
40 g_coupe   = MakeVectorDXDYDZ(1, 0, 0)
41
42 g_tools = []
43 g_tools.append(MakePlane(MakeVertex(cx+t_hauteur, cy, cz), g_coupe, g_trim))
44 g_tools.append(MakePlane(MakeVertex(cx-t_hauteur, cy, cz), g_coupe, g_trim))
45
46 g_partie = MakePartition([g_cyl], g_tools, [], [], ShapeType["SOLID"])
47 g_bas, g_centre, g_haut = SubShapeAllSorted(g_partie, ShapeType["SOLID"])
48
49 # Partie basse du gros cylindre
50 # -----------------------------
51
52 b_hauteur = 10
53 b_base    = 20
54
55 b_boite = MakeBox(cx-t_hauteur, cy-b_base, cz,  cx-t_hauteur-b_hauteur, cy+b_base, cz+g_hauteur)
56 cpd.append(b_boite)
57
58 b_cyl = MakeCut(g_bas, b_boite)
59
60 b_tools = []
61 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy+b_base, cz), MakeVectorDXDYDZ( 1, 1, 0), g_trim))
62 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy-b_base, cz), MakeVectorDXDYDZ(-1, 1, 0), g_trim))
63
64 b_partie = MakePartition([b_cyl], b_tools, [], [], ShapeType["SOLID"])
65 b_element = SubShapeAll(b_partie, ShapeType["SOLID"])
66 cpd = cpd + b_element
67
68 # Partie haute du gros cylindre
69 # -----------------------------
70
71 h_plan = MakePlane(g_base, g_coupe, g_trim)
72
73 cpd.append(MakeMirrorByPlane(b_boite, h_plan))
74
75 for h in b_element:
76     h_symetrie = MakeMirrorByPlane(h, h_plan)
77     cpd.append(h_symetrie)
78
79 # Petit cylindre
80 # --------------
81
82 z_arete = p_rayon/2
83 x_arete = z_arete*t_hauteur*2/g_hauteur
84
85 px = cx-x_arete
86 py = cy-1.5*g_rayon
87 pz = cz+g_hauteur/2
88
89 p_base = MakeVertex(cx, py, pz)
90 p_dir  = MakeVectorDXDYDZ(0, 1, 0)
91 p_cyl  = MakeCylinder(p_base, p_dir, p_rayon, p_hauteur)
92
93 p_boite = MakeBox(px, py, pz-z_arete,  cx+x_arete, py+p_hauteur, pz+z_arete)
94
95 # Partie interieure du petit cylindre
96 # -----------------------------------
97
98 i_cyl   = MakeCommon(p_cyl, g_cyl)
99 i_tuyau = MakeCut(i_cyl, p_boite)
100 i_boite = MakeCommon(p_boite, g_cyl)
101
102 # Partie exterieure du petit cylindre
103 # -----------------------------------
104
105 e_cyl0 = MakeCut(p_cyl, g_cyl)
106 e_cyl  = SubShapeAllSorted(e_cyl0, ShapeType["SOLID"])
107
108 e_tuyau = MakeCut(e_cyl[1], p_boite)
109
110 e_boite0 = MakeCut(p_boite, g_cyl)
111 e_boite  = SubShapeAllSorted(e_boite0, ShapeType["SOLID"])
112
113 cpd.append(e_boite[1])
114
115 # Partie centrale du gros cylindre
116 # --------------------------------
117
118 c_cyl = MakeCut(g_centre, p_cyl)
119
120 # Partitionner
121 # ------------
122
123 p_tools = []
124 p_tools.append(MakePlane(MakeVertex(px, py, pz-z_arete), MakeVectorDXDYDZ(-z_arete, 0, x_arete), g_trim))
125 p_tools.append(MakePlane(MakeVertex(px, py, pz+z_arete), MakeVectorDXDYDZ( z_arete, 0, x_arete), g_trim))
126
127 p_partie = MakePartition([e_tuyau], p_tools, [], [], ShapeType["SOLID"])
128 p_element = SubShapeAll(p_partie, ShapeType["SOLID"])
129 cpd = cpd + p_element
130
131 q_partie = MakePartition([i_tuyau, c_cyl], p_tools, [], [], ShapeType["SOLID"])
132 q_element = SubShapeAll(q_partie, ShapeType["SOLID"])
133
134 q_element = q_element + [i_boite]
135
136 q_tools = []
137 q_tools.append(MakePlane(MakeVertex(cx, cy-b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
138 q_tools.append(MakePlane(MakeVertex(cx, cy+b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
139
140 r_element = []
141 for e in q_element:
142     r_partie = MakePartition([e], q_tools, [], [], ShapeType["SOLID"])
143     r_element = r_element + SubShapeAll(r_partie, ShapeType["SOLID"])
144
145 cpd = cpd + r_element
146
147 # Compound
148 # --------
149
150 piece = RemoveExtraEdges(MakeCompound(cpd))
151
152 # Ajouter la piece dans l'etude
153 # -----------------------------
154
155 piece_id = addToStudy(piece, "ex15_cyl2geometry")
156
157 # Meshing
158 # =======
159
160 # Create a hexahedral mesh
161 # ------------------------
162
163 hexa = smesh.Mesh(piece, "ex15_cyl2geometry:hexa")
164
165 algo = hexa.Segment()
166 algo.NumberOfSegments(12)
167
168 hexa.Quadrangle()
169
170 hexa.Hexahedron()
171
172 # Mesh calculus
173 # -------------
174
175 hexa.Compute()