fig1_polar.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2021 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. # Copyright (C) 2013-2021 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. import numpy as np
  31. import matplotlib.pyplot as plt
  32. from scattnlay import mie, mie_mp
  33. npts = 11/2
  34. # npts = 11
  35. from_theta = 0
  36. to_theta = np.pi*2
  37. outer_arc_points = int(abs(to_theta-from_theta)*npts)
  38. # outer_arc_points = 600
  39. factor = 2 # plot extent compared to sphere radius
  40. index_H2O = 1.33+(1e-6)*1j
  41. WL = 0.532 #mkm
  42. total_r = 125 #mkm
  43. isMP = False
  44. # isMP = True
  45. nm = 1.0 # host medium
  46. # x = 2.0 * np.pi * np.array([total_r/2, total_r], dtype=np.float64) / WL
  47. # m = np.array((index_H2O, index_H2O), dtype=np.complex128) / nm
  48. x = 2.0 * np.pi * np.array([total_r], dtype=np.float64) / WL
  49. m = np.array((index_H2O), dtype=np.complex128) / nm
  50. from_r = 0.01*x[-1]
  51. to_r = x[-1]*factor
  52. r_points = int(outer_arc_points/abs(to_theta-from_theta))
  53. # nmax = int(np.max(x*factor + 11 * (x*factor)**(1.0 / 3.0) + 1))
  54. nmax = -1
  55. print("x =", x)
  56. print("m =", m)
  57. mie.SetLayersSize(x)
  58. mie.SetLayersIndex(m)
  59. mie.RunMieCalculation()
  60. Qsca = mie.GetQsca()
  61. terms = mie.GetMaxTerms()
  62. print(" Qsca = " + str(Qsca)+" terms = "+str(terms))
  63. mie_mp.SetLayersSize(x)
  64. mie_mp.SetLayersIndex(m)
  65. mie_mp.RunMieCalculation()
  66. Qsca = mie_mp.GetQsca()
  67. terms = mie_mp.GetMaxTerms()
  68. print("mp Qsca = " + str(Qsca)+" terms = "+str(terms))
  69. # mie.SetFieldCoords(xp, yp, zp)
  70. # mie.RunFieldCalculation()
  71. # terms = mie.GetMaxTerms()
  72. # E = mie.GetFieldE()
  73. # H = mie.GetFieldH()
  74. theta_all = np.linspace(from_theta, to_theta, outer_arc_points);
  75. r_all = np.linspace(from_r, to_r, r_points)
  76. theta = []
  77. r = []
  78. for i in range(len(r_all)):
  79. for j in range(len(theta_all)):
  80. theta.append(theta_all[j])
  81. r.append(r_all[i])
  82. mie_mp.RunFieldCalculationPolar(outer_arc_points, r_points, from_r, to_r, from_theta, to_theta, 0, 0, True)
  83. Ec = mie_mp.GetFieldE()
  84. # mie.RunFieldCalculationPolar(outer_arc_points, r_points, from_r, to_r, from_theta, to_theta, 0, 0, True)
  85. # Ec = mie.GetFieldE()
  86. print("Field evaluation done.")
  87. Er = np.absolute(Ec)
  88. Eabs = (Er[:, 0]**2 + Er[:, 1]**2 + Er[:, 2]**2)
  89. # Eabs = np.resize(Eabs2, (outer_arc_points, r_points))
  90. print("min(Eabs)=", np.min(Eabs)," max(Eabs)=", np.max(Eabs)," terms = "+str(terms), ' size=', Eabs.size)
  91. fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
  92. vmax = 14
  93. Eabs[Eabs>vmax] = vmax
  94. pos = ax.tricontourf(theta, r, Eabs,
  95. levels=1000,
  96. cmap='gnuplot',
  97. )
  98. plt.colorbar(pos)
  99. ax.yaxis.grid(False)
  100. ax.xaxis.grid(False)
  101. # ax.plot(theta,r, 'ro', ms=0.1)
  102. mp = ''
  103. if isMP: mp = '_mp'
  104. plt.savefig("R"+str(total_r)+"mkm"+mp+"_polar.jpg",
  105. dpi=600
  106. )
  107. # plt.show()