pfield.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. x = np.ones((1, 2), dtype = np.float64)
  36. x[0, 0] = 2.0*np.pi*0.05/1.064
  37. x[0, 1] = 2.0*np.pi*0.06/1.064
  38. m = np.ones((1, 2), dtype = np.complex128)
  39. m[0, 0] = 1.53413/1.3205
  40. m[0, 1] = (0.565838 + 7.23262j)/1.3205
  41. coord = np.zeros((3, 3), dtype = np.float64)
  42. coord[0, 0] = x[0, 0]/2.0
  43. coord[1, 0] = (x[0, 0] + x[0, 1])/2.0
  44. coord[2, 0] = 1.5*x[0, 1]
  45. terms, E, H = fieldnlay(x, m, coord)
  46. Er = np.absolute(E)
  47. # |E|/|Eo|
  48. Eh = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
  49. print x
  50. print m
  51. print np.vstack((coord[:, 0], Eh)).transpose()