TiO2-comsol-compare.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2021 Konstantin Ladutenko <kostyfisik@gmail.com>
  5. #
  6. # This file is part of python-scattnlay
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # The only additional remark is that we expect that all publications
  19. # describing work using this software, or all commercial products
  20. # using it, cite the following reference:
  21. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. from scattnlay import mie
  28. import matplotlib.pyplot as plt
  29. import numpy as np
  30. from optical_constants import read_refractive_index_from_yaml as get_index
  31. def gauss(x, mu, sigma):
  32. return 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (x - mu)**2 / (2 * sigma**2))
  33. from_WL = 300
  34. to_WL = 1100
  35. WL_points= 100
  36. WLs = np.linspace(from_WL, to_WL, WL_points)
  37. from_r = 40/2.
  38. to_r =80/2.
  39. r_points = 20
  40. all_r = np.linspace(from_r, to_r, r_points)
  41. r_mean = 58.3/2.
  42. # r_mean = 50/2.
  43. r_std = 6.3/2.
  44. r_weights = gauss(all_r, r_mean,r_std)/len(all_r)
  45. plt.plot(all_r, r_weights )
  46. plt.xlabel("R, nm")
  47. plt.ylabel("amount")
  48. index_SiO2 = get_index("refractiveindex_info/SiO2-Gao.yml", WLs, units='nm')
  49. # index_Au = get_index("refractiveindex_info/Au-McPeak.yml", WLs, units='nm')
  50. index_Au = get_index("refractiveindex_info/Au-Johnson.yml", WLs, units='nm')
  51. index_TiO2 = get_index("r"
  52. "efractiveindex_info/TiO2-Sarkar.yml", WLs, units='nm')
  53. index_SiO2 *= 0; index_SiO2 += 1.45
  54. index_TiO2[:,1] += 0.0j
  55. # index_Au[:,1] += 1.5j
  56. x = np.ones((3), dtype = np.float64)
  57. m = np.ones((3), dtype = np.complex128)
  58. core_r = 5
  59. inner_shell_h = 10+20
  60. outer_shell_h = 10
  61. host_media = 1.33
  62. Qext_core_shell = np.zeros(len(WLs))
  63. Qext_3l = np.zeros(len(WLs))
  64. for i in range(len(WLs)):
  65. WL = WLs[i]
  66. for j in range(len(all_r)):
  67. # core_r = all_r[j]
  68. # weight = r_weights[j]
  69. weight = 1/len(r_weights)
  70. # print(core_r)
  71. x = host_media*2.0*np.pi/WL*np.array([core_r,
  72. core_r+inner_shell_h,
  73. core_r+inner_shell_h+outer_shell_h])
  74. m = np.array([index_SiO2[i][1], index_Au[i][1],
  75. index_TiO2[i][1]]
  76. )/host_media
  77. # print(x, m)
  78. mie.SetLayersSize(x)
  79. mie.SetLayersIndex(m)
  80. mie.RunMieCalculation()
  81. Qext_3l[i] += mie.GetQext()*weight
  82. x = host_media*2.0*np.pi/WL*np.array([core_r,
  83. core_r+inner_shell_h])
  84. m = np.array([index_SiO2[i][1], index_Au[i][1]])/host_media
  85. mie.SetLayersSize(x)
  86. mie.SetLayersIndex(m)
  87. mie.RunMieCalculation()
  88. Qext_core_shell[i] += mie.GetQext()*weight
  89. comsol_spectra = np.array([[0.420000000000000,2.35836000000000e-15],
  90. [0.440000000000000,2.27000000000000e-15],
  91. [0.460000000000000,2.21146900000000e-15],
  92. [0.480000000000000,2.21744500000000e-15],
  93. [0.500000000000000,2.49989500000000e-15],
  94. [0.520000000000000,3.36257000000000e-15],
  95. [0.540000000000000,3.88983000000000e-15],
  96. [0.560000000000000,4.03982000000000e-15],
  97. [0.580000000000000,3.23889000000000e-15],
  98. [0.600000000000000,3.01499000000000e-15],
  99. [0.620000000000000,2.13147000000000e-15],
  100. [0.640000000000000,9.02930000000000e-16],
  101. [0.660000000000000,4.49688000000000e-16],
  102. [0.680000000000000,2.93514000000000e-16],
  103. [0.700000000000000,2.19381000000000e-16],
  104. [0.720000000000000,1.85272000000000e-16],
  105. [0.740000000000000,1.74517000000000e-16],
  106. [0.760000000000000,1.54702000000000e-16],
  107. [0.780000000000000,1.51191000000000e-16],
  108. [0.800000000000000,1.58785200000000e-16],
  109. [0.820000000000000,1.74967600000000e-16 ] ])
  110. fig, axs2 = plt.subplots(1,1)#, sharey=True, sharex=True)
  111. # axs2.plot(WLs, Qext_3l, color="purple")
  112. axs2.plot(WLs, Qext_core_shell, color="lime", label="Mie, layered")
  113. axs2.plot(comsol_spectra[:,0]*1000, comsol_spectra[:,1]/np.pi/(35e-9**2)*3, color="black", label="Comsol, \nSiO2 with Au NP coating")
  114. axs2.legend()
  115. axs2.set_xlabel("WL, nm")
  116. axs2.set_ylabel("Extinction, a.u.")
  117. # axs2 = axs.twinx()
  118. # axs2.plot(np.array(core_r_vec)*2,an_vec[:,0],"b.",lw=0.8, markersize=1.9,label="$a_0$")
  119. # axs2.plot(np.array(core_r_vec)*2,bn_vec[:,0],"b-", markersize=1.9,label="$b_0$")
  120. # axs2.plot(np.array(core_r_vec)*2,an_vec[:,1],"g.",lw=0.8, markersize=1.9,label="$a_1$")
  121. # axs2.plot(np.array(core_r_vec)*2,bn_vec[:,1],"g-", markersize=1.9,label="$b_1$")
  122. # axs2.legend(loc="upper right")
  123. # axs2.tick_params('y', colors='black')
  124. # axs2.set_ylim(0,1)
  125. # axs2.set_ylabel("Mie",color="black")
  126. plt.savefig("spectra.pdf",pad_inches=0.02, bbox_inches='tight')
  127. plt.show()
  128. plt.clf()
  129. plt.close()