Salome HOME
4f07ceef95fa68a40989496fc7459701bfeddd40
[modules/hexablock.git] / src / TEST_PY / cas_2013 / make_pave.py
1 # !/bin/python
2 # -*- coding: latin-1 -*-
3 # Copyright (C) 2009-2023  CEA, EDF
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 # Hexa : Creation d'hexaedres 
23
24 import hexablock
25 geompy = hexablock.geompy
26 ## import os
27 ## import math
28
29 nbr_fic   = 0
30 the_name  = "pave_troue"
31 the_doc   = None
32 the_grid  = None
33                        ## Constantes
34 Epsilon  = 1e-3
35 BadIndex = -1
36 DirX = 0
37 DirY = 1
38 DirZ = 2
39 X    = 100000.0
40 X0   = X-1
41 HOK  = 0
42 HERR = 1
43 YES  = 1
44 NO   = 0
45 BOF  = -1
46                        ## Parametrage
47 db             = True
48 maillage_actif = True
49
50 # ======================================================= save_vtk
51 def save_vtk () :
52
53     global nbr_fic
54     nbr_fic += 1
55     filename = "%s_%02d.vtk" % (the_name,nbr_fic)
56     the_doc.saveVtk (filename)
57
58
59 # ======================================================= make_toit
60 def make_toit () :
61
62     ichem  = 5
63     jchem  = 3
64
65     for ni in range (imax) :
66         for nj in range (jmax) :
67             if ni != ichem or nj != jchem :
68                the_doc.removeHexa (the_grid.getHexaIJK (ni,nj,kmax))
69
70 # ======================================================= make_trou1
71 def make_trou1 () :
72
73     ic1   = 2
74     jc1   = 2
75     nc1   = 3
76
77     for ni in range (nc1) :
78         for nj in range (nc1) :
79             for nk in range (kmax) :
80                 the_doc.removeHexa (the_grid.getHexaIJK (ic1+ni, jc1+nj, nk))
81
82     xc1   = 65
83     yc1   = 25
84     orig1 = the_doc.addVertex (xc1, yc1, 0)
85     vxy   = the_doc.addVector (1,1,0)
86
87     rayon  = 5
88     rext   = 8
89     nbsect = 12
90     theta    = 360.0 / nbsect
91     cyl1_ray = [ rayon, rext]
92     cyl1_ang = []
93     for na in range (nbsect+1) :
94         cyl1_ang.append (na*theta)
95     cyl1_h = tab_z
96     cyl1_h.pop()
97     cyl1_h.insert (0,0)
98     cyl1 = the_doc.makePipe (orig1, vxy, vz, cyl1_ray, cyl1_ang, cyl1_h)
99
100                      ### Test visu
101
102     va1 = cyl1    .getVertexIJK (1,         1,       0)
103     va2 = cyl1    .getVertexIJK (1,         1,       1)
104     vc1 = the_grid.getVertexIJK (ic1+nc1-1, jc1+nc1, 0)
105     vc2 = the_grid.getVertexIJK (ic1+nc1-1, jc1+nc1, 1)
106
107     cible = the_grid.getQuadIK (ic1+2, jc1+nc1, 0)
108     tab_quads = []
109     for nk in range (len(cyl1_h)-1) :
110         for nj in range (len(cyl1_ang)-1) :
111             tab_quads.append (cyl1.getQuadJK (1, nj, nk))
112
113     if db :
114        va1.setColor (5)
115        vc1.setColor (5)
116        save_vtk ()
117
118        va2.setColor (5)
119        vc2.setColor (5)
120        save_vtk ()
121
122        cible.setColor        (5)
123        tab_quads[0].setColor (5)
124        save_vtk ()
125                      ### Jointure 
126
127     the_doc.joinQuadsUni (tab_quads, cible, va1, vc1, va2, vc2, 1)
128     hexablock.what () 
129     return cyl1
130
131 # ======================================================= make_trou2
132 def make_trou2 () :
133
134     ic2   = 7
135     kc2   = 1
136     for nj in range (jmax) :
137         the_doc.removeHexa (the_grid.getHexaIJK (ic2, nj, kc2))
138
139     xc2   = 105
140     zc2   = 20
141     orig2 = the_doc.addVertex (xc2, 0, zc2)
142     vxz   = the_doc.addVector (1,0,1)
143
144     rayon  = 5
145     rext   = 8
146     nbsect = 4
147     theta  = 360.0 / nbsect
148     cyl2_ray = [ rayon, rext]
149     cyl2_ang = []
150     for na in range (nbsect+1) :
151         cyl2_ang.append (na*theta)
152     cyl2_h = tab_y
153     cyl2_h.insert (0,0)
154     cyl2 = the_doc.makePipe (orig2, vxz, vy, cyl2_ray, cyl2_ang, cyl2_h)
155                      ### Test visu
156
157     va1 = cyl2    .getVertexIJK (1,     0, 0)
158     va2 = cyl2    .getVertexIJK (1,     0, 1)
159     vc1 = the_grid.getVertexIJK (ic2+1, 0, kc2+1)
160     vc2 = the_grid.getVertexIJK (ic2+1, 1, kc2+1)
161
162     cible = the_grid.getQuadJK (ic2+1, 0, kc2)
163     tab_quads = []
164     for nk in range (len(cyl2_h)-1) :
165         for nj in range (len(cyl2_ang)-1) :
166             tab_quads.append (cyl2.getQuadJK (1, nj, nk))
167
168     if db :
169        va1.setColor (5)
170        vc1.setColor (5)
171        save_vtk ()
172
173        va2.setColor (5)
174        vc2.setColor (5)
175        save_vtk ()
176
177        cible.setColor        (5)
178        tab_quads[0].setColor (5)
179        save_vtk ()
180                      ### Jointure 
181
182     the_doc.joinQuadsUni (tab_quads, cible, va1, vc1, va2, vc2, 1)
183     hexablock.what () 
184     return cyl2
185
186 # ======================================================= trait_vertical
187 def trait_vertical () :
188
189     ivert  = 3
190     for nk in range (kmax) :
191         for nj in range (2) :
192             the_doc.removeHexa (the_grid.getHexaIJK (ivert,nj,nk))
193
194 # ================================================================= make_pave
195 def make_pave () :
196
197     global the_doc, the_grid, tab_y, tab_z, vz, vy
198
199     the_doc  = hexablock.addDocument (the_name)
200     vx   = the_doc.addVector (1,0,0)
201     vy   = the_doc.addVector (0,1,0)
202     vz   = the_doc.addVector (0,0,1)
203     orig = the_doc.addVertex (0, 0, 0)
204     orig.setColor (5)
205
206     tab_x = [50, 62.5, 67.5, 70, 75, 85, 105, 120]
207     tab_y = [10, 15, 22.5, 25, 27.5, 40]
208     tab_z = [25, 40, 50, 53]
209                                             ### Modifs 
210     tab_x  = [50, 55, 62.5, 67.5, 75, 85, 95, 115, 120]
211     tab_y  = [10, 15, 22.5, 27.5, 35, 40]
212     tab_z  = [10, 30, 40, 50, 53]
213
214     rayon = 5
215
216     the_grid = the_doc.makeCartesian (orig, vx, vy, vz, tab_x, tab_y, tab_z)
217     save_vtk ()
218
219     global imax,  jmax,  kmax 
220     imax = len (tab_x)
221     jmax = len (tab_y)
222     kmax = len (tab_z) - 1
223
224     make_toit ()
225
226     the_doc.removeHexa (the_grid.getHexaIJK (0,0,kmax-1))
227
228                                    ###    Trou 1
229     make_trou1 ()
230     save_vtk ()
231                                    ###    Trou 2
232     make_trou2 ()
233     save_vtk ()
234                                 ### Les trous
235                                 ### Maillage
236     trait_vertical ()
237
238     if maillage_actif :
239        print("  ________________________ Maillage")
240        the_doc.addLaws (2, True)
241        mesh_hexas = hexablock.mesh(the_doc)
242
243     the_doc.purge ()
244     the_doc.save (the_name)
245     save_vtk ()
246     save_vtk ()
247     save_vtk ()
248     save_vtk ()
249     save_vtk ()
250     return the_doc
251
252 # ================================================================= Begin
253 doc = make_pave  ()
254
255
256