Salome HOME
updated copyright message
[plugins/blsurfplugin.git] / tests / proximity.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-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 ###
27 ### GEOM component
28 ###
29
30 import GEOM
31 from salome.geom import geomBuilder
32 import math
33 import SALOMEDS
34
35
36 geompy = geomBuilder.New()
37
38 # Create a box
39 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
40
41 # Create a sphere near the sides of the box
42 sphere_tmp = geompy.MakeSphereR(5)
43 sphere = geompy.MakeTranslation(sphere_tmp, 6, 6, 50)
44
45 part = geompy.MakePartition([box, sphere])
46 geompy.addToStudy( box, 'box' )
47 geompy.addToStudy( sphere, 'sphere' )
48 geompy.addToStudy( part, 'part' )
49
50 # Create the groups of faces
51 box_faces = geompy.GetShapesOnBox(box, part, geompy.ShapeType["FACE"], GEOM.ST_ON)
52 gr_box_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
53 geompy.UnionList(gr_box_faces, box_faces)
54 geompy.addToStudyInFather(part, gr_box_faces, "box_faces")
55
56 all_faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"])
57 gr_all_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
58 geompy.UnionList(gr_all_faces, all_faces)
59
60 gr_spheres_faces = geompy.CutGroups(gr_all_faces, gr_box_faces)
61 geompy.addToStudyInFather(part, gr_spheres_faces, "spheres_faces")
62
63 ###
64 ### SMESH component
65 ###
66
67 import  SMESH, SALOMEDS
68 from salome.smesh import smeshBuilder
69
70 smesh = smeshBuilder.New()
71 Mesh_1 = smesh.Mesh(part, "Mesh_part")
72 BLSURF = Mesh_1.Triangle(algo=smeshBuilder.BLSURF)
73 BLSURF_Parameters_1 = BLSURF.Parameters()
74 BLSURF_Parameters_1.SetGradation( 1.2 )
75 BLSURF_Parameters_1.SetGeometricMesh( 1 )
76 BLSURF_Parameters_1.SetPhySize( 20 )
77 #BLSURF_Parameters_1.SetMinSize( 0.1 )
78 BLSURF_Parameters_1.SetMaxSize( 20 )
79 BLSURF_Parameters_1.SetAngleMesh( 8 )
80
81 # Old way to set proximity (Mesh Gems 1.1)
82 #BLSURF_Parameters_1.SetOptionValue( 'proximity', '1' )
83 #BLSURF_Parameters_1.SetOptionValue( 'prox_ratio', '1.2' )
84 #BLSURF_Parameters_1.SetOptionValue( 'prox_nb_layer', '3' )
85
86 # New way to set proximity (Mesh Gems >= 1.3)
87 BLSURF_Parameters_1.SetOptionValue( "volume_gradation", "1.2" )
88
89 isDone = Mesh_1.Compute()
90 if not isDone:
91     raise Exception("Compute mesh ended in error")
92
93 # Create the groups on the mesh
94 gr_mesh_box = Mesh_1.Group(gr_box_faces)
95 gr_mesh_spheres = Mesh_1.Group(gr_spheres_faces)
96
97 # Check the minimal area of the box faces to check the proximity
98 min_area, max_area = Mesh_1.GetMinMax(SMESH.FT_Area, gr_mesh_box)
99
100 print("min_area: ", min_area)
101
102 if min_area > 1.5:
103     raise Exception("Wrong minimal area on box. Proximity has not worked.")
104
105 if salome.sg.hasDesktop():
106   salome.sg.updateObjBrowser()