123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
- #
- # Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
- #
- # This file is part of python-scattnlay
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # The only additional remark is that we expect that all publications
- # describing work using this software, or all commercial products
- # using it, cite the following reference:
- # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
- # a multilayered sphere," Computer Physics Communications,
- # vol. 180, Nov. 2009, pp. 2348-2354.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # This test case calculates the electric field along the
- # X, Y and Z axes, for an spherical silver nanoparticle
- # embedded in glass.
- # Refractive index values correspond to a wavelength of
- # 400 nm. Maximum of the surface plasmon resonance (and,
- # hence, of electric field) is expected under those
- # conditions.
- from scattnlay import fieldnlay
- import numpy as np
- n1 = 1.53413
- n2 = 0.565838 + 7.23262j
- nm = 1.3205
- x = np.ones((1, 2), dtype = np.float64)
- x[0, 0] = 2.0*np.pi*nm*0.05/1.064
- x[0, 1] = 2.0*np.pi*nm*0.06/1.064
- m = np.ones((1, 2), dtype = np.complex128)
- m[0, 0] = n1/nm
- m[0, 1] = n2/nm
- nc = 1001
- coordX = np.zeros((nc, 3), dtype = np.float64)
- coordY = np.zeros((nc, 3), dtype = np.float64)
- coordZ = np.zeros((nc, 3), dtype = np.float64)
- scan = np.linspace(-4.0*x[0, 1], 4.0*x[0, 1], nc)
- one = np.ones(nc, dtype = np.float64)
- coordX[:, 0] = scan
- coordY[:, 1] = scan
- coordZ[:, 2] = scan
- terms, Ex, Hx = fieldnlay(x, m, coordX)
- terms, Ey, Hy = fieldnlay(x, m, coordY)
- terms, Ez, Hz = fieldnlay(x, m, coordZ)
- Exr = np.absolute(Ex)
- Eyr = np.absolute(Ey)
- Ezr = np.absolute(Ez)
- # |E|/|Eo|
- Exh = np.sqrt(Exr[0, :, 0]**2 + Exr[0, :, 1]**2 + Exr[0, :, 2]**2)
- Eyh = np.sqrt(Eyr[0, :, 0]**2 + Eyr[0, :, 1]**2 + Eyr[0, :, 2]**2)
- Ezh = np.sqrt(Ezr[0, :, 0]**2 + Ezr[0, :, 1]**2 + Ezr[0, :, 2]**2)
- result = np.vstack((scan, Exh, Eyh, Ezh)).transpose()
- try:
- import matplotlib.pyplot as plt
- fig = plt.figure()
- ax = fig.add_subplot(111)
- ax.errorbar(result[:, 0], one, fmt = 'k')
- ax.errorbar(result[:, 0], result[:, 1], fmt = 'r', label = 'X axis')
- ax.errorbar(result[:, 0], result[:, 2], fmt = 'g', label = 'Y axis')
- ax.errorbar(result[:, 0], result[:, 3], fmt = 'b', label = 'Z axis')
- ax.legend()
- plt.xlabel('X|Y|Z')
- plt.ylabel('|E|/|E$_0$|')
- plt.draw()
- plt.show()
- finally:
- np.savetxt("lfield.txt", result, fmt = "%.5f")
- print result
|