ElectroMagneticPython 2.2.1__py3-none-any.whl → 2.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. EMpy/RCWA.py +32 -12
  2. EMpy/__init__.py +10 -2
  3. EMpy/_version.py +34 -0
  4. EMpy/devices.py +4 -27
  5. EMpy/materials.py +1 -6
  6. EMpy/modesolvers/FD.py +34 -72
  7. EMpy/modesolvers/FMM.py +24 -23
  8. EMpy/modesolvers/__init__.py +1 -0
  9. EMpy/modesolvers/geometries.py +8 -9
  10. EMpy/transfer_matrix.py +1 -1
  11. EMpy/utils.py +12 -24
  12. electromagneticpython-2.2.3.dist-info/METADATA +99 -0
  13. electromagneticpython-2.2.3.dist-info/RECORD +44 -0
  14. {ElectroMagneticPython-2.2.1.dist-info → electromagneticpython-2.2.3.dist-info}/WHEEL +1 -1
  15. electromagneticpython-2.2.3.dist-info/top_level.txt +4 -0
  16. examples/ex_APRR.py +18 -0
  17. examples/ex_NRR.py +40 -0
  18. examples/ex_RCWA.py +95 -0
  19. examples/ex_RCWA_2.py +52 -0
  20. examples/ex_RCWA_3.py +58 -0
  21. examples/ex_SRR.py +23 -0
  22. examples/ex_laser_etch_monitor.py +241 -0
  23. examples/ex_modesolver.py +68 -0
  24. examples/ex_modesolver_2.py +58 -0
  25. examples/ex_modesolver_3.py +48 -0
  26. examples/ex_modesolver_4.py +43 -0
  27. examples/ex_modesolver_dch.py +296 -0
  28. examples/ex_modesolver_dch_anis.py +318 -0
  29. examples/ex_transfer_matrix.py +82 -0
  30. examples/ex_transfer_matrix_2.py +44 -0
  31. examples/ex_transfer_matrix_2.py.png +0 -0
  32. examples/ex_transfer_matrix_3.py +60 -0
  33. examples/lc_data.dat +27 -0
  34. examples/nk.py +1468 -0
  35. scripts/FDTD.py +741 -0
  36. tests/devices_test.py +31 -0
  37. tests/materials_test.py +1 -1
  38. tests/modesolvers_test.py +36 -0
  39. tests/utils_test.py +9 -5
  40. EMpy/version.py +0 -1
  41. ElectroMagneticPython-2.2.1.dist-info/METADATA +0 -109
  42. ElectroMagneticPython-2.2.1.dist-info/RECORD +0 -22
  43. ElectroMagneticPython-2.2.1.dist-info/top_level.txt +0 -2
  44. {ElectroMagneticPython-2.2.1.dist-info → electromagneticpython-2.2.3.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,296 @@
1
+ """Fully vectorial finite-difference mode solver example.
2
+
3
+ Flexible mode solver example for fundamental modes
4
+ by David Hutchings, School of Engineering, University of Glasgow
5
+ David.Hutchings@glasgow.ac.uk
6
+ """
7
+
8
+ import numpy
9
+ import EMpy
10
+ import matplotlib.pyplot as plt
11
+ from matplotlib import ticker
12
+ from scipy import signal
13
+
14
+ """Define cross-section geometry of simulation
15
+ each rectangular element tuple contains
16
+ ("label",xmin,ymin,xmax,ymax,eps=refractive index squared)
17
+ first element tuple defines simulation extent
18
+ units should match units of wavelength wl
19
+ """
20
+ geom = (
21
+ ("base", -0.8, -0.8, 0.8, 1.0, 1.0**2),
22
+ ("substrate", -0.8, -0.8, 0.8, 0.0, 1.5**2),
23
+ ("core1", -0.30, 0.0, 0.0, 0.34, 3.4**2),
24
+ ("core2", 0.0, 0.0, 0.30, 0.145, 3.4**2),
25
+ )
26
+
27
+ wl = 1.55
28
+ nx, ny = 161, 181
29
+
30
+
31
+ def epsfunc(x_, y_):
32
+ """Return a matrix describing a 2d material.
33
+
34
+ :param x_: x values
35
+ :param y_: y values
36
+ :return: 2d-matrix
37
+ """
38
+ # xx, yy = numpy.meshgrid(x_, y_)
39
+ working = geom[0][5] * numpy.ones((x_.size, y_.size))
40
+ for i in range(1, len(geom)):
41
+ ixmin = numpy.searchsorted(x_, geom[i][1], side="left")
42
+ iymin = numpy.searchsorted(y_, geom[i][2], side="left")
43
+ ixmax = numpy.searchsorted(x_, geom[i][3], side="right")
44
+ iymax = numpy.searchsorted(y_, geom[i][4], side="right")
45
+ working[ixmin:ixmax, iymin:iymax] = geom[i][5]
46
+
47
+ return working
48
+
49
+
50
+ x = numpy.linspace(geom[0][1], geom[0][3], nx)
51
+ y = numpy.linspace(geom[0][2], geom[0][4], ny)
52
+
53
+ neigs = 2
54
+ tol = 1e-8
55
+ boundary = "0000"
56
+
57
+ solver = EMpy.modesolvers.FD.VFDModeSolver(wl, x, y, epsfunc, boundary).solve(
58
+ neigs, tol
59
+ )
60
+
61
+ levls = numpy.geomspace(1.0 / 32.0, 1.0, num=11)
62
+ levls2 = numpy.geomspace(1.0 / 1024.0, 1.0, num=11)
63
+ xe = signal.convolve(x, [0.5, 0.5])[1:-1]
64
+ ye = signal.convolve(y, [0.5, 0.5])[1:-1]
65
+
66
+
67
+ def geom_outline():
68
+ ax.set_xlim(geom[0][1], geom[0][3])
69
+ ax.set_ylim(geom[0][2], geom[0][4])
70
+ for i in range(1, len(geom)):
71
+ plt.hlines(geom[i][2], geom[i][1], geom[i][3])
72
+ plt.hlines(geom[i][4], geom[i][1], geom[i][3])
73
+ plt.vlines(geom[i][1], geom[i][2], geom[i][4])
74
+ plt.vlines(geom[i][3], geom[i][2], geom[i][4])
75
+ return
76
+
77
+
78
+ print(solver.modes[0].neff)
79
+ fmax = abs(solver.modes[0].Ex).max()
80
+ fig = plt.figure()
81
+ ax = fig.add_subplot(2, 3, 1)
82
+ plt.contour(
83
+ xe,
84
+ ye,
85
+ abs(solver.modes[0].Ex.T),
86
+ fmax * levls,
87
+ cmap="jet",
88
+ locator=ticker.LogLocator(),
89
+ )
90
+ plt.title("Ex")
91
+ geom_outline()
92
+ ax = fig.add_subplot(2, 3, 2)
93
+ plt.contour(
94
+ xe,
95
+ ye,
96
+ abs(solver.modes[0].Ey.T),
97
+ fmax * levls,
98
+ cmap="jet",
99
+ locator=ticker.LogLocator(),
100
+ )
101
+ plt.title("Ey")
102
+ geom_outline()
103
+ ax = fig.add_subplot(2, 3, 3)
104
+ plt.contour(
105
+ xe,
106
+ ye,
107
+ abs(solver.modes[0].Ez.T),
108
+ fmax * levls,
109
+ cmap="jet",
110
+ locator=ticker.LogLocator(),
111
+ )
112
+ plt.title("Ez")
113
+ geom_outline()
114
+ fmax = abs(solver.modes[0].Hy).max()
115
+ ax = fig.add_subplot(2, 3, 4)
116
+ plt.contour(
117
+ x,
118
+ y,
119
+ abs(solver.modes[0].Hx.T),
120
+ fmax * levls,
121
+ cmap="jet",
122
+ locator=ticker.LogLocator(),
123
+ )
124
+ plt.title("Hx")
125
+ geom_outline()
126
+ ax = fig.add_subplot(2, 3, 5)
127
+ plt.contour(
128
+ x,
129
+ y,
130
+ abs(solver.modes[0].Hy.T),
131
+ fmax * levls,
132
+ cmap="jet",
133
+ locator=ticker.LogLocator(),
134
+ )
135
+ plt.title("Hy")
136
+ geom_outline()
137
+ ax = fig.add_subplot(2, 3, 6)
138
+ plt.contour(
139
+ x,
140
+ y,
141
+ abs(solver.modes[0].Hz.T),
142
+ fmax * levls,
143
+ cmap="jet",
144
+ locator=ticker.LogLocator(),
145
+ )
146
+ plt.title("Hz")
147
+ geom_outline()
148
+ plt.show()
149
+
150
+ ExatH = signal.convolve2d(solver.modes[0].Ex, [[0.25, 0.25], [0.25, 0.25]])
151
+ EyatH = signal.convolve2d(solver.modes[0].Ey, [[0.25, 0.25], [0.25, 0.25]])
152
+ EzatH = signal.convolve2d(solver.modes[0].Ez, [[0.25, 0.25], [0.25, 0.25]])
153
+ # Stokes parameters
154
+ q1 = ExatH * numpy.conjugate(solver.modes[0].Hy)
155
+ q2 = EyatH * numpy.conjugate(solver.modes[0].Hx)
156
+ q3 = EyatH * numpy.conjugate(solver.modes[0].Hy)
157
+ q4 = ExatH * numpy.conjugate(solver.modes[0].Hx)
158
+
159
+ S0 = q1.real - q2.real
160
+ S1 = q1.real + q2.real
161
+ S2 = q3.real - q4.real
162
+ S3 = q3.imag + q4.imag
163
+ denom = S0.sum()
164
+ print("ave S1=", S1.sum() / denom)
165
+ print("ave S2=", S2.sum() / denom)
166
+ print("ave S3=", S3.sum() / denom)
167
+
168
+ fmax = abs(S0).max()
169
+ fig = plt.figure()
170
+ ax = fig.add_subplot(2, 2, 1)
171
+ plt.contour(x, y, abs(S0.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
172
+ plt.title("S0")
173
+ geom_outline()
174
+ ax = fig.add_subplot(2, 2, 2)
175
+ plt.contour(x, y, abs(S1.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
176
+ plt.title("S1")
177
+ geom_outline()
178
+ ax = fig.add_subplot(2, 2, 3)
179
+ plt.contour(x, y, abs(S2.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
180
+ plt.title("S2")
181
+ geom_outline()
182
+ ax = fig.add_subplot(2, 2, 4)
183
+ plt.contour(x, y, abs(S3.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
184
+ plt.title("S3")
185
+ geom_outline()
186
+ plt.show()
187
+
188
+ print(solver.modes[1].neff)
189
+ fmax = abs(solver.modes[1].Ey).max()
190
+ fig = plt.figure()
191
+ ax = fig.add_subplot(2, 3, 1)
192
+ plt.contour(
193
+ xe,
194
+ ye,
195
+ abs(solver.modes[1].Ex.T),
196
+ fmax * levls,
197
+ cmap="jet",
198
+ locator=ticker.LogLocator(),
199
+ )
200
+ plt.title("Ex")
201
+ geom_outline()
202
+ ax = fig.add_subplot(2, 3, 2)
203
+ plt.contour(
204
+ xe,
205
+ ye,
206
+ abs(solver.modes[1].Ey.T),
207
+ fmax * levls,
208
+ cmap="jet",
209
+ locator=ticker.LogLocator(),
210
+ )
211
+ plt.title("Ey")
212
+ geom_outline()
213
+ ax = fig.add_subplot(2, 3, 3)
214
+ plt.contour(
215
+ xe,
216
+ ye,
217
+ abs(solver.modes[1].Ez.T),
218
+ fmax * levls,
219
+ cmap="jet",
220
+ locator=ticker.LogLocator(),
221
+ )
222
+ plt.title("Ez")
223
+ geom_outline()
224
+ fmax = abs(solver.modes[1].Hx).max()
225
+ ax = fig.add_subplot(2, 3, 4)
226
+ plt.contour(
227
+ x,
228
+ y,
229
+ abs(solver.modes[1].Hx.T),
230
+ fmax * levls,
231
+ cmap="jet",
232
+ locator=ticker.LogLocator(),
233
+ )
234
+ plt.title("Hx")
235
+ geom_outline()
236
+ ax = fig.add_subplot(2, 3, 5)
237
+ plt.contour(
238
+ x,
239
+ y,
240
+ abs(solver.modes[1].Hy.T),
241
+ fmax * levls,
242
+ cmap="jet",
243
+ locator=ticker.LogLocator(),
244
+ )
245
+ plt.title("Hy")
246
+ geom_outline()
247
+ ax = fig.add_subplot(2, 3, 6)
248
+ plt.contour(
249
+ x,
250
+ y,
251
+ abs(solver.modes[1].Hz.T),
252
+ fmax * levls,
253
+ cmap="jet",
254
+ locator=ticker.LogLocator(),
255
+ )
256
+ plt.title("Hz")
257
+ geom_outline()
258
+ plt.show()
259
+
260
+ ExatH = signal.convolve2d(solver.modes[1].Ex, [[0.25, 0.25], [0.25, 0.25]])
261
+ EyatH = signal.convolve2d(solver.modes[1].Ey, [[0.25, 0.25], [0.25, 0.25]])
262
+ EzatH = signal.convolve2d(solver.modes[1].Ez, [[0.25, 0.25], [0.25, 0.25]])
263
+ # Stokes parameters
264
+ q1 = ExatH * numpy.conjugate(solver.modes[1].Hy)
265
+ q2 = EyatH * numpy.conjugate(solver.modes[1].Hx)
266
+ q3 = EyatH * numpy.conjugate(solver.modes[1].Hy)
267
+ q4 = ExatH * numpy.conjugate(solver.modes[1].Hx)
268
+
269
+ S0 = q1.real - q2.real
270
+ S1 = q1.real + q2.real
271
+ S2 = q3.real - q4.real
272
+ S3 = q3.imag + q4.imag
273
+ denom = S0.sum()
274
+ print("ave S1=", S1.sum() / denom)
275
+ print("ave S2=", S2.sum() / denom)
276
+ print("ave S3=", S3.sum() / denom)
277
+
278
+ fmax = abs(S0).max()
279
+ fig = plt.figure()
280
+ ax = fig.add_subplot(2, 2, 1)
281
+ plt.contour(x, y, abs(S0.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
282
+ plt.title("S0")
283
+ geom_outline()
284
+ ax = fig.add_subplot(2, 2, 2)
285
+ plt.contour(x, y, abs(S1.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
286
+ plt.title("S1")
287
+ geom_outline()
288
+ ax = fig.add_subplot(2, 2, 3)
289
+ plt.contour(x, y, abs(S2.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
290
+ plt.title("S2")
291
+ geom_outline()
292
+ ax = fig.add_subplot(2, 2, 4)
293
+ plt.contour(x, y, abs(S3.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
294
+ plt.title("S3")
295
+ geom_outline()
296
+ plt.show()
@@ -0,0 +1,318 @@
1
+ """Fully vectorial finite-difference mode solver example.
2
+
3
+ Flexible mode solver example for fundamental modes for anisotropic media
4
+ by David Hutchings, School of Engineering, University of Glasgow
5
+ David.Hutchings@glasgow.ac.uk
6
+ """
7
+
8
+ import numpy
9
+ import EMpy
10
+ import matplotlib.pyplot as plt
11
+ from matplotlib import ticker
12
+ from scipy import signal
13
+
14
+ """Define cross-section geometry of simulation
15
+ each rectangular element tuple contains
16
+ ("label",xmin,ymin,xmax,ymax,eps) for isotropic or
17
+ ("label",xmin,ymin,xmax,ymax,eps_xx, eps_xy, eps_yx, eps_yy, eps_zz) for anisotropic
18
+ first element tuple defines simulation extent
19
+ units should match units of wavelength wl
20
+ """
21
+ geom = (
22
+ ("base", -0.7, -0.5, 0.7, 0.9, 1.44**2),
23
+ ("core", -0.35, 0.0, 0.35, 0.34, 3.48**2),
24
+ ("clad", -0.35, 0.34, 0.35, 0.44, 2.19**2, -0.006j, 0.006j, 2.19**2, 2.19**2),
25
+ ("slot", -0.05, 0.00, 0.05, 0.34, 2.19**2, -0.006j, 0.006j, 2.19**2, 2.19**2),
26
+ )
27
+ # clad corresponds to Ce:TbIG with -3200deg/cm
28
+
29
+ wl = 1.55
30
+ nx, ny = 141, 141
31
+
32
+
33
+ def epsfunc(x_, y_):
34
+ """Return a matrix describing a 2d material.
35
+
36
+ :param x_: x values
37
+ :param y_: y values
38
+ :return: 2d-matrix *5
39
+ """
40
+ # assume base medium is isotropic
41
+ working = numpy.zeros((x_.size, y_.size, 5), dtype="complex")
42
+ working[:, :, 0] = geom[0][5] * numpy.ones((x_.size, y_.size))
43
+ working[:, :, 3] = geom[0][5] * numpy.ones((x_.size, y_.size))
44
+ working[:, :, 4] = geom[0][5] * numpy.ones((x_.size, y_.size))
45
+ for i in range(1, len(geom)):
46
+ ixmin = numpy.searchsorted(x_, geom[i][1], side="left")
47
+ iymin = numpy.searchsorted(y_, geom[i][2], side="left")
48
+ ixmax = numpy.searchsorted(x_, geom[i][3], side="right")
49
+ iymax = numpy.searchsorted(y_, geom[i][4], side="right")
50
+ if len(geom[i]) == 6:
51
+ # isotropic
52
+ working[ixmin:ixmax, iymin:iymax, :] = [
53
+ geom[i][5],
54
+ 0.0,
55
+ 0.0,
56
+ geom[i][5],
57
+ geom[i][5],
58
+ ]
59
+ else:
60
+ # anisotropic
61
+ working[ixmin:ixmax, iymin:iymax, :] = [
62
+ geom[i][5],
63
+ geom[i][6],
64
+ geom[i][7],
65
+ geom[i][8],
66
+ geom[i][9],
67
+ ]
68
+
69
+ return working
70
+
71
+
72
+ x = numpy.linspace(geom[0][1], geom[0][3], nx)
73
+ y = numpy.linspace(geom[0][2], geom[0][4], ny)
74
+
75
+ neigs = 2
76
+ tol = 1e-6
77
+ boundary = "0000"
78
+
79
+ solver = EMpy.modesolvers.FD.VFDModeSolver(wl, x, y, epsfunc, boundary).solve(
80
+ neigs, tol
81
+ )
82
+
83
+ levls = numpy.geomspace(1.0 / 32.0, 1.0, num=11)
84
+ levls2 = numpy.geomspace(1.0 / 1024.0, 1.0, num=11)
85
+ xe = signal.convolve(x, [0.5, 0.5])[1:-1]
86
+ ye = signal.convolve(y, [0.5, 0.5])[1:-1]
87
+
88
+
89
+ def geom_outline():
90
+ ax.set_xlim(geom[0][1], geom[0][3])
91
+ ax.set_ylim(geom[0][2], geom[0][4])
92
+ for i in range(1, len(geom)):
93
+ plt.hlines(geom[i][2], geom[i][1], geom[i][3])
94
+ plt.hlines(geom[i][4], geom[i][1], geom[i][3])
95
+ plt.vlines(geom[i][1], geom[i][2], geom[i][4])
96
+ plt.vlines(geom[i][3], geom[i][2], geom[i][4])
97
+ return
98
+
99
+
100
+ print(solver.modes[0].neff)
101
+ fmax = abs(solver.modes[0].Ex).max()
102
+ fig = plt.figure()
103
+ ax = fig.add_subplot(2, 3, 1)
104
+ plt.contour(
105
+ xe,
106
+ ye,
107
+ abs(solver.modes[0].Ex.T),
108
+ fmax * levls,
109
+ cmap="jet",
110
+ locator=ticker.LogLocator(),
111
+ )
112
+ plt.title("Ex")
113
+ geom_outline()
114
+ ax = fig.add_subplot(2, 3, 2)
115
+ plt.contour(
116
+ xe,
117
+ ye,
118
+ abs(solver.modes[0].Ey.T),
119
+ fmax * levls,
120
+ cmap="jet",
121
+ locator=ticker.LogLocator(),
122
+ )
123
+ plt.title("Ey")
124
+ geom_outline()
125
+ ax = fig.add_subplot(2, 3, 3)
126
+ plt.contour(
127
+ xe,
128
+ ye,
129
+ abs(solver.modes[0].Ez.T),
130
+ fmax * levls,
131
+ cmap="jet",
132
+ locator=ticker.LogLocator(),
133
+ )
134
+ plt.title("Ez")
135
+ geom_outline()
136
+ fmax = abs(solver.modes[0].Hy).max()
137
+ ax = fig.add_subplot(2, 3, 4)
138
+ plt.contour(
139
+ x,
140
+ y,
141
+ abs(solver.modes[0].Hx.T),
142
+ fmax * levls,
143
+ cmap="jet",
144
+ locator=ticker.LogLocator(),
145
+ )
146
+ plt.title("Hx")
147
+ geom_outline()
148
+ ax = fig.add_subplot(2, 3, 5)
149
+ plt.contour(
150
+ x,
151
+ y,
152
+ abs(solver.modes[0].Hy.T),
153
+ fmax * levls,
154
+ cmap="jet",
155
+ locator=ticker.LogLocator(),
156
+ )
157
+ plt.title("Hy")
158
+ geom_outline()
159
+ ax = fig.add_subplot(2, 3, 6)
160
+ plt.contour(
161
+ x,
162
+ y,
163
+ abs(solver.modes[0].Hz.T),
164
+ fmax * levls,
165
+ cmap="jet",
166
+ locator=ticker.LogLocator(),
167
+ )
168
+ plt.title("Hz")
169
+ geom_outline()
170
+ plt.show()
171
+
172
+ ExatH = signal.convolve2d(solver.modes[0].Ex, [[0.25, 0.25], [0.25, 0.25]])
173
+ EyatH = signal.convolve2d(solver.modes[0].Ey, [[0.25, 0.25], [0.25, 0.25]])
174
+ EzatH = signal.convolve2d(solver.modes[0].Ez, [[0.25, 0.25], [0.25, 0.25]])
175
+ # Stokes parameters
176
+ q1 = ExatH * numpy.conjugate(solver.modes[0].Hy)
177
+ q2 = EyatH * numpy.conjugate(solver.modes[0].Hx)
178
+ q3 = EyatH * numpy.conjugate(solver.modes[0].Hy)
179
+ q4 = ExatH * numpy.conjugate(solver.modes[0].Hx)
180
+
181
+ S0 = q1.real - q2.real
182
+ S1 = q1.real + q2.real
183
+ S2 = q3.real - q4.real
184
+ S3 = q3.imag + q4.imag
185
+ denom = S0.sum()
186
+ print("ave S1=", S1.sum() / denom)
187
+ print("ave S2=", S2.sum() / denom)
188
+ print("ave S3=", S3.sum() / denom)
189
+
190
+ fmax = abs(S0).max()
191
+ fig = plt.figure()
192
+ ax = fig.add_subplot(2, 2, 1)
193
+ plt.contour(x, y, abs(S0.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
194
+ plt.title("S0")
195
+ geom_outline()
196
+ ax = fig.add_subplot(2, 2, 2)
197
+ plt.contour(x, y, abs(S1.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
198
+ plt.title("S1")
199
+ geom_outline()
200
+ ax = fig.add_subplot(2, 2, 3)
201
+ plt.contour(x, y, abs(S2.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
202
+ plt.title("S2")
203
+ geom_outline()
204
+ ax = fig.add_subplot(2, 2, 4)
205
+ plt.contour(x, y, abs(S3.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
206
+ plt.title("S3")
207
+ geom_outline()
208
+ plt.show()
209
+
210
+ print(solver.modes[1].neff)
211
+ fmax = abs(solver.modes[1].Ey).max()
212
+ fig = plt.figure()
213
+ ax = fig.add_subplot(2, 3, 1)
214
+ plt.contour(
215
+ xe,
216
+ ye,
217
+ abs(solver.modes[1].Ex.T),
218
+ fmax * levls,
219
+ cmap="jet",
220
+ locator=ticker.LogLocator(),
221
+ )
222
+ plt.title("Ex")
223
+ geom_outline()
224
+ ax = fig.add_subplot(2, 3, 2)
225
+ plt.contour(
226
+ xe,
227
+ ye,
228
+ abs(solver.modes[1].Ey.T),
229
+ fmax * levls,
230
+ cmap="jet",
231
+ locator=ticker.LogLocator(),
232
+ )
233
+ plt.title("Ey")
234
+ geom_outline()
235
+ ax = fig.add_subplot(2, 3, 3)
236
+ plt.contour(
237
+ xe,
238
+ ye,
239
+ abs(solver.modes[1].Ez.T),
240
+ fmax * levls,
241
+ cmap="jet",
242
+ locator=ticker.LogLocator(),
243
+ )
244
+ plt.title("Ez")
245
+ geom_outline()
246
+ fmax = abs(solver.modes[1].Hx).max()
247
+ ax = fig.add_subplot(2, 3, 4)
248
+ plt.contour(
249
+ x,
250
+ y,
251
+ abs(solver.modes[1].Hx.T),
252
+ fmax * levls,
253
+ cmap="jet",
254
+ locator=ticker.LogLocator(),
255
+ )
256
+ plt.title("Hx")
257
+ geom_outline()
258
+ ax = fig.add_subplot(2, 3, 5)
259
+ plt.contour(
260
+ x,
261
+ y,
262
+ abs(solver.modes[1].Hy.T),
263
+ fmax * levls,
264
+ cmap="jet",
265
+ locator=ticker.LogLocator(),
266
+ )
267
+ plt.title("Hy")
268
+ geom_outline()
269
+ ax = fig.add_subplot(2, 3, 6)
270
+ plt.contour(
271
+ x,
272
+ y,
273
+ abs(solver.modes[1].Hz.T),
274
+ fmax * levls,
275
+ cmap="jet",
276
+ locator=ticker.LogLocator(),
277
+ )
278
+ plt.title("Hz")
279
+ geom_outline()
280
+ plt.show()
281
+
282
+ ExatH = signal.convolve2d(solver.modes[1].Ex, [[0.25, 0.25], [0.25, 0.25]])
283
+ EyatH = signal.convolve2d(solver.modes[1].Ey, [[0.25, 0.25], [0.25, 0.25]])
284
+ EzatH = signal.convolve2d(solver.modes[1].Ez, [[0.25, 0.25], [0.25, 0.25]])
285
+ # Stokes parameters
286
+ q1 = ExatH * numpy.conjugate(solver.modes[1].Hy)
287
+ q2 = EyatH * numpy.conjugate(solver.modes[1].Hx)
288
+ q3 = EyatH * numpy.conjugate(solver.modes[1].Hy)
289
+ q4 = ExatH * numpy.conjugate(solver.modes[1].Hx)
290
+
291
+ S0 = q1.real - q2.real
292
+ S1 = q1.real + q2.real
293
+ S2 = q3.real - q4.real
294
+ S3 = q3.imag + q4.imag
295
+ denom = S0.sum()
296
+ print("ave S1=", S1.sum() / denom)
297
+ print("ave S2=", S2.sum() / denom)
298
+ print("ave S3=", S3.sum() / denom)
299
+
300
+ fmax = abs(S0).max()
301
+ fig = plt.figure()
302
+ ax = fig.add_subplot(2, 2, 1)
303
+ plt.contour(x, y, abs(S0.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
304
+ plt.title("S0")
305
+ geom_outline()
306
+ ax = fig.add_subplot(2, 2, 2)
307
+ plt.contour(x, y, abs(S1.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
308
+ plt.title("S1")
309
+ geom_outline()
310
+ ax = fig.add_subplot(2, 2, 3)
311
+ plt.contour(x, y, abs(S2.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
312
+ plt.title("S2")
313
+ geom_outline()
314
+ ax = fig.add_subplot(2, 2, 4)
315
+ plt.contour(x, y, abs(S3.T), fmax * levls2, cmap="jet", locator=ticker.LogLocator())
316
+ plt.title("S3")
317
+ geom_outline()
318
+ plt.show()
@@ -0,0 +1,82 @@
1
+ """Transfer matrix example.
2
+
3
+ Solve for both an isotropic and anisotropic multilayer.
4
+ """
5
+
6
+ from matplotlib import pyplot as plt
7
+ import numpy as np
8
+
9
+ import EMpy
10
+
11
+ n = np.array([1.0, 2.0, 2.3, 4.3, 3.0])
12
+ d = np.array([np.inf, 1e-6, 2.3e-6, 0.1e-6, np.inf])
13
+
14
+ iso_layers = EMpy.utils.Multilayer()
15
+ aniso_layers = EMpy.utils.Multilayer()
16
+
17
+ for i in range(n.size):
18
+ iso_layers.append(
19
+ EMpy.utils.Layer(
20
+ EMpy.materials.IsotropicMaterial(
21
+ "mat", n0=EMpy.materials.RefractiveIndex(n[i])
22
+ ),
23
+ d[i],
24
+ )
25
+ )
26
+ aniso_layers.append(
27
+ EMpy.utils.Layer(
28
+ EMpy.materials.AnisotropicMaterial(
29
+ "Air",
30
+ epsilon_tensor=EMpy.materials.EpsilonTensor(
31
+ epsilon_tensor_const=n[i] ** 2 * EMpy.constants.eps0 * np.eye(3)
32
+ ),
33
+ ),
34
+ d[i],
35
+ )
36
+ )
37
+
38
+ theta_inc = EMpy.utils.deg2rad(10.0)
39
+ theta_inc_x = theta_inc
40
+ theta_inc_y = 0.0
41
+ wls = np.linspace(1.4e-6, 1.7e-6, 100)
42
+ solution_iso = EMpy.transfer_matrix.IsotropicTransferMatrix(
43
+ iso_layers, theta_inc
44
+ ).solve(wls)
45
+ solution_aniso = EMpy.transfer_matrix.AnisotropicTransferMatrix(
46
+ aniso_layers, theta_inc_x, theta_inc_y
47
+ ).solve(wls)
48
+
49
+ plt.figure()
50
+ plt.plot(
51
+ wls,
52
+ solution_iso.Rs,
53
+ wls,
54
+ solution_iso.Ts,
55
+ wls,
56
+ solution_iso.Rp,
57
+ wls,
58
+ solution_iso.Tp,
59
+ )
60
+ plt.title("isotropic")
61
+
62
+ plt.figure()
63
+ plt.plot(
64
+ wls,
65
+ solution_aniso.R[0, 0, :],
66
+ wls,
67
+ solution_aniso.R[1, 0, :],
68
+ wls,
69
+ solution_aniso.R[0, 1, :],
70
+ wls,
71
+ solution_aniso.R[1, 1, :],
72
+ wls,
73
+ solution_aniso.T[0, 0, :],
74
+ wls,
75
+ solution_aniso.T[1, 0, :],
76
+ wls,
77
+ solution_aniso.T[0, 1, :],
78
+ wls,
79
+ solution_aniso.T[1, 1, :],
80
+ )
81
+ plt.title("anisotropic")
82
+ plt.show()