fmmnc.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 non-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. % ky0: incident plane wave wavevector y-projection
  23. % (ky0=0 corresponds to the collinear diffraction)
  24. % kg: wavelength-to-period ratio (grating vector)
  25. % kh: grating depth multiplied by the vacuum wavenumber
  26. % eps1: permittivity of the substrate
  27. % eps2: permittivity of the superstrate
  28. % FE: Fourier matrix of the grating profile
  29. %% output:
  30. % SM: scattering matrix of size (2*no,2*no,2,2)
  31. % block SM(:,:,1,1) corresponds to refelection from substrate to substrate
  32. % block SM(:,:,2,2) corresponds to refelection from superstrate to superstrate
  33. % block SM(:,:,2,1) corresponds to transmission from substrate to superstrate
  34. % block SM(:,:,1,2) corresponds to transmission from superstrate to substrate
  35. % first no components in each of the two first dimensions if the S-matrix
  36. % correspond to the TE polarization, and indeces from no+1 to 2*no
  37. % correspond to the TM polarization
  38. % central harmonic index is ind_0 = ceil(no/2)
  39. % for example, an ampitude of the TE-polarized transmitted wave to i-th diffraction order
  40. % from the substrate to the superstrate under the TM plane wave illumination
  41. % with unit amplitude is SM(ind_0+i, no+ind_0, 2, 1)
  42. %% implementation
  43. function [SM] = fmmnc(no, kx0, ky0, kg, kh, eps1, eps2, FE)
  44. % block indices
  45. ib1 = 1:no;
  46. ib2 = no+1:2*no;
  47. ib3 = 2*no+1:3*no;
  48. ib4 = 3*no+1:4*no;
  49. % wavevector projections
  50. [kz1, kz2, kx, kxy] = fmm_kxz(no, kx0, ky0, kg, eps1, eps2);
  51. % permittivity Toeplitz matrices
  52. ME = toeplitz(FE(no:2*no-1,1),FE(no:-1:1,1)); % permittivity Toeplitz matrix
  53. MU = toeplitz(FE(no:2*no-1,2),FE(no:-1:1,2)); % inverse permittivity Toeplitz matrix
  54. % initialize the eigenvectors
  55. EV = zeros(2*no,2*no);
  56. HV = zeros(2*no,2*no);
  57. % matrix for the electric field
  58. IMU = eye(no)/MU;
  59. TM = ME\((kx').*IMU);
  60. EV(ib1,ib1) = IMU - (kx').*TM - (ky0^2)*eye(no);
  61. EV(ib2,ib1) = ky0*(diag(kx) - TM);
  62. EV(ib2,ib2) = ME - diag(kxy.*kxy);
  63. % solve the eigenvalue problem for the electric field
  64. [EV,MB] = eig(EV);
  65. beta = transpose(sqrt(diag(MB))); % row of eigenvalues
  66. ind = angle(beta) < -1e-7; % check the branch of the square root
  67. beta(ind) = -beta(ind);
  68. % calculate the magnetic field eigen vectors
  69. HV(ib2,ib2) = diag(ky0*kx);
  70. HV(ib1,ib1) = -HV(ib2,ib2);
  71. HV(ib2,ib1) = IMU - (ky0^2)*eye(no);
  72. HV(ib1,ib2) = diag(kx.*kx) - ME;
  73. HV = (HV*EV).*(1./beta);
  74. bexp = exp((1i*kh)*beta);
  75. % apply the boundary conditions:
  76. % calculate T-matrices
  77. TS = fmmnc_calc_T(no,EV,HV,kx,ky0,kxy,kz1,eps1); % susbtrate-grating T-matrix
  78. TC = fmmnc_calc_T(no,EV,HV,kx,ky0,kxy,kz2,eps2); % grating-cover T-matrix
  79. % initialization
  80. M1 = zeros(4*no,4*no);
  81. M2 = zeros(4*no,4*no);
  82. % combine T-matrices
  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. % attain S-matrix
  104. SM = M2S(M1/M2);
  105. end