scattPEC.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2017 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. #
  6. # This file is part of python-scattnlay
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # The only additional remark is that we expect that all publications
  19. # describing work using this software, or all commercial products
  20. # using it, cite at least one of the following references:
  21. # [1] O. Peña and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. # [2] K. Ladutenko, U. Pal, A. Rivera, and O. Peña-Rodríguez, "Mie
  25. # calculation of electromagnetic near-field for a multilayered
  26. # sphere," Computer Physics Communications, vol. 214, May 2017,
  27. # pp. 225-230.
  28. #
  29. # You should have received a copy of the GNU General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. # This test case calculates the differential scattering
  32. # cross section for different x values of a PEC sphere
  33. # The differential cross section from wave optics is:
  34. # d(Csca)/d(a**2*Omega) = S11(Theta)/x**2
  35. from scattnlay import scattnlay
  36. import numpy as np
  37. dX = 3
  38. Xmax = 21.0
  39. m = np.array([1.0 + 0.0j], dtype = np.complex128)
  40. theta = np.linspace(0.0, np.pi, 500, dtype = np.float64)
  41. result = theta*180.0/np.pi
  42. for xl in np.arange(dX, Xmax, dX, dtype = np.float64):
  43. x = np.array([[xl]], dtype = np.float64)
  44. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m, theta, pl=0)
  45. S11 = S1[0].real*S1[0].real + S1[0].imag*S1[0].imag + S2[0].real*S2[0].real + S2[0].imag*S2[0].imag
  46. result = np.vstack((result, S11/(2.0*xl*xl)))
  47. result = result.transpose()
  48. try:
  49. import matplotlib.pyplot as plt
  50. plt.plot(result[ : , 0], result[ : , 1:])
  51. ax = plt.gca()
  52. ax.set_xlim(0, 180)
  53. ax.set_yscale('log')
  54. # ax.set_ylim(1e-4, 1e3)
  55. plt.xlabel('Theta')
  56. plt.draw()
  57. plt.show()
  58. finally:
  59. np.savetxt("scattPEC.txt", result, fmt = "%.5f")
  60. print result