Salome HOME
608fe39da92a9a896301fefb7847e35c3419f107
[modules/hexablock.git] / src / TEST_PY / recettes / troisCylindres.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 #### import geompy
26 geompy = hexablock.geompy
27
28 # Charger la geometrie
29 # ====================
30
31 nom = "troisCylindres"
32
33 piece = geompy.ImportBREP(nom+".brep")
34
35 # Selectionner des sous-parties de la geometrie
36 # ---------------------------------------------
37
38 sommets = geompy.SubShapeAllSortedCentres(piece, geompy.ShapeType["VERTEX"])
39 aretes  = geompy.SubShapeAllSortedCentres(piece, geompy.ShapeType["EDGE"  ])
40
41 moy_b_x, moy_b_y, moy_b_z = geompy.PointCoordinates(sommets[14])
42 moy_p_x, moy_p_y, moy_p_z = geompy.PointCoordinates(sommets[ 6])
43 moy_g_x, moy_g_y, moy_g_z = geompy.PointCoordinates(sommets[ 3])
44
45 grand0, grand_xb, grand_yb, grand_zb,  grand1, grand2, grand3,  grand_rayon = geompy.KindOfShape(aretes[ 0])
46 grand4, grand_xh, grand_yh, grand_zh,  grand5, grand6, grand7,  grand8      = geompy.KindOfShape(aretes[ 1])
47
48 moyen0, moyen_x , moyen_y , moyen_z ,  moyen1, moyen2, moyen3,  moyen_rayon = geompy.KindOfShape(aretes[20])
49
50 petit0, petit_xb, petit_yb, petit_zb,  petit1, petit2, petit3,  petit_rayon = geompy.KindOfShape(aretes[12])
51 petit4, petit_xh, petit_yh, petit_zh,  petit5, petit6, petit7,  petit8      = geompy.KindOfShape(aretes[13])
52
53 # Construire le modele de bloc
54 # ============================
55
56 doc = hexablock.addDocument(nom)
57
58 ### doc.addShape(piece,nom)
59
60 # Construire le grand cylindre
61 # ----------------------------
62
63 grand_base = doc.addVertex(grand_xb, grand_yb, grand_zb)
64 grand_oppo = doc.addVertex(grand_xh, grand_yh, grand_zh)
65
66 grand_dir = doc.addVectorVertices(grand_base, grand_oppo)
67
68 grand_hauteur = grand_dir.getNorm()
69
70 ###  grand_cylindre = doc.addCylinder(grand_base, grand_dir, grand_rayon, grand_hauteur)
71
72 # Construire le moyen cylindre cote grand
73 # ---------------------------------------
74
75 moy_g_r1 = 0.8
76 moy_g_r2 = 0.5
77
78 moy_g_base_x = moy_p_x + (moy_g_x-moy_p_x)*moy_g_r1 + moyen_x - moy_b_x
79 moy_g_base_y = moy_p_y + (moy_g_y-moy_p_y)*moy_g_r1 + moyen_y - moy_b_y
80 moy_g_base_z = moy_p_z + (moy_g_z-moy_p_z)*moy_g_r1 + moyen_z - moy_b_z
81
82 moy_g_base = doc.addVertex(moy_g_base_x, moy_g_base_y, moy_g_base_z)
83 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 )
84
85 moy_g_dir = doc.addVectorVertices(moy_g_base, moy_g_oppo)
86
87 moy_g_hauteur = moy_g_dir.getNorm()
88
89 ###  moy_g_cylindre = doc.addCylinder(moy_g_base, moy_g_dir, moyen_rayon, moy_g_hauteur)
90
91 # Construire le moyen cylindre cote petit
92 # ---------------------------------------
93
94 moy_p_r = 0.18
95
96 moy_p_base = doc.addVertex(moyen_x, moyen_y, moyen_z)
97 moy_b_base = doc.addVertex(moy_b_x, moy_b_y, moy_b_z)
98 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 )
99
100 moy_p_dir = doc.addVectorVertices(moy_b_base, moy_p_oppo)
101
102 moy_p_hauteur = moy_p_dir.getNorm()*1.2
103
104 ###  moy_p_cylindre = doc.addCylinder(moy_p_base, moy_p_dir, moyen_rayon, moy_p_hauteur)
105
106 # Construire le petit cylindre
107 # ----------------------------
108
109 petit_base = doc.addVertex(petit_xb, petit_yb, petit_zb)
110 petit_oppo = doc.addVertex(petit_xh, petit_yh, petit_zh)
111
112 petit_dir  = doc.addVectorVertices(petit_base, petit_oppo)
113
114 petit_hauteur = petit_dir.getNorm()
115
116 ###  petit_cylindre = doc.addCylinder(petit_base, petit_dir, petit_rayon, petit_hauteur)
117
118 # Construire le T et la X
119 # -----------------------
120
121 en_te = doc.makeCylinders (grand_base, grand_dir, grand_rayon, grand_hauteur, 
122                            moy_g_base, moy_g_dir, moyen_rayon, moy_g_hauteur)
123
124 hexablock.what ()
125
126 croix = doc.makeCylinders (moy_p_base, moy_p_dir, moyen_rayon, moy_p_hauteur,
127                            petit_base, petit_dir, petit_rayon, petit_hauteur)
128
129 hexablock.what ()
130
131 # Relier le T et la X
132 # -------------------
133
134 CYL_SMALL  = 0
135 CYL_BIG    = 1
136 CYL_KMAX   = 3
137 CYL_JMAX   = 4
138
139
140 qstart = croix.getQuadIJ (CYL_BIG, 0,0,CYL_KMAX)
141 ##  qstart.setColor(5)
142 croix_quads = [qstart]
143
144 for nj in range (CYL_JMAX) :
145     quad = croix.getQuadIJ (CYL_BIG, 1,nj, CYL_KMAX)
146     quad.setColor(5)
147     croix_quads.append (quad)
148
149 qdest = en_te.getQuadIJ (CYL_SMALL, 0,0,0)
150 qdest.setColor(5)
151
152 va1 = qstart.getVertex (0)
153 va2 = qstart.getVertex (1)
154
155 vb1 = qdest.nearestVertex (va1)
156 vb2 = qdest.nearestVertex (va2)
157
158 prisme = doc.joinQuadsUni (croix_quads, qdest, va1,vb1,va2,vb2, 1)
159
160 # Associer
161 # ========
162
163
164 # Mailler le modele de bloc avec association
165 # ------------------------------------------
166
167 doc.addLaws(10, True)
168
169 law = doc.addLaw("Uniform", 4)
170 for j in range(doc.countPropagation()):
171     propa = doc.getPropagation(j)
172     propa.setLaw(law)
173
174 doc.save("troisCylindres")
175 doc.setName("troisCylindres")
176 doc.saveVtk("troisCylindres1.vtk")
177 hexablock.addToStudy(doc)
178
179 blocs = hexablock.mesh(doc, dim=3)
180
181 muv, mue, muq, muh = hexablock.dump(doc, blocs)