4 salome.salome_init_without_session()
7 from salome.geom import geomBuilder
8 from salome.smesh import smeshBuilder
10 geom_builder = geomBuilder.New()
11 smesh_builder = smeshBuilder.New()
14 Box_1 = geom_builder.MakeBoxDXDYDZ(200., 200., 200.)
15 geom_builder.addToStudy(Box_1, "Box_1")
17 faces = geom_builder.SubShapeAll(Box_1, geom_builder.ShapeType["FACE"])
21 geom_builder.addToStudyInFather(Box_1, Face_1, "Face_1")
22 geom_builder.addToStudyInFather(Box_1, Face_2, "Face_2")
24 # build a quadrangle mesh 3x3 on Face_1
25 Mesh_1 = smesh_builder.Mesh(Face_1)
26 algo1D = Mesh_1.Segment()
27 algo1D.NumberOfSegments(3)
30 isDone = Mesh_1.Compute()
31 if not isDone: raise Exception('Mesh Mesh_1 : computation failed')
33 # build a triangle mesh on Face_2
34 Mesh_2 = smesh_builder.Mesh(Face_2)
36 algo1D = Mesh_2.Segment()
37 algo1D.NumberOfSegments(1)
38 algo2D = Mesh_2.Triangle()
39 algo2D.MaxElementArea(240)
41 isDone = Mesh_2.Compute()
42 if not isDone: raise Exception('Mesh Mesh_2 : computation failed')
45 pattern = smesh_builder.GetPattern()
47 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
48 if (isDone != 1): print('LoadFromFace :', pattern.GetErrorCode())
50 # apply the pattern to a face of the first mesh
51 facesToSplit = Mesh_1.GetElementsByType(SMESH.FACE)
52 print("Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit)))
53 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
54 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
55 if (isDone != 1): print('MakeMesh :', pattern.GetErrorCode())
57 # create quadrangle mesh
58 Mesh_3 = smesh_builder.Mesh(Box_1)
59 Mesh_3.Segment().NumberOfSegments(1)
62 isDone = Mesh_3.Compute()
63 if not isDone: raise Exception('Mesh Mesh_3 : computation failed')
65 # create a 3d pattern (hexahedrons)
66 pattern_hexa = smesh_builder.GetPattern()
68 smp_hexa = """!!! Nb of points:
85 !!! Indices of points of 4 elements:
91 pattern_hexa.LoadFromFile(smp_hexa)
93 # apply the pattern to a mesh
94 volsToSplit = Mesh_3.GetElementsByType(SMESH.VOLUME)
95 print("Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit)))
96 pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
97 isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
98 if (isDone != 1): print('MakeMesh :', pattern_hexa.GetErrorCode())
100 # create one more quadrangle mesh
101 Mesh_4 = smesh_builder.Mesh(Box_1)
102 Mesh_4.Segment().NumberOfSegments(1)
105 isDone = Mesh_4.Compute()
106 if not isDone: raise Exception('Mesh Mesh_4 : computation failed')
108 # create another 3d pattern (pyramids)
109 pattern_pyra = smesh_builder.GetPattern()
111 smp_pyra = """!!! Nb of points:
122 !!! Indices of points of 6 elements:
130 pattern_pyra.LoadFromFile(smp_pyra)
132 # apply the pattern to a face mesh
133 volsToSplit = Mesh_4.GetElementsByType(SMESH.VOLUME)
134 print("Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit)))
135 pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
136 isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
137 if (isDone != 1): print('MakeMesh :', pattern_pyra.GetErrorCode())