Salome HOME
Enable C++0x/C++11 support
[plugins/blsurfplugin.git] / tests / test_periodicity_reflexion.py
1 # -*- coding: utf-8 -*-
2
3 import salome
4
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8
9 import math
10
11 simple = False
12
13 r = 10
14 dist = 10
15
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")
20
21 p3 = geompy.MakeVertex(25., 5., 25.)
22 sphere1 = geompy.MakeSpherePntR(p3, 15.)
23 geompy.addToStudy(sphere1, "sphere1")
24
25 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
26 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
27 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
28
29 p4 = geompy.MakeVertex(100., 0., 0.)
30 axe = geompy.MakePrismVecH(p4, Vz, 1)
31 geompy.addToStudy(axe, "axe")
32
33 sphere1_rota = geompy.MakeRotation(sphere1, axe, -math.pi/2.)
34 geompy.addToStudy(sphere1_rota, "sphere1_rota")
35
36 part = geompy.MakePartition([box], [sphere1, sphere1_rota])
37 geompy.addToStudy(part, "part")
38
39 left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
40 left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
41 geompy.UnionList(left, left_faces)
42 geompy.addToStudyInFather(part, left, "left")
43
44 right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
45 right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
46 geompy.UnionList(right, right_faces)
47 geompy.addToStudyInFather(part, right, "right")
48
49 back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
50 back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
51 geompy.UnionList(back, back_faces)
52 geompy.addToStudyInFather(part, back, "back")
53
54 front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
55 front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
56 geompy.UnionList(front, front_faces)
57 geompy.addToStudyInFather(part, front, "front")
58
59 bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
60 bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
61 geompy.UnionList(bottom, bottom_faces)
62 geompy.addToStudyInFather(part, bottom, "bottom")
63
64 top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
65 top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
66 geompy.UnionList(top, top_faces)
67 geompy.addToStudyInFather(part, top, "top")
68
69 sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
70 geompy.UnionList(sources, left_faces)
71 geompy.UnionList(sources, back_faces)
72 geompy.UnionList(sources, top_faces)
73 geompy.addToStudyInFather(part, sources, "sources")
74
75
76 # Mesh
77 # ====
78
79 import SMESH
80 from salome.smesh import smeshBuilder
81 smesh = smeshBuilder.New(salome.myStudy)
82
83 from salome.BLSURFPlugin import BLSURFPluginBuilder
84
85 Mesh = smesh.Mesh(part, "Mesh")
86
87 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
88 algo2d.SetGeometricMesh( 1 )
89 algo2d.SetAngleMesh( 4 )
90 algo2d.SetPhySize( 8 )
91 algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
92 # Deactivate PreCAD
93 algo2d.SetTopology(BLSURFPluginBuilder.FromCAD)
94
95 def rota_z(shape1):
96     shape2 = geompy.MakeRotation(shape1, axe, -math.pi/2)
97     return shape2
98
99 algo2d.AddAdvancedFacesPeriodicity(left, front, rota_z)
100
101 gr_left = Mesh.Group(left)
102 gr_right = Mesh.Group(right)
103 gr_front = Mesh.Group(front)
104 gr_back = Mesh.Group(back)
105 gr_bottom = Mesh.Group(bottom)
106 gr_top = Mesh.Group(top)
107
108 Mesh.Compute()
109
110 left_rotated = Mesh.RotateObjectMakeMesh( gr_left, axe, -math.pi/2, NewMeshName='left_rotated' )
111
112 def checkProjection(gr, mesh_translated, tol=1e-7):
113     name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
114     mesh_source = smesh.CopyMesh(gr, gr.GetName())
115     mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
116     ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
117     coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
118     mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
119     mesh_nodes = mesh_check.GetNodesId()
120     if len(ll_coincident_nodes) != mesh_translated.NbNodes():
121         non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
122         mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
123         raise Exception("Projection failed for %s"%name)
124         
125 checkProjection(gr_front, left_rotated)
126
127 salome.sg.updateObjBrowser(0)
128