Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / TEST_PY / test_unit / hexa_quads.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 # Hexa : Creation d'hexaedres 
22
23 import hexablock
24 import os
25
26 #---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
27 # ================================================================= save_schema
28 class FileVtk :
29     def __init__ (self, doc, radical):
30         self.document = doc
31         self.count    = 0
32         self.radical  = radical
33
34     def save (self) :
35         """
36         sauvegarde vtk du modele de bloc
37         """
38         self.count += 1
39         file_name = os.path.join(self.radical + str(self.count) + '.vtk')
40         self.document.saveVtk(file_name)
41
42 # ================================================================= add_grid
43 def add_grid (doc, size_x, size_y, size_z) :
44     orig = doc.addVertex(0, 0, 0)
45
46     vx = doc.addVector (1, 0, 0)
47     vy = doc.addVector (0, 1, 0)
48     vz = doc.addVector (0, 0, 1)
49     grid = doc.makeCartesian (orig, vx, vy, vz, size_x, size_y, size_z)
50     return grid
51
52 # ========================================================== test_hexa_quads_5
53 def test_hexa_quads_5 () :
54     doc  = hexablock.addDocument ("default")
55     vtk  = FileVtk (doc, "HexaQuads5");
56     grid = add_grid (doc, 3, 3, 2)
57     vtk.save ()
58
59     hexa = grid.getHexaIJK (1,1,1)
60
61     qa = hexa.getQuad (0)
62     qb = hexa.getQuad (1)
63     qc = hexa.getQuad (2)
64     qd = hexa.getQuad (3)
65     qe = hexa.getQuad (4)
66     qf = hexa.getQuad (5)
67
68     doc.removeQuad (qb)
69     vtk.save ()
70
71     doc.addHexa5Quads (qa, qc, qd, qe, qf);
72     vtk.save ()
73
74     doc.removeElements (grid)
75     vtk.save ()
76
77 # ========================================================== test_hexa_quads_ab
78 def test_hexa_quads_ab () :
79     doc  = hexablock.addDocument ("default")
80     vtk  = FileVtk (doc, "HexaQuadsAB");
81     grid = add_grid (doc, 1, 1, 3)
82     vtk.save ()
83
84     hexa = grid.getHexaIJK (0,0,1)
85
86     qa = hexa.getQuad (0)
87     qb = hexa.getQuad (1)
88     qc = hexa.getQuad (2)
89     qd = hexa.getQuad (3)
90     qe = hexa.getQuad (4)
91     qf = hexa.getQuad (5)
92
93     doc.removeQuad (qc)
94     doc.removeQuad (qd)
95     doc.removeQuad (qe)
96     doc.removeQuad (qf)
97     vtk.save ()
98
99     doc.addHexa2Quads (qa, qb)
100     vtk.save ()
101
102     doc.removeElements (grid)
103     vtk.save ()
104
105 # ========================================================== test_hexa_quads_ac
106 def test_hexa_quads_ac () :
107     doc  = hexablock.addDocument ("default")
108     vtk  = FileVtk (doc, "HexaQuadsAC");
109     grid = add_grid (doc, 2, 1, 2)
110     vtk.save ()
111
112     hexa = grid.getHexaIJK (1,0,1)
113
114     qa = hexa.getQuad (0)
115     qb = hexa.getQuad (1)
116     qc = hexa.getQuad (2)
117     qd = hexa.getQuad (3)
118     qe = hexa.getQuad (4)
119     qf = hexa.getQuad (5)
120
121     doc.removeQuad (qb)
122     doc.removeQuad (qc)
123     doc.removeQuad (qd)
124     doc.removeQuad (qf)
125     vtk.save ()
126
127     doc.addHexa2Quads (qa, qe)
128     vtk.save ()
129
130     doc.removeElements (grid)
131     vtk.save ()
132
133 # ======================================================= test_hexa_quads_acd
134 def test_hexa_quads_acd () :
135
136     doc  = hexablock.addDocument ("default")
137     vtk  = FileVtk (doc, "HexaQuadsACD");
138     grid = add_grid (doc, 3, 1, 2)
139     vtk.save ()
140
141     hexa = grid.getHexaIJK (1,0,1)
142
143     qa = hexa.getQuad (0)
144     qb = hexa.getQuad (1)
145     qc = hexa.getQuad (2)
146     qd = hexa.getQuad (3)
147     qe = hexa.getQuad (4)
148     qf = hexa.getQuad (5)
149
150     doc.removeQuad (qb)
151     doc.removeQuad (qc)
152     doc.removeQuad (qd)
153     vtk.save ()
154
155     doc.addHexa3Quads (qa, qe, qf)
156     vtk.save ()
157
158     doc.removeElements (grid)
159     vtk.save ()
160
161
162 # ======================================================= test_hexa_quads_ace
163 def test_hexa_quads_ace () :
164
165     doc  = hexablock.addDocument ("default")
166     vtk  = FileVtk (doc, "HexaQuadsACE");
167     grid = add_grid (doc, 2, 2, 2)
168     vtk.save ()
169
170     hexa = grid.getHexaIJK (1,0,1)
171
172     qa = hexa.getQuad (0)
173     qb = hexa.getQuad (1)
174     qc = hexa.getQuad (2)
175     qd = hexa.getQuad (3)
176     qe = hexa.getQuad (4)
177     qf = hexa.getQuad (5)
178
179     doc.removeQuad (qb)
180     doc.removeQuad (qc)
181     doc.removeQuad (qf)
182     vtk.save ()
183
184     doc.addHexa3Quads (qa, qd, qe)
185     vtk.save ()
186
187     doc.removeElements (grid)
188     vtk.save ()
189
190 # ======================================================= test_hexa_quads_abcd
191 def test_hexa_quads_abcd () :
192
193     doc  = hexablock.addDocument ("default")
194     vtk  = FileVtk (doc, "HexaQuadsABCD");
195     grid = add_grid (doc, 3, 1, 3)
196     vtk.save ()
197
198     hexa = grid.getHexaIJK (1,0,1)
199
200     qa = hexa.getQuad (0)
201     qb = hexa.getQuad (1)
202     qc = hexa.getQuad (2)
203     qd = hexa.getQuad (3)
204     qe = hexa.getQuad (4)
205     qf = hexa.getQuad (5)
206
207     doc.removeQuad (qc)
208     doc.removeQuad (qd)
209     vtk.save ()
210
211     doc.addHexa4Quads (qa, qb, qe, qf)
212     vtk.save ()
213
214     doc.removeElements (grid)
215     vtk.save ()
216
217 # ======================================================= test_hexa_quads_abce
218 def test_hexa_quads_abce () :
219
220     doc  = hexablock.addDocument ("default")
221     vtk  = FileVtk (doc, "HexaQuadsABCE");
222     grid = add_grid (doc, 3, 2, 2)
223     vtk.save ()
224
225     hexa = grid.getHexaIJK (1,0,1)
226
227     qa = hexa.getQuad (0)
228     qb = hexa.getQuad (1)
229     qc = hexa.getQuad (2)
230     qd = hexa.getQuad (3)
231     qe = hexa.getQuad (4)
232     qf = hexa.getQuad (5)
233
234     doc.removeQuad (qc)
235     doc.removeQuad (qb)
236     vtk.save ()
237
238     doc.addHexa4Quads (qa, qd, qe, qf)
239     vtk.save ()
240
241     doc.removeElements (grid)
242     vtk.save ()
243
244
245 # ================================================================= Begin
246
247 test_hexa_quads_5  ()
248 test_hexa_quads_ab ()
249 test_hexa_quads_ac ()
250 test_hexa_quads_acd ()
251 test_hexa_quads_ace ()
252 test_hexa_quads_abcd ()
253 test_hexa_quads_abce ()