Salome HOME
1150ed356f07dfcc0402333ae3cd20b947696bce
[plugins/blsurfplugin.git] / tests / attractor_point_outside_face.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-2023  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 sys
22 import salome
23
24 salome.salome_init()
25
26 import  SMESH, SALOMEDS
27
28 ## Compute the minimum area of the faces of the mesh
29 def getMinArea(mesh):
30   faces = mesh.GetElementsByType(SMESH.FACE)
31   areas = [mesh.GetArea(face) for face in faces]
32   return min(areas)
33
34 ###
35 ### GEOM component
36 ###
37
38 import GEOM
39 from salome.geom import geomBuilder
40 import math
41 import SALOMEDS
42
43
44 geompy = geomBuilder.New()
45
46 O = geompy.MakeVertex(0, 0, 0)
47 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
48 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
49 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
50 radius = 10
51 height = 100
52 Cylinder_1 = geompy.MakeCylinderRH(radius, height)
53
54 p_half_height = geompy.MakeVertex(0, 0, height/2.)
55 plane_z = geompy.MakePlane(p_half_height, OZ, 2.5*radius)
56
57 Part_1 = geompy.MakePartition([Cylinder_1], [plane_z], Limit=geompy.ShapeType["FACE"])
58
59
60 geompy.addToStudy( O, 'O' )
61 geompy.addToStudy( OX, 'OX' )
62 geompy.addToStudy( OY, 'OY' )
63 geompy.addToStudy( OZ, 'OZ' )
64 geompy.addToStudy( Part_1, 'Part_1' )
65
66
67 p_edge_vert_opp_1 = geompy.MakeVertex(-radius, 0, 0)
68 geompy.addToStudy( p_edge_vert_opp_1, 'p_edge_vert_opp_1' )
69
70 edge_vert_opp_1 = geompy.MakePrismVecH(p_edge_vert_opp_1, OZ, height/2.)
71 geompy.addToStudy( edge_vert_opp_1, 'edge_vert_opp_1' )
72
73 p_edge_vert_opp_2 = geompy.MakeVertex(-radius, 0, height/4.)
74 geompy.addToStudy( p_edge_vert_opp_2, 'p_edge_vert_opp_2' )
75
76 p_face_cyl_1 = geompy.MakeVertex(0, radius, height/4.)
77 p_face_cyl_2 = geompy.MakeVertex(0, radius, 3*height/4.)
78
79 face_1 = geompy.GetFaceNearPoint(Part_1, p_face_cyl_1)
80 face_2 = geompy.GetFaceNearPoint(Part_1, p_face_cyl_2)
81
82 geompy.addToStudyInFather(Part_1, face_1, "face_1")
83 geompy.addToStudyInFather(Part_1, face_2, "face_2")
84
85 ###
86 ### SMESH component
87 ###
88
89 from salome.smesh import smeshBuilder
90
91 smesh = smeshBuilder.New()
92 Mesh_1 = smesh.Mesh(Part_1)
93 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
94 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
95 MG_CADSurf_Parameters_1.SetPhySize( 14.1421 )
96 MG_CADSurf_Parameters_1.SetMinSize( 0.141421 )
97 MG_CADSurf_Parameters_1.SetMaxSize( 28.2843 )
98 MG_CADSurf_Parameters_1.SetChordalError( 7.07107 )
99 #MG_CADSurf_Parameters_1.SetAttractorGeom( sub_Face_1, Edge_1, 1, 14.1421, 5, 5 )
100
101 ok = Mesh_1.Compute()
102
103 if not ok:
104   raise Exception("Mesh not computed")
105
106 min_area_without_attractor = getMinArea(Mesh_1)
107
108 print("min_area_without_attractor: ", min_area_without_attractor)
109
110 MG_CADSurf_Parameters_1.SetAttractorGeom( face_1, edge_vert_opp_1, 1, 14.1421, 5, 5 )
111 # the attractor is not on the face. It is done on purpose to test this out of bounds case.
112 MG_CADSurf_Parameters_1.SetAttractorGeom( face_2, p_edge_vert_opp_2, 1, 14.1421, 5, 5 )
113
114 ok = Mesh_1.Compute()
115
116 if not ok:
117   raise Exception("Mesh with attractors not computed")
118
119 min_area_with_attractor = getMinArea(Mesh_1)
120
121 print("min_area_with_attractor: ", min_area_with_attractor)
122
123 assert min_area_with_attractor < min_area_without_attractor
124
125 assert min_area_with_attractor < 1
126
127 if salome.sg.hasDesktop():
128   salome.sg.updateObjBrowser()