-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMINormal.py
203 lines (173 loc) · 8.2 KB
/
MMINormal.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#%%
import meep as mp
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#from meep.materials import cSi
#from meep.materials import SiO2
cSi = mp.Medium(epsilon=3.9766)
SiO2 = mp.Medium(epsilon=1.4585)
# Variables for Geometry
um_scale = 1.0
wvl = 1.55
wg_height = 0.22
w_MMI = 3.25
l_MMI = 38.5
w_Input = 0.5
w_Output = 1.475
l_Taper = 6
separation = 0.3
l_Access = 3
w_PML = 1
end_of_input = l_MMI/2 + l_Taper+ 0.5
buffer = wvl * 4
l_cell = l_MMI + 2*l_Taper + 2*l_Access + 2*w_PML + buffer
w_cell = w_MMI + 2*w_PML + buffer
h_cell = wg_height + 2*w_PML + buffer
taper_y1 = w_Output/2 + w_Input/2 + separation/2
taper_y2 = w_Output/2 - w_Input/2 + separation/2
output_y1 = separation/2
output_y2 = output_y1 + w_Output
taper_x1 = l_MMI/2
taper_x2 = l_MMI/2 + l_Taper
wg_end_x = taper_x2 + 0.5
wg_center_y = w_Output/2 + separation/2
l_wg = l_cell/2 - taper_x2
wg_center_x = l_MMI/2 + l_Taper + l_wg/2
# Set up frequency range
freq= um_scale/wvl
fwidth= 0.2*freq
nfreqs = int(wvl*1000*0.2)
# Resolution so that there are over 10 pixels per micron
resolution = 80
## Geometry-- MMI centered at the origin
cell = mp.Vector3(l_cell, w_cell, 0)
#%%
# Long waveguide across the cell, centered at the source's y position and the other one too
geometry_straight = [mp.Block(mp.Vector3(l_cell, w_cell, wg_height), center= mp.Vector3(0,0,0), material=SiO2),
mp.Block(mp.Vector3(l_cell, w_Input, wg_height), center=mp.Vector3(0,-wg_center_y,0), material=cSi)]
#%%
#Adding the basic geometry (access waveguides, tapers, MMI body)
geometry = [mp.Block(mp.Vector3(l_cell, w_cell, wg_height), center = mp.Vector3(0,0,0), material=SiO2),
mp.Block(mp.Vector3(l_MMI, w_MMI, wg_height), center=mp.Vector3(0,0,0), material=cSi),
mp.Block(mp.Vector3(l_wg, w_Input, wg_height), center=mp.Vector3(-wg_center_x, wg_center_y,0), material=cSi),
mp.Block(mp.Vector3(l_wg, w_Input, wg_height), center=mp.Vector3(-wg_center_x, -wg_center_y,0), material=cSi),
mp.Block(mp.Vector3(l_wg, w_Input, wg_height), center=mp.Vector3(wg_center_x, wg_center_y,0), material=cSi),
mp.Block(mp.Vector3(l_wg, w_Input, wg_height), center=mp.Vector3(wg_center_x, -wg_center_y,0), material=cSi),
mp.Prism(vertices=[mp.Vector3(-taper_x2, taper_y1, 0), mp.Vector3(-taper_x2, taper_y2, 0), mp.Vector3(-taper_x1, output_y1, 0), mp.Vector3(-taper_x1, output_y2, 0)], height= wg_height, material=cSi),
mp.Prism(vertices=[mp.Vector3(-taper_x2, -taper_y1, 0), mp.Vector3(-taper_x2, -taper_y2, 0), mp.Vector3(-taper_x1, -output_y1, 0), mp.Vector3(-taper_x1, -output_y2, 0)], height= wg_height, material=cSi),
mp.Prism(vertices=[mp.Vector3(taper_x2, taper_y1, 0), mp.Vector3(taper_x2, taper_y2, 0), mp.Vector3(taper_x1, output_y1, 0), mp.Vector3(taper_x1, output_y2, 0)], height= wg_height, material=cSi),
mp.Prism(vertices=[mp.Vector3(taper_x2, -taper_y1, 0), mp.Vector3(taper_x2, -taper_y2, 0), mp.Vector3(taper_x1, -output_y1, 0), mp.Vector3(taper_x1, -output_y2, 0)], height= wg_height, material=cSi)]
#%%
pml_layers = [mp.PML(w_PML)]
# Source
sources = [mp.EigenModeSource(src= mp.GaussianSource(freq, fwidth=fwidth), center= mp.Vector3(-end_of_input-0.25, -wg_center_y, 0), size=mp.Vector3(0, w_Input+wvl, 2.8),eig_parity=mp.ODD_Z+mp.EVEN_Y, direction=mp.X)]
# Monitor positions for each waveguide
monLo_center = mp.Vector3(wg_end_x, wg_center_y,0)
monHi_center = mp.Vector3(wg_end_x, -wg_center_y,0)
mon_size = mp.Vector3(0, w_Input+wvl, wg_height+wvl)
#%%
# Normalization simulation
sim = mp.Simulation(cell_size=cell,
geometry=geometry_straight,
boundary_layers=pml_layers,
sources=sources,
default_material=SiO2,
resolution=resolution
)
incident_mode = sim.add_mode_monitor(freq, fwidth, nfreqs, mp.ModeRegion(center= mp.Vector3(-end_of_input,-wg_center_y,0), size=mon_size, direction=mp.Z))
#mp.stop_when_fields_decayed(dt=50,c=mp.Ez, pt=monHi_center, decay_by=1e-4)
sim.run(until= 600)
# This will have everything coming out of the source so can be used as denominator
incident_mode_alpha = sim.get_eigenmode_coefficients(incident_mode,[1],eig_parity=mp.ODD_Z+mp.EVEN_Y, direction=mp.Z).alpha[0,:,0]
incident_flux_data = sim.get_flux_data(incident_mode)
#%%
sim.reset_meep()
#%%
# Simulation with the scattering geometry
sim = mp.Simulation(cell_size=cell,
geometry=geometry,
boundary_layers=pml_layers,
sources=sources,
default_material=SiO2,
resolution=resolution
)
#Monitors for the input ports
input_mode = sim.add_mode_monitor(freq, fwidth, nfreqs, mp.ModeRegion(center= mp.Vector3(-end_of_input,-wg_center_y,0), size=mon_size, direction=mp.Z))
input_hi_mode = sim.add_mode_monitor(freq, fwidth, nfreqs, mp.ModeRegion(center= mp.Vector3(-end_of_input,wg_center_y,0), size=mon_size, direction=mp.Z))
#Monitors for the output ports
output_lo_mode= sim.add_mode_monitor(freq, fwidth, nfreqs, mp.ModeRegion(center= monLo_center, size=mon_size, direction=mp.Z))
output_hi_mode= sim.add_mode_monitor(freq, fwidth, nfreqs, mp.ModeRegion(center= monHi_center, size=mon_size, direction=mp.Z))
#%%
# Load minus flux data before running the scattering simulation
sim.load_minus_flux_data(input_mode, incident_flux_data)
#%%
sim.run(until= 600)
#%%
#Finding the forward eigenmode coefficients for the input port with the source and the two output ports
outputLoAlpha = sim.get_eigenmode_coefficients(output_lo_mode,[1],eig_parity=mp.ODD_Z+mp.EVEN_Y, direction=mp.Z).alpha[0,:,0]
outputHiAlpha = sim.get_eigenmode_coefficients(output_hi_mode,[1],eig_parity=mp.ODD_Z+mp.EVEN_Y, direction=mp.Z).alpha[0,:,0]
#%%
inputLoAlpha = sim.get_eigenmode_coefficients(input_mode,[1],eig_parity=mp.ODD_Z+mp.EVEN_Y, direction=mp.Z).alpha[0,:,1]
inputHiAlpha = sim.get_eigenmode_coefficients(input_hi_mode,[1],eig_parity=mp.ODD_Z+mp.EVEN_Y, direction=mp.Z).alpha[0,:,1]
#%%
# Calculate the transmittance for the upper and lower output ports
trans_Lo = abs(outputLoAlpha[:])**2/abs(incident_mode_alpha[:])**2
trans_Hi = abs(outputHiAlpha[:])**2/abs(incident_mode_alpha[:])**2
#%%
# Calculate reflectance for the input ports
refl_Lo = abs(inputLoAlpha[:])**2/abs(incident_mode_alpha[:])**2
refl_Hi = abs(inputHiAlpha[:])**2/abs(incident_mode_alpha[:])**2
# Calculate phases of the outputs
outputLoPhase = np.angle(outputLoAlpha[:])
outputHiPhase = np.angle(outputHiAlpha[:])
freqs= mp.get_flux_freqs(input_mode)
# Create dataframe to store necessary data
df = pd.DataFrame({"Frequency": freqs, "StraightAlpha": incident_mode_alpha, "InputLoAlpha": inputLoAlpha, "OutputLoAlpha": outputLoAlpha, "OutputHiAlpha": outputHiAlpha, "Low Transmission": trans_Lo, "High Transmission": trans_Hi, "Low Refl": refl_Lo, "High Refl": refl_Hi, "Low Phase": outputLoPhase, "High Phase": outputHiPhase})
df.to_csv("MMIOutput.csv")
#%%
# Show the simulation
plt.figure()
sim.plot2D()
plt.axis("off")
plt.savefig("MMIGeometry.png")
# Shows the electric field in the z direction
ez_data = sim.get_array(center=mp.Vector3(), size=cell, component=mp.Ez)
plt.imsave("EzFields-Straight.png", ez_data.transpose(), cmap='RdBu')
#%%
# Plotting the throughput
freqs = np.array(freqs)
wvls = 1/freqs[:]
g = np.exp((-(freqs[:]-freq)**2/fwidth**2))
fig, ax = plt.subplots()
ax.plot(wvls[:],trans_Lo, color='blue')
ax.set_xlabel('Wavelength (um)')
'''ax2 = ax.twinx()
ax2.plot(wvls[:], g[:])'''
fig.savefig("TransmissionLow.png")
fig, ax = plt.subplots()
ax.plot(wvls[:],trans_Hi, color='red')
ax.set_xlabel('Wavelength (um)')
'''ax2 = ax.twinx()
ax2.plot(wvls[:], g[:])'''
fig.savefig("TransmissionHigh.png")
#%%
# Plotting the reflectance
fig, ax = plt.subplots()
ax.plot(wvls[:], refl_Lo, color='blue')
ax.set_xlabel('Wavelength (um)')
'''ax2 = ax.twinx()
ax2.plot(wvls[:], g[:])'''
fig.savefig("ReflectanceLow.png")
fig, ax = plt.subplots()
ax.plot(wvls[:], refl_Hi, color='red')
ax.set_xlabel('Wavelength (um)')
'''ax2 = ax.twinx()
ax2.plot(wvls[:], g[:])'''
fig.savefig("ReflectanceHigh.png")
# Plot the phase
fig, ax = plt.subplots()
ax.plot(wvls[:], outputLoPhase, color='blue')
ax.plot(wvls[:], outputHiPhase, color='red')
ax.set_xlabel('Wavelength (um)')
fig.savefig("Phase.png")