Skip to content

Commit 9104ff8

Browse files
authored
Merge pull request #93 from WenjieYao/emscatter
Update electromagnetic scattering tutorial
2 parents cf3f42f + 4bb74a5 commit 9104ff8

8 files changed

Lines changed: 180581 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
${{ runner.os }}-test-
9494
${{ runner.os }}-
9595
- uses: julia-actions/julia-buildpkg@v1
96-
- run: cd test/; julia --project=.. --color=yes --check-bounds=yes runtests.jl darcy.jl inc_navier_stokes.jl stokes.jl poisson_dev_fe.jl
96+
- run: cd test/; julia --project=.. --color=yes --check-bounds=yes runtests.jl darcy.jl inc_navier_stokes.jl stokes.jl poisson_dev_fe.jl emscatter.jl
9797
tutorials_set_4:
9898
name: Tutorials4 ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
9999
runs-on: ${{ matrix.os }}

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
88
DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
99
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1010
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
11+
GridapGmsh = "3025c34a-b394-11e9-2a55-3fee550c04c8"
1112
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
1213
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
1314
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -16,9 +17,11 @@ NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
1617
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1718
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1819
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
20+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1921

2022
[compat]
2123
Gridap = "0.16.3"
24+
GridapGmsh = "0.4"
2225
julia = "1.3"
2326

2427
[extras]

assets/emscatter/Illustration.png

52.2 KB
Loading

assets/emscatter/MeshGenerator.jl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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)

assets/emscatter/Results.png

697 KB
Loading

deps/build.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ files = [
1616
"Stokes equation" => "stokes.jl",
1717
"Isotropic damage model" => "isotropic_damage.jl",
1818
"Fluid-Structure Interaction"=>"fsi_tutorial.jl",
19+
"Electromagnetic scattering in 2D"=>"emscatter.jl",
1920
"Low-level API Poisson equation"=>"poisson_dev_fe.jl",
2021
"On using DrWatson.jl"=>"validation_DrWatson.jl"]
2122

0 commit comments

Comments
 (0)