1
0

fmmtd_kxyz.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. %{
  2. Copyright © 2020 Alexey A. Shcherbakov. All rights reserved.
  3. This file is part of GratingFMM.
  4. GratingFMM is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. GratingFMM is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GratingFMM. If not, see <https://www.gnu.org/licenses/>.
  14. %}
  15. %% description:
  16. % calculate grating vectors for 2D grating (periodicity in x and y directions)
  17. % and plane wave propagation constants in homogeneous media below and
  18. % above the grating
  19. %% input:
  20. % xno, yno: numbers of Fourier harmonics in X and Y dimensions
  21. % kx0, ky0: wavevector projections of an incident plane wave
  22. % kgx, kgy: wavelength-to-period ratios
  23. % eps1: permittivity of a medium below the grating (substrate)
  24. % eps2: permittivity of a medium above the grating (superstrate)
  25. %% output:
  26. % kz1: row of propagation constants in the substrate
  27. % kz2: row of propagation constants in the superstrate
  28. % kx: row of grating vectors in x-direction
  29. % ky: row of grating vectors in y-direction
  30. % kxy: row of grating vectors in xy plane
  31. %% implementation:
  32. function [kz1, kz2, kx, ky, kxy] = fmmtd_kxyz(xno, yno, kx0, ky0, kgx, kgy, eps1, eps2)
  33. [kx,ky] = meshgrid(kx0 + kgx*(linspace(1,xno,xno) - ceil(xno/2)), ...
  34. ky0 + kgy*(linspace(1,yno,yno) - ceil(yno/2)));
  35. kx = reshape(kx,1,[]);
  36. ky = reshape(ky,1,[]);
  37. kxy = kx.^2 + ky.^2;
  38. kz1 = sqrt(eps1 - kxy);
  39. kz2 = sqrt(eps2 - kxy);
  40. ind = angle(kz1) < -1e-12;
  41. kz1(ind) = -kz1(ind);
  42. ind = angle(kz2) < -1e-12;
  43. kz2(ind) = -kz2(ind);
  44. kxy = sqrt(kxy);
  45. end