-1
$\begingroup$

I am trying to mesh a geometry using the gmsh python api, however it seems like my algorithm selection option (i.e. gmsh.option.setNumber("Mesh.Algorithm", 8) ) is being ignored. Can anyone tell me if this is a bug or if I am simply making a mistake. This code replicates the problem:

import gmsh
import sys  
h=1.0
    
gmsh.initialize(sys.argv)

#gmsh.option.setNumber("General.Terminal", 1)
#use the quad mesh alogrithm Mesh.Algorithm = 8
gmsh.option.setNumber("Mesh.Algorithm", 8);

model = gmsh.model
model.add("L-Shape")

#have some duplicate points to make this more like my actual problem
coords=[[0,0],[100,0],[100,0],[100,30],[50,30],[50,100],[50,100],[0,100]]
points=[]
lines=[]

#add points
for point in range(len(coords)):
    points.append(gmsh.model.geo.addPoint(coords[point][0], coords[point][1], 0,h))
    
#add lines
for i in range(len(points)):
    #print(points[i],points[(i +1) % len(points)])
    lines.append(gmsh.model.geo.addLine(points[i],points[(i +1) % len(points)]))
  


#join lines into a surface!
gmsh.model.geo.addCurveLoop(lines, 1)
gmsh.model.geo.addPlaneSurface([1],1)

#and mesh it!
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate()

gmsh.fltk.run()
gmsh.finalize()

Which generates this (clearly triangular) mesh. How can I get gmsh to use the quad mesh algorithm from within the python API instead?

resulting triangular mesh

$\endgroup$
2
  • 1
    $\begingroup$ This is a problem best asked on the gmsh specific forums. $\endgroup$ Jun 9 at 1:40
  • $\begingroup$ You have to turn "recombine" on. The triangles will then be recombined into quads. $\endgroup$ Jun 9 at 1:40

1 Answer 1

3
$\begingroup$

Based on the comment from Biswajit Banerjee (above) I determined that I was missing mesh recombine option:

 gmsh.option.setNumber("Mesh.RecombineAll", 1)

Adding this to the code fixes the issue (this apparently also addressed in appendix A of the manual.

import gmsh
import sys

h=5

gmsh.initialize(sys.argv)

#gmsh.option.setNumber("General.Terminal", 1)
#use the quad mesh alogrithm
gmsh.option.setNumber("Mesh.Algorithm", 8)

model = gmsh.model
model.add("L-Shape")

#have some duplicate points to make this more like my actual problem
coords=[[0,0],[100,0],[100,0],[100,30],[50,30],[50,100],[50,100],[0,100]]
points=[]
lines=[]

#add points
for point in range(len(coords)):
    points.append(gmsh.model.geo.addPoint(coords[point][0], coords[point][1], 0,h))
    
#add lines
for i in range(len(points)):
    #print(points[i],points[(i +1) % len(points)])
    lines.append(gmsh.model.geo.addLine(points[i],points[(i +1) % len(points)]))
  


#join lines into a surface!
gmsh.model.geo.addCurveLoop(lines, 1)
gmsh.model.geo.addPlaneSurface([1],1)

#and mesh it!
gmsh.option.setNumber("Mesh.RecombineAll", 1)
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate()

gmsh.fltk.run()
gmsh.finalize()
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.