1import gmsh
2import sys
3import math
4
5gmsh.initialize(sys.argv)
6
7gmsh.model.add("2d surface mesh with purely discrete boundary")
8
9# create a discrete curve with N nodes and N line elements
10gmsh.model.addDiscreteEntity(1, 100)
11N = 50
12dt = 2 * math.pi / N
13pts = [[math.cos(i * dt), math.sin(i * dt), 0] for i in range(N)]
14flat_pts = [item for sublist in pts for item in sublist]
15gmsh.model.mesh.addNodes(1, 100, range(1, N + 1), flat_pts)
16n = [
17    item for sublist in [[i, i + 1] for i in range(1, N + 1)]
18    for item in sublist
19]
20n[-1] = 1
21gmsh.model.mesh.addElements(1, 100, [1], [range(1, N + 1)], [n])
22
23# create a plane surface from the discrete curve
24gmsh.model.geo.addCurveLoop([100], 101)
25gmsh.model.geo.addPlaneSurface([101], 102)
26gmsh.model.geo.synchronize()
27
28# mesh the surface
29gmsh.model.mesh.generate(2)
30if '-nopopup' not in sys.argv:
31    gmsh.fltk.run()
32
33gmsh.finalize()
34