登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
发个FDTD程序 大家共享
发帖
回复
1
2
8144
阅读
14
回复
[
求助
]
发个FDTD程序 大家共享
离线
dearlxf520
UID :4992
注册:
2007-09-17
登录:
2007-09-26
发帖:
19
等级:
仿真新人
0楼
发表于: 2007-09-24 13:26:10
1-D:
)2 Omsh
function FDTD_debug
O@n1E'S/
h3 Bs
%constants
f,e7;u z%
c_0 = 3E8; % Speed of light in free space
)ifEgBT
Nz = 100; % Number of cells in z-direction
d;Uzl1;
Nt = 200; % Number of time steps
yUZ;keQ_Tw
N = Nz; % Global number of cells
!A5UT-
ZO`{t1
E = zeros(Nz,1); % E component
,g2oqq ?
E2 = zeros(Nz,1);
.:<-E%
E1 = zeros(Nz,1);
hH=H/L_Z
Es = zeros(Nz,Nz); % Es is the output for surf function
;OE= ;\
%H = zeros(Nz,1); % H component
Q%x |
pulse = 0; % Pulse
3A~53W$M
n'dxa<F2|
%to be set
319 &:
mu_0 = 4.0*pi*1.0e-7; % Permeability of free space
6" s}<
eps_0 = 1.0/(c_0*c_0*mu_0); % Permittivty of free space
im}=
*2$I, ~(P
c_ref = c_0; % Reference velocity
Wq4>!|
eps_ref = eps_0;
|.]:#)^X?
mu_ref = mu_0;
d"7l<y5
s'4S,
f_0 = 10e9; % Excitation frequency
4bT21J37
f_ref = f_0; % Reference frequency
*1Q~/<W
pi'w40!:
omega_0 = 2.0*pi*f_0; % Excitation circular frequency
.x 1&
omega_ref = omega_0;
@M:Uf7
v|VfSLZTb
lambda_ref = c_ref/f_ref; % Reference wavelength
k8]uy2R6}
FG?69b>
Dx_ref = lambda_ref/20; % Reference cells width
n+C,v.X
Dz = Dx_ref;
yNwYP%"y
nDz = Dz/Dx_ref;
K#O8P+n5[
71nI`.Z
Z = Nz*Dz;
xz@/^Cj
r = 1; % Normalized time step
]3+xJz~=
Dt_ref = r*Dx_ref/c_ref; % Reference time step
QasUgZ
Dt = Dt_ref;
"`sr#
'+!@c&d#%o
% Source position
YW|KkHi*
Nz_Source = 0.5*Nz;
"R"7'sJMI
N_Source = Nz_Source;
}~Am{Er<l
b r"47i
for n = 1:Nt-1
kF09t5Lr
t = Dt_ref*r*(n-1); % Actual time
$@[`/Uh
?q&*|-%)_d
%Source function series
NAy3Zd}
Source_type = 1;
~AD%aHR
switch Source_type
yK1Z&7>J>
case 1 % modified source function
J9tQ@3{f
ncycles = 2;
,ZVC@P,L
if t < ncycles*2.0*pi/(omega_0)
L5E|1T
pulse = -0.5*( 1.0 - cos(omega_0*t/ncycles) ) * sin(omega_0*t);
~"<AYJlO
else
}'?N+MN
pulse = 0;
n1X.]|6'
end
gtcU'4~
case 2 % sigle cos source function
ERql^Yr
if t < 2.0*pi/(omega_0)
-^y$RJC
pulse = 8*c_0^2*Dt_ref^2*mu_ref*omega_0*cos(omega_0*t);
=Ws-s f]
else
FfDe&/,/
pulse = 0;
%&c+}m
end
t+R8{9L-
case 3 % Gaussian pulse
8x`?Yc
if t < Dt_ref*r*50
y~&R(x~w
pulse = -40*c_0*(t-t*25/(n-1))*exp(-(t-t*25/(n-1))^2/2/(50/2.3548)^2/(t/(n-1))^2);
1NP(3yt%
else
\= M*x
pulse = 0;
+) pO82
end
t)yWQV
end
H#/}FoBiS
E2(N_Source) = E2(N_Source) - r*pulse;
\'rh7!v-u
E1 = E2;
Z#-:zD7_
E2 = E;
5LT{]&`9
g$qNK`y
m = 2:Nz-1;
SA5 g~{"
E(m) = r^2*(E2(m+1) - 2*E2(m) + E2(m-1)) + 2*E2(m) - E1(m);
p8%/T>hK
OygR5s +
%Boundary
mN_KAln
E(1) = 0; E(Nz) = 0; % Dirichlet
R:= %gl!
%E(1) = E(2);E(Nz) = E(Nz-1); % Neumann
JN{.-k4Ha
%E(Nz) = E2(Nz-1) + (r-1)/(r+1)*(E(Nz-1)-E2(Nz)); % Mur ABC @ right side z = Nz
?m)3n0Uh
%E(1) = E2(2) + (r-1)/(r+1)*(E(2)-E2(1)); % Mur ABC @ left side z = 0
~*Fbs! ;,
N2!HkUy2
%display
4X0k1Fw)Y
%choice***********************************************
Kr$ w"]
display = 3; % choice: '1' = line plot; '2' = imagesc; '3' = surf
@KM !g,f
switch display
rt\i@}
case 1
@"`J~uK
i = 1:Nz;
vgfLI}|5
plot(i, E(i));
:R/szE*Ak
axis([0 Nz -4 4]);
K_@[%
case 2
sqAZjfy@
A = rot90(E);
z|VQp,ra
imagesc(A);
Gw"H#9J} T
case 3
,ux?wa+
i = 1:Nz;
!nQ!J+ g
for j = 1:Nz
,S|v>i,@
Es(i,j) = E(i);
9-<EeV_/
end
*x^W`i
Es = rot90(Es);
X 8TwMt
j = 1:Nz;
r!qr'Ht<
surf(i,j,Es);
+="?[:
axis([0 Nz 0 Nz -4 4])
&_q&TEi
otherwise
Q4gsOxP
A = rot90(E);
82w='~y
imagesc(A);
3SRz14/W_R
end
&