1 # -*- coding: utf-8 -*-
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
16 p1 = geompy.MakeVertex(0., 0., 0.)
17 p2 = geompy.MakeVertex(100., 100., 100.)
18 box = geompy.MakeBoxTwoPnt(p1, p2)
19 geompy.addToStudy(box, "box")
21 p3 = geompy.MakeVertex(25., 5., 25.)
22 sphere1 = geompy.MakeSpherePntR(p3, 15.)
23 geompy.addToStudy(sphere1, "sphere1")
25 sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
26 geompy.addToStudy(sphere1_trans, "sphere1_trans")
28 sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
29 geompy.addToStudy(sphere1_trans, "sphere1_trans")
31 p4 = geompy.MakeVertex(5, 50, 90)
32 sphere2 = geompy.MakeSpherePntR(p4, 20.)
34 sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0)
35 geompy.addToStudy(sphere2_trans, "sphere2_trans")
37 sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100)
38 geompy.addToStudy(sphere2_trans2, "sphere2_trans2")
40 sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100)
41 geompy.addToStudy(sphere2_trans3, "sphere2_trans3")
46 part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3])
47 geompy.addToStudy(part, "part")
49 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
50 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
51 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
53 left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
54 left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
55 geompy.UnionList(left, left_faces)
56 geompy.addToStudyInFather(part, left, "left")
58 right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
59 right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
60 geompy.UnionList(right, right_faces)
61 geompy.addToStudyInFather(part, right, "right")
63 back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
64 back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
65 geompy.UnionList(back, back_faces)
66 geompy.addToStudyInFather(part, back, "back")
68 front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
69 front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
70 geompy.UnionList(front, front_faces)
71 geompy.addToStudyInFather(part, front, "front")
73 bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
74 bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
75 geompy.UnionList(bottom, bottom_faces)
76 geompy.addToStudyInFather(part, bottom, "bottom")
78 top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
79 top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
80 geompy.UnionList(top, top_faces)
81 geompy.addToStudyInFather(part, top, "top")
83 sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
84 geompy.UnionList(sources, left_faces)
85 geompy.UnionList(sources, back_faces)
86 geompy.UnionList(sources, top_faces)
87 geompy.addToStudyInFather(part, sources, "sources")
94 from salome.smesh import smeshBuilder
95 smesh = smeshBuilder.New(salome.myStudy)
97 Mesh = smesh.Mesh(part, "Mesh")
99 algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
100 algo2d.SetGeometricMesh( 1 )
101 algo2d.SetAngleMesh( 4 )
102 algo2d.SetPhySize( 8 )
103 algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
106 shape2 = geompy.MakeTranslation(shape1, 100, 0., 0)
110 shape2 = geompy.MakeTranslation(shape1, 0, 100., 0)
114 shape2 = geompy.MakeTranslation(shape1, 0, 0, 100.)
117 def AddAdvancedFacesPeriodicity(faces1, faces2, f_transf):
118 # Periodicity left/right
119 source_faces = geompy.SubShapeAll(faces1, geompy.ShapeType["FACE"])
123 for source_face in source_faces:
124 geompy.addToStudyInFather(faces1, source_face, "source_face_%i"%i)
125 p_source = geompy.MakeVertexInsideFace(source_face)
126 p_target = f_transf(p_source)
127 target_face = geompy.GetFaceNearPoint(faces2, p_target)
128 geompy.addToStudyInFather(faces2, target_face, "target_face_%i"%i)
129 algo2d.AddFacePeriodicity(source_face, target_face)
132 source_edges = geompy.SubShapeAll(source_face, geompy.ShapeType["EDGE"])
133 for source_edge in source_edges:
134 geompy.addToStudyInFather(faces1, source_edge, "source_edge_%i"%(j))
135 p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
136 p_target = f_transf(p_source)
137 target_edge = geompy.GetEdgeNearPoint(faces2, p_target)
138 geompy.addToStudyInFather(faces2, target_edge, "target_edge_%i"%(j))
139 algo2d.AddEdgePeriodicity(source_face, source_edge, target_face, target_edge)
142 source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
143 for source_vertex in source_vertices:
144 geompy.addToStudyInFather(faces1, source_vertex, "source_vertex_%i"%(k))
145 target_vertex_tmp = f_transf(source_vertex)
146 target_vertex = geompy.GetSame(faces2, target_vertex_tmp)
147 geompy.addToStudyInFather(faces2, target_vertex, "target_vertex_%i"%(k))
148 algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
152 AddAdvancedFacesPeriodicity(back, front, proj_x)
153 AddAdvancedFacesPeriodicity(left, right, proj_y)
154 AddAdvancedFacesPeriodicity(bottom, top, proj_z)
156 gr_left = Mesh.Group(left)
157 gr_right = Mesh.Group(right)
158 gr_front = Mesh.Group(front)
159 gr_back = Mesh.Group(back)
160 gr_bottom = Mesh.Group(bottom)
161 gr_top = Mesh.Group(top)
165 left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' )
166 front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' )
167 bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' )
169 def checkProjection(gr, mesh_translated, tol=1e-7):
170 name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
171 mesh_source = smesh.CopyMesh(gr, gr.GetName())
172 mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
173 ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
174 coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
175 mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
176 mesh_nodes = mesh_check.GetNodesId()
177 if len(ll_coincident_nodes) != mesh_translated.NbNodes():
178 non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
179 mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
180 raise Exception("Projection failed for %s"%name)
182 checkProjection(gr_right, left_translated)
183 checkProjection(gr_back, front_translated)
184 checkProjection(gr_top, bottom_translated)
186 salome.sg.updateObjBrowser(0)