Salome HOME
178b2ccdd4d05141ab11a80b6cdad3500ef31a91
[modules/hexablock.git] / src / TEST_PY / test_unit / troisCylindres_v5.py
1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2023  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 geompy = hexablock.geompy
26
27 # Charger la geometrie
28 # ====================
29
30 nom = "troisCylindres"
31
32 piece = geompy.ImportBREP(nom+".brep")
33
34 # Selectionner des sous-parties de la geometrie
35 # ---------------------------------------------
36
37 sommets = geompy.SubShapeAllSortedCentres(piece, geompy.ShapeType["VERTEX"])
38 aretes  = geompy.SubShapeAllSortedCentres(piece, geompy.ShapeType["EDGE"  ])
39
40 moy_b_x, moy_b_y, moy_b_z = geompy.PointCoordinates(sommets[14])
41 moy_p_x, moy_p_y, moy_p_z = geompy.PointCoordinates(sommets[ 6])
42 moy_g_x, moy_g_y, moy_g_z = geompy.PointCoordinates(sommets[ 3])
43
44 grand0, grand_xb, grand_yb, grand_zb,  grand1, grand2, grand3,  grand_rayon = geompy.KindOfShape(aretes[ 0])
45 grand4, grand_xh, grand_yh, grand_zh,  grand5, grand6, grand7,  grand8      = geompy.KindOfShape(aretes[ 1])
46
47 moyen0, moyen_x , moyen_y , moyen_z ,  moyen1, moyen2, moyen3,  moyen_rayon = geompy.KindOfShape(aretes[20])
48
49 petit0, petit_xb, petit_yb, petit_zb,  petit1, petit2, petit3,  petit_rayon = geompy.KindOfShape(aretes[12])
50 petit4, petit_xh, petit_yh, petit_zh,  petit5, petit6, petit7,  petit8      = geompy.KindOfShape(aretes[13])
51
52 # Construire le modele de bloc
53 # ============================
54
55 doc = hexablock.addDocument(nom)
56
57 doc.addShape(piece,nom)
58
59 # Construire le grand cylindre
60 # ----------------------------
61
62 grand_base = doc.addVertex(grand_xb, grand_yb, grand_zb)
63 grand_oppo = doc.addVertex(grand_xh, grand_yh, grand_zh)
64
65 grand_dir = doc.addVectorVertices(grand_base, grand_oppo)
66
67 grand_hauteur = grand_dir.getNorm()
68
69 grand_cylindre = doc.addCylinder(grand_base, grand_dir, grand_rayon, grand_hauteur)
70
71 # Construire le moyen cylindre cote grand
72 # ---------------------------------------
73
74 moy_g_r1 = 0.8
75 moy_g_r2 = 0.5
76
77 moy_g_base_x = moy_p_x + (moy_g_x-moy_p_x)*moy_g_r1 + moyen_x - moy_b_x
78 moy_g_base_y = moy_p_y + (moy_g_y-moy_p_y)*moy_g_r1 + moyen_y - moy_b_y
79 moy_g_base_z = moy_p_z + (moy_g_z-moy_p_z)*moy_g_r1 + moyen_z - moy_b_z
80
81 moy_g_base = doc.addVertex(moy_g_base_x, moy_g_base_y, moy_g_base_z)
82 moy_g_oppo = doc.addVertex( (grand_xh+grand_xb) * moy_g_r2, (grand_yh+grand_yb) * moy_g_r2, (grand_zh+grand_zb) * moy_g_r2 )
83
84 moy_g_dir = doc.addVectorVertices(moy_g_base, moy_g_oppo)
85
86 moy_g_hauteur = moy_g_dir.getNorm()
87
88 moy_g_cylindre = doc.addCylinder(moy_g_base, moy_g_dir, moyen_rayon, moy_g_hauteur)
89
90 # Construire le moyen cylindre cote petit
91 # ---------------------------------------
92
93 moy_p_r = 0.18
94
95 moy_p_base = doc.addVertex(moyen_x, moyen_y, moyen_z)
96 moy_b_base = doc.addVertex(moy_b_x, moy_b_y, moy_b_z)
97 moy_p_oppo = doc.addVertex( moy_p_x+(moy_g_x-moy_p_x) * moy_p_r, moy_p_y+(moy_g_y-moy_p_y) * moy_p_r, moy_p_z+(moy_g_z-moy_p_z) * moy_p_r )
98
99 moy_p_dir = doc.addVectorVertices(moy_b_base, moy_p_oppo)
100
101 moy_p_hauteur = moy_p_dir.getNorm()
102
103 moy_p_cylindre = doc.addCylinder(moy_p_base, moy_p_dir, moyen_rayon, moy_p_hauteur)
104
105 # Construire le petit cylindre
106 # ----------------------------
107
108 petit_base = doc.addVertex(petit_xb, petit_yb, petit_zb)
109 petit_oppo = doc.addVertex(petit_xh, petit_yh, petit_zh)
110
111 petit_dir = doc.addVectorVertices(petit_base, petit_oppo)
112
113 petit_hauteur = petit_dir.getNorm()
114
115 petit_cylindre = doc.addCylinder(petit_base, petit_dir, petit_rayon, petit_hauteur)
116
117 # Construire le T et la X
118 # -----------------------
119
120 en_te = doc.makeCylinders(grand_cylindre, moy_g_cylindre)
121 croix = doc.makeCylinders(moy_p_cylindre, petit_cylindre)
122
123 # Relier le T et la X
124 # -------------------
125
126 croix_quads = []
127
128 for i in range(1, -1, -1):
129     for j in range( [hexablock.CV_MAXI_INT, hexablock.CV_MAXI_EXT][i] ):
130         quad = croix.getQuadIJ(hexablock.CYL_BIG, i, j, hexablock.CYL_BIG_SLICES)
131         croix_quads.append(quad)
132
133 en_te_q = en_te.getQuadIJ(hexablock.CYL_SMALL, 1, hexablock.V_N, 0)
134
135 en_te_v0 = en_te.getVertexIJK(hexablock.CYL_SMALL, 2, hexablock.V_N , 0)
136 en_te_v1 = en_te.getVertexIJK(hexablock.CYL_SMALL, 2, hexablock.V_NW, 0)
137
138 croix_v0 = croix.getVertexIJK(hexablock.CYL_BIG, 2, hexablock.V_E , hexablock.CYL_BIG_SLICES)
139 croix_v1 = croix.getVertexIJK(hexablock.CYL_BIG, 2, hexablock.V_NE, hexablock.CYL_BIG_SLICES)
140
141 prisme = doc.joinQuads(croix_quads, en_te_q,  croix_v0, en_te_v0,  croix_v1, en_te_v1,  1)
142
143 # Associer
144 # ========
145
146 # fkl: comme pour la tuyauterie: associer pour le prisme (sauf si item 142 et 146 de Taches.ods)
147
148 # Mailler le modele de bloc
149 # =========================
150
151 # Definir 5 groupes de faces
152 # --------------------------
153
154 groupe_grand_a = doc.addQuadGroup("Grand_A")
155 groupe_grand_b = doc.addQuadGroup("Grand_B")
156 groupe_moyen_f = doc.addQuadGroup("Moyen")
157 groupe_petit_a = doc.addQuadGroup("Petit_A")
158 groupe_petit_b = doc.addQuadGroup("Petit_B")
159
160 for i in range(2):
161     for j in range( [hexablock.CV_MAXI_INT, hexablock.CV_MAXI_EXT][i] ):
162         quad = en_te.getQuadIJ(hexablock.CYL_BIG  , i, j, 0)
163         groupe_grand_a.addElement(quad)
164
165         quad = en_te.getQuadIJ(hexablock.CYL_BIG  , i, j, hexablock.CYL_BIG_SLICES)
166         groupe_grand_b.addElement(quad)
167
168         quad = croix.getQuadIJ(hexablock.CYL_BIG  , i, j, 0)
169         groupe_moyen_f.addElement(quad)
170
171         quad = croix.getQuadIJ(hexablock.CYL_SMALL, i, j, 0)
172         groupe_petit_a.addElement(quad)
173
174         quad = croix.getQuadIJ(hexablock.CYL_SMALL, i, j, hexablock.CYL_SMALL_SLICES)
175         groupe_petit_b.addElement(quad)
176
177 # Definir 3 groupes de volumes
178 # ----------------------------
179
180 groupe_grand = doc.addHexaGroup("Grand")
181 groupe_moyen = doc.addHexaGroup("Moyen")
182 groupe_petit = doc.addHexaGroup("Petit")
183
184 for i in range( doc.countUsedHexa() ):
185     h = doc.getUsedHexa(i)
186     groupe_moyen.addElement(h)
187
188 for i in range(2):
189     for j in range( [hexablock.CV_MAXI_INT, hexablock.CV_MAXI_EXT][i] ):
190         for k in [ 0, hexablock.CYL_BIG_SLICES-1 ]:
191             h = en_te.getHexaIJK(hexablock.CYL_BIG, i, j, k)
192             groupe_grand.addElement(h)
193             groupe_moyen.removeElement(h)
194
195         for k in [0, hexablock.CYL_SMALL_SLICES-1 ]:
196             h = croix.getHexaIJK(hexablock.CYL_SMALL, i, j, k)
197             groupe_petit.addElement(h)
198             groupe_moyen.removeElement(h)
199
200 # Mailler le modele de bloc avec association
201 # ------------------------------------------
202
203 ########## hexablock.addLaws(doc, 10, True) Ne marche pas
204
205 law = doc.addLaw("Uniform", 4)
206 for j in range(doc.countPropagation()):
207     propa = doc.getPropagation(j)
208     propa.setLaw(law)
209
210 doc.save("troisCylindres_v5")
211 doc.setName("troisCylindres_v5")
212 hexablock.addToStudy(doc)
213
214 blocs = hexablock.mesh(doc, dim=3)
215
216 muv, mue, muq, muh = hexablock.dump(doc, blocs)