fmmtd.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. % calculation of a grating S-matrix by the Fourier Modal Method
  17. % in the case of the diffraction by 2D gratings being periodic in x and y
  18. % dimensions of the Cartesian coordinates
  19. %% input:
  20. % xno, yno: numbers of Fourier harmonics
  21. % kx0, ky0: incident plane wave x and y projections (Bloch wavevector projections)
  22. % kgx, kgy: wavelength-to-period ratios (grating vector projections)
  23. % kh: grating depth multiplied by the vacuum wavenumber
  24. % eps1: permittivity of the substrate
  25. % eps2: permittivity of the superstrate
  26. % FE: Fourier matrix of the grating profile
  27. %% output:
  28. % SM: scattering matrix of size (2*no,2*no,2,2) where no = xno*yno
  29. % is the total number of Fourier harmonics
  30. % block SM(:,:,1,1) corresponds to refelection from substrate to substrate
  31. % block SM(:,:,2,2) corresponds to refelection from superstrate to superstrate
  32. % block SM(:,:,2,1) corresponds to transmission from substrate to superstrate
  33. % block SM(:,:,1,2) corresponds to transmission from superstrate to substrate
  34. % first (no) components in each of the two first dimensions of the S-matrix
  35. % correspond to the TE polarization, and indeces from (no+1) to (2*no)
  36. % correspond to the TM polarization
  37. % central harmonic index is ind_0 = (ceil(xno/2)-1)*yno+ceil(yno/2)
  38. % for example, an ampitude of the TE-polarized transmitted wave to i-th diffraction order
  39. % from the substrate to the superstrate under the TM plane wave illumination
  40. % with unit amplitude is SM(ind_0+i, no+ind_0, 2, 1)
  41. %% implementation
  42. function [SM] = fmmtd(xno, yno, kx0, ky0, kgx, kgy, kh, eps1, eps2, FE)
  43. no = xno*yno;
  44. ib1 = 1:no;
  45. ib2 = no+1:2*no;
  46. ib3 = 2*no+1:3*no;
  47. ib4 = 3*no+1:4*no;
  48. % wavevector projections
  49. [kz1, kz2, kx, ky, kxy] = fmmtd_kxyz(xno, yno, kx0, ky0, kgx, kgy, eps1, eps2);
  50. ME = toeplitz2(FE{1,1},xno,yno);
  51. MU = toeplitz2(FE{1,2},xno,yno);
  52. % solve the eigenvalue problem:
  53. EV = zeros(2*no,2*no);
  54. HV = zeros(2*no,2*no);
  55. % matrix for the electric field
  56. EV(ib1,ib1) = ((kx').*MU).*ky;
  57. EV(ib1,ib2) = -((kx').*MU).*kx;
  58. EV(2*no*no+1:2*no+1:end) = EV(2*no*no+1:2*no+1:end) + 1;
  59. EV(ib2,ib1) = ((ky').*MU).*ky;
  60. EV(no+1:2*no+1:2*no*no) = EV(no+1:2*no+1:2*no*no) - 1;
  61. EV(ib2,ib2) = -((ky').*MU).*kx;
  62. % matrix for the magnetic field
  63. HV(2*no*no+no+1:2*no+1:end) = HV(2*no*no+no+1:2*no+1:end) + kx.*ky;
  64. HV(1:2*no+1:2*no*no) = -HV(2*no*no+no+1:2*no+1:end);
  65. HV(ib1,ib2) = -ME;
  66. HV(2*no*no+1:2*no+1:end) = HV(2*no*no+1:2*no+1:end) + kx.^2;
  67. HV(ib2,ib1) = ME;
  68. HV(no+1:2*no+1:2*no*no) = HV(no+1:2*no+1:2*no*no) - ky.^2;
  69. % solve the eigenvalue problem for the electric field
  70. [EV,MB] = eig(EV*HV);
  71. beta = transpose(sqrt(diag(MB))); % row of eigenvalues
  72. ind = angle(beta) < -1e-7; % check the branch of the square root
  73. beta(ind) = -beta(ind);
  74. % calculate the magnetic field amplitude eigen vectors
  75. HV = (HV*EV).*(1./beta);
  76. % calculate T-matrices
  77. TS = fmmtd_calc_T(no,EV,HV,kx,ky,kxy,kz1,eps1); % substrate-grating T-matrix
  78. TC = fmmtd_calc_T(no,EV,HV,kx,ky,kxy,kz2,eps2); % grating-cover T-matrix
  79. % combine T-matrices
  80. bexp = exp((1i*kh)*beta);
  81. M1 = zeros(4*no,4*no);
  82. M2 = zeros(4*no,4*no);
  83. M1([ib1,ib2],[ib1,ib2]) = TS([ib3,ib4],[ib1,ib2]);
  84. M1([ib3,ib4],[ib3,ib4]) = TC([ib1,ib2],[ib3,ib4]);
  85. M1(ib1,ib3) = TS(ib3,ib3).*bexp(ib1);
  86. M1(ib2,ib3) = TS(ib4,ib3).*bexp(ib1);
  87. M1(ib1,ib4) = TS(ib3,ib4).*bexp(ib2);
  88. M1(ib2,ib4) = TS(ib4,ib4).*bexp(ib2);
  89. M1(ib3,ib1) = TC(ib1,ib1).*bexp(ib1);
  90. M1(ib4,ib1) = TC(ib2,ib1).*bexp(ib1);
  91. M1(ib3,ib2) = TC(ib1,ib2).*bexp(ib2);
  92. M1(ib4,ib2) = TC(ib2,ib2).*bexp(ib2);
  93. M2([ib1,ib2],[ib1,ib2]) = TS([ib1,ib2],[ib1,ib2]);
  94. M2([ib3,ib4],[ib3,ib4]) = TC([ib3,ib4],[ib3,ib4]);
  95. M2(ib1,ib3) = TS(ib1,ib3).*bexp(ib1);
  96. M2(ib2,ib3) = TS(ib2,ib3).*bexp(ib1);
  97. M2(ib1,ib4) = TS(ib1,ib4).*bexp(ib2);
  98. M2(ib2,ib4) = TS(ib2,ib4).*bexp(ib2);
  99. M2(ib3,ib1) = TC(ib3,ib1).*bexp(ib1);
  100. M2(ib4,ib1) = TC(ib4,ib1).*bexp(ib1);
  101. M2(ib3,ib2) = TC(ib3,ib2).*bexp(ib2);
  102. M2(ib4,ib2) = TC(ib4,ib2).*bexp(ib2);
  103. % S-matrix
  104. SM = M2S(M1/M2);
  105. end
  106. %
  107. % END
  108. %