fmmtd_balance.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 the power balance (check the energy conservation law) in case
  17. % of the diffraction by 2D gratings being periodic in x and y dimensions
  18. %% input:
  19. % xno, yno: numbers of Fourier harmonics
  20. % total number of Fourier harmonics is no = xno*yno;
  21. % V_inc: incident field amplitude matrix of size (2*no, 2)
  22. % V_dif: diffracted field amplitude matrix of size (2*no, 2)
  23. % first index of V_inc, V_dif indicates diffraction harmonics
  24. % with indices 1:no being TE orders and no+1:2*no being TM orders
  25. % (0-th order index is ind_0 = (ceil(xno/2)-1)*yno+ceil(yno/2))
  26. % second index of V_inc, V_dif, V_eff indicates whether the diffraction orders
  27. % are in the substrate (V(:,1)) or in the superstrate (V(:,2))
  28. % kx0, ky0: incident plane wave wavevector x and y projections (Bloch wavevector projections)
  29. % kgx, kgy: wavelength-to-period ratios (grating vectors)
  30. % eps1, eps2: substrate and superstrate permittivities
  31. %% output:
  32. % if the incident field has propagating harmonics the function returns the
  33. % normalized difference between the incident and diffractied field total
  34. % power, otherwise (if the incident field is purely evanescent) it returns
  35. % the total power carried by propagating diffraction orders
  36. %% implementation
  37. function [b] = fmmtd_balance(xno, yno, V_inc, V_dif, kx0, ky0, kgx, kgy, eps1, eps2)
  38. no = xno*yno;
  39. ib1 = 1:no; ib2 = no+1:2*no;
  40. [kz1, kz2] = fmmtd_kxyz(xno, yno, kx0, ky0, kgx, kgy, eps1, eps2);
  41. kz1 = transpose(kz1);
  42. kz2 = transpose(kz2);
  43. P_inc = sum( abs((V_inc(ib1,1)).^2).*real(kz1) + abs((V_inc(ib1,2)).^2).*real(kz2) ) ...
  44. + sum( abs((V_inc(ib2,1)).^2).*real(kz1/eps1) + abs((V_inc(ib2,2)).^2).*real(kz2/eps2) );
  45. P_dif = sum( abs((V_dif(ib1,1)).^2).*real(kz1) + abs((V_dif(ib1,2)).^2).*real(kz2) ) ...
  46. + sum( abs((V_dif(ib2,1)).^2).*real(kz1/eps1) + abs((V_dif(ib2,2)).^2).*real(kz2/eps2) );
  47. if (abs(P_inc) > 1e-15)
  48. b = abs(P_dif/P_inc-1);
  49. else
  50. b = 0.5*P_dif;
  51. end
  52. end
  53. %
  54. % END
  55. %