1
0

calc_emntd_bin.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 a permittivity Fourier matrix of a 2D binary grating
  17. % being periodic in x and y dimensions of the 3D Cartesian coordinates
  18. %% input:
  19. % xno, yno: numbers of Fourier harmonics
  20. % cx, cy: rows of centers of a 2D rectangular mesh filling the grating period along
  21. % x and y dimensions normalized by the period (each value should be between -0.5 and 0.5)
  22. % dx, dy: rows of widths of a 2D rectangular mesh elements along
  23. % x and y dimensions normalized by the period (each value should be between 0 and 1)
  24. % eps: row of permittivities for each mesh element (length(eps) should be
  25. % equal to length(cx)*length(cy))
  26. %% output:
  27. % FE: cell array containing two Fourier matrices of the permittivity and
  28. % inverse permittivity
  29. %% implementation:
  30. function [FE] = calc_emntd_bin(xno, yno, cx, cy, dx, dy, eps)
  31. nx = length(cx);
  32. ny = length(cy);
  33. if (length(cx)~=length(dx)) || (length(cy)~=length(dy)) || (length(eps)~=(nx*ny))
  34. error("incorrect binary grating definition");
  35. end
  36. FE = cellmat(1,2,2*yno-1,2*xno-1);
  37. [CX,CY] = meshgrid(cx,cy);
  38. [DX,DY] = meshgrid(dx,dy);
  39. ix = linspace(1,xno-1,xno-1);
  40. iy = linspace(1,yno-1,yno-1);
  41. [IX,IY] = meshgrid(ix,iy);
  42. for ip = 1:nx*ny
  43. fx = (sin(ix*pi*DX(ip))./(pi*ix)).*exp((-2*pi*1i*CX(ip))*ix);
  44. fy = (sin(iy*pi*DY(ip))./(pi*iy)).*exp((-2*pi*1i*CY(ip))*iy);
  45. FX = (sin(IX*pi*DX(ip))./(pi*IX)).*exp((-2*pi*1i*CX(ip))*IX);
  46. FY = (sin(IY*pi*DY(ip))./(pi*IY)).*exp((-2*pi*1i*CY(ip))*IY);
  47. M = zeros(2*yno-1,2*xno-1);
  48. M(yno+1:2*yno-1,xno) = DX(ip)*fy;
  49. M(yno-1:-1:1,xno) = conj(M(yno+1:2*yno-1,xno));
  50. M(yno,xno+1:2*xno-1) = DY(ip)*fx;
  51. M(yno,xno-1:-1:1) = conj(M(yno,xno+1:2*xno-1));
  52. M(yno+1:2*yno-1,xno+1:2*xno-1) = FX.*FY;
  53. M(yno+1:2*yno-1,xno-1:-1:1) = conj(FX).*FY;
  54. M(yno-1:-1:1,xno+1:2*xno-1) = FX.*conj(FY);
  55. M(yno-1:-1:1,xno-1:-1:1) = conj(FX.*FY);
  56. FE{1,1} = FE{1,1} + eps(ip)*M;
  57. FE{1,2} = FE{1,2} + (1/eps(ip))*M;
  58. FE{1,1}(yno,xno) = FE{1,1}(yno,xno) + DX(ip)*DY(ip)*eps(ip);
  59. FE{1,2}(yno,xno) = FE{1,2}(yno,xno) + DX(ip)*DY(ip)/eps(ip);
  60. end
  61. end
  62. %
  63. % end of calc_emntd_cyl
  64. %