1 # -*- coding: iso-8859-1 -*-
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
11 O = geompy.MakeVertex(0, 0, 0)
12 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
13 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
14 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
16 Face_1 = geompy.MakeFaceHW(10, 10, 1)
17 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
18 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 )
19 vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
20 Curve_1 = geompy.MakeInterpol(vertices, True, True)
22 part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
23 geompy.addToStudy(part, "part")
25 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
26 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
27 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
29 p1 = geompy.MakeVertex(-5, -5, 0)
30 p2 = geompy.MakeVertex(5, 5, 0)
31 left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
32 left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
33 geompy.UnionList(left, left_edges)
34 geompy.addToStudyInFather(part, left, "left")
36 right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
37 right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
38 geompy.UnionList(right, right_edges)
39 geompy.addToStudyInFather(part, right, "right")
41 bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
42 bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
43 geompy.UnionList(bottom, bottom_edges)
44 geompy.addToStudyInFather(part, bottom, "bottom")
46 top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
47 top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
48 geompy.UnionList(top, top_edges)
49 geompy.addToStudyInFather(part, top, "top")
56 from salome.smesh import smeshBuilder
57 smesh = smeshBuilder.New(salome.myStudy)
59 Mesh = smesh.Mesh(part, "Mesh")
61 algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
62 algo2d.SetVerbosity(1)
63 #algo2d.SetTopology(smesh.PreCAD)
64 algo2d.SetGeometricMesh( 1 )
65 algo2d.SetAngleMesh( 4 )
66 algo2d.SetPhySize( 8 )
67 #algo2d.SetGradation(1.05)
68 algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
72 p_axe = geompy.MakeVertex(5, -5, 0)
73 axe = geompy.MakePrismVecH(p_axe, Vz, 1)
75 shape2 = geompy.MakeRotation(shape1, axe, -math.pi/2)
78 def AddAdvancedEdgesPeriodicity(edges1, edges2, f_transf):
79 source_edges = geompy.SubShapeAll(edges1, geompy.ShapeType["EDGE"])
82 for source_edge in source_edges:
83 geompy.addToStudyInFather(edges1, source_edge, "source_edge_%i"%j)
84 p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
85 p_target = f_transf(p_source)
86 target_edge = geompy.GetEdgeNearPoint(part, p_target)
87 geompy.addToStudyInFather(edges2, target_edge, "target_edge_%i"%j)
88 algo2d.AddEdgePeriodicityWithoutFaces(source_edge, target_edge)
92 source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
93 for source_vertex in source_vertices:
94 geompy.addToStudyInFather(edges1, source_vertex, "source_vertex_%i"%k)
95 target_vertex_tmp = geompy.MakeTranslation(source_vertex, 10, 0., 0)
96 target_vertex_tmp = f_transf(source_vertex)
97 target_vertex = geompy.GetSame(part, target_vertex_tmp)
98 geompy.addToStudyInFather(edges2, target_vertex, "target_vertex_%i"%k)
99 algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
103 AddAdvancedEdgesPeriodicity(bottom, right, rota_z)
107 gr_left = Mesh.Group(left)
108 gr_right = Mesh.Group(right)
109 gr_bottom = Mesh.Group(bottom)
110 gr_top = Mesh.Group(top)
114 bottom_rotated = Mesh.RotateObjectMakeMesh( gr_bottom, axe, -math.pi/2, NewMeshName='bottom_rotated' )
116 def checkProjection(gr, mesh_translated, tol=1e-7):
117 name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
118 mesh_source = smesh.CopyMesh(gr, gr.GetName())
119 mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
120 ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
121 coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
122 mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
123 mesh_nodes = mesh_check.GetNodesId()
124 if len(ll_coincident_nodes) != mesh_translated.NbNodes():
125 non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
126 mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
127 raise Exception("Projection failed for %s"%name)
129 checkProjection(gr_right, bottom_rotated)
131 if salome.sg.hasDesktop():
132 salome.sg.updateObjBrowser(1)