addsource.m

来自「fdtd计算二维光子晶体带隙」· M 代码 · 共 35 行

M
35
字号
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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?