Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / doc / salome / examples / transforming_meshes_ex12.py
1 # Create boundary elements
2
3 from smesh import *
4 SetCurrentStudy(salome.myStudy)
5
6 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
7 gFaces = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])
8 f1,f2 = gFaces[0],gFaces[1]
9 geompy.addToStudy(box,"box")
10 geompy.addToStudyInFather(box,f1,"face1")
11 geompy.addToStudyInFather(box,f2,"face2")
12
13 twoFaces = geompy.MakeCompound([f1,f2])
14
15 ## -----------
16 ##
17 ## 2D from 3D
18 ##
19 ## -----------
20 dim = SMESH.BND_2DFROM3D
21
22 init_mesh = Mesh(box, "box")
23 init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
24
25 # remove some faces
26 faces = init_mesh.GetElementsByType( SMESH.FACE )
27 nb_faces = len( faces )
28 rm_face = faces[ : nb_faces/2]
29 init_mesh.RemoveElements( rm_face )
30
31 # restore boundary in this mesh
32 mesh = CopyMesh( init_mesh, "2D from 3D")
33 groupName = "bnd 2D"
34 nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
35
36 # restore boundary (only) in other mesh
37 meshName = "2D boundary of " + init_mesh.GetName()
38 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
39
40 # restore boundary in mesh copy
41 meshName = init_mesh.GetName() + " + boundary"
42 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
43
44
45 ## -----------
46 ##
47 ## 1D from 2D
48 ##
49 ## -----------
50 dim = SMESH.BND_1DFROM2D
51
52 init_mesh = Mesh(f1, "2D mesh")
53 init_mesh.AutomaticHexahedralization()
54
55 # remove some edges
56 edges = init_mesh.GetElementsByType( SMESH.EDGE )
57 nb_edges = len( edges )
58 rm_edge = edges[ : nb_edges/2]
59 init_mesh.RemoveElements( rm_edge )
60
61
62 # restore boundary edges in this mesh
63 mesh = CopyMesh( init_mesh, "1D from 2D")
64 groupName = "bnd 1D"
65 nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
66
67 # restore boundary edges (only) in other mesh
68 meshName = "1D boundary of " + init_mesh.GetName()
69 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
70
71 # restore boundary edges in mesh copy
72 meshName = init_mesh.GetName() + " + boundary"
73 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
74
75
76
77 ## ------------------
78 ##
79 ## 1D from 2D GROUPS
80 ##
81 ## ------------------
82 dim = SMESH.BND_1DFROM3D
83
84 init_mesh = Mesh(box, "box")
85 init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
86 # remove all edges
87 rm_edges = init_mesh.GetElementsByType( SMESH.EDGE )
88 init_mesh.RemoveElements( rm_edges )
89
90 # make groups of faces
91 fGroup1 = init_mesh.Group( f1, "f1" )
92 fGroup2 = init_mesh.Group( f2, "f2" )
93
94 # make 1D boundary around groups in this mesh
95 mesh = CopyMesh( init_mesh, "1D from 2D groups", toCopyGroups=True)
96 groups = mesh.GetGroups()
97 nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName,groups=groups)
98
99 # make 1D boundary (only) in other mesh
100 meshName =  "boundary from groups of " + init_mesh.GetName()
101 groups = init_mesh.GetGroups()
102 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName,groups=groups)
103
104 # make 1D boundary in mesh copy
105 meshName = init_mesh.GetName() + " + boundary from groups"
106 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName,
107                                                          groups=groups, toCopyAll=True)
108