[Gmsh] Building meshes through the gmsh api

Lawrence Mitchell lawrence.mitchell at imperial.ac.uk
Mon Sep 16 15:07:15 CEST 2013

Dear gmshers,

I would like to use the gmsh API to define a geometry and then mesh it.
 The meshes I am trying to build are quite simple, unit square, cube,
circle and spherical structured meshes.  So I am using the extrusion
capabilities.  I'm using the python interface, but examples in C++ would
probably be fine.

Currently I do something like the following:

Build .geo file source string

e.g. for a circle:

cat > circle.geo<<EOF
            lc = 1e-2;
            Point(1) = {0, -0.5, 0, lc};
            boundary[] = Extrude {0, 1, 0} {
                Point{1}; Layers{4};
            surface[] = Extrude{{0, 0, 1},{0, 0, 0}, 1.9999 * Pi}{
            Physical Line(1) = { boundary[1] };
            Physical Surface(2) = { surface[1] };

Now I do:

model = gmshpy.GModel()

Given how simple my meshes are, I'd like to replace the writing to a geo
file and immediately reading by directly building the geometry
programmatically.  But I'm unsure how to specify extruded entities.  Any

Additionally, for the circle mesh case, is there an obvious way I can
build a semi-structured mesh in this way, but avoid the large number of
elements meeting at the centre?



More information about the gmsh mailing list