test01.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 is a test against the program n-mie (version 3a) for the test case
  32. # distributed by them (extended for x up to 100)
  33. # n-mie is based in the algorithm described in:
  34. # Wu Z.P., Wang Y.P.
  35. # Electromagnetic scattering for multilayered spheres:
  36. # recursive algorithms
  37. # Radio Science 1991. V. 26. P. 1393-1401.
  38. # Voshchinnikov N.V., Mathis J.S.
  39. # Calculating Cross Sections of Composite Interstellar Grains
  40. # Astrophys. J. 1999. V. 526. #1.
  41. # The test consist in 5 layers with the following parameters
  42. # m1=1.8 i1.7
  43. # m2=0.8 i0.7
  44. # m3=1.2 i0.09
  45. # m4=2.8 i0.2
  46. # m5=1.5 i0.4
  47. # v1/Vt=0.1
  48. # v2/Vt=0.26
  49. # v3/Vt=0.044
  50. # v4/Vt=0.3666
  51. import scattnlay
  52. import os
  53. from scattnlay import scattnlay
  54. import numpy as np
  55. size = np.linspace(0.1, 100., 1000)
  56. x = np.vstack(( 0.1**(1.0/3.0)*size,
  57. 0.36**(1.0/3.0)*size,
  58. 0.404**(1.0/3.0)*size,
  59. 0.7706**(1.0/3.0)*size,
  60. size)).transpose()
  61. m = np.array((1.8 + 1.7j, 0.8 + 0.7j, 1.2 + 0.09j,
  62. 2.8 + 0.2j, 1.5 + 0.4j), dtype = np.complex128)
  63. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  64. result = np.vstack((x[:, 4], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  65. try:
  66. import matplotlib.pyplot as plt
  67. plt.figure(1)
  68. plt.subplot(311)
  69. plt.plot(x[:, 4], Qext, 'k')
  70. plt.ylabel('Qext')
  71. plt.subplot(312)
  72. plt.plot(x[:, 4], Qsca, 'r')
  73. plt.ylabel('Qsca')
  74. plt.subplot(313)
  75. plt.plot(x[:, 4], Albedo, 'g')
  76. plt.ylabel('Albedo')
  77. plt.xlabel('X')
  78. plt.show()
  79. finally:
  80. np.savetxt("test01.txt", result, fmt = "%.5f")
  81. print(result)