Salome HOME
Update copyrights
[plugins/blsurfplugin.git] / tests / periodicity_reflexion_prepro.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2019  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import salome
22 import math
23
24 import GEOM
25 from salome.geom import geomBuilder
26 geompy = geomBuilder.New()
27
28 simple = False
29
30 r = 10
31 dist = 10
32
33 p1 = geompy.MakeVertex(0., 0., 0.)
34 p2 = geompy.MakeVertex(100., 100., 100.)
35 box = geompy.MakeBoxTwoPnt(p1, p2)
36 geompy.addToStudy(box, "box")
37
38 p3 = geompy.MakeVertex(50., 5., 25.)
39 sphere1 = geompy.MakeSpherePntR(p3, 15.)
40 geompy.addToStudy(sphere1, "sphere1")
41
42 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
43 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
44 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
45
46 p4 = geompy.MakeVertex(100., 0., 0.)
47 axe = geompy.MakePrismVecH(p4, Vz, 1)
48 geompy.addToStudy(axe, "axe")
49
50 sphere1_rota = geompy.MakeRotation(sphere1, axe, -math.pi/2.)
51 geompy.addToStudy(sphere1_rota, "sphere1_rota")
52
53 part = geompy.MakePartition([box], [sphere1, sphere1_rota])
54 geompy.addToStudy(part, "part")
55
56 left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
57 left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
58 geompy.UnionList(left, left_faces)
59 geompy.addToStudyInFather(part, left, "left")
60
61 right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
62 right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
63 geompy.UnionList(right, right_faces)
64 geompy.addToStudyInFather(part, right, "right")
65
66 back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
67 back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
68 geompy.UnionList(back, back_faces)
69 geompy.addToStudyInFather(part, back, "back")
70
71 front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
72 front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
73 geompy.UnionList(front, front_faces)
74 geompy.addToStudyInFather(part, front, "front")
75
76 bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
77 bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
78 geompy.UnionList(bottom, bottom_faces)
79 geompy.addToStudyInFather(part, bottom, "bottom")
80
81 top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
82 top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
83 geompy.UnionList(top, top_faces)
84 geompy.addToStudyInFather(part, top, "top")
85
86 p1_rota = geompy.MakeRotation(p1, axe, -math.pi/2.)
87 geompy.addToStudy(sphere1_rota, "sphere1_rota")
88
89 p5 = geompy.MakeVertex(100, 0, 100)
90 geompy.addToStudy(p5, "p5")
91
92 # Mesh
93 # ====
94
95 import SMESH
96 from salome.smesh import smeshBuilder
97 smesh = smeshBuilder.New()
98
99 Mesh = smesh.Mesh(part, "Mesh")
100
101 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
102 algo2d.SetGeometricMesh( 1 )
103 algo2d.SetAngleMesh( 4 )
104 algo2d.SetPhySize( 8 )
105
106 # Periodicity
107 #algo2d.SetVerbosity(10)
108 #algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
109 algo2d.AddPreCadFacesPeriodicity(left, front, [p1, p4, p5], [p1_rota, p4, p5])
110
111
112 gr_left = Mesh.Group(left)
113 gr_right = Mesh.Group(right)
114 gr_front = Mesh.Group(front)
115 gr_back = Mesh.Group(back)
116 gr_bottom = Mesh.Group(bottom)
117 gr_top = Mesh.Group(top)
118
119 Mesh.Compute()
120
121 left_rotated = Mesh.RotateObjectMakeMesh( gr_left, axe, -math.pi/2, NewMeshName='left_rotated' )
122
123 def checkProjection(gr, mesh_translated, tol=1e-7):
124     name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
125     mesh_source = smesh.CopyMesh(gr, gr.GetName())
126     mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
127     ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
128     coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
129     mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
130     mesh_nodes = mesh_check.GetNodesId()
131     if len(ll_coincident_nodes) != mesh_translated.NbNodes():
132         non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
133         mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
134         raise Exception("Projection failed for %s"%name)
135         
136 checkProjection(gr_front, left_rotated)
137
138 salome.sg.updateObjBrowser()
139