Salome HOME
Merge V9_dev branch into master
[plugins/blsurfplugin.git] / tests / proximity.py
1 # -*- coding: utf-8 -*-
2
3 import sys
4 import salome
5
6 salome.salome_init()
7
8 ###
9 ### GEOM component
10 ###
11
12 import GEOM
13 from salome.geom import geomBuilder
14 import math
15 import SALOMEDS
16
17
18 geompy = geomBuilder.New()
19
20 # Create a box
21 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
22
23 # Create a sphere near the sides of the box
24 sphere_tmp = geompy.MakeSphereR(5)
25 sphere = geompy.MakeTranslation(sphere_tmp, 6, 6, 50)
26
27 part = geompy.MakePartition([box, sphere])
28 geompy.addToStudy( box, 'box' )
29 geompy.addToStudy( sphere, 'sphere' )
30 geompy.addToStudy( part, 'part' )
31
32 # Create the groups of faces
33 box_faces = geompy.GetShapesOnBox(box, part, geompy.ShapeType["FACE"], GEOM.ST_ON)
34 gr_box_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
35 geompy.UnionList(gr_box_faces, box_faces)
36 geompy.addToStudyInFather(part, gr_box_faces, "box_faces")
37
38 all_faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"])
39 gr_all_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
40 geompy.UnionList(gr_all_faces, all_faces)
41
42 gr_spheres_faces = geompy.CutGroups(gr_all_faces, gr_box_faces)
43 geompy.addToStudyInFather(part, gr_spheres_faces, "spheres_faces")
44
45 ###
46 ### SMESH component
47 ###
48
49 import  SMESH, SALOMEDS
50 from salome.smesh import smeshBuilder
51
52 smesh = smeshBuilder.New()
53 Mesh_1 = smesh.Mesh(part, "Mesh_part")
54 BLSURF = Mesh_1.Triangle(algo=smeshBuilder.BLSURF)
55 BLSURF_Parameters_1 = BLSURF.Parameters()
56 BLSURF_Parameters_1.SetGradation( 1.2 )
57 BLSURF_Parameters_1.SetGeometricMesh( 1 )
58 BLSURF_Parameters_1.SetPhySize( 20 )
59 #BLSURF_Parameters_1.SetMinSize( 0.1 )
60 BLSURF_Parameters_1.SetMaxSize( 20 )
61 BLSURF_Parameters_1.SetAngleMesh( 8 )
62
63 # Old way to set proximity (Mesh Gems 1.1)
64 #BLSURF_Parameters_1.SetOptionValue( 'proximity', '1' )
65 #BLSURF_Parameters_1.SetOptionValue( 'prox_ratio', '1.2' )
66 #BLSURF_Parameters_1.SetOptionValue( 'prox_nb_layer', '3' )
67
68 # New way to set proximity (Mesh Gems >= 1.3)
69 BLSURF_Parameters_1.SetOptionValue( "volume_gradation", "1.2" )
70
71 isDone = Mesh_1.Compute()
72 if not isDone:
73     raise Exception("Compute mesh ended in error")
74
75 # Create the groups on the mesh
76 gr_mesh_box = Mesh_1.Group(gr_box_faces)
77 gr_mesh_spheres = Mesh_1.Group(gr_spheres_faces)
78
79 # Check the minimal area of the box faces to check the proximity
80 min_area, max_area = Mesh_1.GetMinMax(SMESH.FT_Area, gr_mesh_box)
81
82 print("min_area: ", min_area)
83
84 if min_area > 1.5:
85     raise Exception("Wrong minimal area on box. Proximity has not worked.")
86
87 if salome.sg.hasDesktop():
88   salome.sg.updateObjBrowser()