fig1.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  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 at least one of the following references:
  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. # [2] K. Ladutenko, U. Pal, A. Rivera, and O. Pena-Rodriguez, "Mie
  26. # calculation of electromagnetic near-field for a multilayered
  27. # sphere," Computer Physics Communications, vol. 214, May 2017,
  28. # pp. 225-230.
  29. #
  30. # You should have received a copy of the GNU General Public License
  31. # along with this program. If not, see <http:#www.gnu.org/licenses/>.
  32. import scattnlay
  33. from scattnlay import fieldnlay
  34. from scattnlay import scattnlay
  35. import numpy as np
  36. from matplotlib import pyplot as plt
  37. npts = 151
  38. factor = 3. # plot extent compared to sphere radius
  39. index_H2O = 1.33+0.j
  40. WL = 0.532 #mkm
  41. total_r = 3 #mkm
  42. nm = 1.0 # host medium
  43. x = 2.0 * np.pi * np.array([total_r / 4.0 * 3.0, total_r], dtype=np.float64) / WL
  44. m = np.array((index_H2O, index_H2O), dtype=np.complex128) / nm
  45. print("x =", x)
  46. print("m =", m)
  47. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  48. np.array([x]), np.array([m]))
  49. print("Qsca = " + str(Qsca))
  50. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  51. np.array([x]), np.array([m]), mp=True)
  52. print("mp Qsca = " + str(Qsca))
  53. scan = np.linspace(-factor*x[-1], factor*x[-1], npts)
  54. zero = np.zeros(npts*npts, dtype = np.float64)
  55. coordX, coordZ = np.meshgrid(scan, scan)
  56. coordX.resize(npts * npts)
  57. coordZ.resize(npts * npts)
  58. coordY = zero
  59. terms, E, H = fieldnlay(
  60. np.array([x]), np.array([m]),
  61. coordX, coordY, coordZ,
  62. mp=True
  63. )
  64. Ec = E[0, :, :]
  65. Er = np.absolute(Ec)
  66. Eabs2 = (Er[:, 0]**2 + Er[:, 1]**2 + Er[:, 2]**2)
  67. Eabs_data = np.resize(Eabs2, (npts, npts))
  68. label = r'$|E|^2$'
  69. plt.imshow(Eabs_data,
  70. cmap='jet',
  71. vmin=0., vmax=14
  72. )
  73. print(np.min(Eabs_data), np.max(Eabs_data))
  74. plt.savefig("R"+str(total_r)+"mkm_mp.jpg")
  75. # plt.show()