登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
发个FDTD程序 大家共享
发帖
回复
1
2
8145
阅读
14
回复
[
求助
]
发个FDTD程序 大家共享
离线
dearlxf520
UID :4992
注册:
2007-09-17
登录:
2007-09-26
发帖:
19
等级:
仿真新人
0楼
发表于: 2007-09-24 13:26:10
1-D:
?h\fwF3
function FDTD_debug
:8=7)cW
j]P'xrWl]8
%constants
l$/.B=]
c_0 = 3E8; % Speed of light in free space
x,L<{A`z
Nz = 100; % Number of cells in z-direction
#83`T&Xw*
Nt = 200; % Number of time steps
4 ))Z Bq?
N = Nz; % Global number of cells
"lLwgh;
P8[rp
E = zeros(Nz,1); % E component
Vq$8!#~w
E2 = zeros(Nz,1);
%>Q[j`9y
E1 = zeros(Nz,1);
5Q7Z$A1a 9
Es = zeros(Nz,Nz); % Es is the output for surf function
|r['"6
%H = zeros(Nz,1); % H component
?`hA :X<
pulse = 0; % Pulse
FNlS)Bs
z;iNfs0i$
%to be set
]"ou?ot }
mu_0 = 4.0*pi*1.0e-7; % Permeability of free space
SFJ"(ey$
eps_0 = 1.0/(c_0*c_0*mu_0); % Permittivty of free space
P_}wjz}9ZX
}iIZA>eF
c_ref = c_0; % Reference velocity
tzJ7wXRr
eps_ref = eps_0;
*\gYs{,
mu_ref = mu_0;
ANWfRtiU#
i/|}#yw8A
f_0 = 10e9; % Excitation frequency
]}4JT
f_ref = f_0; % Reference frequency
3Zdwt\OQ
m)Ta5w^
omega_0 = 2.0*pi*f_0; % Excitation circular frequency
D| |)H
omega_ref = omega_0;
k~Z;S QyN
:_k5[KT.]9
lambda_ref = c_ref/f_ref; % Reference wavelength
)5Wt(p:T6_
i+90##4<?
Dx_ref = lambda_ref/20; % Reference cells width
X~g U$
Dz = Dx_ref;
Q%r KKOX8
nDz = Dz/Dx_ref;
FRhHp(0}5
{:]u 6l
Z = Nz*Dz;
3FY87R
r = 1; % Normalized time step
q{Ao j
Dt_ref = r*Dx_ref/c_ref; % Reference time step
>)^Q p-
Dt = Dt_ref;
&8\6%C
+R"Y~ m{F
% Source position
%\^VxM
Nz_Source = 0.5*Nz;
4ibOVBG:*,
N_Source = Nz_Source;
t#d{hEr
InA=ty]"_U
for n = 1:Nt-1
4v.{C"M
t = Dt_ref*r*(n-1); % Actual time
L.2!Q3&
(h"-#q8$
%Source function series
*47HN7
Source_type = 1;
"*<)pnJ
switch Source_type
TrPw*4h 9s
case 1 % modified source function
70-nAv
ncycles = 2;
\&/V p`
if t < ncycles*2.0*pi/(omega_0)
(1e,9!?
pulse = -0.5*( 1.0 - cos(omega_0*t/ncycles) ) * sin(omega_0*t);
"O~7s}
else
18,;2Sr44
pulse = 0;
fU<_bg
end
8'qq!WR~
case 2 % sigle cos source function
/Bq4! n+
if t < 2.0*pi/(omega_0)
v`hn9O
pulse = 8*c_0^2*Dt_ref^2*mu_ref*omega_0*cos(omega_0*t);
muAgsH$/
else
:Z%-&)F
pulse = 0;
R0~w F>
end
?t)Mt]("
case 3 % Gaussian pulse
i&^]qL|J
if t < Dt_ref*r*50
]w0_!Z&
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);
@d|3c7` A
else
BdrYc^?JL]
pulse = 0;
DGbEQiX$\
end
,n{R,]y\
end
~jJF&*)
E2(N_Source) = E2(N_Source) - r*pulse;
J4%"38l
E1 = E2;
f|6 Y
E2 = E;
6t=)1T
\NTVg6>qN
m = 2:Nz-1;
K;7ea47m N
E(m) = r^2*(E2(m+1) - 2*E2(m) + E2(m-1)) + 2*E2(m) - E1(m);
hx! :F"#
BD- c<K"
%Boundary
tH=jaFJ
E(1) = 0; E(Nz) = 0; % Dirichlet
f cnv[B..{
%E(1) = E(2);E(Nz) = E(Nz-1); % Neumann
~6=aoF5"3?
%E(Nz) = E2(Nz-1) + (r-1)/(r+1)*(E(Nz-1)-E2(Nz)); % Mur ABC @ right side z = Nz
,Cd4Q7T
%E(1) = E2(2) + (r-1)/(r+1)*(E(2)-E2(1)); % Mur ABC @ left side z = 0
6<fcG
>-,$
%display
& LhQr-g
%choice***********************************************
XTJA"y
display = 3; % choice: '1' = line plot; '2' = imagesc; '3' = surf
\ [bJ@f*."
switch display
<ivq}(%72
case 1
(QTQxZ
i = 1:Nz;
O{x-9p
plot(i, E(i));
kho$At)V
axis([0 Nz -4 4]);
6zIK%<
case 2
3tW}a`z9
A = rot90(E);
.On3ZN
imagesc(A);
@ 3rJ $6W
case 3
{b|V;/
i = 1:Nz;
9^7z"*@#
for j = 1:Nz
RK/>5
Es(i,j) = E(i);
+w?-#M#
end
D@ %!|:
Es = rot90(Es);
&o]fBdn
j = 1:Nz;
2y IDyo
surf(i,j,Es);
b#-=Dbe
axis([0 Nz 0 Nz -4 4])
e(I;[G +%,
otherwise
tIk$4)ZAl
A = rot90(E);
[Lcy &+
imagesc(A);
'w0?-
end
dDA,Ps
pause(0.005);
xFcW%m>9C
end
_ h/:r1
rgo!t028^
2D:
t>P[Yld"
function FDTD_2D_Yee_2D_TM_final
`(r0+Qx
e=+q*]>
%constants
5 qMP u|A
c_0 = 3E8; % Speed of light in free space
q'9;
mu_0 = 4.0*pi*1.0e-7; % Permeability of free space
;6$W-W _
eps_0 = 1.0/(c_0*c_0*mu_0); % Permittivty of free space
0a9[}g1=#
XVF!l>nE
%to be set
WDI3*
Nx = 100; % Number of cells in x-direction
/[5\T2GI
Ny = 100; % Number of cells in y-direction
7^;-[?l
Nt = 500; % Number of time steps
a4XK.[O
+7{8T{
c_ref = c_0; % Reference velocity
=zR9^k
eps_ref = eps_0;
@O/"s~d-
mu_ref = mu_0;
P6")OWd
`# :(F z
f_0 = 10e9; % Excitation frequency
'U,\5jj'Y
f_ref = f_0; % Reference frequency
GL _hRu
,#bT
omega_0 = 2.0*pi*f_0; % Excitation circular frequency
&oE'|^G
omega_ref = omega_0;
NtmmPJ|5
FE1'MUT_
lambda_ref = c_ref/f_ref; % Reference wavelength
mA#;6?6
5&.I9}[)j
Dx_ref = lambda_ref/20; % Reference cells width
!$/P8T``M
Dy_ref = lambda_ref/20;
Wj8WT)cB
<sn,X0W
X = Nx*Dx_ref;
"pO**z$Z
Y = Ny*Dy_ref;
g 'Wr+(A_
e5D\m g)
r = 0.5; % Normalized factor
V/xjI<