fig1_polar.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 = 151/2
  34. npts = 51/2
  35. factor = 3 # plot extent compared to sphere radius
  36. # total_r = 0.055/2/np.pi # mkm
  37. total_r = 1
  38. isMP = False
  39. # isMP = True
  40. # terms_in = 210
  41. terms_in = -1
  42. from_theta = 0
  43. to_theta = np.pi*2
  44. outer_arc_points = int(abs(to_theta-from_theta)*npts)
  45. # outer_arc_points = 600
  46. index_H2O = 1.33+(1e-6)*1j
  47. # index_H2O = 1.001
  48. # WL = 0.532 #mkm
  49. WL = 1 #mkm
  50. mp = ''
  51. if isMP: mp = '_mp'
  52. nm = 1.0 # host medium
  53. # x = 2.0 * np.pi * np.array([total_r/2, total_r], dtype=np.float64) / WL
  54. # m = np.array((index_H2O, index_H2O), dtype=np.complex128) / nm
  55. #
  56. x = 2.0 * np.pi * np.array([total_r], dtype=np.float64) / WL
  57. m = np.array((index_H2O), dtype=np.complex128) / nm
  58. # x = 2.0 * np.pi * np.array([total_r], dtype=np.float64) / 1
  59. # m = np.array((1.5+1j), dtype=np.complex128) / nm
  60. from_r = x[-1]*0.001
  61. to_r = x[-1]*factor
  62. r_points = int(outer_arc_points/abs(to_theta-from_theta))
  63. # nmax = int(np.max(x*factor + 11 * (x*factor)**(1.0 / 3.0) + 1))
  64. nmax = -1
  65. print("x =", x)
  66. print("m =", m)
  67. mie.SetLayersSize(x)
  68. mie.SetLayersIndex(m)
  69. mie.RunMieCalculation()
  70. Qsca = mie.GetQsca()
  71. terms = mie.GetMaxTerms()
  72. print(" Qsca = " + str(Qsca)+" terms = "+str(terms))
  73. mie_mp.SetLayersSize(x)
  74. mie_mp.SetLayersIndex(m)
  75. mie_mp.RunMieCalculation()
  76. Qsca = mie_mp.GetQsca()
  77. terms = mie_mp.GetMaxTerms()
  78. print("mp Qsca = " + str(Qsca)+" terms = "+str(terms))
  79. # exit(1)
  80. # mie.SetFieldCoords(xp, yp, zp)
  81. # mie.RunFieldCalculation()
  82. # terms = mie.GetMaxTerms()
  83. # E = mie.GetFieldE()
  84. # H = mie.GetFieldH()
  85. theta_all = np.linspace(from_theta, to_theta, outer_arc_points);
  86. r_all = np.linspace(from_r, to_r, r_points)
  87. theta = []
  88. r = []
  89. for i in range(len(r_all)):
  90. for j in range(len(theta_all)):
  91. theta.append(theta_all[j])
  92. r.append(r_all[i])
  93. if isMP:
  94. mie_mp.RunFieldCalculationPolar(4, 3, x[-1], x[-1]*3, 0, np.pi, 0, 0, False, terms_in)
  95. mie_mp.RunFieldCalculationPolar(outer_arc_points, r_points, from_r, to_r, from_theta, to_theta, 0, 0, False, terms_in)
  96. Eabs = (mie_mp.GetFieldEabs())**2
  97. terms = mie_mp.GetMaxTerms()
  98. else:
  99. # mie.RunFieldCalculationPolar(4, 3, x[-1], x[-1]*3, 0, np.pi, 0, 0, True, -1)
  100. # Eabs = (mie.GetFieldEabs())**2
  101. # print(Eabs)
  102. # exit(1)
  103. mie.RunFieldCalculationPolar(outer_arc_points, r_points, from_r, to_r, from_theta, to_theta, 0, 0, False, terms_in)
  104. Eabs = (mie.GetFieldEabs())**2
  105. terms = mie.GetMaxTerms()
  106. print(mp, "min(Eabs)=", np.min(Eabs)," max(Eabs)=", np.max(Eabs)," terms = "+str(terms), ' size=', Eabs.size)
  107. fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
  108. vmax = 14
  109. Eabs[Eabs>vmax] = vmax
  110. pos = ax.tricontourf(theta, r, Eabs,
  111. levels=1000,
  112. cmap='gnuplot',
  113. )
  114. plt.colorbar(pos)
  115. ax.yaxis.grid(False)
  116. ax.xaxis.grid(False)
  117. # ax.plot(theta,r, 'ro', ms=0.1)
  118. plt.savefig("R"+str(total_r)+"mkm"+mp+"_polar.jpg",
  119. dpi=600
  120. )
  121. # plt.show()