]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - tests/periodicity_2D_prepro.py
Salome HOME
Merge V8_4_BR branch.
[plugins/blsurfplugin.git] / tests / periodicity_2D_prepro.py
1 # -*- coding: iso-8859-1 -*-
2
3 import sys
4 import salome
5
6 ###
7 ### GEOM component
8 ###
9
10 import math
11
12 import GEOM
13 from salome.geom import geomBuilder
14 geompy = geomBuilder.New(salome.myStudy)
15
16 O = geompy.MakeVertex(0, 0, 0)
17 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
18 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
19 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
20 Face_1 = geompy.MakeFaceHW(10, 10, 1)
21 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
22 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 )
23 vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
24 Curve_1 = geompy.MakeInterpol(vertices, True, True)
25
26 part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
27 geompy.addToStudy(part, "part")
28
29 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
30 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
31 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
32
33 p1 = geompy.MakeVertex(-5, -5, 0)
34 p2 = geompy.MakeVertex(5, 5, 0)
35 left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
36 left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
37 geompy.UnionList(left, left_edges)
38 geompy.addToStudyInFather(part, left, "left")
39
40 right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
41 right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
42 geompy.UnionList(right, right_edges)
43 geompy.addToStudyInFather(part, right, "right")
44
45 bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
46 bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
47 geompy.UnionList(bottom, bottom_edges)
48 geompy.addToStudyInFather(part, bottom, "bottom")
49
50 top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
51 top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
52 geompy.UnionList(top, top_edges)
53 geompy.addToStudyInFather(part, top, "top")
54
55 source_face = geompy.GetFaceNearPoint(part, p1)
56 geompy.addToStudyInFather(part, source_face, "source_face")
57
58
59 # Mesh
60 # ====
61
62 import SMESH
63 from salome.smesh import smeshBuilder
64 smesh = smeshBuilder.New(salome.myStudy)
65
66 Mesh = smesh.Mesh(part, "Mesh")
67
68 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
69 algo2d.SetGeometricMesh( 1 )
70 algo2d.SetAngleMesh( 4 )
71 algo2d.SetPhySize( 8 )
72 #algo2d.SetGradation(1.05)
73
74 # Periodicity
75 #algo2d.SetVerbosity(10)
76 algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
77 algo2d.AddPreCadEdgesPeriodicity(left, right)
78 algo2d.AddPreCadEdgesPeriodicity(bottom, top)
79
80
81 Mesh.Compute()
82
83 gr_left = Mesh.Group(left)
84 gr_right = Mesh.Group(right)
85 gr_bottom = Mesh.Group(bottom)
86 gr_top = Mesh.Group(top)
87
88 Mesh.Compute()
89
90 left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' )
91 bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' )
92
93 def checkProjection(gr, mesh_translated, tol=1e-7):
94     name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
95     mesh_source = smesh.CopyMesh(gr, gr.GetName())
96     mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
97     ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
98     coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
99     mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
100     mesh_nodes = mesh_check.GetNodesId()
101     if len(ll_coincident_nodes) != mesh_translated.NbNodes():
102         non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
103         mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
104         raise Exception("Projection failed for %s"%name)
105         
106 checkProjection(gr_right, left_translated)
107 checkProjection(gr_top, bottom_translated)
108
109 if salome.sg.hasDesktop():
110   salome.sg.updateObjBrowser(True)