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