Salome HOME
Merge V9_dev branch into master
[plugins/blsurfplugin.git] / tests / attractor_point_outside_face.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 radius = 10
33 height = 100
34 Cylinder_1 = geompy.MakeCylinderRH(radius, height)
35
36 p_half_height = geompy.MakeVertex(0, 0, height/2.)
37 plane_z = geompy.MakePlane(p_half_height, OZ, 2.5*radius)
38
39 Part_1 = geompy.MakePartition([Cylinder_1], [plane_z], Limit=geompy.ShapeType["FACE"])
40
41
42 geompy.addToStudy( O, 'O' )
43 geompy.addToStudy( OX, 'OX' )
44 geompy.addToStudy( OY, 'OY' )
45 geompy.addToStudy( OZ, 'OZ' )
46 geompy.addToStudy( Part_1, 'Part_1' )
47
48
49 p_edge_vert_opp_1 = geompy.MakeVertex(-radius, 0, 0)
50 geompy.addToStudy( p_edge_vert_opp_1, 'p_edge_vert_opp_1' )
51
52 edge_vert_opp_1 = geompy.MakePrismVecH(p_edge_vert_opp_1, OZ, height/2.)
53 geompy.addToStudy( edge_vert_opp_1, 'edge_vert_opp_1' )
54
55 p_edge_vert_opp_2 = geompy.MakeVertex(-radius, 0, height/4.)
56 geompy.addToStudy( p_edge_vert_opp_2, 'p_edge_vert_opp_2' )
57
58 p_face_cyl_1 = geompy.MakeVertex(0, radius, height/4.)
59 p_face_cyl_2 = geompy.MakeVertex(0, radius, 3*height/4.)
60
61 face_1 = geompy.GetFaceNearPoint(Part_1, p_face_cyl_1)
62 face_2 = geompy.GetFaceNearPoint(Part_1, p_face_cyl_2)
63
64 geompy.addToStudyInFather(Part_1, face_1, "face_1")
65 geompy.addToStudyInFather(Part_1, face_2, "face_2")
66
67 ###
68 ### SMESH component
69 ###
70
71 from salome.smesh import smeshBuilder
72
73 smesh = smeshBuilder.New()
74 Mesh_1 = smesh.Mesh(Part_1)
75 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
76 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
77 MG_CADSurf_Parameters_1.SetPhySize( 14.1421 )
78 MG_CADSurf_Parameters_1.SetMinSize( 0.141421 )
79 MG_CADSurf_Parameters_1.SetMaxSize( 28.2843 )
80 MG_CADSurf_Parameters_1.SetChordalError( 7.07107 )
81 #MG_CADSurf_Parameters_1.SetAttractorGeom( sub_Face_1, Edge_1, 1, 14.1421, 5, 5 )
82
83 ok = Mesh_1.Compute()
84
85 if not ok:
86   raise Exception("Mesh not computed")
87
88 min_area_without_attractor = getMinArea(Mesh_1)
89
90 print("min_area_without_attractor: ", min_area_without_attractor)
91
92 MG_CADSurf_Parameters_1.SetAttractorGeom( face_1, edge_vert_opp_1, 1, 14.1421, 5, 5 )
93 # the attractor is not on the face. It is done on purpose to test this out of bounds case.
94 MG_CADSurf_Parameters_1.SetAttractorGeom( face_2, p_edge_vert_opp_2, 1, 14.1421, 5, 5 )
95
96 ok = Mesh_1.Compute()
97
98 if not ok:
99   raise Exception("Mesh with attractors not computed")
100
101 min_area_with_attractor = getMinArea(Mesh_1)
102
103 print("min_area_with_attractor: ", min_area_with_attractor)
104
105 assert min_area_with_attractor < min_area_without_attractor
106
107 assert min_area_with_attractor < 1
108
109 if salome.sg.hasDesktop():
110   salome.sg.updateObjBrowser(True)