www.gusucode.com > FDTD计算二维光子带隙的程序 > FDTD计算二维光子带隙的程序/247787/AddSource.m

    function AddSource

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Electromagnetic Finite-Difference Time-Domain %
% Version 1.20, Release 1                       %
%                                               %
%   (C) Copyright 2005                          %
%   Sharif University of Technology             %
%   School of Electrical Engineering            %
%   All Rights Reserved                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global dT Time U Tx Ty Source Y LatticeCnt xPMLCnt
global NormalizedFrequency DiffusionLength yPMLCnt
global SourceWidth SourceDuration Profile
global xSource ySource Mode TE TM

if Time>SourceDuration | Source==0
    return
end

t=(Time-1)*dT;
w=2*pi*NormalizedFrequency/LatticeCnt;

if Source==1
    U(xSource+xPMLCnt,ySource+yPMLCnt)=sin(w*t);
else
    y=((1:Y)-Y/2)/sqrt(Y)/DiffusionLength;
    ymin=round(Y/2-SourceWidth/2);
    ymax=round(Y/2+SourceWidth/2);
    x=xSource+xPMLCnt;
    U(x-1,ymin:ymax)=0; % Deactivate for bidirectional plane source
    U(x,ymin:ymax)=sin(w*t)*Profile(ymin:ymax);
end