Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / TEST_PY / recettes / tuyau.py
1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2024  CEA, EDF
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # Francis KLOSS : 2012 : CEA-Saclay, DEN, DM2S, SFME, LGLS, F-91191 Gif-sur-Yvette, France
22 # ========================================================================================
23
24 import hexablock
25 ### import geompy
26 geompy = hexablock.geompy
27
28 # Charger la geometrie
29 # ====================
30
31 nom = "tuyau"
32
33 geometrie = geompy.ImportBREP(nom+".brep")
34
35 # Selectionner des sous-parties de la geometrie
36 # ---------------------------------------------
37
38 aretes  = geompy.SubShapeAllSortedCentres    (geometrie, geompy.ShapeType["EDGE"])
39 edge_id = geompy.SubShapeAllSortedCentresIDs (geometrie, geompy.ShapeType["EDGE"])
40 faces   = geompy.SubShapeAllSortedCentres    (geometrie, geompy.ShapeType["FACE"])
41 face_id = geompy.SubShapeAllSortedCentresIDs (geometrie, geompy.ShapeType["FACE"])
42
43 subid_arc_int_bas  = 30
44 subid_arc_int_haut = 34
45 subid_arc_ext_bas  = 12
46 subid_arc_ext_haut = 16
47
48 arc_int_bas  = aretes[12]
49 arc_int_haut = aretes[13]
50 arc_ext_bas  = aretes[11]
51 arc_ext_haut = aretes[14]
52
53 subid_ell_int_bas  = 21
54 subid_ell_int_haut = 33
55 subid_ell_ext_bas  =  8
56 subid_ell_ext_haut = 15
57
58 ell_int_bas  = aretes[2]
59 ell_int_haut = aretes[3]
60 ell_ext_bas  = aretes[1]
61 ell_ext_haut = aretes[4]
62
63 subid_gen_int_avan = 26
64 subid_gen_int_arri = 28
65 subid_gen_ext_avan =  5
66 subid_gen_ext_arri = 10
67
68 gen_int_avan = aretes[8]
69 gen_int_arri = aretes[7]
70 gen_ext_avan = aretes[9]
71 gen_ext_arri = aretes[6]
72
73 subid_face_int_bas  = 24
74 subid_face_int_haut = 31
75 subid_face_ext_bas  =  3
76 subid_face_ext_haut = 13
77
78 face_int_bas  = faces[4]
79 face_int_haut = faces[5]
80 face_ext_bas  = faces[2]
81 face_ext_haut = faces[3]
82
83 # Construire le modele de bloc
84 # ============================
85
86 doc = hexablock.addDocument(nom)
87
88 # Definir le tuyau
89 # ----------------
90
91 origin = doc.addVertex(0, 0, 0)
92
93 direction = doc.addVector(1, 0, 0)
94
95 # Construire le modele de blocs du tuyau
96 # --------------------------------------
97
98 base = doc.addVector(0, 1, 0)
99
100 ###  tuyau = doc.addPipe(origin, direction, 1, 2, 10)
101 ###  modele = doc.makePipe(tuyau, base, 1, 4, 1)
102
103 modele = doc.makePipeUni (origin, base, direction, 1.0, 2.0, 360.0, 10.0, 1, 4, 1)
104
105 # Associer le modele de bloc a la geometrie
106 # =========================================
107
108 sh_tuyau = hexablock.addShape (doc, geometrie,nom)
109 doc.clearAssociation()
110
111 # Associer les cercles
112 # --------------------
113
114 cer_int_dep = modele.getVertexIJK(0, 0, 1)
115 cer_ext_dep = modele.getVertexIJK(1, 0, 1)
116
117 cer_int = []
118 cer_ext = []
119 for j in range(4):
120     a = modele.getEdgeJ(0, j, 1)
121     cer_int.append(a)
122
123     a = modele.getEdgeJ(1, j, 1)
124     cer_ext.append(a)
125
126 doc.associateClosedLine(cer_int_dep, cer_int, [sh_tuyau], [34,30], 1, True)
127 doc.associateClosedLine(cer_ext_dep, cer_ext, [sh_tuyau], [16,12], 1, True)
128
129 # Associer les ellipses
130 # ---------------------
131
132 ell_int_dep = modele.getVertexIJK(0, 0, 0)
133 ell_ext_dep = modele.getVertexIJK(1, 0, 0)
134
135 ell_int = []
136 ell_ext = []
137 for j in range(4):
138     a = modele.getEdgeJ(0, j, 0)
139     ell_int.append(a)
140
141     a = modele.getEdgeJ(1, j, 0)
142     ell_ext.append(a)
143
144 doc.associateClosedLine(ell_int_dep, ell_int, [sh_tuyau], [33,21], 1, True)
145 doc.associateClosedLine(ell_ext_dep, ell_ext, [sh_tuyau], [15, 8], 1, True)
146
147 # Associer les generatrices
148 # -------------------------
149
150 def generatrice(face):
151     n = 10
152     l = []
153     for i in range(0, n+1):
154         v = float(i) / n
155         s = geompy.MakeVertexOnSurface(face, 0.5, v)
156         l.append(s)
157
158     return geompy.MakeInterpol(l)
159
160 gen = []
161 gen_int_haut = generatrice(face_int_haut)
162 gen_ext_haut = generatrice(face_ext_haut)
163 gen_int_bas  = generatrice(face_int_bas )
164 gen_ext_bas  = generatrice(face_ext_bas )
165 gen.append(gen_int_haut)
166 gen.append(gen_ext_haut)
167 gen.append(gen_int_bas)
168 gen.append(gen_ext_bas)
169
170 generatrices = geompy.MakeCompound(gen)
171 sh_gen = hexablock.addShape (doc, generatrices, "generatrices")
172
173 modele.getEdgeK(0, 0, 0).addAssociation(sh_tuyau, 28, 0, 1)
174 modele.getEdgeK(1, 0, 0).addAssociation(sh_tuyau, 10, 0, 1)
175
176 modele.getEdgeK(0, 1, 0).addAssociation(sh_gen  ,  2, 0, 1)
177 modele.getEdgeK(1, 1, 0).addAssociation(sh_gen  ,  5, 0, 1)
178
179 modele.getEdgeK(0, 2, 0).addAssociation(sh_tuyau, 26, 0, 1)
180 modele.getEdgeK(1, 2, 0).addAssociation(sh_tuyau,  5, 0, 1)
181
182 modele.getEdgeK(0, 3, 0).addAssociation(sh_gen  ,  8, 0, 1)
183 modele.getEdgeK(1, 3, 0).addAssociation(sh_gen  , 11, 0, 1)
184
185 # Associer les faces courbees
186 # ---------------------------
187
188 modele.getQuadJK(0, 0, 0).addAssociation(sh_tuyau, 31)
189 modele.getQuadJK(0, 1, 0).addAssociation(sh_tuyau, 31)
190 modele.getQuadJK(0, 2, 0).addAssociation(sh_tuyau, 24)
191 modele.getQuadJK(0, 3, 0).addAssociation(sh_tuyau, 24)
192
193 modele.getQuadJK(1, 0, 0).addAssociation(sh_tuyau, 13)
194 modele.getQuadJK(1, 1, 0).addAssociation(sh_tuyau, 13)
195 modele.getQuadJK(1, 2, 0).addAssociation(sh_tuyau,  3)
196 modele.getQuadJK(1, 3, 0).addAssociation(sh_tuyau,  3)
197
198 # Mailler le modele de bloc
199 # =========================
200
201 # Definir 3 groupes d'aretes
202 # --------------------------
203
204 groupe_cercles      = doc.addEdgeGroup("Cercles")
205 groupe_ellipses     = doc.addEdgeGroup("Ellipses")
206 groupe_generatrices = doc.addEdgeGroup("Generatrices")
207
208 # Definir 4 groupes de faces
209 # --------------------------
210
211 groupe_couronne  = doc.addQuadGroup("Couronne")
212 groupe_ovale     = doc.addQuadGroup("Ovale")
213 groupe_interieur = doc.addQuadGroup("Interieur")
214 groupe_exterieur = doc.addQuadGroup("Exterieur")
215
216 # Constituer les groupes d'aretes
217 # -------------------------------
218
219 for i in range(2):
220     for j in range(4):
221         arete = modele.getEdgeJ(i, j, 1)
222         groupe_cercles.addElement(arete)
223
224         arete = modele.getEdgeJ(i, j, 0)
225         groupe_ellipses.addElement(arete)
226
227         arete = modele.getEdgeK(i, j, 0)
228         groupe_generatrices.addElement(arete)
229
230 # Constituer les groupes de faces
231 # -------------------------------
232
233 for j in range(4):
234     quad = modele.getQuadIJ(0, j, 1)
235     groupe_couronne.addElement(quad)
236
237     quad = modele.getQuadIJ(0, j, 0)
238     groupe_ovale.addElement(quad)
239
240     quad = modele.getQuadJK(0, j, 0)
241     groupe_interieur.addElement(quad)
242
243     quad = modele.getQuadJK(1, j, 0)
244     groupe_exterieur.addElement(quad)
245
246 # Mailler le modele de bloc avec ses associations
247 # -----------------------------------------------
248
249 ##########  hexablock.addLaws(doc, 0.7, True) Ne marche pas
250
251 law = doc.addLaw("Uniform", 4)
252 for j in range(doc.countPropagation()):
253     propa = doc.getPropagation(j)
254     propa.setLaw(law)
255
256 doc.save("tuyau_v5")
257 doc.setName("tuyau_v5")
258 hexablock.addToStudy(doc)
259
260 blocs = hexablock.mesh(doc)
261
262 muv, mue, muq, muh = hexablock.dump(doc, blocs)