fig1.py 3.4 KB

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