123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- import scattnlay
- from scattnlay import fieldnlay
- from scattnlay import scattnlay
- import numpy as np
- import cmath
- epsilon_Si = 13.64 + 0.047j
- epsilon_Ag = -28.05 + 1.525j
- index_Si = np.sqrt(epsilon_Si)
- index_Ag = np.sqrt(epsilon_Ag)
- WL=800
- core_width = 17.74
- inner_width = 23.31
- outer_width = 22.95
- core_r = core_width
- inner_r = core_r+inner_width
- outer_r = inner_r+outer_width
- nm = 1.0
- x = np.ones((1, 3), dtype = np.float64)
- x[0, 0] = 2.0*np.pi*core_r/WL
- x[0, 1] = 2.0*np.pi*inner_r/WL
- x[0, 2] = 2.0*np.pi*outer_r/WL
- m = np.ones((1, 3), dtype = np.complex128)
- m[0, 0] = index_Si/nm
- m[0, 1] = index_Ag/nm
- m[0, 2] = index_Si/nm
- print "x =", x
- print "m =", m
- npts = 281
- factor=2.5
- scan = np.linspace(-factor*x[0, 2], factor*x[0, 2], npts)
- coordX, coordZ = np.meshgrid(scan, scan)
- coordX.resize(npts*npts)
- coordZ.resize(npts*npts)
- coordY = np.zeros(npts*npts, dtype = np.float64)
- coord = np.vstack((coordX, coordY, coordZ)).transpose()
- terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
- terms, E, H = fieldnlay(x, m, coord)
- print("Qabs = "+str(Qabs));
- Er = np.absolute(E)
- Hr = np.absolute(H)
- Eabs = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
- Eangle = np.angle(E[0, :, 0])/np.pi*180
- Habs= np.sqrt(Hr[0, :, 0]**2 + Hr[0, :, 1]**2 + Hr[0, :, 2]**2)
- Hangle = np.angle(H[0, :, 1])/np.pi*180
- result = np.vstack((coordX, coordY, coordZ, Eabs)).transpose()
- result2 = np.vstack((coordX, coordY, coordZ, Eangle)).transpose()
- try:
- import matplotlib.pyplot as plt
- from matplotlib import cm
- from matplotlib.colors import LogNorm
-
-
- Eabs_data = np.resize(Eabs, (npts, npts)).T
- Eangle_data = np.resize(Eangle, (npts, npts)).T
- Habs_data = np.resize(Habs, (npts, npts)).T
- Hangle_data = np.resize(Hangle, (npts, npts)).T
- fig, axs = plt.subplots(2,2)
- fig.tight_layout()
-
- scale_x = np.linspace(min(coordX)*WL/2.0/np.pi/nm, max(coordX)*WL/2.0/np.pi/nm, npts)
- scale_z = np.linspace(min(coordZ)*WL/2.0/np.pi/nm, max(coordZ)*WL/2.0/np.pi/nm, npts)
-
-
-
-
-
-
- axs[0,0].set_title('Eabs')
- cax = axs[0,0].imshow(Eabs_data, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower'
-
- , extent = (min(scale_x), max(scale_x), min(scale_z), max(scale_z))
-
- )
- axs[0,0].axis("image")
- axs[0,1].set_title('Eangle')
- cax = axs[0,1].imshow(Eangle_data, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower'
-
- , extent = (min(scale_x), max(scale_x), min(scale_z), max(scale_z))
-
- )
- axs[1,0].set_title('Habs')
- cax = axs[1,0].imshow(Habs_data, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower'
-
- , extent = (min(scale_x), max(scale_x), min(scale_z), max(scale_z))
-
- )
- axs[1,1].set_title('Hangle')
- cax = axs[1,1].imshow(Hangle_data, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower'
-
- , extent = (min(scale_x), max(scale_x), min(scale_z), max(scale_z))
-
- )
-
-
-
-
-
-
-
-
- from matplotlib import patches
- for m in (0,1):
- for n in (0,1):
- s1 = patches.Arc((0, 0), 2.0*core_r, 2.0*core_r, angle=0.0, zorder=2,
- theta1=0.0, theta2=360.0, linewidth=1, color='black')
- s2 = patches.Arc((0, 0), 2.0*inner_r, 2.0*inner_r, angle=0.0, zorder=2,
- theta1=0.0, theta2=360.0, linewidth=1, color='black')
- s3 = patches.Arc((0, 0), 2.0*outer_r, 2.0*outer_r, angle=0.0, zorder=2,
- theta1=0.0, theta2=360.0, linewidth=1, color='black')
- axs[m,n].add_patch(s1)
- axs[m,n].add_patch(s2)
- axs[m,n].add_patch(s3)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- plt.savefig("SiAgSi.png")
- plt.draw()
- plt.show()
- plt.clf()
- plt.close()
- finally:
- np.savetxt("field.txt", result, fmt = "%.5f")
- print result
|