Skip to content

tutorial on using .geo files from Julia #27

@stevengj

Description

@stevengj

It would be nice to have some more tutorial examples in this package, especially because the Gmsh API docs are so minimal.

For example, one common desire is to be able to use .geo files, but to programmatically set parameters from Julia, so that you get some of the ease-of-use of the gmsh GUI but the flexibility of a programmatic interface. It turns out that this is possible, but it took me a while to figure out.

The trick to using a "foo.geo" from Julia is to do something like:

gmsh.clear()
gmsh.parser.parse("foo.geo")
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(2)
gmsh.write("foo.msh")

which behaves exactly as if you had translated each line of "foo.geo" into Julia and pasted the translation right at the point where you ran parse("foo.geo").

The powerful thing here is that you can also set variables programmatically from within Julia. Suppose we have a variable lc as in the t1.geo tutorial file. The trick is to define your .geo variables with DefineConstant — for example, in the t1.geo file, do:

DefineConstant[ lc = 1e-2 ];

Then you can override the value of lc by either the -setnumber command-line option or by the equivalent in the Julia API:

gmsh.clear()
gmsh.parser.setNumber("lc", [5e-3])   # overrides subsequent DefineConstant variables
gmsh.parser.parse(geo)
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(2)
gmsh.write("foo.msh")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions