fmm.m 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 collinear diffraction by 1D gratings being periodic in x
  18. % dimension of the Cartesian coordinates
  19. %% input:
  20. % no: number of Fourier harmonics
  21. % kx0: incident plane wave wavevector x-projection (Bloch wavevector)
  22. % kg: wavelength-to-period ratio (grating vector)
  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. % pol: polarization, either "TE" or "TM"
  28. %% output:
  29. % SM: scattering matrix of size (no,no,2,2)
  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. % central harmonic index is ind_0 = ceil(no/2)
  35. % for example, an ampitude of the transmitted wave to i-th diffraction order
  36. % from the substrate to the superstrate under the plane wave illumination
  37. % with unit amplitude is SM(ind_0+i, ind_0, 2, 1)
  38. %% implementation
  39. function [SM] = fmm(no, kx0, kg, kh, eps1, eps2, FE, pol)
  40. % wavevector projections
  41. [kz1, kz2, kx] = fmm_kxz(no, kx0, 0, kg, eps1, eps2);
  42. % block indices
  43. ib1 = 1:no;
  44. ib2 = no+1:2*no;
  45. % solve the eigenvalue problem:
  46. ME = toeplitz(FE(no:2*no-1,1),FE(no:-1:1,1)); % permittivity Toeplitz matrix
  47. if (strcmp(pol,'TE')) % if TE polarization
  48. ME(1:no+1:end) = ME(1:no+1:end) - (kx.^2);
  49. [EV,MB] = eig(ME);
  50. beta = transpose(sqrt(diag(MB)));
  51. % check the branch of the square root
  52. ind = angle(beta) < -1e-7;
  53. beta(ind) = -beta(ind);
  54. % eigen vector of the magnetic field
  55. HV = -EV.*beta; % Hx
  56. else % if TM polarization
  57. MU = eye(no) / toeplitz(FE(no:2*no-1,2),FE(no:-1:1,2)); % inverce permittivity Toeplitz matrix
  58. ME = -(diag(kx) / ME).*kx;
  59. ME(1:no+1:end) = ME(1:no+1:end) + 1;
  60. [EV,MB] = eig(ME*MU);
  61. beta = transpose(sqrt(diag(MB)));
  62. % check the branch of the square root
  63. ind = angle(beta) < -1e-7;
  64. beta(ind) = -beta(ind);
  65. % eigen vector of the magnetic field
  66. HV = (MU*EV)./beta;
  67. end
  68. bexp = exp((1i*kh)*beta);
  69. % apply the boundary conditions:
  70. TS = fmm_calc_T(no,EV,HV,kz1,eps1,pol); % susbtrate-grating T-matrix
  71. TC = fmm_calc_T(no,EV,HV,kz2,eps2,pol); % grating-cover T-matrix
  72. % combine T-matrices
  73. M1 = zeros(2*no,2*no);
  74. M2 = zeros(2*no,2*no);
  75. M1(ib1,ib1) = TS(ib2,ib1);
  76. M1(ib1,ib2) = TS(ib2,ib2).*bexp;
  77. M1(ib2,ib1) = TC(ib1,ib1).*bexp;
  78. M1(ib2,ib2) = TC(ib1,ib2);
  79. M2(ib1,ib1) = TS(ib1,ib1);
  80. M2(ib1,ib2) = TS(ib1,ib2).*bexp;
  81. M2(ib2,ib1) = TC(ib2,ib1).*bexp;
  82. M2(ib2,ib2) = TC(ib2,ib2);
  83. SM = M2S(M1/M2);
  84. end