我有FDTD任务,但进展不顺利。每当我放入一个源并让模拟运行一点时(注意 - 如果你测试你必须使用调试器并逐步完成循环增量,否则会出现大量溢出)。
在我见过的大多数模拟中,人们将Ex和Ey分成不同的部分,我将它们放入一个大的E矩阵并使用索引偏移(见Ep(u,v + 1)和E(u) + 1,v)独立计算Ey和Ex。
我用作参考的来源是: http://fdtd.wikispaces.com/ 和 http://www.mathworks.com/matlabcentral/fileexchange/21000-tiny-fdtd-v1-0 那个是声学,但运作良好。
close all;
%% Some user modifiable parameters
mu0 = pi*4E-7; % pH/µm
e0 = 8.854187E-12; % Picofarads/micron
c = 1/sqrt(mu0*e0);
cellsizeX = 100; % Size of Yee-Cell in microns
cellsizeY = 100; % Size of Yee-Cell in microns
numX = 100; % Number of cells in X direction
numY = 100; % Number of cells in Y direction
lambda = 700*10^-9;
dx = lambda/20;
dy = lambda/20;
dt = (c*sqrt(dx^-2+dy^-2))^-1;
t0 = 100; %index time of gaussian pulse peak
width = 10; %peakyness of gaussian pulse
%% Initialise the H and E array
H = zeros(2*numX, 2*numY);
Hp = zeros(2*numX, 2*numY);
E = zeros(2*numX+1,2*numY+1);
Ep = zeros(2*numX+1,2*numY+1);
Etemp = zeros(2*numX+1,2*numY+1);
Htemp = zeros(2*numX, 2*numY);
P = zeros(2*numX+1,2*numY+1);
Pp = zeros(2*numX+1,2*numY+1);
% Scaling factors for H and E fields
CEx = dt/(dx*mu0);
CEy = dt/(dy*mu0);
CHx = dt/(dy*e0);
CHy = dt/(dx*e0);
x = 2:2:2*numX; %2*numX-2;
%Initialize Permibilities
Perm = ones(2*numX+1,2*numY+1);
%% FDTD loop
for n = 1:1500;
if(n < 200)
E(numX-10:2:numX+10,numY+1) = 1E-19*sin(2*pi*428E12*n*dt); %exp(-.5 * ((n-t0)/width).^2); %insert hard source
end;
for u = 2:2:2*numX-1
for v = 2:2:2*numY-1
Hp(u,v) = H(u,v) + (dt/mu0)*( -(E(u+1,v) - E(u-1,v))/dx) + ( E(u,v+1) - E(u,v-1)/dy ); % Solving for Hplus
Ep(u,v+1) = E(u,v+1) + (dt/(dy*e0))*(Hp(u,v+2) - Hp(u, v)); % Solving for Ex plus
Ep(u+1, v) = E(u+1, v) - (dt/(dx*e0))*(Hp(u+2, v) - Hp(u, v)); % Solving for Ey plus
end
end;
% Dirichlet Boundary Conditions
Ep(1,:) = 0;
Ep(:,1) = 0;
Ep(2*numX+1,:) = 0;
Ep(:,2*numX+1) = 0;
% Plotting
surf(Ep); shading interp; lighting phong; colormap hot; axis off; zlim([0 1]);
set(gcf,'Color', [0 0 0], 'Number', 'on', 'Name', sprintf('FDTD Project, step = %i', n));
%title(sprintf('Time = %.2f microsec',n*dt*1e12),'Color',[1 0 0],'FontSize', 22);
drawnow;
E = Ep;
H = Hp;
end;
end;
答案 0 :(得分:1)
2件事:
1 - Ep(:,2*numX+1,:) = 0;
是否正确? (即它应该是Ep(:,2*numX+1) = 0;
?)
2 - 最后,我想您可能想要将代码更改为
if (max(max(Ep)) > 1e-3)
E = Ep/max(max(Ep));
else E = Ep;
end
if (max(max(Hp)) > 1e-3)
H = Hp/max(max(Hp));
else H = Hp;
end
max(Ep)将为您提供1x100矩阵。 1e-3用于保护,您可以将其降低到您选择的任何值。