Salome HOME
Merge V9_dev branch into master
[plugins/blsurfplugin.git] / tests / attractor_edge_on_border.py
1 # -*- coding: utf-8 -*-
2
3 import sys
4 import salome
5
6 salome.salome_init()
7
8 import  SMESH, SALOMEDS
9
10 ## Compute the minimum area of the faces of the mesh
11 def getMinArea(mesh):
12   faces = mesh.GetElementsByType(SMESH.FACE)
13   areas = [mesh.GetArea(face) for face in faces]
14   return min(areas)
15
16 ###
17 ### GEOM component
18 ###
19
20 import GEOM
21 from salome.geom import geomBuilder
22 import math
23 import SALOMEDS
24
25
26 geompy = geomBuilder.New()
27
28 O = geompy.MakeVertex(0, 0, 0)
29 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
30 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
31 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
32 Face_1 = geompy.MakeFaceHW(100, 100, 1)
33 Box_1 = geompy.MakePrismVecH(Face_1, OZ, -100)
34 # define the edge slightly longer than the face to test out of bounds case.
35 P1 = geompy.MakeVertex(-50.5, 0, 0)
36 P2 = geompy.MakeVertex(50.5, 0, 0)
37 Edge_1 = geompy.MakeEdge(P1, P2)
38 geompy.addToStudy( O, 'O' )
39 geompy.addToStudy( OX, 'OX' )
40 geompy.addToStudy( OY, 'OY' )
41 geompy.addToStudy( OZ, 'OZ' )
42 geompy.addToStudy( Face_1, 'Face_1' )
43 geompy.addToStudy( Box_1, 'Box_1' )
44 geompy.addToStudy( Edge_1, 'Edge_1' )
45
46 sub_Face_1 = geompy.GetInPlace(Box_1, Face_1)
47 geompy.addToStudyInFather(Box_1, sub_Face_1, "Face_1")
48
49 ###
50 ### SMESH component
51 ###
52
53 from salome.smesh import smeshBuilder
54
55 smesh = smeshBuilder.New()
56 Mesh_1 = smesh.Mesh(Box_1)
57 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
58 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
59 MG_CADSurf_Parameters_1.SetPhySize( 14.1421 )
60 MG_CADSurf_Parameters_1.SetMinSize( 0.141421 )
61 MG_CADSurf_Parameters_1.SetMaxSize( 28.2843 )
62 MG_CADSurf_Parameters_1.SetChordalError( 7.07107 )
63 #MG_CADSurf_Parameters_1.SetAttractorGeom( sub_Face_1, Edge_1, 1, 14.1421, 5, 5 )
64
65 Mesh_1.Compute()
66
67 min_area_without_attractor = getMinArea(Mesh_1)
68
69 print("min_area_without_attractor: ", min_area_without_attractor)
70
71 MG_CADSurf_Parameters_1.SetAttractorGeom( sub_Face_1, Edge_1, 1, 14.1421, 5, 5 )
72
73 Mesh_1.Compute()
74
75 min_area_with_attractor = getMinArea(Mesh_1)
76
77 print("min_area_with_attractor: ", min_area_with_attractor)
78
79 assert min_area_with_attractor < min_area_without_attractor
80
81 assert min_area_with_attractor < 1
82
83 if salome.sg.hasDesktop():
84   salome.sg.updateObjBrowser(True)