scattSiO2.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2017 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. # Copyright (C) 2013-2017 Konstantin Ladutenko <kostyfisik@gmail.com>
  6. #
  7. # This file is part of 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. Peña 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. Peña-Rodríguez, "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. # This test case calculates the differential scattering
  33. # cross section for different x values of a SiO2 sphere
  34. # The differential cross section from wave optics is:
  35. # d(Csca)/d(a**2*Omega) = S11(Theta)/x**2
  36. from scattnlay import scattnlay
  37. import numpy as np
  38. dX = 3
  39. Xmax = 21.0
  40. m = np.array([1.46 + 0.0j], dtype = np.complex128)
  41. theta = np.linspace(0.0, np.pi, 500, dtype = np.float64)
  42. result = theta*180.0/np.pi
  43. for xl in np.arange(dX, Xmax, dX, dtype = np.float64):
  44. x = np.array([[xl]], dtype = np.float64)
  45. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m, theta)
  46. 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
  47. result = np.vstack((result, S11/(2.0*xl*xl)))
  48. result = result.transpose()
  49. try:
  50. import matplotlib.pyplot as plt
  51. plt.plot(result[ : , 0], result[ : , 1:])
  52. ax = plt.gca()
  53. ax.set_xlim(0, 180)
  54. ax.set_yscale('log')
  55. # ax.set_ylim(1e-4, 1e3)
  56. plt.xlabel('Theta')
  57. plt.draw()
  58. plt.show()
  59. finally:
  60. np.savetxt("scattSiO2.txt", result, fmt = "%.5f")
  61. print result