field-Ag-flow.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. # Copyright (C) 2013-2015 Konstantin Ladutenko <kostyfisik@gmail.com>
  6. #
  7. # This file is part of python-scattnlay
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # The only additional remark is that we expect that all publications
  20. # describing work using this software, or all commercial products
  21. # using it, cite the following reference:
  22. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  23. # a multilayered sphere," Computer Physics Communications,
  24. # vol. 180, Nov. 2009, pp. 2348-2354.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. # This test case calculates the electric field in the
  29. # E-k plane, for an spherical Ag nanoparticle.
  30. from scattnlay import fieldnlay, scattnlay
  31. from fieldplot import fieldplot
  32. import numpy as np
  33. import cmath
  34. # # a)
  35. # WL=400 #nm
  36. # core_r = WL/20.0
  37. # epsilon_Ag = -2.0 + 10.0j
  38. # # b)
  39. # WL=400 #nm
  40. # core_r = WL/20.0
  41. # epsilon_Ag = -2.0 + 1.0j
  42. # c)
  43. WL = 354 # nm
  44. core_r = WL / 20.0
  45. epsilon_Ag = -2.0 + 0.28j
  46. # d)
  47. # WL=367 #nm
  48. # core_r = WL/20.0
  49. # epsilon_Ag = -2.71 + 0.25j
  50. # WL=500 #nm
  51. # core_r = 615.0
  52. # epsilon_Ag = 4.0
  53. index_Ag = np.sqrt(epsilon_Ag)
  54. # n1 = 1.53413
  55. # n2 = 0.565838 + 7.23262j
  56. nm = 1.0
  57. x = 2.0 * np.pi * np.array([core_r / 4.0 * 3.0, core_r], dtype=np.float64) / WL
  58. m = np.array((index_Ag, index_Ag), dtype=np.complex128) / nm
  59. print("x =", x)
  60. print("m =", m)
  61. comment = 'bulk-WL' + str(WL) + 'nm_r' + str(core_r) + 'nm_epsilon' + str(epsilon_Ag) + '-flow'
  62. WL_units = 'nm'
  63. npts = 251
  64. factor = 2.1
  65. flow_total = 41
  66. # flow_total = 21
  67. # flow_total = 0
  68. crossplane = 'XZ'
  69. # crossplane='YZ'
  70. # crossplane='XY'
  71. # Options to plot: Eabs, Habs, Pabs, angleEx, angleHy
  72. field_to_plot = 'Pabs'
  73. # field_to_plot='angleEx'
  74. import matplotlib.pyplot as plt
  75. fig, axs = plt.subplots(1, 1) # , sharey=True, sharex=True)
  76. fig.tight_layout()
  77. fieldplot(fig, axs, x, m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor,
  78. flow_total, density=50.0, maxlength=40.0, arrowstyle='-',
  79. subplot_label=' ', draw_shell=True)
  80. # fieldplot(x,m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total, is_flow_extend=False)
  81. # for ax in axs:
  82. # ax.locator_params(axis='x',nbins=5)
  83. # ax.locator_params(axis='y',nbins=5)
  84. fig.subplots_adjust(hspace=0.3, wspace=-0.1)
  85. plt.savefig(comment + "-R" + str(int(round(x[-1] * WL / 2.0 / np.pi))) + "-" + crossplane + "-"
  86. + field_to_plot + ".pdf", pad_inches=0.02, bbox_inches='tight')
  87. plt.draw()
  88. # plt.show()
  89. plt.clf()
  90. plt.close()