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