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