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