Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D Mesh w/ quads only #331

Closed
ryancoe opened this issue Apr 28, 2020 · 3 comments
Closed

2D Mesh w/ quads only #331

ryancoe opened this issue Apr 28, 2020 · 3 comments

Comments

@ryancoe
Copy link

ryancoe commented Apr 28, 2020

I'm interested in using pygmsh to generate a surface (2D) mesh with only quads. I figured out how to do this in gmsh using the Mesh.SubdivisionAlgorithm and Mesh.RecombineAll via the gmsh command line interace:

gmsh -2 test.geo -format vtk -bin -o test.vtk -clscale 0.25 -clcurv 7.2 \
-setnumber Mesh.SubdivisionAlgorithm 1 -setnumber Mesh.RecombineAll 1

However, when I pass these options to pygmsh.generate_mesh via the extra_gmsh_arguments they don't seem to work. Even more odd, I can see from the log what pygmsh is calling -- when I copy this to my command line I get the desired result.

MWE below:

import pygmsh
import numpy as np
import os

geom = pygmsh.opencascade.Geometry()

fbname = 'test'
ofst = 0.1
geom.add_cylinder(x0=[0.0, 0.0, 0+ofst],
                         axis=[0.0, 0.0, -2],
                         radius=1,
                         angle=2 * np.pi,
                         char_length=1)

mshRefFactor = 0.25
mshArgs = ['-clscale', str(mshRefFactor),
           '-clcurv', str(360/50),
           '-setnumber', 'Mesh.SubdivisionAlgorithm 1',
           '-setnumber', 'Mesh.RecombineAll 1']
mesh = pygmsh.generate_mesh(geom,
                            dim=2,
                            extra_gmsh_arguments=mshArgs,
                            remove_lower_dim_cells=True,
                            gmsh_path='/usr/local/bin/gmsh',
                            geo_filename=fbname + '.geo',
                            msh_filename=fbname + '.vtk',
                            mesh_file_type='vtk')

os.system('gmsh -2 test.geo -format vtk -bin -o testCLI.vtk -clscale 0.25 \
          -clcurv 7.2 -setnumber Mesh.SubdivisionAlgorithm 1 \
              -setnumber Mesh.RecombineAll 1')
$ python mwePygmsh.py 
Info    : Running '/usr/local/bin/gmsh -2 test.geo -format vtk -bin -o test.vtk -clscale 0.25 -clcurv 7.2 -setnumber Mesh.SubdivisionAlgorithm 1 -setnumber Mesh.RecombineAll 1' [Gmsh 4.5.6, 1 node, max. 1 thread]
Info    : Started on Tue Apr 28 13:47:42 2020
Info    : Reading 'test.geo'...
Info    : Done reading 'test.geo'
Info    : Meshing 1D...
Info    : [  0 %] Meshing curve 1 (Circle)
Info    : [ 40 %] Meshing curve 2 (Line)
Info    : [ 70 %] Meshing curve 3 (Circle)
Info    : Done meshing 1D (0.000661 s)
Info    : Meshing 2D...
Info    : [  0 %] Meshing surface 1 (Cylinder, Frontal-Delaunay)
Info    : [ 40 %] Meshing surface 2 (Plane, Frontal-Delaunay)
Info    : [ 70 %] Meshing surface 3 (Plane, Frontal-Delaunay)
Info    : Done meshing 2D (0.022969 s)
Info    : 465 nodes 993 elements
Info    : Writing 'test.vtk'...
Info    : Done writing 'test.vtk'
Info    : Stopped on Tue Apr 28 13:47:42 2020

msh file: test.vtk

geo file: test.geo
Info    : Running 'gmsh -2 test.geo -format vtk -bin -o testCLI.vtk -clscale 0.25 -clcurv 7.2 -setnumber Mesh.SubdivisionAlgorithm 1 -setnumber Mesh.RecombineAll 1' [Gmsh 4.5.6, 1 node, max. 1 thread]
Info    : Started on Tue Apr 28 13:47:42 2020
Info    : Reading 'test.geo'...
Info    : Done reading 'test.geo'
Info    : Meshing 1D...
Info    : [  0 %] Meshing curve 1 (Circle)
Info    : [ 40 %] Meshing curve 2 (Line)
Info    : [ 70 %] Meshing curve 3 (Circle)
Info    : Done meshing 1D (0.000738 s)
Info    : Meshing 2D...
Info    : [  0 %] Meshing surface 1 (Cylinder, Frontal-Delaunay)
Info    : [  0 %] Blossom: 856 internal 56 closed
Info    : [  0 %] Blossom recombination completed (0.003377 s): 296 quads, 0 triangles, 0 invalid quads, 0 quads with Q < 0.1, avg Q = 0.651414, min Q = 0.315895
Info    : [ 40 %] Meshing surface 2 (Plane, Frontal-Delaunay)
Info    : [ 40 %] Blossom: 226 internal 28 closed
Info    : [ 40 %] Blossom recombination completed (0.001559 s): 80 quads, 0 triangles, 0 invalid quads, 0 quads with Q < 0.1, avg Q = 0.740646, min Q = 0.524194
Info    : [ 70 %] Meshing surface 3 (Plane, Frontal-Delaunay)
Info    : [ 70 %] Blossom: 235 internal 28 closed
Info    : [ 70 %] Blossom recombination completed (0.002262 s): 80 quads, 0 triangles, 0 invalid quads, 0 quads with Q < 0.1, avg Q = 0.771524, min Q = 0.488293
Info    : Done meshing 2D (0.028026 s)
Info    : Refining mesh...
Info    : Meshing order 2 (curvilinear on)...
Info    : [  0 %] Meshing curve 1 order 2
Info    : [ 20 %] Meshing curve 2 order 2
Info    : [ 30 %] Meshing curve 3 order 2
Info    : [ 50 %] Meshing surface 1 order 2
Info    : [ 60 %] Meshing surface 2 order 2
Info    : [ 80 %] Meshing surface 3 order 2
Info    : [ 90 %] Meshing volume 1 order 2
Info    : Done meshing order 2 (0.012253 s)
Info    : Done refining mesh (0.012763 s)
Info    : 1826 nodes 1958 elements
Info    : Writing 'testCLI.vtk'...
Info    : Done writing 'testCLI.vtk'
Info    : Stopped on Tue Apr 28 13:47:42 2020

From pygmsh:
Screen Shot 2020-04-28 at 1 45 07 PM

From gmsh:
Screen Shot 2020-04-28 at 1 45 11 PM

@gdmcbain
Copy link
Contributor

Try separating the arguments of -setnumber:

mshArgs = ['-clscale', str(mshRefFactor),
           '-clcurv', str(360/50),
           '-setnumber', 'Mesh.SubdivisionAlgorithm', '1',
           '-setnumber', 'Mesh.RecombineAll', '1']

@ryancoe
Copy link
Author

ryancoe commented Apr 29, 2020

Ahh, thanks!

@ryancoe ryancoe closed this as completed Apr 29, 2020
@nschloe
Copy link
Owner

nschloe commented Apr 29, 2020

@ryancoe +1 on the good bug report. I wish they were all like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants