calc-multipole-spectra.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2019-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. import sys
  28. sys.path.insert(0,'..') # to be able to import scattnlay from the upper dir
  29. from scattnlay import scattnlay,scattcoeffs,fieldnlay, mie
  30. import matplotlib.pyplot as plt
  31. import numpy as np
  32. import cmath
  33. from_WL = 300
  34. to_WL = 1000
  35. WL_points= 1000
  36. WLs = np.linspace(from_WL, to_WL, WL_points)
  37. index_NP = 4+0.01j
  38. x = np.ones((1), dtype = np.float64)
  39. m = np.ones((1), dtype = np.complex128)
  40. core_r = 100
  41. Qsca_vec = []
  42. Qsca_mode_vec = []
  43. for WL in WLs:
  44. x[0] = 2.0*np.pi*core_r/WL
  45. m[0] = index_NP
  46. mie.SetLayersSize(x)
  47. mie.SetLayersIndex(m)
  48. mie.SetModeNmaxAndType(-1,-1)
  49. mie.RunMieCalculation()
  50. Qsca = mie.GetQsca()
  51. mie.SetModeNmaxAndType(1,0)
  52. mie.RunMieCalculation()
  53. Qsca_mode = mie.GetQsca()
  54. print(np.array([Qsca]))
  55. Qsca_vec.append(Qsca)
  56. Qsca_mode_vec.append(Qsca_mode)
  57. fig, axs2 = plt.subplots(1,1)#, sharey=True, sharex=True)
  58. axs2.plot(WLs, Qsca_vec, color="blue")
  59. axs2.plot(WLs, Qsca_mode_vec, color="red")
  60. plt.savefig("spectra.pdf",pad_inches=0.02, bbox_inches='tight')
  61. plt.show()
  62. plt.clf()
  63. plt.close()