plasmon-modal-efficiency.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import os
  6. c = 299792458.0
  7. eps_0 = 8.854187817e-12 # F/m
  8. pi = np.pi
  9. verbose = 6
  10. # r of monitor
  11. r = 146.513e-9
  12. debug = True
  13. def read_data(dirname):
  14. data = {}
  15. WLs = []
  16. for r,d,f in os.walk(dirname):
  17. for fname in f:
  18. WLs.append(fname)
  19. for fname in WLs:
  20. fdata = np.transpose(
  21. np.genfromtxt(dirname+"/"+fname, delimiter=", ",skip_header=1
  22. ,dtype=None, encoding = None
  23. , converters={0: lambda s: complex(s),
  24. 1: lambda s: complex(s),
  25. 2: lambda s: complex(s.replace('i', 'j')),
  26. 3: lambda s: complex(s.replace('i', 'j')),
  27. 4: lambda s: complex(s.replace('i', 'j')),
  28. 5: lambda s: complex(s.replace('i', 'j')),
  29. 6: lambda s: complex(s.replace('i', 'j')),
  30. 7: lambda s: complex(s.replace('i', 'j')),
  31. 8: lambda s: complex(s.replace('i', 'j'))
  32. }
  33. )
  34. )
  35. data[float(fname[2:-4])]=fdata
  36. if debug: break
  37. return data
  38. def find_nearest(array,value):
  39. idx = (np.abs(array-value)).argmin()
  40. return array[idx],idx
  41. def get_WLs_idx(WLs, data):
  42. dist = 1 #mkm
  43. mmedia = 1 # vacuum
  44. shift = 1 # one mesh step
  45. WLs_idx = []
  46. for wl in WLs:
  47. val, idx = find_nearest(data[dist][mmedia][shift][0,:],wl*1e-9)
  48. WLs_idx.append(idx)
  49. return WLs_idx
  50. # def check_field_match(data_in_air, data_in_gold,wl_idx,z_vec,kappa1,kappa2,eps2):
  51. # z = z_vec[i]*1e-9
  52. # if verbose > 8: print("z =",z)
  53. # H1_0 = H1[i]/np.exp(-kappa1[wl_idx]*z)
  54. # H2_0 = H2[i]/np.exp(-kappa2[wl_idx]*z)
  55. # E1_0 = E1[i]/np.exp(-kappa1[wl_idx]*z)
  56. # E2_0 = E2[i]/np.exp(-kappa2[wl_idx]*z)
  57. # E2_0e = E2[i]/np.exp(-kappa2[wl_idx]*z)*eps2[wl_idx]
  58. # if verbose > 8:
  59. # print("H0 air (%5.4g %+5.4gj)"%(np.real(H1_0), np.imag(H1_0)),
  60. # " from H1 (%5.4g %+5.4gj)"%(np.real(H1[i]), np.imag(H1[i])))
  61. def analyze(data,wl):
  62. # print(data[0,:]) # all z values
  63. #data = "z, dip.power, Ex, Ey, Ez, Hx, Hy, Hz, n_Au"
  64. # 0, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 "
  65. lambd = wl
  66. omega = 2*pi*c/lambd
  67. eps_d = complex(1) # air, z>0
  68. eps_m = data[8,0]**2 # metal, z<0
  69. dip_power = data[1,0]
  70. z = data[0,:]
  71. idx_d = np.nonzero(z>1e-10)
  72. idx_0 = np.nonzero(np.logical_and(z<=1e-10, z>=-1e-10))
  73. idx_m = np.nonzero(z<-1e-10)
  74. z_d = z[idx_d]
  75. z_0 = z[idx_0]
  76. z_m = z[idx_m]
  77. if (not np.array_equal(np.hstack((z_m, z_0, z_d)), z)):
  78. print("ERROR! loosing z values!")
  79. raise
  80. Ex = data[2,:]
  81. Ex_m = data[2,idx_m][0]
  82. Ey_m = data[3,idx_m][0]
  83. Ez_m = data[4,idx_m][0]
  84. Hx_m = data[5,idx_m][0]
  85. Hy_m = data[6,idx_m][0]
  86. Hz_m = data[7,idx_m][0]
  87. E_m = np.array([Ex_m,Ey_m,Ez_m])
  88. H_m = np.array([Hx_m,Hy_m,Hz_m])
  89. Ex_d = data[2,idx_d][0]
  90. Ey_d = data[3,idx_d][0]
  91. Ez_d = data[4,idx_d][0]
  92. Hx_d = data[5,idx_d][0]
  93. Hy_d = data[6,idx_d][0]
  94. Hz_d = data[7,idx_d][0]
  95. E_d = np.array([Ex_d,Ey_d,Ez_d])
  96. H_d = np.array([Hx_d,Hy_d,Hz_d])
  97. k_0 = omega/c #air
  98. k_sp = k_0*np.sqrt(eps_d*eps_m/(eps_d+eps_m)) # eq5, supmat
  99. chi_d = np.sqrt( eps_d*k_0**2 - k_sp**2 ) # desc. after eq6c, supmat
  100. chi_m = np.sqrt( eps_m*k_0**2 - k_sp**2 ) # desc. after eq6c, supmat
  101. h_sp_d = np.exp(1j*chi_d*z_d) # eq6a, supmat
  102. e_sp_x_d = chi_d/(omega*eps_0*eps_d)*np.exp(1j*chi_d*z_d) # eq6b, supmat
  103. e_sp_z_d = k_sp/(omega*eps_0*eps_d)*np.exp(1j*chi_d*z_d) # eq6c, supmat
  104. h_sp_m = np.exp(1j*-chi_m*z_m) # eq6a, supmat
  105. e_sp_x_m = -chi_m/(omega*eps_0*eps_m)*np.exp(1j*-chi_m*z_m) # eq6b, supmat
  106. e_sp_z_m = k_sp/(omega*eps_0*eps_m)*np.exp(1j*-chi_m*z_m) # eq6c, supmat
  107. if verbose > 5:
  108. print("r =",r)
  109. # print("S from full field",np.real(np.cross(E,np.conj(H))))
  110. # print("H0 air (%5.4g %+5.4gj)"%(np.real(H1_0[wl_idx]), np.imag(H1_0[wl_idx])),
  111. # " from H1 (%5.4g %+5.4gj)"%(np.real(H1[0][wl_idx]), np.imag(H1[0][wl_idx])))
  112. # #plasmon_power = 1.0/2.0 * np.real( E1[0] * np.conj(H1[0])) # TODO check minus sign!!
  113. # plasmon_power = -1.0/2.0 * 2.0*np.pi*R * ( # TODO check minus sign!!
  114. # np.real( E1_0 * np.conj(H1_0) )
  115. # / (2.0 * np.real(kappa1))
  116. # +
  117. # np.real( E2_0 * np.conj(H1_0) )
  118. # / (2.0 * np.real(kappa2))
  119. # )* np.exp( 2.0*np.imag(k_spp)*R ) # TODO check minus sign!!
  120. # #print(np.abs(plasmon_power/ dip_power))
  121. # eta0 = plasmon_power[0]/ dip_power[0] *100
  122. # ppw = plasmon_power[0]
  123. # print("\n")
  124. # print(dirname)
  125. # print("Power: plasmon %4.3g W of dipoles %4.3g W, efficiency %5.3g%% from:"%(ppw, float(np.abs(dip_power[0])),float(np.abs( eta0))), ppw, eta0)
  126. # plt.plot(lambd*1e9, plasmon_power/ dip_power)
  127. # plt.ylim(0,0.04)
  128. # plt.xlim(550,800)
  129. # #plt.plot(lambd*1e9, np.real(eps2))
  130. # # plt.plot(lambd*1e9, np.real(k_spp))
  131. # # plt.plot(lambd*1e9, k_0)
  132. # #plt.semilogy(lambd*1e9, np.absolute(plasmon_power/ dip_power))
  133. # # # legend = []
  134. # # # legend.append(zshift[shift]+"@"+str(WLs[i])+" nm")
  135. # # # plt.legend(legend)
  136. # # # #plt.xlabel(r'THz')
  137. # plt.xlabel(r'$\lambda$, nm')
  138. # plt.ylabel(r'$P_{spp}/P_{dipole}$',labelpad=-5)
  139. # #plt.title(' R = '+str(core_r)+' nm')
  140. # plt.savefig(dirname+"_power_ratio."+file_ext)
  141. # plt.clf()
  142. # plt.close()
  143. file_ext="pdf"
  144. dirname="bigourdan-Au-sub-Cyl-dipole-W.fsp.1D.monitor_1.results"
  145. def main ():
  146. data = read_data(dirname)
  147. for wl in data:
  148. analyze(data[wl],wl)
  149. main()