Salome HOME
ef0eb74deca42428756a7b608826ad9545f11e61
[plugins/blsurfplugin.git] / tests / attractor.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 Face_1 = geompy.MakeFaceHW(100, 100, 1)
51 Circle_1 = geompy.MakeCircle(None, None, 20)
52 geompy.addToStudy( O, 'O' )
53 geompy.addToStudy( OX, 'OX' )
54 geompy.addToStudy( OY, 'OY' )
55 geompy.addToStudy( OZ, 'OZ' )
56 geompy.addToStudy( Face_1, 'Face_1' )
57 geompy.addToStudy( Circle_1, 'Circle_1' )
58
59 ###
60 ### SMESH component
61 ###
62
63 from salome.smesh import smeshBuilder
64
65 smesh = smeshBuilder.New()
66 Mesh_1 = smesh.Mesh(Face_1)
67 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
68 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
69 MG_CADSurf_Parameters_1.SetPhySize( 14.1421 )
70 MG_CADSurf_Parameters_1.SetMinSize( 0.141421 )
71 MG_CADSurf_Parameters_1.SetMaxSize( 28.2843 )
72 MG_CADSurf_Parameters_1.SetChordalError( 7.07107 )
73 #MG_CADSurf_Parameters_1.SetAttractorGeom( Face_1, Circle_1, 1, 14.1421, 5, 5 )
74
75 Mesh_1.Compute()
76
77 min_area_without_attractor = getMinArea(Mesh_1)
78
79 print("min_area_without_attractor: ", min_area_without_attractor)
80
81 MG_CADSurf_Parameters_1.SetAttractorGeom( Face_1, Circle_1, 1, 14.1421, 5, 5 )
82
83 Mesh_1.Compute()
84
85 min_area_with_attractor = getMinArea(Mesh_1)
86
87 print("min_area_with_attractor: ", min_area_with_attractor)
88
89 assert min_area_with_attractor < min_area_without_attractor
90
91 assert min_area_with_attractor < 1
92
93 if salome.sg.hasDesktop():
94   salome.sg.updateObjBrowser()