Salome HOME
Merge from V6_main 01/04/2013
[modules/hexablock.git] / src / TEST_PY / recettes / tuyau.py
1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2013  CEA/DEN, EDF R&D
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.
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 geompy
25 import hexablock
26
27 # Charger la géométrie
28 # ====================
29
30 nom = "tuyau"
31
32 geometrie = geompy.ImportBREP(nom+".brep")
33
34 # Sélectionner des sous-parties de la géométrie
35 # ---------------------------------------------
36
37 aretes = geompy.SubShapeAllSortedCentres(geometrie, geompy.ShapeType["EDGE"])
38 faces  = geompy.SubShapeAllSortedCentres(geometrie, geompy.ShapeType["FACE"])
39
40 arc_int_bas  = aretes[12]
41 arc_int_haut = aretes[13]
42 arc_ext_bas  = aretes[11]
43 arc_ext_haut = aretes[14]
44
45 ell_int_bas  = aretes[2]
46 ell_int_haut = aretes[3]
47 ell_ext_bas  = aretes[1]
48 ell_ext_haut = aretes[4]
49
50 gen_int_avan = aretes[8]
51 gen_int_arri = aretes[7]
52 gen_ext_avan = aretes[9]
53 gen_ext_arri = aretes[6]
54
55 face_int_bas  = faces[4]
56 face_int_haut = faces[5]
57 face_ext_bas  = faces[2]
58 face_ext_haut = faces[3]
59
60 # Construire le modèle de bloc
61 # ============================
62
63 doc = hexablock.addDocument(nom)
64
65 # Définir le tuyau
66 # ----------------
67
68 base = doc.addVertex(0, 0, 0)
69
70 direction = doc.addVector(1, 0, 0)
71
72 tuyau = doc.addPipe(base, direction, 1, 2, 10)
73
74 # Construire le modele de blocs du tuyau
75 # --------------------------------------
76
77 depart = doc.addVector(0, 1, 0)
78
79 modele = doc.makePipe(tuyau, depart, 1, 4, 1)
80
81 # Associer le modèle de bloc à la géométrie
82 # =========================================
83
84 doc.setShape(geometrie)
85
86 # Associer les cercles
87 # --------------------
88
89 cer_int_dep = modele.getVertexIJK(0, 0, 0)
90 cer_ext_dep = modele.getVertexIJK(1, 0, 0)
91
92 cer_int = []
93 cer_ext = []
94 for j in xrange(4):
95     a = modele.getEdgeJ(0, j, 0)
96     cer_int.append(a)
97
98     a = modele.getEdgeJ(1, j, 0)
99     cer_ext.append(a)
100
101 doc.associateClosedLine(cer_int_dep, cer_int[0], cer_int[1:], arc_int_haut, 1, True, [arc_int_bas])
102 doc.associateClosedLine(cer_ext_dep, cer_ext[0], cer_ext[1:], arc_ext_haut, 1, True, [arc_ext_bas])
103
104 # Associer les ellipses
105 # ---------------------
106
107 ell_int_dep = modele.getVertexIJK(0, 0, 1)
108 ell_ext_dep = modele.getVertexIJK(1, 0, 1)
109
110 ell_int = []
111 ell_ext = []
112 for j in xrange(4):
113     a = modele.getEdgeJ(0, j, 1)
114     ell_int.append(a)
115
116     a = modele.getEdgeJ(1, j, 1)
117     ell_ext.append(a)
118
119 doc.associateClosedLine(ell_int_dep, ell_int[0], ell_int[1:], ell_int_haut, 1, True, [ell_int_bas])
120 doc.associateClosedLine(ell_ext_dep, ell_ext[0], ell_ext[1:], ell_ext_haut, 1, True, [ell_ext_bas])
121
122 # Associer les génératrices
123 # -------------------------
124
125 def generatrice(face):
126     n = 10
127     l = []
128     for i in xrange(0, n+1):
129         v = float(i) / n
130         s = geompy.MakeVertexOnSurface(face, 0.5, v)
131         l.append(s)
132
133     return geompy.MakeInterpol(l)
134
135 gen_int_haut = generatrice(face_int_haut)
136 gen_ext_haut = generatrice(face_ext_haut)
137 gen_int_bas  = generatrice(face_int_bas )
138 gen_ext_bas  = generatrice(face_ext_bas )
139
140 modele.getEdgeK(0, 0, 0).addAssociation(gen_int_arri, 0, 1)
141 modele.getEdgeK(1, 0, 0).addAssociation(gen_ext_arri, 0, 1)
142
143 modele.getEdgeK(0, 1, 0).addAssociation(gen_int_haut, 0, 1)
144 modele.getEdgeK(1, 1, 0).addAssociation(gen_ext_haut, 0, 1)
145
146 modele.getEdgeK(0, 2, 0).addAssociation(gen_int_avan, 0, 1)
147 modele.getEdgeK(1, 2, 0).addAssociation(gen_ext_avan, 0, 1)
148
149 modele.getEdgeK(0, 3, 0).addAssociation(gen_int_bas , 0, 1)
150 modele.getEdgeK(1, 3, 0).addAssociation(gen_ext_bas , 0, 1)
151
152 # Associer les faces courbées
153 # ---------------------------
154
155 modele.getQuadJK(0, 0, 0).addAssociation(face_int_haut)
156 modele.getQuadJK(0, 1, 0).addAssociation(face_int_haut)
157 modele.getQuadJK(0, 2, 0).addAssociation(face_int_bas )
158 modele.getQuadJK(0, 3, 0).addAssociation(face_int_bas )
159
160 modele.getQuadJK(1, 0, 0).addAssociation(face_ext_haut)
161 modele.getQuadJK(1, 1, 0).addAssociation(face_ext_haut)
162 modele.getQuadJK(1, 2, 0).addAssociation(face_ext_bas )
163 modele.getQuadJK(1, 3, 0).addAssociation(face_ext_bas )
164
165 # Mailler le modèle de bloc
166 # =========================
167
168 # Définir 3 groupes d'arêtes
169 # --------------------------
170
171 groupe_cercles      = doc.addEdgeGroup("Cercles")
172 groupe_ellipses     = doc.addEdgeGroup("Ellipses")
173 groupe_generatrices = doc.addEdgeGroup("Generatrices")
174
175 # Définir 4 groupes de faces
176 # --------------------------
177
178 groupe_couronne  = doc.addQuadGroup("Couronne")
179 groupe_ovale     = doc.addQuadGroup("Ovale")
180 groupe_interieur = doc.addQuadGroup("Interieur")
181 groupe_exterieur = doc.addQuadGroup("Exterieur")
182
183 # Constituer les groupes d'arêtes
184 # -------------------------------
185
186 for i in xrange(2):
187     for j in xrange(4):
188         arete = modele.getEdgeJ(i, j, 0)
189         groupe_cercles.addElement(arete)
190
191         arete = modele.getEdgeJ(i, j, 1)
192         groupe_ellipses.addElement(arete)
193
194         arete = modele.getEdgeK(i, j, 0)
195         groupe_generatrices.addElement(arete)
196
197 # Constituer les groupes de faces
198 # -------------------------------
199
200 for j in xrange(4):
201     quad = modele.getQuadIJ(0, j, 0)
202     groupe_couronne.addElement(quad)
203
204     quad = modele.getQuadIJ(0, j, 1)
205     groupe_ovale.addElement(quad)
206
207     quad = modele.getQuadJK(0, j, 0)
208     groupe_interieur.addElement(quad)
209
210     quad = modele.getQuadJK(1, j, 0)
211     groupe_exterieur.addElement(quad)
212
213 # Mailler le modèle de bloc avec ses associations
214 # -----------------------------------------------
215
216 hexablock.addLaws(doc, 0.7, True)
217
218 blocs = hexablock.mesh(doc)
219
220 muv, mue, muq, muh = hexablock.dump(doc, blocs)