Преглед изворни кода

Загрузить файлы ''

Shcherbakov Alexey Shcherbakov пре 4 година
родитељ
комит
61775b921f
3 измењених фајлова са 207 додато и 0 уклоњено
  1. 64 0
      demo_fmm.m
  2. 73 0
      demo_fmmnc.m
  3. 70 0
      demo_fmmtd.m

+ 64 - 0
demo_fmm.m

@@ -0,0 +1,64 @@
+%{
+Copyright © 2020 Alexey A. Shcherbakov. All rights reserved.
+
+This file is part of GratingFMM.
+
+GratingFMM is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+GratingFMM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GratingFMM. If not, see <https://www.gnu.org/licenses/>.
+%}
+%% demonstration script for the collinear 1D grating Fourier Modal Method calculations
+clc;
+format long;
+%% initialization
+wl = 1; % wavelength in micrometers
+wv = 2*pi/wl; % wavevector
+pol = 'TM'; % polarization, "TE" or "TM"
+  % grating parameters
+gp = 1.5; % grating period
+gh = 0.5; % grating depth
+  % dimensionless parameters
+kg = wl/gp;
+kh = wv*gh;
+	% permittivities
+eps_sub = 1.5^2; % substrate permittivity
+eps_gr = 3.17^2; %grating permittivity
+eps_sup = 1; % superstrate permittivity
+	% method parameters
+no = 15; % number of Fourier modes
+ind0 = ceil(no/2); % index of the zero harmonic (0th order diffraction)
+	% incidence
+theta = 10; % angle of incidence
+kx0 = sin(theta*pi/180); % incidence wavevector projection
+V_inc = zeros(no,2); % matrix of incident field amplitudes
+	% second index indicates wether the amplitudes are in the substrate (1) in the superstrate (2)
+V_inc(ind0,2) = 1; % plane wave coming from the superstrate
+
+%% scattering matrix calculation
+	% calculate Fourier image matrix of the dielectric permittivity function
+	% for a lamellar grating with filling factor 0.4
+FM = calc_emn_lam(no,0.4,eps_gr,eps_sup); % lamellar grating
+	% scattering matrix of the grating
+SM = fmm(no,kx0,kg,kh,eps_sub,eps_sup,FM,pol);
+
+%% diffraction of a plane wave example
+V_dif = zeros(no,2); % allocate a vector of diffracted field amplitudes
+	% apply the calculated scattering matrix to the incident vector:
+V_dif(:,1) = SM(:,:,1,1)*V_inc(:,1) + SM(:,:,1,2)*V_inc(:,2); % diffraction to the substrate
+V_dif(:,2) = SM(:,:,2,1)*V_inc(:,1) + SM(:,:,2,2)*V_inc(:,2); % diffraction to the superstrate
+  % check the power conservation
+b = fmm_balance(no,V_inc,V_dif,kx0,kg,eps_sub,eps_sup,pol);
+disp(b); % precicision of the power conservation
+	% calculate the vector of diffraction efficiencies
+V_eff = fmm_efficiency(no,V_inc,V_dif,kx0,kg,eps_sub,eps_sup,pol);
+disp(V_eff(ind0,1)); % 0th order power transmission coefficient
+disp(V_eff(ind0,2)); % 0th order power reflection coefficient

+ 73 - 0
demo_fmmnc.m

@@ -0,0 +1,73 @@
+%{
+Copyright © 2020 Alexey A. Shcherbakov. All rights reserved.
+
+This file is part of GratingFMM.
+
+GratingFMM is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+GratingFMM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GratingFMM. If not, see <https://www.gnu.org/licenses/>.
+%}
+%% demonstration script for the non-collinear 1D grating Fourier Modal Method calculations
+clc;
+format long;
+%% initialization
+wl = 1; % wavelength in micrometers
+wv = 2*pi/wl; % wavevector
+	% grating parameters
+gp = 1.5; % grating period
+gh = 0.5; % grating depth
+	% dimensionless parameters
+kg = wl/gp;
+kh = wv*gh;
+	% permittivities
+eps_sub = 1.5^2; % substrate permittivity
+eps_gr = 3.17^2; % grating permittivity
+eps_sup = 1; % superstrate permittivity
+	% method parameters
+no = 15; % number of Fourier modes
+ind0 = ceil(no/2); % index of the zero harmonic (0th order diffraction)
+	% incidence
+theta = 10; % angle of incidence (angle between the direction of incidence
+						% and the vertical axis being perpendicular to the grating plane)
+phi = 0; % turn angle in the grating plane,
+					% phi = 0 corresponds to the case of collinear diffraction
+	% incidence wavevector projections:
+kx0 = sin(theta*pi/180)*cos(phi*pi/180);
+ky0 = sin(theta*pi/180)*sin(phi*pi/180);
+V_inc = zeros(2*no,2); % matrix of incident field amplitudes
+	% first index indicates different Fourier harmonics, first (no) correspond
+	% to the TE polarization; second (no) correspond to the TM polarization
+	% second index indicates wether the amplitudes are in the substrate (1) in the superstrate (2)
+V_inc(1*no+ind0,2) = 1; % "TM" polarized plane wave (0-th harmonic) incoming from the superstrate
+
+%% scattering matrix calculation
+	% calculate Fourier image matrix of the dielectric permittivity function
+	% for a lamellar grating with filling factor 0.4
+FM = calc_emn_lam(no,0.4,eps_gr,eps_sup);
+	% scattering matrix of the grating
+SM = fmmnc(no,kx0,ky0,kg,kh,eps_sub,eps_sup,FM);
+
+%% diffraction of a plane wave example
+V_sca = zeros(2*no,2); % allocate a vector of diffracted field amplitudes
+	% apply the calculated scattering matrix to the incident vector:
+V_sca(:,1) = SM(:,:,1,1)*V_inc(:,1) + SM(:,:,1,2)*V_inc(:,2); % diffraction to the substrate
+V_sca(:,2) = SM(:,:,2,1)*V_inc(:,1) + SM(:,:,2,2)*V_inc(:,2); % diffraction to the superstrate
+  % check the power conservation
+b = fmmnc_balance(no,V_inc,V_sca,kx0,ky0,kg,eps_sub,eps_sup);
+disp(b); % precicision of the power conservation
+	% calculate the vector of diffraction efficiencies:
+V_eff = fmmnc_efficiency(no,V_inc,V_sca,kx0,ky0,kg,eps_sub,eps_sup);
+disp(V_eff(0*no+ind0,1)); % zero order power transmission to TE
+disp(V_eff(0*no+ind0,2)); % zero order power reflection to TE
+disp(V_eff(1*no+ind0,1)); % zero order power transmission to TM
+disp(V_eff(1*no+ind0,2)); % zero order power reflection to TM
+

+ 70 - 0
demo_fmmtd.m

@@ -0,0 +1,70 @@
+%{
+Copyright © 2020 Alexey A. Shcherbakov. All rights reserved.
+
+This file is part of GratingFMM.
+
+GratingFMM is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+GratingFMM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GratingFMM. If not, see <https://www.gnu.org/licenses/>.
+%}
+%% demonstration script for the 2D grating Fourier Modal Method calculations
+clc;
+%format long;
+%% initialization
+wl = 1; % wavelength in micrometers
+phi = 0;
+theta = 0.001; % for normal incidence take a small non-zero value
+kx0 = sin(theta*pi/180)*cos(phi*pi/180); % incidence wavevector horizontal projection (dimensionless) (Bloch wavevector)
+ky0 = sin(theta*pi/180)*sin(phi*pi/180); % incidence wavevector horizontal projection (dimensionless) (Bloch wavevector)
+gpx = 0.72; % grating period in x dimension
+gpy = 0.72; % grating period it y dimension
+gh = 0.5; % grating depth
+
+wv = 2*pi/wl; % wavevector
+
+  % dimensionless variables
+kgx = wl/gpx;
+kgy = wl/gpy;
+kh = wv*gh;
+
+xno = 15; % number of Fourier modes
+yno = 15; % number of Fourier modes
+no = xno*yno;
+ixy = (ceil(xno/2)-1)*yno+ceil(yno/2);
+eps_sub = 1.5; % substrate permittivity
+eps_gr = 3.17^2; % get_epsAu_Drude(wl); %grating permittivity
+eps_sup = 1; % superstrate permittivity
+
+	%% S-matrix calculation
+	% calculate Fourier image matrix of the dielectric permittivity function
+	% for a 2D lamellar grating with filling factors 0.5,0.5
+FE = calc_emntd_lam(xno,yno,0.5,0.5,eps_gr,eps_sup);
+	% scattering matrix of the grating
+SM = fmmtd(xno,yno,kx0,ky0,kgx,kgy,kh,eps_sub,eps_sup,FE);
+
+%% diffraction of a plane wave example
+	% incident field amplitude vector
+V_inc = zeros(2*no,2);
+V_inc((ceil(xno/2)-1)*yno+ceil(yno/2),2) = 1; % TE polarized plane wave (0-th harmonic) coming from the superstrate
+	% define diffracted amplitude vector
+V_dif = zeros(2*no,2);
+	% calculate diffraction vector
+V_dif(:,1) = SM(:,:,1,1)*V_inc(:,1) + SM(:,:,1,2)*V_inc(:,2); % diffraction to the substrate
+V_dif(:,2) = SM(:,:,2,1)*V_inc(:,1) + SM(:,:,2,2)*V_inc(:,2); % diffraction to the superstrate
+V_eff = fmmtd_efficiency(xno,yno,V_inc,V_dif,kx0,ky0,kgx,kgy,eps_sub,eps_sup);
+disp("efficiency:");
+disp(V_eff(ixy,1)); % 0th order power transmission coefficient
+disp(V_eff(ixy,2)); % 0th order power reflection coefficient
+	% calculate the power balance
+b = fmmtd_balance(xno,yno,V_inc,V_dif,kx0,ky0,kgx,kgy,eps_sub,eps_sup);
+disp("balance:");
+disp(b);