登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
新手请教Traflove书中附带的2D程序
发帖
回复
1
2
3
3953
阅读
23
回复
[
求助
]
新手请教Traflove书中附带的2D程序
离线
wq_463
UID :20925
注册:
2008-11-06
登录:
2021-04-22
发帖:
227
等级:
仿真三级
0楼
发表于: 2008-12-20 19:45:32
— 本帖被 gwzhao 执行加亮操作(2008-12-21) —
这个程序有不少地方看不明啊,我把程序贴出来把不明白的地方打个问号,希望有人给解释一下
H"lq!C`
我的qq243640120,希望做PML的朋友能加我,大家共同交流
19O /Q,9
%***********************************************************************
2<53y~Yi%
% 2-D FDTD TE code with PML absorbing boundary conditions
b$\3Y'":
%***********************************************************************
XMo#LS
%
c+$alwL~
% Program author: Susan C. Hagness
xD+n2:I{
% Department of Electrical and Computer Engineering
]pr( hk
% University of Wisconsin-Madison
6&/n/g
% 1415 Engineering Drive
?4v&TB@
% Madison, WI 53706-1691
78&(>8@m
% 608-265-5739
0V6gNEAUg
% [url=mailto:hagness@engr.wisc.edu]hagness@engr.wisc.edu[/url]
'oSs5lW
%
w&<-pIa`
% Date of this version: February 2000
dnt: U!TW@
%
^x(BZolkm
% This MATLAB M-file implements the finite-difference time-domain
.vHSKd{
% solution of Maxwell's curl equations over a two-dimensional
&6 .r=,BO
% Cartesian space lattice comprised of uniform square grid cells.
#vCtH2
%
e<o{3*%p)
% To illustrate the algorithm, a 6-cm-diameter metal cylindrical
mTXeIng?
% scatterer in free space is modeled. The source excitation is
+I1>; {{
% a Gaussian pulse with a carrier frequency of 5 GHz.
EwDFU K
%
L5$r<t<
% The grid resolution (dx = 3 mm) was chosen to provide 20 samples
<nDuN*|
% per wavelength at the center frequency of the pulse (which in turn
?IRp3H
% provides approximately 10 samples per wavelength at the high end
|35"V3bs
% of the excitation spectrum, around 10 GHz).
OXc!^2^
%
Q${0(#Nu
% The computational domain is truncated using the perfectly matched
AX=$r]_
% layer (PML) absorbing boundary conditions. The formulation used
gI<e=|J6w
% in this code is based on the original split-field Berenger PML. The
2VObj7F
% PML regions are labeled as shown in the following diagram:
.:gZ*ks~
%
V ':?rEN|
% ----------------------------------------------
GBnf]A,^@
% | | BACK PML | |
W2cgxT
% ----------------------------------------------
8U}BSM_<2
% |L | /| R|
uFPJ}m[>5
% |E | (ib,jb) | I|
@vzv9c[
% |F | | G|
^1y (N>W
% |T | | H|
+Y;/10p
% | | MAIN GRID | T|
? t<yk(q
% |P | | |
&,E^y,r
% |M | | P|
CqHCJ '
% |L | (1,1) | M|
/J{ e_a
% | |/ | L|
NvCq5B$C
% ----------------------------------------------
('k;Ikut
% | | FRONT PML | |
Hw[(v[v
% ----------------------------------------------
2_i/ F)W
%
P X/{
% To execute this M-file, type "fdtd2D" at the MATLAB prompt.
}i,LP1R
% This M-file displays the FDTD-computed Ex, Ey, and Hz fields at
vzDoF0Ts*p
% every 4th time step, and records those frames in a movie matrix,
$M%<i~VXe&
% M, which is played at the end of the simulation using the "movie"
9w\yWxl
% command.
ZH6#(;b
%
b {fZU?o
%***********************************************************************
,pfHNK-u
clear
+pDZ,c,
%***********************************************************************
pxC:VJ;
% Fundamental constants
NQb!?w
%***********************************************************************
D|m]]B
cc=2.99792458e8; %speed of light in free space
?X{ul
muz=4.0*pi*1.0e-7; %permeability of free space
D}4*Il?
epsz=1.0/(cc*cc*muz); %permittivity of free space
6,Aj5jG
freq=5.0e+9; %center frequency of source excitation
2Lravb3
lambda=cc/freq; %center wavelength of source excitation
#a7 Wx}
omega=2.0*pi*freq;
~J #^L*
%***********************************************************************
4rXjso|
% Grid parameters
7O)j]eeoL
%***********************************************************************
EPO*{bN7O
ie=100; %number of grid cells in x-direction
}t.J;(ff:
je=50; %number of grid cells in y-direction
.FV wZ:d
ib=ie+1;
%K@s0uQ
jb=je+1;
WGy3SV )
is=15; %location of z-directed hard source
d3%1P)
js=je/2; %location of z-directed hard source
4-ijuqjN
dx=3.0e-3; %space increment of square lattice
qU!xh)
dt=dx/(2.0*cc); %time step
7,vvL8\NHu
nmax=300; %total number of time steps
B?o ?LI
iebc=8; %thickness of left and right PML region
}<G"w5.<
jebc=8; %thickness of front and back PML region
uh,~CvXU]
rmax=0.00001;
4n1-@qTPF~
orderbc=2;
!{On_>`,
ibbc=iebc+1;
{|cuu"j26
jbbc=jebc+1;
`2}H$D
iefbc=ie+2*iebc; %x方向的总网格数
c;RB!`9"
jefbc=je+2*jebc;
"`A@_;At`
ibfbc=iefbc+1;
]<y _ =>
jbfbc=jefbc+1;
x.gRTR`7(
%***********************************************************************
$~ 6Y\O
% Material parameters
Ekq&.qjYG"
%***********************************************************************
Hz A+Oi
media=2; %?
snU $Na3
eps=[1.0 1.0];
<hG] f%
sig=[0.0 1.0e+7];
>b^|SL
mur=[1.0 1.0];
"Yh[-[,
sim=[0.0 0.0];
d:|(l^]{r
%***********************************************************************
8M9LY9C
% Wave excitation
gie.K1@|
%***********************************************************************
SU.9;I !
rtau=160.0e-12;
X0G Mly
tau=rtau/dt;
fK-tvP0}*
delay=3*tau;
lawjGI
source=zeros(1,nmax);
_4!SO5T
for n=1:7.0*tau
;4E(n
source(n)=sin(omega*(n-delay)*dt)*exp(-((n-delay)^2/tau^2)); %??????????
F|Y}X|x8Q
end
BgPwIK x
%***********************************************************************
(WoKrd.!
% Field arrays
z>n<+tso
%***********************************************************************
ZAKNyA2
ex=zeros(ie,jb); %fields in main grid
/K+GM8rtE
ey=zeros(ib,je);
z xe6M~+
hz=zeros(ie,je);
(<.uvq61
exbcf=zeros(iefbc,jebc); %fields in front PML region
{u7%Z}<0
eybcf=zeros(ibfbc,jebc);
vsFRWpq
hzxbcf=zeros(iefbc,jebc);
3WH"NC-O<
hzybcf=zeros(iefbc,jebc);
+Ndo$|XCy]
exbcb=zeros(iefbc,jbbc); %fields in back PML region
pxj}%LH
eybcb=zeros(ibfbc,jebc);
FPg5!O%
hzxbcb=zeros(iefbc,jebc);
<W$Ig@4[.d
hzybcb=zeros(iefbc,jebc);
;|nC;D]
exbcl=zeros(iebc,jb); %fields in left PML region
]m ED3#
eybcl=zeros(iebc,je);
Z:TW{:lrI
hzxbcl=zeros(iebc,je);
'a&( r;
hzybcl=zeros(iebc,je);
{'(1c)q>
exbcr=zeros(iebc,jb); %fields in right PML region
[xaglZ9HNo
eybcr=zeros(ibbc,je); %???????为什么跟LIFT的不一样呢
hu=b,
hzxbcr=zeros(iebc,je);
FrPpRe %!
hzybcr=zeros(iebc,je);
,2*^G;J1
%***********************************************************************
]g}Tqf/N%
% Updating coefficients
K@0gBgN
%***********************************************************************
G"_ 8`l
for i=1:media
m\h. sg&
eaf =dt*sig(i)/(2.0*epsz*eps(i));
.JkcCEe{G
ca(i)=(1.0-eaf)/(1.0+eaf);
d5b \kR r
cb(i)=dt/epsz/eps(i)/dx/(1.0+eaf);
7&I+mw/X
haf =dt*sim(i)/(2.0*muz*mur(i));
|Wo_5|E
da(i)=(1.0-haf)/(1.0+haf);
lQt&K1m
db(i)=dt/muz/mur(i)/dx/(1.0+haf);
f76bEe/B9
end
u0& aw
%***********************************************************************
,7wxVR%Ys
% Geometry specification (main grid)
cwe@W PE2
%***********************************************************************
EUVB>%P
% Initialize entire main grid to free space
f;Cu@z{b
caex(1:ie,1:jb)=ca(1);
Muhq,>!U
cbex(1:ie,1:jb)=cb(1);
,F4_ps?(
caey(1:ib,1:je)=ca(1);
hvc%6A\nm
cbey(1:ib,1:je)=cb(1);
M@R_t(&=
dahz(1:ie,1:je)=da(1);
x+mfQcSD&
dbhz(1:ie,1:je)=db(1);
/Ah|Po
% Add metal cylinder
.bwKG`F
diam=20; % diameter of cylinder: 6 cm
.1O
rad=diam/2.0; % radius of cylinder: 3 cm
O&ur|&v
icenter=4*ie/5; % i-coordinate of cylinder's center
^:c:~F6J
jcenter=je/2; % j-coordinate of cylinder's center
fJjtrvNy)
for i=1:ie
Dg:2*m_!j{
for j=1:je
83^|a5
dist2=(i+0.5-icenter)^2 + (j-jcenter)^2;
!i"Z
if dist2 <= rad^2
Hcts^zm2u
caex(i,j)=ca(2);
xr }jw
cbex(i,j)=cb(2);
n\U3f M>N
end
mAI<