efficiency-plasmon-plot.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. c = 299792458
  6. pi = np.pi
  7. def read_data(dirname, distance, zshift):
  8. media = [1,2] # 1 - positive zshift, 2 - negative (need to add a minus sign for real shift).
  9. #min_mesh_step = 2.5 #nm
  10. data = []
  11. data.append([])
  12. for x in distance:
  13. data.append([])
  14. data[x].append([])
  15. for m in media:
  16. data[x].append([])
  17. for z in zshift:
  18. monitor_name = "mon_x"+str(x)+"mkm_media"+str(m)+"_zshift"+z+"nm"
  19. data[x][m].append(
  20. np.transpose(
  21. np.genfromtxt(dirname+"/"+monitor_name+".txt", 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. )
  36. return data
  37. def find_nearest(array,value):
  38. idx = (np.abs(array-value)).argmin()
  39. return array[idx],idx
  40. def get_WLs_idx(WLs, data):
  41. dist = 1 #mkm
  42. mmedia = 1 # vacuum
  43. shift = 1 # one mesh step
  44. WLs_idx = []
  45. for wl in WLs:
  46. val, idx = find_nearest(data[dist][mmedia][shift][0,:],wl*1e-9)
  47. WLs_idx.append(idx)
  48. return WLs_idx
  49. def analyze(data, dist, z_vec, wl_idx):
  50. #data = [dist][mmedia][shift] "lambda, dip.power, Ex, Ey, Ez, Hx, Hy, Hz, n_Au"
  51. # 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 "
  52. data_in_air = np.array(data[dist][1])
  53. data_in_gold = np.array(data[dist][2])
  54. lambd = data_in_air[0][0,:]
  55. omega = 2*pi*c/lambd
  56. eps1 = complex(1)
  57. n_Au = data_in_air[0][8,:]
  58. eps2 = n_Au**2
  59. k_0 = omega/c #air
  60. k_spp = k_0*np.sqrt(eps1*eps2/(eps1+eps2))
  61. kappa1= np.sqrt(k_spp**2 - eps1*k_0**2)
  62. kappa2= np.sqrt(k_spp**2 - eps2*k_0**2)
  63. # TODO def check_field_match():
  64. H1 = data_in_air[:,6,wl_idx]
  65. H2 = data_in_gold[:,6,wl_idx]
  66. E1 = data_in_air[:,4,wl_idx]
  67. E2 = data_in_gold[:,4,wl_idx]
  68. for i in range(len(z_vec)):
  69. z = z_vec[i]*1e-9
  70. print("z =",z)
  71. H1_0 = H1[i]/np.exp(-kappa1[wl_idx]*z)
  72. H2_0 = H2[i]/np.exp(-kappa2[wl_idx]*z)
  73. E1_0 = E1[i]/np.exp(-kappa1[wl_idx]*z)
  74. E2_0 = E2[i]/np.exp(-kappa2[wl_idx]*z)*eps2[wl_idx]
  75. print("H0 air (%5.4g %+5.4gj)"%(np.real(H1_0), np.imag(H1_0)),
  76. " from H1 (%5.4g %+5.4gj)"%(np.real(H1[i]), np.imag(H1[i])))
  77. print("H0 gold (%5.4g %+5.4gj)"%(np.real(H2_0), np.imag(H2_0)),
  78. " from H2 (%5.4g %+5.4gj)"%(np.real(H2[i]), np.imag(H2[i])))
  79. print("E0 air (%5.4g %+5.4gj)"%(np.real(E1_0), np.imag(E1_0)),
  80. " from E1 (%5.4g %+5.4gj)"%(np.real(E1[i]), np.imag(E1[i])))
  81. print("E0*eps2 (%5.4g %+5.4gj)"%(np.real(E2_0), np.imag(E2_0)),
  82. " from E2 (%5.4g %+5.4gj)"%(np.real(E2[i]), np.imag(E2[i])))
  83. # H1_0 = H1/np.exp(-kappa1*
  84. # print(H1[0], H2[0],H1[0]- H2[0])
  85. # pl_data = (np.absolute(data_gold[:,2,wl_idx]*np.sqrt(dist)))
  86. # plt.semilogy(z_vec, pl_data,marker="o")
  87. # # legend = []
  88. # # legend.append(zshift[shift]+"@"+str(WLs[i])+" nm")
  89. # # plt.legend(legend)
  90. # # #plt.xlabel(r'THz')
  91. # plt.xlabel(r'Z shift, nm')
  92. # plt.ylabel(r'$Abs(E_x) \sqrt{R}$',labelpad=-5)
  93. # # plt.title(' r = '+str(core_r))
  94. # plt.savefig(dirname+"_z."+file_ext)
  95. # plt.clf()
  96. # plt.close()
  97. file_ext="png"
  98. dirname="template-dipole-on-sphere-on-surf-z.fsp.results"
  99. def main ():
  100. distance = [1,2,3,4,5,6,7,8,9,10]
  101. zshift = ["5","20","200","400","600"]
  102. z_vec = [int(val) for val in zshift]
  103. data = read_data(dirname, distance, zshift)
  104. #WLs=[300,350,400,450,600,700,800]
  105. #WLs=[600,700, 800, 450]
  106. WLs=[600]#, 450]
  107. WLs_idx = get_WLs_idx(WLs, data)
  108. dist = 10 #mkm
  109. wl_idx = WLs_idx[0]
  110. analyze(data, dist, z_vec, wl_idx)
  111. # legend = []
  112. # for shift in range(len(zshift)):
  113. # for i in range(len(WLs)):
  114. # pl_data = []
  115. # idx = WLs_idx[i]
  116. # legend.append(zshift[shift]+"@"+str(WLs[i])+" nm")
  117. # for dist in distance:
  118. # pl_data.append(np.absolute(data[dist][mmedia][shift][2,idx]*np.sqrt(dist)))
  119. # print(len(pl_data))
  120. # plt.semilogy(distance, pl_data,marker="o")
  121. # plt.legend(legend)
  122. # # #plt.xlabel(r'THz')
  123. # plt.xlabel(r'Monitor R, $\mu$m')
  124. # plt.ylabel(r'$Abs(E_x) \sqrt{R}$',labelpad=-5)
  125. # # plt.title(' r = '+str(core_r))
  126. # plt.savefig(dirname+"_WLs."+file_ext)
  127. # plt.clf()
  128. # plt.close()
  129. main()