Salome HOME
Integrate GMSH NR
[plugins/gmshplugin.git] / tests / gmsh_tetra_algorithms_for_box.py
1 #!/usr/bin/env python
2
3 '''
4 This file creates a box using GEOM then meshes the same using Gmsh's different algorithms
5
6 1. Frontal Delaunay ----> Gmsh_Parameters.Set3DAlgo( 0 )
7 2. Frontal Hex      ----> Gmsh_Parameters.Set3DAlgo( 1 )
8 3. MMG3D            ----> Gmsh_Parameters.Set3DAlgo( 2 )
9 4. R-Tree           ----> Gmsh_Parameters.Set3DAlgo( 3 )
10
11 This file is solely for the propose of testing and we do overwrite the meshes.
12 '''
13
14 import salome
15 salome.salome_init()
16
17 #------------------------------------ 
18 # GEOM: Creating a box of size 10^3
19 #------------------------------------
20 import GEOM
21 from salome.geom import geomBuilder
22
23 geompy = geomBuilder.New()
24 Box_1 = geompy.MakeBoxDXDYDZ(10, 10, 10)
25
26 #------------------------------------ 
27 # SMESH: Using Gmsh algorithm with size (3,10) (min,max)
28 #------------------------------------
29 import  SMESH
30 from salome.smesh import smeshBuilder
31 smesh = smeshBuilder.New()
32
33 Mesh_1 = smesh.Mesh(Box_1)
34 GMSH = Mesh_1.Tetrahedron(algo=smeshBuilder.GMSH)
35 Gmsh_Parameters = GMSH.Parameters()
36 Gmsh_Parameters.Set2DAlgo( 0 )
37 Gmsh_Parameters.SetMinSize( 3 )
38 Gmsh_Parameters.SetMaxSize( 10 )
39 Gmsh_Parameters.SetIs2d( 0 )
40
41
42 errorMsg=''
43 okMsg=''
44
45 #-------------------------------------
46 # Test: Frontal Delaunay
47 #-------------------------------------
48 try:
49   Gmsh_Parameters.Set3DAlgo( 0 )
50   isDone = Mesh_1.Compute()
51   if not isDone:
52     errorMsg+= '\n ERROR: failed to mesh the box using Frontal Delaunay algorithm from Gmsh\n'
53   else:
54     okMsg+= '\n PASSED: Successfully meshed the box using Frontal Delaunay algorithm from Gmsh\n'
55 except:
56       errorMsg+='\n ERROR: Exception raised in Mesh computation'
57
58 #-------------------------------------
59 # Test: Frontal Hex
60 #-------------------------------------
61 try:
62   Gmsh_Parameters.Set3DAlgo( 1 )
63   isDone = Mesh_1.Compute()
64   if not isDone:
65     errorMsg+= '\n ERROR: failed to mesh the box using Frontal Hex algorithm from Gmsh\n'
66   else:
67     okMsg+= '\n PASSED: Successfully meshed the box using Frontal Hex algorithm from Gmsh\n'    
68 except:
69       errorMsg+='\n ERROR: Exception raised in Mesh computation'
70
71 #-------------------------------------
72 # Test: MMG3D
73 #-------------------------------------      
74 try:
75   Gmsh_Parameters.Set3DAlgo( 2 )
76   isDone = Mesh_1.Compute()
77   if not isDone:
78     errorMsg+= '\n ERROR: failed to mesh the box using MMG3D algorithm from Gmsh\n'
79   else:
80     okMsg+= '\n PASSED: Successfully meshed the box using MMG3D algorithm from Gmsh\n'    
81 except:
82       errorMsg+='\n ERROR: Exception raised in Mesh computation'
83       
84 #-------------------------------------
85 # Test: R-Tree Algorithm
86 #-------------------------------------           
87 try:
88   Gmsh_Parameters.Set3DAlgo( 3 )
89   isDone = Mesh_1.Compute()
90   if not isDone:
91     errorMsg+= '\n ERROR: failed to mesh the box using  R-Tree algorithm from Gmsh\n'
92   else:
93     okMsg+= '\n PASSED: Successfully meshed the box using R-Tree algorithm from Gmsh\n'    
94 except:
95       errorMsg+='\n ERROR: Exception raised in Mesh computation'
96
97 #-------------------------------------
98 # Message that test are OK or not
99 #-------------------------------------
100
101 if okMsg!= '':
102   print (okMsg)
103       
104 if errorMsg!= '':
105   raise RuntimeError (errorMsg + "\n Test is KO.")  
106
107 if salome.sg.hasDesktop():
108   salome.sg.updateObjBrowser()