optical_force.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 optical force over a silver nanoparticle,
  33. # as a function of the irradiance and the radius.
  34. from scattnlay import scattnlay
  35. import numpy as np
  36. from scipy.constants import pi, c
  37. radius = np.linspace(0.5, 180.0, 360)
  38. nAg = np.sqrt(-4.0 + 0.7j)
  39. wl = 400.0
  40. x = 2.0*pi*np.array([radius], dtype = np.float64).transpose()/wl
  41. m = np.array([nAg], dtype = np.complex128)
  42. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  43. F = pi*Qpr*radius*radius/c/1e9
  44. result = np.vstack((radius, 1e11*F, 1e13*F, 1e15*F)).transpose()
  45. try:
  46. import matplotlib.pyplot as plt
  47. plt.figure(1)
  48. plt.subplot(311)
  49. plt.plot(radius, 1e11*F, 'k', label = '10$^{11}$ W/m$^2$')
  50. plt.plot(radius, 1e13*F, 'b', label = '10$^{13}$ W/m$^2$')
  51. plt.plot(radius, 1e15*F, 'g', label = '10$^{15}$ W/m$^2$')
  52. plt.ylabel('F (nN)')
  53. plt.legend(loc = 4)
  54. ax = plt.gca()
  55. ax.set_yscale('log')
  56. plt.subplot(312)
  57. plt.plot(radius, g, 'r', label = 'g')
  58. plt.ylabel('g')
  59. plt.subplot(313)
  60. plt.plot(radius, Qext, 'k', label = 'Q$_{ext}$')
  61. plt.plot(radius, Qsca, 'b', label = 'Q$_{sca}$')
  62. plt.plot(radius, Qpr, 'g', label = 'Q$_{pr}$')
  63. plt.ylabel('Q')
  64. plt.legend()
  65. plt.xlabel('R (nm)')
  66. plt.show()
  67. finally:
  68. #np.savetxt("test_force.txt", result, fmt = "%.5e")
  69. print result