]> SALOME platform Git repositories - plugins/gmshplugin.git/blob - tests/gmsh_compound_mesh_3d.py
Salome HOME
Integrate GMSH NR
[plugins/gmshplugin.git] / tests / gmsh_compound_mesh_3d.py
1 #!/usr/bin/env python
2
3 '''
4 This file creates a compound solid of cube and a sphere. Then meshes them with 
5 Gmsh using compound mesh feature of Gmsh.
6 '''
7 import salome
8 salome.salome_init()
9
10 #-------------------------------------
11 ### SHAPER component
12 #-------------------------------------
13
14 from salome.shaper import model
15 model.begin()
16 partSet = model.moduleDocument()
17
18 ### Create Part
19 Part_1 = model.addPart(partSet)
20 Part_1_doc = Part_1.document()
21
22 ### Create Box
23 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
24
25 ### Create Sphere
26 Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 5)
27
28 ### Create Fuse
29 Fuse_1 = model.addFuse(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_1"), model.selection("COMPOUND", "all-in-Sphere_1")], keepSubResults = True)
30
31 ### Create Group
32 Group_1_objects = [model.selection("FACE", "Box_1_1/Front"),
33                    model.selection("FACE", "Box_1_1/Top"),
34                    model.selection("FACE", "Fuse_1_1/Modified_Face&Box_1_1/Left"),
35                    model.selection("FACE", "Box_1_1/Right"),
36                    model.selection("FACE", "Fuse_1_1/Modified_Face&Box_1_1/Back"),
37                    model.selection("FACE", "Fuse_1_1/Modified_Face&Box_1_1/Bottom")]
38 Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects)
39
40 model.end()
41
42 #-------------------------------------
43 ### SHAPERSTUDY component
44 #-------------------------------------
45
46 model.publishToShaperStudy()
47 import SHAPERSTUDY
48 Fuse_1_1, Group_1_1, = SHAPERSTUDY.shape(model.featureStringId(Fuse_1))
49
50
51 #-------------------------------------
52 ### SMESH component
53 #-------------------------------------
54
55 import  SMESH, SALOMEDS
56 from salome.smesh import smeshBuilder
57
58 smesh = smeshBuilder.New()
59
60 Mesh_1 = smesh.Mesh(Fuse_1_1)
61 GMSH = Mesh_1.Tetrahedron(algo=smeshBuilder.GMSH)
62 Gmsh_Parameters = GMSH.Parameters()
63 Gmsh_Parameters.Set2DAlgo( 0 )
64 Gmsh_Parameters.SetMinSize( 0.5 )
65 Gmsh_Parameters.SetMaxSize( 1 )
66 Gmsh_Parameters.SetIs2d( 0 )
67 Gmsh_Parameters.SetCompoundOnShape(Group_1_1)
68 Group_1_2 = Mesh_1.GroupOnGeom(Group_1_1,'Group_1',SMESH.FACE)
69 #isDone = Mesh_1.Compute()
70 #[ Group_1_2 ] = Mesh_1.GetGroups()
71
72 errorMsg=''
73 okMsg=''
74
75
76 #-------------------------------------
77 # Test: Frontal Delaunay
78 #-------------------------------------
79 try:
80   isDone = Mesh_1.Compute()
81   if not isDone:
82     errorMsg+= '\n ERROR: failed to mesh the compound cube-sphere surface using Delaunay algorithm from Gmsh\n'
83   else:
84     okMsg+= '\n PASSED: Successfully meshed the compound cube-sphere surface using Delaunay algorithm from Gmsh\n'
85 except:
86       errorMsg+='\n ERROR: Exception raised in Mesh computation'
87
88 #-------------------------------------
89 # Message that test are OK or not
90 #-------------------------------------
91
92 if okMsg!= '':
93   print (okMsg)
94       
95 if errorMsg!= '':
96   raise RuntimeError (errorMsg + "\n Test is KO.")
97
98
99
100 if salome.sg.hasDesktop():
101   smesh.SetName(GMSH.GetAlgorithm(), 'GMSH')
102   smesh.SetName(Group_1_2, 'Group_1')
103   smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1')
104   smesh.SetName(Gmsh_Parameters, 'Gmsh Parameters')
105   salome.sg.updateObjBrowser()