lfield-SiAgSi.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.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. # This test case calculates the electric field in the
  28. # E-k plane, for an spherical Si-Ag-Si nanoparticle. Core radius is 17.74 nm,
  29. # inner layer 23.31nm, outer layer 22.95nm. Working wavelength is 800nm, we use
  30. # silicon epsilon=13.64+i0.047, silver epsilon= -28.05+i1.525
  31. import scattnlay
  32. from scattnlay import fieldnlay
  33. import numpy as np
  34. # epsilon_Si = 13.64 + 0.047j
  35. # epsilon_Ag = -28.05 + 1.525j
  36. epsilon_Si = 2.0 + 0.047j
  37. epsilon_Ag = -2.0 + 1.525j
  38. index_Si = np.sqrt(epsilon_Si)
  39. index_Ag = np.sqrt(epsilon_Ag)
  40. # Values for 800 nm, taken from http://refractiveindex.info/
  41. index_Si = 3.69410 + 0.0065435j
  42. index_Ag = 0.18599 + 4.9886j
  43. WL=800 #nm
  44. core_width = 17.74 #nm Si
  45. inner_width = 23.31 #nm Ag
  46. outer_width = 22.95 #nm Si
  47. core_r = core_width
  48. inner_r = core_r+inner_width
  49. outer_r = inner_r+outer_width
  50. # n1 = 1.53413
  51. # n2 = 0.565838 + 7.23262j
  52. nm = 1.0
  53. x = np.ones((1, 3), dtype = np.float64)
  54. x[0, 0] = 2.0*np.pi*core_r/WL
  55. x[0, 1] = 2.0*np.pi*inner_r/WL
  56. x[0, 2] = 2.0*np.pi*outer_r/WL
  57. m = np.ones((1, 3), dtype = np.complex128)
  58. m[0, 0] = index_Si/nm
  59. m[0, 1] = index_Si/nm
  60. m[0, 2] = index_Ag/nm
  61. print "x =", x
  62. print "m =", m
  63. npts = 1001
  64. scan = np.linspace(-4.0*x[0, 2], 4.0*x[0, 2], npts)
  65. coord = np.zeros((npts, 3), dtype = np.float64)
  66. coord[:, 0] = scan
  67. terms, E, H = fieldnlay(x, m, coord)
  68. Er = np.absolute(E)
  69. # |E|/|Eo|
  70. Eh = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
  71. result = np.vstack((scan, Eh)).transpose()
  72. try:
  73. import matplotlib.pyplot as plt
  74. fig = plt.figure()
  75. ax = fig.add_subplot(111)
  76. ax.errorbar(result[:, 0], result[:, 1], fmt = 'r', label = 'X axis')
  77. ax.legend()
  78. plt.xlabel('X')
  79. plt.ylabel('|E|/|Eo|')
  80. plt.draw()
  81. plt.show()
  82. finally:
  83. np.savetxt("lfield.txt", result, fmt = "%.5f")
  84. print result