登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
求助!Sullivan书中程序FD1D_2.2.c有个地方没懂
发帖
回复
811
阅读
2
回复
[
求助
]
求助!Sullivan书中程序FD1D_2.2.c有个地方没懂
离线
lawrencelsq
UID :100451
注册:
2012-10-15
登录:
2012-11-30
发帖:
3
等级:
旁观者
0楼
发表于: 2012-10-15 17:50:19
程序中在对Ex进行傅里叶变换之后那段对入射脉冲作傅里叶变换的if语句有什么意义?为什么乘的是ex[10]而不是加入脉冲的位置的ex[5]?T<100在这里又怎么解释?求各位指教,小弟初学,先谢过了。
z:4_f:70
$xWUzg1<U
# include <math.h>
()48> ||
# include <stdlib.h>
-]+pwZ4g
# include <stdio.h>
2?SbkU/3|P
?xrOhA9
# define KE 200 /* KE is the number of cells to be used */
$rI 1|;^
void main ()
7[w<v(Rc
{
^sB0$|DU
float dx[KE], ex[KE], hy[KE], ix[KE];
&a;?o~%*]i
float ga[KE],gb[KE];
vENf3;o0
B0%=! &
int n,m,k,kc,ke,kstart,NSTEPS;
pQK SPr
float T,ddx,dt,epsz,epsilon,sigma;
xP!QV~$>
float t0,spread,pi,pulse;
#-@uLc
A&bj l[s
FILE *fp;
>=|p30\b
U8AH,?]#
float ex_low_m1,ex_low_m2,ex_high_m1,ex_high_m2;
-rn6ZSD)
float real_pt[5][KE],imag_pt[5][KE];
0~z\WSo
float freq[5],arg[5],ampn[5][KE],phasen[5][KE];
J|].h
float real_in[5],imag_in[5],amp_in[5],phase_in[5];
PO?_i>mA
// float mag[KE];
-sfv"?
bi^?SH\
pi = 3.14159;
}Uwji
kc = KE/2; /* Center of the problem space*/
fum.G{}
ddx = .01; /* Cell size */
c(e>Rmh
dt = ddx/6e8; /* Time steps */
r34MDUZdI
epsz = 8.8e-12;
#K6cBfqI
)9:5?,SO
printf (" %6.4f %10.5e \n",ddx,dt);
H#DvCw
"X8jpg
/*Initialize to free space */
t2s/zxt
F,{mF2U*$
for (k = 0; k <KE; k++)
`/ayg:WSU
{
!TJ,:c]4{!
ga[k] = 1.;
q+y\pdhdO
gb[k] = 0.;
ZGDT 6,
ex[k] = 0;
i5t6$|u:&m
dx[k] = 0;
".tL+A[
hy[k] = 0;
tw>2<zmSi%
ix[k] = 0;
]Ob|!L(
// mag[k] = 0;
C!*.jvhT
G %6P`:
for (m=0; m<=2; m++)
dniU{v
{
(rd [tc
real_pt[m][k] = 0; /* Real and imaginary parts of Fourier Transform */
BUJ\[/
imag_pt[m][k] = 0;
3_~iq>l
ampn[m][k] = 0; /* Amplitude and phase of the Fourier Transforms */
P0jr>j@^-
phasen[m][k] =0;
#5Z`Q^
}
9MYk5q.X:
}
=I'3C']Z W
7P7OTN
for ( m=0; m<=2; m++)
hU8Y&R)=9
{
`om+p?j
real_in[m] = 0; /* Fourier Trans of input pulse */
52dD(
imag_in[m] = 0;
%^pi
}
{^ b2nOMv
yGf7k>K'
ex_low_m1=0;
. \"k49M`
ex_low_m2=0;
8s@N NjV
ex_high_m1=0;
]MV8rC[\
ex_high_m2=0;
E5d$n*A
8~]D!c8; a
/* Parameters for the Fourier Transform */
wOl?(w=|
12KC4,C&1i
freq[0] = 100.e6;
sa(.Anmlj
freq[1] = 200.e6;
w8UuwFG?<
freq[2] = 500.e6;
-juG[zn
hd(FOKOP
for (n=0; n<=2; n++)
IB/3=4n^|
{
AO$AT_s
arg[n] = 2*pi*freq[n]*dt;
A913*O:\
printf ("%2d %6.2f %7.5f \n",n,freq[n]*1e-6,arg[n]);
lGl'A}]#$
}
Ki2!sADd
\A"o[A2v
printf ("Dielectric starts at -->");
kkF)Tro\
scanf ("%d",&kstart);
C/Khp +
printf ("Epsilon -->");
i(^U<DW$
scanf ("%f",&epsilon);
>H!Mx_fDL
printf ("Conductivity -->");
rNii,_
scanf ("%f",&sigma);
6:]N%
printf ("%d %6.2f %6.2f \n",kstart,epsilon,sigma);
#_@cI(P
r8J 7zTD&
/* Initialize the parameters */
6!ve6ZB[p
"y,YC M`
for (k=kstart; k<KE; k++)
t>I.1AS
{
_*fNa!@hY
ga[k] = 1./(epsilon+sigma*dt/epsz);
6'r8.~O
gb[k] = sigma*dt/epsz;
o)AwM"
}
.p&@;fZ
{`QHg O
for (k=1; k<KE; k++)
,erf{"Nh
{
[|DKBJ
printf ("%2d ga[k]=%4.2f gb[k]=%4.2f\n",k,ga[k],gb[k]);
/|1p7{km
}
En?V\|,
_1p8(n
/* These parameters specify the input pulse */
:TH cI;PG8
aa`(2%(:
t0=50.0; /* Center of the incident pulse */
h_vTA
spread=10.0; /* Width of the incident pulse */
jO-?t9^
QO/0VB42
T=0;
XH"+oW
NSTEPS=1;
d,b4q&^X8
while ( NSTEPS>0)
<U@N^#
{
d,V#5l-6
/* Main part of the program */
[@vz0!@s5
Xv8-<Ks
printf ("NSTEPS --> "); /* NSTEPS is the number of times the */
G@[8P?M=Z
scanf (" %d", &NSTEPS); /* main loop has executed */
gBm'9|?
printf (" %d \n",NSTEPS);
-3EQRqVg
O?JJE8~']
V&M*,#(?
for (n=1; n<=NSTEPS; n++)
1cLtTE
{
d;Vy59}eY
T=T+1; /* T keeps track of the total number */
%9J@##+
/* of times the main loop is executed */
Nr~$i% [
/* Main FDTD Loop */
G<;~nAo?f0
vk& gR
/* Calculate the Dx field */
fFjpQ~0
MzJCiX^
for (k=1; k<KE; k++)
2 |s ohF
{
tnRf!A;m
dx[k] = dx[k] +.5*(hy[k-1]-hy[k]);
E-bswUVaEE
}
Tlsh[@Q
hmO2s/~
/* Initialize with a Guassian pulse */
jwDlz.sW!
9\?OV@
pulse = exp(-.5*(pow( (t0-T)/spread,2.0) ));
7A)\:k
dx[5] = dx[5] + pulse;
*qd:f!Q3
printf ("%5.1f %6.2f %6.2f\n",T,pulse,dx[5]);
/BL:"t@-
FzT.9Vz7
/* Calculate Ex from Dx */
P[nc8z[
2bp@m;g$
for ( k=1; k<KE;k++)
XA>W>|
{
Dcl$?
ex[k] = ga[k]*(dx[k] - ix[k]);
5p;AON
ix[k] = ix[k] + gb[k]*ex[k];
Jz}nV1G(jz
}
94u{k1d x
rs&]46i/p
/* Calculate the Fourier transform of Ex. */
*@2Bh4
for ( k=0;k<KE;k++)
;c(a)_1
{
,=:K&5mCv
for (m=0;m<=2;m++)
KA5)]UF`l
{
XO <wK
real_pt[m][k] = real_pt[m][k] + cos(arg[m]*T)*ex[k];
w,LtQhQ
imag_pt[m][k] = imag_pt[m][k] - sin(arg[m]*T)*ex[k];
m&UP@hUV-
}
/`*{57/3
}
=)[m[@,c
-@W9+Zf5
/* Fourier Transform of the input pulse */
HN5m %R&`
^SdF\uk{?6
if (T<100)
?\}Gi(VVE
{
'wND
for (m=0; m<=2; m++)
:!`"GaTy
{
Xn6#q3;^|
real_in[m] = real_in[m] + cos (arg[m]*T)*ex[10];
Z'z)Oo
imag_in[m] = imag_in[m] - sin (arg[m]*T)*ex[10];
$)i`!7`4=
}
3Vb4zZsl
}
-+#%]P8l
h0GoF A<
;H_/o+
/*Absorbing Boundary Conditions*/
Xz+%Ym
-aoYoJ '
ex[0] = ex_low_m2;
-Zt!H%U
ex_low_m2 = ex_low_m1;
[{znwK@
ex_low_m1 = ex[1];
i"2OsGT
!#tVQ2O
ex[KE-1] = ex_high_m2;
q2qi~}l
ex_high_m2 = ex_high_m1;
_C?j\Wy
ex_high_m1 = ex[KE-2];
g{8RPw]
*]6g-E?:@
/* Calculate the Hy field */
CVj^{||eF
K:PH:e
for ( k=0; k<KE-1; k++)
|VBt:dd<
{
~ZHjP_5Q
hy[k] = hy[k] + .5*(ex[k]-ex[k+1]);
p@m0Oi,=
}
*c0H_8e
}
LK^|JE u
FaL\6w
/* End of the Main FDTD Loop */
Hq3|>OqC2Q
/k#-OXP~
/* At the end of the calculation,print out
U<Pjn)M~B
the Ex and Hy fields */
"HMEoZ
p=8Qv
for (k=0; k<KE; k++)
d+9V% T
{
OxlA)$.hpu
printf ("%2d %6.2f %6.2f \n",k,dx[k],ex[k]);
+#}GmUwPG$
}
yk+ 50/L
~P4C`Q1PT#
/* Write the E field out ot a file "Ex" */
Av X1*
fp=fopen( "Ex","w");
jk AjYR .
for (k=0;k<KE;k++)
]P4WfV d
{
S*h52li
fprintf (fp," %6.3f \n",ex[k]);
/x<g$!`X
}
Wh[QR-7Ew
fclose(fp);
Kl1v^3\{
YB#fAU
/* Calculate the amplitude and phase of each frequency */
w_9^YO!!
)DSeXS[ e
/* Amplitude and phase of the input pulse */
`KJ(. m
for ( m=0; m<=2; m++)
kB7vc>@1
{
ZoW1Cc&p
amp_in[m] = sqrt (pow (imag_in[m],2) + pow(real_in[m],2));
P*|N)S)X%
phase_in[m] = atan2 (imag_in[m],real_in[m]);
pGbfdX
?|nl93m
printf ( "%d Input Pulse : %8.4f %8.4f %8.4f %7.2f \n",
#8$?# dT
m,real_in[m],imag_in[m],amp_in[m],(180.0/pi)*phase_in[m]);
cG|fau<G
h<9s& p
for ( k=0; k<KE; k++)
P}bIp+
{
P"YdB|I
ampn[m][k] = (1./amp_in[m])*sqrt( pow(real_pt[m][k],2.)
%b6$N_M{H1
  ..
s\*L5{kiSl
\Z-th,t
未注册仅能浏览
部分内容
,查看
全部内容及附件
请先
登录
或
注册
共
条评分
离线
lawrencelsq
UID :100451
注册:
2012-10-15
登录:
2012-11-30
发帖:
3
等级:
旁观者
1楼
发表于: 2012-10-15 18:16:25
没人么 求大神们指教啊
共
条评分
离线
lx84
呵呵
UID :30566
注册:
2009-04-22
登录:
2020-09-16
发帖:
866
等级:
积极交流六级
2楼
发表于: 2012-10-15 18:55:46
在自由空间内在那个观察点傅里叶变换对结果都没有影响;关键事在你做傅里叶变换的时间段内必须有完整的时域波形;这个T<100;也就是说100步内在x=10观察点形成了完整波形,这不影响最后结果;当然你也可以用T<NSTEPS;只不过100步以后都是0,做福利也变换也没什么意义了。
共
条评分
继续!
发帖
回复