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