-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstraight_wave_guide.py
More file actions
73 lines (55 loc) · 2.06 KB
/
straight_wave_guide.py
File metadata and controls
73 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import meep as mp
import matplotlib.pyplot as plt
# -------------------- Parameters --------------------
Size_x = 3
Size_y = 10
Size_z = 0
cell_size = mp.Vector3(Size_x, Size_y, Size_z)
resolution = 25 # cells per micron
pml_size = 10 / resolution
pml_layers = [mp.PML(thickness=pml_size)]
n_core = 3.5 # Silicon
n_clad = 1.44 # SiO2
core = mp.Medium(index=n_core)
cladding = mp.Medium(index=n_clad)
w = 0.5 # width
h = 0.22 # height
geometry = [
mp.Block(center=mp.Vector3(), size=mp.Vector3(w, mp.inf, h), material=core),
]
# -------------------- Source --------------------
wl0 = 1.55
min_wl = 1.4
max_wl = 1.7
freq = 1. / wl0
min_freq = 1 / max_wl
max_freq = 1 / min_wl
f_width = max_freq - min_freq
pulse = mp.GaussianSource(freq, fwidth=f_width * 2)
source_pos_y = -Size_y // 2 + pml_size + 0.1
sources = [mp.EigenModeSource(pulse,
center=mp.Vector3(y=source_pos_y),
size=mp.Vector3(x=Size_x, z=Size_z),
direction=mp.Y,
eig_band=1)]
# -------------------- Simulation --------------------
sim = mp.Simulation(cell_size=cell_size,
resolution=resolution,
boundary_layers=pml_layers,
sources=sources,
geometry=geometry)
# -------------------- Save geometry --------------------
sim.plot2D(output_plane=mp.Volume(center=mp.Vector3(), size=mp.Vector3(Size_x, Size_y)))
plt.savefig("simXY.png")
plt.close()
# -------------------- Animation --------------------
animate = mp.Animate2D(
fields=mp.Ez,
normalize=True,
field_parameters={'alpha': 0.8, 'cmap':'RdBu', 'interpolation':'none'},
boundary_parameters={'hatch':'o', 'linewidth':1.5, 'facecolor':'y', 'edgecolor':'b', 'alpha':0.3},
output_plane=mp.Volume(center=mp.Vector3(), size=mp.Vector3(Size_x, Size_y))
)
sim.run(mp.at_every(0.2, animate), until_after_sources=mp.stop_when_fields_decayed(5, mp.Ez, mp.Vector3(0, Size_y/2 - pml_size - 0.1), 1e-4))
animate.to_mp4(fps=30, filename='straight_wave_guide.mp4')
plt.close()