1 # -*- coding: utf-8 -*-
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
12 nb_faces_tolerance = 10
14 ## Return the min and max areas of a mesh
15 def getMinMaxArea(mesh):
16 faces = mesh.GetElementsByType(SMESH.FACE)
17 areas = [mesh.GetArea(face) for face in faces]
22 O = geompy.MakeVertex(0, 0, 0)
23 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
24 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
25 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
27 Face_1 = geompy.MakeFaceHW(10, 10, 1)
28 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
29 Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
30 vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
31 Curve_1 = geompy.MakeInterpol(vertices, True, True)
33 p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001)
34 geompy.addToStudy(p_small, "p_small")
36 p_small2 = geompy.MakeVertexOnCurve(Curve_1, 0.5)
37 geompy.addToStudy(p_small2, "p_small2")
39 p_small3 = geompy.MakeVertexOnCurve(Curve_1, 0.501)
40 geompy.addToStudy(p_small3, "p_small3")
42 part = geompy.MakePartition([Face_1], [Curve_1, p_small, p_small2, p_small3], Limit=geompy.ShapeType["FACE"])
43 geompy.addToStudy(part, "part")
45 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
46 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
47 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
49 p1 = geompy.MakeVertex(-5, -5, 0)
50 p2 = geompy.MakeVertex(5, 5, 0)
51 left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
52 left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
53 geompy.UnionList(left, left_edges)
54 geompy.addToStudyInFather(part, left, "left")
56 right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
57 right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
58 geompy.UnionList(right, right_edges)
59 geompy.addToStudyInFather(part, right, "right")
61 bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
62 bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
63 geompy.UnionList(bottom, bottom_edges)
64 geompy.addToStudyInFather(part, bottom, "bottom")
66 top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
67 top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
68 geompy.UnionList(top, top_edges)
69 geompy.addToStudyInFather(part, top, "top")
71 faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"])
73 for i, face in enumerate(faces):
74 geompy.addToStudyInFather(part, face, "face_%i"%(i+1))
75 sub_shapes.append(face)
81 from salome.smesh import smeshBuilder
82 smesh = smeshBuilder.New(salome.myStudy)
84 # Test gradation with quadrangles
85 Mesh_1 = smesh.Mesh(part, "Mesh")
87 algo2d = Mesh_1.Triangle(algo=smeshBuilder.BLSURF)
88 params = algo2d.Parameters()
89 params.SetGeometricMesh( 1 )
90 params.SetAngleMesh( 4 )
91 params.SetPhySize( 8 )
92 algo2d.SetGradation(1.05)
93 params.SetQuadAllowed( True )
98 raise Exception("Error when computing Mesh_1")
100 # Check the areas of Mesh_1
101 mini_1, maxi_1 = getMinMaxArea(Mesh_1)
105 if abs(mini_1-mini_1_ref) > area_tolerance:
106 raise Exception("Min area of Mesh_1 incorrect")
108 if abs(maxi_1-maxi_1_ref) > area_tolerance:
109 raise Exception("Max area of Mesh_1 incorrect")
111 # Check the number of faces of Mesh_1
112 nb_faces_1 = Mesh_1.NbFaces()
113 nb_faces_1_ref = 1208
115 if abs(nb_faces_1-nb_faces_1_ref) > nb_faces_tolerance:
116 raise Exception("Number of faces of Mesh_1 incorrect")
119 # Test no gradation with quadrangles and anisotropy
120 # RQ: this kind of mesh is not suitable for simulation
121 # but gives a coarse mesh like a stl geometry
122 Mesh_2 = smesh.Mesh(part, "Mesh")
124 algo2d = Mesh_2.Triangle(algo=smeshBuilder.BLSURF)
125 params = algo2d.Parameters()
126 params.SetGeometricMesh( 1 )
127 params.SetAngleMesh( 4 )
128 params.SetPhySize( 8 )
129 algo2d.SetGradation(1.05)
130 params.SetQuadAllowed( True )
131 params.SetAnisotropic(True)
133 ok = Mesh_2.Compute()
136 raise Exception("Error when computing Mesh_2")
138 # Check the areas of Mesh_2
139 mini_2, maxi_2 = getMinMaxArea(Mesh_2)
140 mini_2_ref = 0.000408
143 if abs(mini_2-mini_2_ref) > area_tolerance:
144 raise Exception("Min area of Mesh_2 incorrect")
146 if abs(maxi_2-maxi_2_ref) > area_tolerance:
147 raise Exception("Max area of Mesh_2 incorrect")
149 # Check the number of faces of Mesh_2
150 nb_faces_2 = Mesh_2.NbFaces()
152 if abs(nb_faces_2-nb_faces_2_ref) > nb_faces_tolerance:
153 raise Exception("Number of faces of Mesh_2 incorrect")
155 if salome.sg.hasDesktop():
156 salome.sg.updateObjBrowser(1)