6 salome.salome_init_without_session()
13 from salome.geom import geomBuilder
18 geompy = geomBuilder.New()
20 ## Creates a polygon given its centre, external radius and number of sides
21 def makePolygon(p_centre, radius, nb_sides, theName=""):
24 x, y, z = geompy.PointCoordinates(p_centre)
25 for i in range(nb_sides):
26 angle = i*2*math.pi/nb_sides
27 p = geompy.MakeVertex(x+radius*math.cos(angle), y+radius*math.sin(angle), 0)
29 wire = geompy.MakePolyline(points, True)
30 face = geompy.MakeFace(wire, 1)
32 geompy.addToStudy(face, theName)
35 ## Creates a solid by adding a vertex on its top
36 def makeSummitSolid(face, height, theName=""):
38 p_cdg = geompy.MakeCDG(face)
39 p_top = geompy.MakeTranslation(p_cdg, 0, 0, height)
40 edges = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"])
43 p1, p2 = geompy.SubShapeAll(edge, geompy.ShapeType["VERTEX"])
44 wire = geompy.MakePolyline([p1, p2, p_top], True)
45 face = geompy.MakeFace(wire, 1)
47 shell = geompy.MakeShell(faces)
48 solid = geompy.MakeSolid(shell)
50 geompy.addToStudy(solid, theName)
53 O = geompy.MakeVertex(0, 0, 0)
54 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
55 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
56 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
57 geompy.addToStudy( O, 'O' )
58 geompy.addToStudy( OX, 'OX' )
59 geompy.addToStudy( OY, 'OY' )
60 geompy.addToStudy( OZ, 'OZ' )
64 triangle = makePolygon(O, 1, 3, "triangle")
66 P1 = geompy.MakeVertex(2, 0, 0)
67 quadrangle = makePolygon(P1, 1, 4, "quadrangle")
69 P2 = geompy.MakeVertex(4, 0, 0)
70 pentagon = makePolygon(P2, 1, 5, "pentagon")
72 P3 = geompy.MakeVertex(6, 0, 0)
73 hexagon = makePolygon(P3, 1, 6, "hexagon")
75 P4 = geompy.MakeVertex(8, 0, 0)
76 heptagon = makePolygon(P4, 1, 7, "heptagon")
78 P5 = geompy.MakeVertex(10, 0, 0)
79 octagon = makePolygon(P5, 1, 7, "octagon")
81 polygons = [triangle, quadrangle, pentagon, hexagon, heptagon, octagon]
83 for polygon in polygons:
84 name = polygon.GetName()
85 polygon_extruded = geompy.MakePrismVecH(polygon, OZ, height, theName="%s_prism"%name)
86 polygon_summit = makeSummitSolid(polygon, -height, theName="%s_summit"%name)
87 polyhedrons += [polygon_extruded, polygon_summit]
89 solids = geompy.MakeCompound(polyhedrons, theName="solids")
96 import SMESH, SALOMEDS
97 from salome.smesh import smeshBuilder
99 smesh = smeshBuilder.New()
101 Mesh_1 = smesh.Mesh(solids)
102 Regular_1D = Mesh_1.Segment()
103 Number_of_Segments_1 = Regular_1D.NumberOfSegments(1)
104 PolygonPerFace_2D = Mesh_1.Polygon()
105 PolyhedronPerSolid_3D = Mesh_1.Polyhedron()
107 ok = Mesh_1.Compute()
109 raise Exception("Error when computing Mesh")
112 vol_geom = geompy.BasicProperties(solids)[2]
113 vol_mesh = Mesh_1.GetVolume()
115 assert abs(vol_geom - vol_mesh) < 1e-12
117 assert Mesh_1.NbVolumes() == 12
119 # check type of elements
120 assert Mesh_1.NbTetras() == 1
121 assert Mesh_1.NbHexas() == 1
122 assert Mesh_1.NbPyramids() == 1
123 assert Mesh_1.NbPrisms() == 1
124 assert Mesh_1.NbHexagonalPrisms() == 1
125 assert Mesh_1.NbPolyhedrons() == 7
128 if salome.sg.hasDesktop():
129 salome.sg.updateObjBrowser()