fig1.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 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. import inspect
  38. print("Using scattnlay from ", inspect.getfile(scattnlay))
  39. npts = 251
  40. factor = 3. # plot extent compared to sphere radius
  41. index_H2O = 1.33+0.j
  42. WL = 0.532 #mkm
  43. total_r = 1 #mkm
  44. isMP = False
  45. # isMP = True
  46. # nmax = 230
  47. nmax = -1
  48. nm = 1.0 # host medium
  49. x = 2.0 * np.pi * np.array([total_r], dtype=np.float64) / WL
  50. m = np.array((index_H2O), dtype=np.complex128) / nm
  51. print("x =", x)
  52. print("m =", m)
  53. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  54. np.array([x]), np.array([m]))
  55. print("Qsca = " + str(Qsca)+" terms = "+str(terms))
  56. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  57. np.array([x]), np.array([m]), mp=True)
  58. print("mp Qsca = " + str(Qsca)+" terms = "+str(terms))
  59. scan = np.linspace(-factor*x[-1], factor*x[-1], npts)
  60. zero = np.zeros(npts*npts, dtype = np.float64)
  61. coordX, coordZ = np.meshgrid(scan, scan)
  62. coordX.resize(npts * npts)
  63. coordZ.resize(npts * npts)
  64. coordY = zero
  65. terms, E, H = fieldnlay(
  66. np.array([x]), np.array([m]),
  67. coordX, coordY, coordZ,
  68. mp=isMP,
  69. nmax=nmax
  70. )
  71. Ec = E[0, :, :]
  72. Er = np.absolute(Ec)
  73. Eabs2 = (Er[:, 0]**2 + Er[:, 1]**2 + Er[:, 2]**2)
  74. Eabs_data = np.resize(Eabs2, (npts, npts))
  75. label = r'$|E|^2$'
  76. pos = plt.imshow(Eabs_data,
  77. cmap='gnuplot',
  78. # cmap='jet',
  79. vmin=0., vmax=14
  80. )
  81. plt.colorbar(pos)
  82. print(np.min(Eabs_data), np.max(Eabs_data)," terms = "+str(terms))
  83. mp = ''
  84. if isMP: mp = '_mp'
  85. plt.savefig("R"+str(total_r)+"mkm"+mp+".jpg",
  86. # dpi=300
  87. )
  88. # plt.show()