Replace Hexahedron
The following example explain how to replace hexa in script mode. For parameters description see the gui documentation of replace hexa.
elts = doc.replace (qpattern, pd2,c1, pa2,c2, pb2,c3)
Operations on elts: Elements
Complete example
1# -*- coding: latin-1 -*-
2# Copyright (C) 2009-2026 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####### Test replace hexa ###############
22
23import hexablock
24
25doc = hexablock.addDocument ("default")
26
27
28# Hexa : Grid construction
29
30orig = doc.addVertex ( 0, 0, 0)
31vx = doc.addVector ( 1 ,0, 0)
32vy = doc.addVector ( 0, 1, 0)
33vz = doc.addVector ( 0, 0, 1)
34
35size_x = 3
36size_y = 3
37size_z = 3
38
39grid = doc.makeCartesian (orig, vx, vy, vz, size_x, size_y, size_z)
40
41c1 = grid.getVertexIJK (1, 2, size_z)
42c2 = grid.getVertexIJK (1, 1, size_z)
43c3 = grid.getVertexIJK (2, 1, size_z)
44
45
46# Hexa : Hexa construction
47
48pa1 = doc.addVertex (-1, -1, 0)
49pb1 = doc.addVertex ( 1, -1, 0)
50pc1 = doc.addVertex ( 1, 1, 0)
51pd1 = doc.addVertex (-1, 1, 0)
52
53pa2 = doc.addVertex (-2, -2, 0)
54pb2 = doc.addVertex ( 2, -2, 0)
55pc2 = doc.addVertex ( 2, 2, 0)
56pd2 = doc.addVertex (-2, 2, 0)
57
58edab1 = doc.addEdge (pa1, pb1)
59edbc1 = doc.addEdge (pb1, pc1)
60edcd1 = doc.addEdge (pc1, pd1)
61edda1 = doc.addEdge (pd1, pa1)
62
63edab2 = doc.addEdge (pa2, pb2)
64edbc2 = doc.addEdge (pb2, pc2)
65edcd2 = doc.addEdge (pc2, pd2)
66edda2 = doc.addEdge (pd2, pa2)
67
68edaa = doc.addEdge (pa1, pa2)
69edbb = doc.addEdge (pb1, pb2)
70edcc = doc.addEdge (pc1, pc2)
71eddd = doc.addEdge (pd1, pd2)
72
73qpattern = []
74qpattern.append (doc.addQuad (edab1, edbc1, edcd1, edda1))
75qpattern.append (doc.addQuad (edab1, edbb, edab2, edaa))
76qpattern.append (doc.addQuad (edbc1, edcc, edbc2, edbb))
77qpattern.append (doc.addQuad (edcd1, eddd, edcd2, edcc))
78qpattern.append (doc.addQuad (edda1, edaa, edda2, eddd))
79
80##### doc.saveVtk ("replace0.vtk")
81
82# Hexa replacement (on the grid)
83doc.replace (qpattern, pd2,c1, pa2,c2, pb2,c3)
84
85##### doc.saveVtk ("replace1.vtk")
86
Result
Before hexa replacement
After hexa replacement
GUI command: Replace hexahedron