]> SALOME platform Git repositories - plugins/gmshplugin.git/commitdiff
Salome HOME
Integrate GMSH NR
authorAfeef <afeef.badri@gmail.com>
Mon, 20 Sep 2021 14:54:07 +0000 (16:54 +0200)
committernghodban <Nabil.Ghodbane@c-s.fr>
Mon, 20 Sep 2021 14:54:07 +0000 (16:54 +0200)
tests/gmsh_compound_mesh_2d.py [new file with mode: 0644]
tests/gmsh_compound_mesh_3d.py [new file with mode: 0644]
tests/gmsh_tetra_algorithms_for_box.py [new file with mode: 0644]
tests/gmsh_triangulation_algorithms_for_square.py [new file with mode: 0644]
tests/tests.set

diff --git a/tests/gmsh_compound_mesh_2d.py b/tests/gmsh_compound_mesh_2d.py
new file mode 100644 (file)
index 0000000..da298b4
--- /dev/null
@@ -0,0 +1,139 @@
+#!/usr/bin/env python
+
+'''
+This file creates a compound surface of a square and a circle. Then meshes them with 
+Gmsh using compound mesh feature of Gmsh.
+'''
+import salome
+salome.salome_init()
+
+#-------------------------------------
+### SHAPER component
+#-------------------------------------
+
+from salome.shaper import model
+model.begin()
+partSet = model.moduleDocument()
+
+### Create Part
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+### Create Sketch
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+
+### Create SketchLine
+SketchLine_1 = Sketch_1.addLine(25, 0, 0, 0)
+
+### Create SketchProjection
+SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
+SketchPoint_1 = SketchProjection_1.createdFeature()
+Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
+
+### Create SketchLine
+SketchLine_2 = Sketch_1.addLine(0, 0, 0, 25)
+
+### Create SketchLine
+SketchLine_3 = Sketch_1.addLine(0, 25, 25, 25)
+
+### Create SketchLine
+SketchLine_4 = Sketch_1.addLine(25, 25, 25, 0)
+Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
+Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+Sketch_1.setHorizontal(SketchLine_1.result())
+Sketch_1.setVertical(SketchLine_2.result())
+Sketch_1.setHorizontal(SketchLine_3.result())
+Sketch_1.setVertical(SketchLine_4.result())
+Sketch_1.setEqual(SketchLine_1.result(), SketchLine_4.result())
+Sketch_1.setLength(SketchLine_1.result(), 25)
+
+### Create SketchCircle
+SketchCircle_1 = Sketch_1.addCircle(25, 25, 12.5)
+Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchCircle_1.center())
+Sketch_1.setRadius(SketchCircle_1.results()[1], 12.5)
+model.do()
+
+### Create Face
+Face_1_objects = [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchCircle_1_2f-SketchCircle_1_2f"),
+                  model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchCircle_1_2r-SketchLine_3r-SketchLine_2r-SketchLine_1r"),
+                  model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchLine_4r-SketchLine_3r")]
+Face_1 = model.addFace(Part_1_doc, Face_1_objects)
+
+### Create Group
+Group_1_objects = [model.selection("FACE", "Face_1_2"),
+                   model.selection("FACE", "Face_1_3"),
+                   model.selection("FACE", "Face_1_1")]
+Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects)
+
+### Create Shell
+Shell_1_objects = [model.selection("FACE", "Face_1_1"),
+                   model.selection("FACE", "Face_1_2"),
+                   model.selection("FACE", "Face_1_3")]
+Shell_1 = model.addShell(Part_1_doc, Shell_1_objects)
+
+### Create Group
+Group_2_objects = [model.selection("FACE", "Shell_1_1/Modified_Face&Face_1_2/Face_1_2"),
+                   model.selection("FACE", "Shell_1_1/Modified_Face&Face_1_3/Face_1_3"),
+                   model.selection("FACE", "Shell_1_1/Modified_Face&Face_1_1/Face_1_1")]
+Group_2 = model.addGroup(Part_1_doc, "Faces", Group_2_objects)
+
+model.end()
+
+#-------------------------------------
+### SHAPERSTUDY component
+#-------------------------------------
+
+model.publishToShaperStudy()
+import SHAPERSTUDY
+Shell_1_1, Group_2_1, = SHAPERSTUDY.shape(model.featureStringId(Shell_1))
+
+#-------------------------------------
+### SMESH component
+#-------------------------------------
+
+import  SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New()
+
+Mesh_1 = smesh.Mesh(Shell_1_1)
+GMSH_2D = Mesh_1.Triangle(algo=smeshBuilder.GMSH_2D)
+Gmsh_Parameters = GMSH_2D.Parameters()
+Gmsh_Parameters.Set2DAlgo( 0 )
+Gmsh_Parameters.SetMaxSize( 10 )
+Gmsh_Parameters.SetMinSize( 5 )
+Gmsh_Parameters.SetIs2d( 1 )
+Gmsh_Parameters.SetCompoundOnShape(Group_2_1)
+isDone = Mesh_1.Compute()
+
+errorMsg=''
+okMsg=''
+
+#-------------------------------------
+# Test: Frontal Delaunay
+#-------------------------------------
+try:
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the compound square-circle surface using Delaunay algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the compound square-circle surface using Delaunay algorithm from Gmsh\n'
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Message that test are OK or not
+#-------------------------------------
+
+if okMsg!= '':
+  print (okMsg)
+      
+if errorMsg!= '':
+  raise RuntimeError (errorMsg + "\n Test is KO.")
+
+if salome.sg.hasDesktop():
+  smesh.SetName(GMSH_2D.GetAlgorithm(), 'GMSH_2D')
+  smesh.SetName(Mesh_1.GetMesh(), 'Mesh_compound_square-circle')
+  smesh.SetName(Gmsh_Parameters, 'Gmsh Parameters')
+  salome.sg.updateObjBrowser()
diff --git a/tests/gmsh_compound_mesh_3d.py b/tests/gmsh_compound_mesh_3d.py
new file mode 100644 (file)
index 0000000..6291de2
--- /dev/null
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+
+'''
+This file creates a compound solid of cube and a sphere. Then meshes them with 
+Gmsh using compound mesh feature of Gmsh.
+'''
+import salome
+salome.salome_init()
+
+#-------------------------------------
+### SHAPER component
+#-------------------------------------
+
+from salome.shaper import model
+model.begin()
+partSet = model.moduleDocument()
+
+### Create Part
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+### Create Box
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+
+### Create Sphere
+Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 5)
+
+### Create Fuse
+Fuse_1 = model.addFuse(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_1"), model.selection("COMPOUND", "all-in-Sphere_1")], keepSubResults = True)
+
+### Create Group
+Group_1_objects = [model.selection("FACE", "Box_1_1/Front"),
+                   model.selection("FACE", "Box_1_1/Top"),
+                   model.selection("FACE", "Fuse_1_1/Modified_Face&Box_1_1/Left"),
+                   model.selection("FACE", "Box_1_1/Right"),
+                   model.selection("FACE", "Fuse_1_1/Modified_Face&Box_1_1/Back"),
+                   model.selection("FACE", "Fuse_1_1/Modified_Face&Box_1_1/Bottom")]
+Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects)
+
+model.end()
+
+#-------------------------------------
+### SHAPERSTUDY component
+#-------------------------------------
+
+model.publishToShaperStudy()
+import SHAPERSTUDY
+Fuse_1_1, Group_1_1, = SHAPERSTUDY.shape(model.featureStringId(Fuse_1))
+
+
+#-------------------------------------
+### SMESH component
+#-------------------------------------
+
+import  SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+
+smesh = smeshBuilder.New()
+
+Mesh_1 = smesh.Mesh(Fuse_1_1)
+GMSH = Mesh_1.Tetrahedron(algo=smeshBuilder.GMSH)
+Gmsh_Parameters = GMSH.Parameters()
+Gmsh_Parameters.Set2DAlgo( 0 )
+Gmsh_Parameters.SetMinSize( 0.5 )
+Gmsh_Parameters.SetMaxSize( 1 )
+Gmsh_Parameters.SetIs2d( 0 )
+Gmsh_Parameters.SetCompoundOnShape(Group_1_1)
+Group_1_2 = Mesh_1.GroupOnGeom(Group_1_1,'Group_1',SMESH.FACE)
+#isDone = Mesh_1.Compute()
+#[ Group_1_2 ] = Mesh_1.GetGroups()
+
+errorMsg=''
+okMsg=''
+
+
+#-------------------------------------
+# Test: Frontal Delaunay
+#-------------------------------------
+try:
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the compound cube-sphere surface using Delaunay algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the compound cube-sphere surface using Delaunay algorithm from Gmsh\n'
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Message that test are OK or not
+#-------------------------------------
+
+if okMsg!= '':
+  print (okMsg)
+      
+if errorMsg!= '':
+  raise RuntimeError (errorMsg + "\n Test is KO.")
+
+
+
+if salome.sg.hasDesktop():
+  smesh.SetName(GMSH.GetAlgorithm(), 'GMSH')
+  smesh.SetName(Group_1_2, 'Group_1')
+  smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1')
+  smesh.SetName(Gmsh_Parameters, 'Gmsh Parameters')
+  salome.sg.updateObjBrowser()
diff --git a/tests/gmsh_tetra_algorithms_for_box.py b/tests/gmsh_tetra_algorithms_for_box.py
new file mode 100644 (file)
index 0000000..6ca8995
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+
+'''
+This file creates a box using GEOM then meshes the same using Gmsh's different algorithms
+
+1. Frontal Delaunay ----> Gmsh_Parameters.Set3DAlgo( 0 )
+2. Frontal Hex      ----> Gmsh_Parameters.Set3DAlgo( 1 )
+3. MMG3D            ----> Gmsh_Parameters.Set3DAlgo( 2 )
+4. R-Tree           ----> Gmsh_Parameters.Set3DAlgo( 3 )
+
+This file is solely for the propose of testing and we do overwrite the meshes.
+'''
+
+import salome
+salome.salome_init()
+
+#------------------------------------ 
+# GEOM: Creating a box of size 10^3
+#------------------------------------
+import GEOM
+from salome.geom import geomBuilder
+
+geompy = geomBuilder.New()
+Box_1 = geompy.MakeBoxDXDYDZ(10, 10, 10)
+
+#------------------------------------ 
+# SMESH: Using Gmsh algorithm with size (3,10) (min,max)
+#------------------------------------
+import  SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New()
+
+Mesh_1 = smesh.Mesh(Box_1)
+GMSH = Mesh_1.Tetrahedron(algo=smeshBuilder.GMSH)
+Gmsh_Parameters = GMSH.Parameters()
+Gmsh_Parameters.Set2DAlgo( 0 )
+Gmsh_Parameters.SetMinSize( 3 )
+Gmsh_Parameters.SetMaxSize( 10 )
+Gmsh_Parameters.SetIs2d( 0 )
+
+
+errorMsg=''
+okMsg=''
+
+#-------------------------------------
+# Test: Frontal Delaunay
+#-------------------------------------
+try:
+  Gmsh_Parameters.Set3DAlgo( 0 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using Frontal Delaunay algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Frontal Delaunay algorithm from Gmsh\n'
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Test: Frontal Hex
+#-------------------------------------
+try:
+  Gmsh_Parameters.Set3DAlgo( 1 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using Frontal Hex algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Frontal Hex algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Test: MMG3D
+#-------------------------------------      
+try:
+  Gmsh_Parameters.Set3DAlgo( 2 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using MMG3D algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using MMG3D algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+      
+#-------------------------------------
+# Test: R-Tree Algorithm
+#-------------------------------------           
+try:
+  Gmsh_Parameters.Set3DAlgo( 3 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using  R-Tree algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using R-Tree algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Message that test are OK or not
+#-------------------------------------
+
+if okMsg!= '':
+  print (okMsg)
+      
+if errorMsg!= '':
+  raise RuntimeError (errorMsg + "\n Test is KO.")  
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser()
diff --git a/tests/gmsh_triangulation_algorithms_for_square.py b/tests/gmsh_triangulation_algorithms_for_square.py
new file mode 100644 (file)
index 0000000..8340c58
--- /dev/null
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+
+'''
+This file creates a square using GEOM then meshes the same using Gmsh's different algorithms
+
+1. Automatic              ----> Gmsh_Parameters.Set2DAlgo( 0 )
+2. mesh Adapt             ----> Gmsh_Parameters.Set2DAlgo( 1 )
+3. Delaunay               ----> Gmsh_Parameters.Set2DAlgo( 2 )
+4. Frontal                ----> Gmsh_Parameters.Set2DAlgo( 3 )
+5. Delaunay For Quads     ----> Gmsh_Parameters.Set2DAlgo( 3 )
+6. Packing Parallelograms ----> Gmsh_Parameters.Set2DAlgo( 3 )
+
+This file is solely for the propose of testing and we do overwrite the meshes.
+'''
+
+import salome
+salome.salome_init()
+
+#------------------------------------ 
+# GEOM: Creating a square of size 10^2
+#------------------------------------
+import GEOM
+from salome.geom import geomBuilder
+
+geompy = geomBuilder.New()
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+
+#------------------------------------ 
+# SMESH: Using Gmsh algorithm with size (1,5) (min,max)
+#------------------------------------
+import  SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New()
+
+Mesh_1 = smesh.Mesh(Face_1)
+GMSH_2D = Mesh_1.Triangle(algo=smeshBuilder.GMSH_2D)
+Gmsh_Parameters = GMSH_2D.Parameters()
+Gmsh_Parameters.SetMinSize( 1 )
+Gmsh_Parameters.SetMaxSize( 5 )
+Gmsh_Parameters.SetIs2d( 1 )
+
+errorMsg=''
+okMsg=''
+
+
+#-------------------------------------
+# Test: Automatic
+#-------------------------------------
+try:
+  Gmsh_Parameters.Set2DAlgo( 0 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using Automatic algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Automatic algorithm from Gmsh\n'
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Test:  Mesh Adapt
+#-------------------------------------
+try:
+  Gmsh_Parameters.Set2DAlgo( 1 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using Mesh Adapt algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Mesh Adapt algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Test: Delaunay
+#-------------------------------------      
+try:
+  Gmsh_Parameters.Set2DAlgo( 2 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using Delaunay algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Delaunay algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+      
+#-------------------------------------
+# Test: Frontal Algorithm
+#-------------------------------------           
+try:
+  Gmsh_Parameters.Set2DAlgo( 3 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using  Frontal algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Frontal algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+
+#-------------------------------------
+# Test: Delaunay For Quads Algorithm
+#-------------------------------------           
+try:
+  Gmsh_Parameters.Set2DAlgo( 4 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using  Delaunay For Quads algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Delaunay For Quads algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+      
+
+#-------------------------------------
+# Test: Packing Parallelolagrams  Algorithm
+#-------------------------------------           
+try:
+  Gmsh_Parameters.Set2DAlgo( 5 )
+  isDone = Mesh_1.Compute()
+  if not isDone:
+    errorMsg+= '\n ERROR: failed to mesh the box using  Packing Parallelolagrams algorithm from Gmsh\n'
+  else:
+    okMsg+= '\n PASSED: Successfully meshed the box using Packing Parallelolagrams algorithm from Gmsh\n'    
+except:
+      errorMsg+='\n ERROR: Exception raised in Mesh computation'
+      
+            
+#-------------------------------------
+# Message that test are OK or not
+#-------------------------------------
+
+if okMsg!= '':
+  print (okMsg)
+      
+if errorMsg!= '':
+  raise RuntimeError (errorMsg + "\n Test is KO.") 
+
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser()
index cff6ae19e13e716c1050a51a1a2602fd26e06750..3c3928b658a2ce28707f5b98cfb9a8a998a9c6f9 100644 (file)
@@ -21,4 +21,8 @@
 
 SET(TEST_NAMES
   basicGroup
+  gmsh_compound_mesh_2d
+  gmsh_compound_mesh_3d
+  gmsh_tetra_algorithms_for_box
+  gmsh_triangulation_algorithms_for_square
 )