pfield.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2015 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 the following reference:
  21. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. # This test case calculates the electric field along three
  28. # points, for an spherical silver nanoparticle embedded in glass.
  29. # Refractive index values correspond to a wavelength of
  30. # 400 nm. Maximum of the surface plasmon resonance (and,
  31. # hence, of electric field) is expected under those
  32. # conditions.
  33. from scattnlay import fieldnlay
  34. import numpy as np
  35. n1 = 1.53413
  36. n2 = 0.565838 + 7.23262j
  37. nm = 1.3205
  38. x = np.ones((1, 3), dtype = np.float64)
  39. x[0, 0] = 2.0*np.pi*nm*0.05/1.064
  40. x[0, 1] = 2.0*np.pi*nm*0.06/1.064
  41. x[0, 2] = 2.0*np.pi*nm*0.07/1.064
  42. m = np.ones((1, 3), dtype = np.complex128)
  43. m[0, 0] = n1/nm
  44. m[0, 1] = n2/nm
  45. m[0, 2] = 1.0
  46. coord = np.zeros((3, 3), dtype = np.float64)
  47. coord[0, 0] = x[0, 0]/2.0
  48. coord[1, 0] = (x[0, 0] + x[0, 1])/2.0
  49. coord[2, 0] = 1.5*x[0, 1]
  50. terms, E, H = fieldnlay(x, m, coord)
  51. Er = np.absolute(E)
  52. # |E|/|Eo|
  53. Eh = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
  54. print "x =", x
  55. print "m =", m
  56. print np.vstack((coord[:, 0], Eh)).transpose()