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(10)
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' )
73 shape2 = geompy.MakeTranslation(shape1, 10, 0., 0)
77 shape2 = geompy.MakeTranslation(shape1, 0, 10., 0)
80 def AddAdvancedEdgesPeriodicity(edges1, edges2, f_transf):
81 source_edges = geompy.SubShapeAll(edges1, geompy.ShapeType["EDGE"])
84 for source_edge in source_edges:
85 geompy.addToStudyInFather(edges1, source_edge, "source_edge_%i"%j)
86 p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
87 p_target = f_transf(p_source)
88 target_edge = geompy.GetEdgeNearPoint(part, p_target)
89 geompy.addToStudyInFather(edges2, target_edge, "target_edge_%i"%j)
90 algo2d.AddEdgePeriodicityWithoutFaces(source_edge, target_edge)
94 source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
95 for source_vertex in source_vertices:
96 geompy.addToStudyInFather(edges1, source_vertex, "source_vertex_%i"%k)
97 target_vertex_tmp = geompy.MakeTranslation(source_vertex, 10, 0., 0)
98 target_vertex_tmp = f_transf(source_vertex)
99 target_vertex = geompy.GetSame(part, target_vertex_tmp)
100 geompy.addToStudyInFather(edges2, target_vertex, "target_vertex_%i"%k)
101 algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
105 AddAdvancedEdgesPeriodicity(left, right, proj_x)
106 AddAdvancedEdgesPeriodicity(bottom, top, proj_y)
110 gr_left = Mesh.Group(left)
111 gr_right = Mesh.Group(right)
112 gr_bottom = Mesh.Group(bottom)
113 gr_top = Mesh.Group(top)
117 left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' )
118 bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' )
120 def checkProjection(gr, mesh_translated, tol=1e-7):
121 name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
122 mesh_source = smesh.CopyMesh(gr, gr.GetName())
123 mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
124 ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
125 coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
126 mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
127 mesh_nodes = mesh_check.GetNodesId()
128 if len(ll_coincident_nodes) != mesh_translated.NbNodes():
129 non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
130 mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
131 raise Exception("Projection failed for %s"%name)
133 checkProjection(gr_right, left_translated)
134 checkProjection(gr_top, bottom_translated)
136 if salome.sg.hasDesktop():
137 salome.sg.updateObjBrowser(1)