]> SALOME platform Git repositories - modules/smesh.git/blob - doc/examples/transforming_meshes_ex14.py
Salome HOME
[bos #35147] [EDF] (2023-T1) Decompose Viscous Layer API.
[modules/smesh.git] / doc / examples / transforming_meshes_ex14.py
1 # Create 2D mesh from 3D 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
15 gFaces = geom_builder.SubShapeAllSorted(box, geom_builder.ShapeType["FACE"])
16 f1,f2 = gFaces[0],gFaces[1]
17 geom_builder.addToStudy(box,"box")
18 geom_builder.addToStudyInFather(box,f1,"face1")
19 geom_builder.addToStudyInFather(box,f2,"face2")
20
21 twoFaces = geom_builder.MakeCompound([f1,f2])
22
23 ## -----------
24 ##
25 ## Create 2D from 3D elements
26 ##
27 ## -----------
28
29 init_mesh = smesh_builder.Mesh(box, "box")
30 init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
31 init_mesh.Compute()
32
33 mesh_1 = smesh_builder.CopyMesh(init_mesh, "Mesh_1")
34 #Return the number of created faces in the original mesh.
35 nb, new_mesh, new_group = mesh_1.MakeBoundaryOfEachElement()
36
37 if nb != 54: raise Exception("Error on MakeBoundaryOfEachElement call. The number of created elements does not match.")
38 if new_mesh.GetId() != mesh_1.GetId(): raise Exception("The mesh created from MakeBoundaryElements should be the same of the call")
39 if new_group: raise Exception("The group created from MakeBoundaryElements should be undefined")
40
41 mesh_2 = smesh_builder.CopyMesh(init_mesh, "Mesh_2")
42
43 #Return the number of created faces and a new_mesh and new_group 
44 nb, new_mesh, new_group = mesh_2.MakeBoundaryOfEachElement("MyFacesElements", "Face_Mesh")
45 if nb != 54: raise Exception("Error on MakeBoundaryOfEachElement call. The number of created elements does not match.")
46 if new_mesh.GetId() == mesh_2.GetId(): raise Exception("The mesh created from MakeBoundaryElements should be the different of the call")
47 if not new_group: raise Exception("The group created from MakeBoundaryElements should be defined")