1+ using Gmsh
2+ import Gmsh: gmsh
3+ function MeshGenerator (L,H,xc,r,hs,d_pml,lc)
4+ gmsh. initialize ()
5+ gmsh. option. setNumber (" General.Terminal" , 1 )
6+ gmsh. option. setNumber (" Mesh.Algorithm" , 6 )
7+ gmsh. clear ()
8+ gmsh. model. add (" geometry" )
9+
10+ # Add points
11+ gmsh. model. geo. addPoint (- L/ 2 - d_pml, - H/ 2 - d_pml, 0 , lc, 1 )
12+ gmsh. model. geo. addPoint ( L/ 2 + d_pml, - H/ 2 - d_pml, 0 , lc, 2 )
13+ gmsh. model. geo. addPoint ( L/ 2 + d_pml, hs , 0 , lc, 3 )
14+ gmsh. model. geo. addPoint (- L/ 2 - d_pml, hs , 0 , lc, 4 )
15+ gmsh. model. geo. addPoint ( L/ 2 + d_pml, H/ 2 + d_pml, 0 , lc, 5 )
16+ gmsh. model. geo. addPoint (- L/ 2 - d_pml, H/ 2 + d_pml, 0 , lc, 6 )
17+ gmsh. model. geo. addPoint ( xc[1 ]- r , xc[2 ] , 0 , lc, 7 )
18+ gmsh. model. geo. addPoint ( xc[1 ] , xc[2 ] , 0 , lc, 8 )
19+ gmsh. model. geo. addPoint ( xc[1 ]+ r , xc[2 ] , 0 , lc, 9 )
20+ # Add lines
21+ gmsh. model. geo. addLine ( 1 , 2 , 1 )
22+ gmsh. model. geo. addLine ( 2 , 3 , 2 )
23+ gmsh. model. geo. addLine ( 3 , 4 , 3 )
24+ gmsh. model. geo. addLine ( 1 , 4 , 4 )
25+ gmsh. model. geo. addLine ( 3 , 5 , 5 )
26+ gmsh. model. geo. addLine ( 5 , 6 , 6 )
27+ gmsh. model. geo. addLine ( 4 , 6 , 7 )
28+ gmsh. model. geo. addCircleArc ( 7 , 8 , 9 , 8 )
29+ gmsh. model. geo. addCircleArc ( 9 , 8 , 7 , 9 )
30+ # Construct curve loops and surfaces
31+ gmsh. model. geo. addCurveLoop ([1 , 2 , 3 , - 4 ], 1 )
32+ gmsh. model. geo. addCurveLoop ([5 , 6 ,- 7 , - 3 ], 2 )
33+ gmsh. model. geo. addCurveLoop ([8 , 9 ], 3 )
34+ gmsh. model. geo. addPlaneSurface ([1 ,3 ], 1 )
35+ gmsh. model. geo. addPlaneSurface ([2 ], 2 )
36+ gmsh. model. geo. addPlaneSurface ([3 ], 3 )
37+ # Physical groups
38+ # gmsh.model.addPhysicalGroup(0, [1,2,3,4,5,6], 1)
39+ # gmsh.model.setPhysicalName(0, 1, "DirichletNodes")
40+ gmsh. model. addPhysicalGroup (1 , [1 ,6 ], 2 )
41+ gmsh. model. setPhysicalName (1 , 2 , " DirichletEdges" )
42+ gmsh. model. addPhysicalGroup (0 , [7 ,9 ], 3 )
43+ gmsh. model. setPhysicalName (0 , 3 , " CylinderNodes" )
44+ gmsh. model. addPhysicalGroup (1 , [8 ,9 ], 4 )
45+ gmsh. model. setPhysicalName (1 , 4 , " CylinderEdges" )
46+ gmsh. model. addPhysicalGroup (2 , [3 ], 5 )
47+ gmsh. model. setPhysicalName (2 , 5 , " Cylinder" )
48+ gmsh. model. addPhysicalGroup (2 , [1 ,2 ], 6 )
49+ gmsh. model. setPhysicalName (2 , 7 , " Air" )
50+ gmsh. model. addPhysicalGroup (1 , [3 ], 7 )
51+ gmsh. model. setPhysicalName (1 , 7 , " Source" )
52+ gmsh. model. geo. synchronize ()
53+
54+ gmsh. model. mesh. setPeriodic (1 , [2 ], [4 ],
55+ [1 , 0 , 0 , L+ 2 * d_pml, 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ])
56+ gmsh. model. mesh. setPeriodic (1 , [5 ], [7 ],
57+ [1 , 0 , 0 , L+ 2 * d_pml, 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ])
58+
59+ # We can then generate a 2D mesh...
60+ gmsh. model. mesh. generate (2 )
61+ # ... and save it to disk
62+ gmsh. write (" geometry.msh" )
63+ gmsh. finalize ()
64+ end
65+
66+ # Geometry parameters
67+ λ = 1.0 # Wavelength (arbitrary unit)
68+ L = 4.0 # Width of the area
69+ H = 6.0 # Height of the area
70+ xc = [0 - 1.0 ] # Center of the cylinder
71+ r = 1.0 # Radius of the cylinder
72+ hs = 2.0 # y-position of the source (plane wave)
73+ d_pml = 0.8 # Thickness of the PML
74+
75+ resol = 20.0 # Number of points per wavelength
76+ lc = λ/ resol # Characteristic length
77+
78+ MeshGenerator (L,H,xc,r,hs,d_pml,lc)
0 commit comments