field-Ag-flow.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #import scattnlay
  31. from scattnlay import fieldnlay
  32. from scattnlay import scattnlay
  33. from fieldplot import fieldplot
  34. import numpy as np
  35. import cmath
  36. # # a)
  37. #WL=400 #nm
  38. #core_r = WL/20.0
  39. #epsilon_Ag = -2.0 + 10.0j
  40. # # b)
  41. #WL=400 #nm
  42. #core_r = WL/20.0
  43. #epsilon_Ag = -2.0 + 1.0j
  44. # # c)
  45. # WL=354 #nm
  46. # core_r = WL/20.0
  47. # epsilon_Ag = -2.0 + 0.28j
  48. # d)
  49. #WL=367 #nm
  50. #core_r = WL/20.0
  51. #epsilon_Ag = -2.71 + 0.25j
  52. WL=500 #nm
  53. core_r = 50.0
  54. epsilon_Ag = 4.0
  55. index_Ag = np.sqrt(epsilon_Ag)
  56. # n1 = 1.53413
  57. # n2 = 0.565838 + 7.23262j
  58. nm = 1.0
  59. x = np.ones((2), dtype = np.float64)
  60. x[0] = 2.0*np.pi*core_r/WL/4.0*3.0
  61. x[1] = 2.0*np.pi*core_r/WL
  62. m = np.ones((2), dtype = np.complex128)
  63. m[0] = index_Ag/nm
  64. m[1] = index_Ag/nm
  65. print( "x =", x)
  66. print( "m =", m)
  67. comment='bulk-Ag-flow'
  68. WL_units='nm'
  69. npts = 151
  70. factor=2.1
  71. flow_total = 9
  72. #flow_total = 21
  73. #flow_total = 0
  74. #crossplane='XZ'
  75. #crossplane='YZ'
  76. crossplane='XY'
  77. # Options to plot: Eabs, Habs, Pabs, angleEx, angleHy
  78. field_to_plot='Eabs'
  79. #field_to_plot='angleEx'
  80. import matplotlib.pyplot as plt
  81. fig, axs = plt.subplots(1,1)#, sharey=True, sharex=True)
  82. fig.tight_layout()
  83. fieldplot(fig, axs, x,m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total,
  84. subplot_label=' ',is_flow_extend=False)
  85. #fieldplot(x,m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total, is_flow_extend=False)
  86. # for ax in axs:
  87. # ax.locator_params(axis='x',nbins=5)
  88. # ax.locator_params(axis='y',nbins=5)
  89. fig.subplots_adjust(hspace=0.3, wspace=-0.1)
  90. plt.savefig(comment+"-R"+str(int(round(x[-1]*WL/2.0/np.pi)))+"-"+crossplane+"-"
  91. +field_to_plot+".pdf",pad_inches=0.02, bbox_inches='tight')
  92. plt.draw()
  93. # plt.show()
  94. plt.clf()
  95. plt.close()