123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import scattnlay
- from scattnlay import fieldnlay
- from scattnlay import scattnlay
- import numpy as np
- import cmath
- def get_index(array,value):
- idx = (np.abs(array-value)).argmin()
- return idx
- def GetFlow(scale_x, scale_z, Ec, Hc, a, b, nmax):
-
- flow_x = [a]
- flow_z = [b]
- x_pos = flow_x[-1]
- z_pos = flow_z[-1]
- x_idx = get_index(scale_x, x_pos)
- z_idx = get_index(scale_z, z_pos)
- S=np.cross(Ec[npts*z_idx+x_idx], np.conjugate(Hc[npts*z_idx+x_idx]) ).real
-
- Snorm_prev=S/np.linalg.norm(S)
- for n in range(0, nmax):
-
-
- x_pos = flow_x[-1]
- z_pos = flow_z[-1]
- x_idx = get_index(scale_x, x_pos)
- z_idx = get_index(scale_z, z_pos)
- S=np.cross(Ec[npts*z_idx+x_idx], np.conjugate(Hc[npts*z_idx+x_idx]) ).real
-
- Snorm=S/np.linalg.norm(S)
-
- dpos = abs(scale_z[0]-scale_z[1])/2.0
- dx = dpos*Snorm[0]
- dz = dpos*Snorm[2]
- x_pos = x_pos+dx
- z_pos = z_pos+dz
-
- flow_x.append(x_pos)
- flow_z.append(z_pos)
- return flow_x, flow_z
- WL=354
- core_r = WL/20.0
- epsilon_Ag = -2.0 + 0.28j
- index_Ag = np.sqrt(epsilon_Ag)
- nm = 1.0
- x = np.ones((1, 1), dtype = np.float64)
- x[0, 0] = 2.0*np.pi*core_r/WL
- m = np.ones((1, 1), dtype = np.complex128)
- m[0, 0] = index_Ag/nm
- print "x =", x
- print "m =", m
- npts = 281
- factor=5
- scan = np.linspace(-factor*x[0, 0], factor*x[0, 0], 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)
- Er = np.absolute(E)
- Hr = np.absolute(H)
- P=[]
- for n in range(0, len(E[0])):
- P.append(np.linalg.norm( np.cross(E[0][n], np.conjugate(H[0][n]) ).real/2 ))
- print(min(P))
- Eabs = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
- Ec = E[0, :, :]
- Hc = H[0, :, :]
- 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
- try:
- import matplotlib.pyplot as plt
- from matplotlib import cm
- from matplotlib.colors import LogNorm
-
-
- Eabs_data = np.resize(P, (npts, npts)).T
-
-
-
-
- fig, ax = plt.subplots(1,1)
-
-
- 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)
-
-
-
-
-
-
-
- cax = ax.imshow(Eabs_data, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower'
-
- , extent = (min(scale_x), max(scale_x), min(scale_z), max(scale_z))
-
- )
- ax.axis("image")
-
-
-
-
-
- plt.xlabel('Z, nm')
- plt.ylabel('X, nm')
-
- from matplotlib import patches
- 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')
- ax.add_patch(s1)
- from matplotlib.path import Path
-
- flow_total = 31
- for flow in range(0,flow_total):
- flow_x, flow_z = GetFlow(scale_x, scale_z, Ec, Hc,
- min(scale_x)+flow*(scale_x[-1]-scale_x[0])/(flow_total-1),
- min(scale_z),
- npts*6)
- verts = np.vstack((flow_z, flow_x)).transpose().tolist()
-
- codes = [Path.LINETO]*len(verts)
- codes[0] = Path.MOVETO
- path = Path(verts, codes)
- patch = patches.PathPatch(path, facecolor='none', lw=1, edgecolor='white')
- ax.add_patch(patch)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- plt.draw()
- plt.show()
- plt.clf()
- plt.close()
- finally:
- print("Qabs = "+str(Qabs));
|