S
sixfu
Guest
Som učenia FDTD pomocou Sullivan knihy --- Elektromagnetická Simulácia Pomocou metódy FDTD, a nemůžu si právo vyplývajúce z kódexu uvedených v knihe pre fd2d_3.2.c.Tiež som tento kód stiahnutý z jeho webových stránok, to nefunguje taky.Môže každý subjekt, pomôž mi, aby na to!
Díky moc!
Nižšie je uvedený zdrojový kód knihy:
************************************************** *****
/ * Fd2d_3.2.c.TM 2D program s PML * /
#
Include <math.h>
#
Include <stdlib.h>
#
Include <stdio.h>
#
Define IE 140
#
Define JE 140
main ()
(
float ga [CZ] [JE] dz [CZ] [JE], ez [CZ] [JE], Hx [CZ] [JE] hy [CZ] [JE];
int l, n, i, j, ic, jc, nsteps, npml;
float ddx, dt, T, epsz, pi, epsilon, sigma, EAF;
float xn, xxn, xnum, XD, curl_e;
float t0, šírenie, pulz;
float gi2 [CZ], gi3 [CZ];
float gj2 [JE], gj3 [CZ];
float fi1 [CZ], FI2 [CZ], fi3 [JE];
float fj1 [JE], fj2 [JE], fj3 [JE];
float ihx [CZ] [JE], ihy [CZ] [JE];
FILE * fp, * fopen ();
ic = IE/2-20;
jc = JE/2-20;
ddx =, 01; / * Cell veľkosti * /
dt = ddx/6e8; / * Časové kroky * /
epsz = 8.8e-12;
pi = 3.14159;
/ * Inicializovať na pole * /
u (j = 0; j <JE; j ) (
printf ( "% 2d", j);
for (i = 0; i <IE, i ) (
dz [j] = 0.0;
Hx [j] = 0.0;
hy [j] = 0.0;
ihx [j] = 0.0;
ihy [j] = 0.0;
ga [j] = 1.0;
printf ( "% 5.2f", ga [j]);
)
printf ( "\ n");
)
/ * Vypočítajte PML parametre * /
for (i = 0; i <IE, i ) (
gi2 = 1.0;
gi3 = 1.0;
fi1 = 0.0;
FI2 = 1.0;
fi3 = 1.0;
)
u (j = 0; j <IE, j ) (
gj2 [j] = 1.0;
gj3 [j] = 1.0;
fj1 [j] = 0.0;
fj2 [j] = 1.0;
fj3 [j] = 1.0;
)
printf ( "Počet PML bunky ->");
scanf ( "% d", & npml);
for (i = 0; i <= npml, i ) (
xnum = npml - i;
XD = npml;
xxn = xnum / XD;
xn = 0,25 * pow (xxn, 3,0);
printf ( "% d% 7.4f% 7.4f \ n", i, xxn, xn);
gi2 = 1.0 / (1.0 xn);
gi2 [CZ-1-i] = 1.0 / (1.0 xn);
gi3 = (1,0 - xn) / (1,0 xn);
gi3 [IE-i-1] = (1,0 - xn) / (1,0 xn);
xxn = (xnum-.5) / XD;
xn = 0,25 * pow (xxn, 3,0);
fi1 = xn;
fi1 [CZ-2-i] = xn;
FI2 = 1.0 / (1.0 xn);
FI2 [CZ-2-i] = 1.0 / (1.0 xn);
fi3 = (1,0 - xn) / (1,0 xn);
fi3 [CZ-2-i] = (1,0 - xn) / (1,0 xn);
)
u (j = 0; j <= npml j ) (
xnum = npml - j;
XD = npml;
xxn = xnum / XD;
xn = 0,25 * pow (xxn, 3,0);
printf ( "% d% 7.4f% 7.4f \ n", i, xxn, xn);
gj2 [j] = 1.0 / (1.0 xn);
gj2 [JE-1-j] = 1.0 / (1.0 xn);
gj3 [j] = (1,0 - xn) / (1,0 xn);
gj3 [JE-j-1] = (1,0 - xn) / (1,0 xn);
xxn = (xnum-.5) / XD;
xn = 0,25 * pow (xxn, 3,0);
fj1 [j] = xn;
fj1 [JE-2-j] = xn;
fj2 [j] = 1.0 / (1.0 xn);
fj2 [JE-2-j] = 1.0 / (1.0 xn);
fj3 [j] = (1,0 - xn) / (1,0 xn);
fj3 [JE-2-j] = (1,0 - xn) / (1,0 xn);
)
printf ( "gi fi \ n");
for (i = 0; i <IE, i ) (
printf ( "% 2d% 5.2f% 5.2f \ n"
i, gi2 , gi3 ),
printf ( "% 5.2f% 5.2f% 5.2f \ n"
fi1 , FI2 , fi3 );
)
printf ( "GJ FJ \ n");
u (j = 0; j <JE; j ) (
printf ( "% 2d% 5.2f% 5.2f \ n"
j, gj2 [j], gj3 [j]),
printf ( "% 5.2f% 5.2f% 5.2f \ n"
fj1 [j], fj2 [j], fj3 [j]);
)
t0 = 40,0;
šírenia = 12,0;
T = 0;
nsteps = 1;
while (nsteps> 0) (
printf ( "nsteps ->");
scanf ( "% d", & nsteps);
printf ( "% d \ n", nsteps);
k (n = 1, n <= nsteps n ) (
T = T 1;
/ * ---- Štart Hlavná FDTD slučky ---- * /
/ * Vypočítajte Dz pole * /
u (j = 1, j <IE, j ) (
for (i = 1; i <IE, i ) (
dz [j] = gi3 * gj3 [j] * dz [j]
Gi2 * gj2 [j] *. 5 * (hy [j] - hy [i-1] [j]
- Hx [j] Hx [j-1]);
)
)
/ * Sínusové Zdroj * /
/ * Impulz = sin (2 * pi * 1500 * 1e6 * dt * T); * /
pulz = exp (-. 5 * pow ((t-t0) / šírenie, 2.));
dz [IC] [jc] = pulz;
/ * Vypočítajte Ez pole * /
/ * Nechajte Ez okraja na 0, v rámci PML * /
u (j = 1, j <JE-1, j ) (
for (i = 1; i <IE-1, i ) (
EZ [j] = g [j] * dz [j];
)
)
printf ( "% 3f% 6.2f \ n", T, ez [IC] [jc]);
/ * Vypočítajte Hx pole * /
u (j = 0; j <JE-1, j ) (
for (i = 0; i <IE, i ) (
curl_e = EZ [j] - ez [j 1];
ihx [j] = ihx [j] fi1 * curl_e;
Hx [j] = fj3 [j] * Hx [j]
Fj2 [j] *. 5 * (curl_e ihx [j]);
)
)
/ * Vypočítajte Hy pole * /
u (j = 0; j <= JE-1, j ) (
for (i = 0; i <IE-1, i ) (
curl_e = EZ [i 1] [j] - ez [j];
ihy [j] = ihy [j] fj1 [j] * curl_e;
hy [j] = fi3 * hy [j]
FI2 *. 5 * (curl_e ihy [j]);
)
)
)
/ * ---- Koniec hlavnej slučky FDTD ---- * /
u (j = 1, j <JE; j ) (
printf ( "% 2d", j);
for (i = 1; i <= IE; i ) (
printf ( "% 4.1f", EZ [j]);
)
printf ( "\ n");
)
/ *
Zápis E poľa do súboru "Ez" * /
fp = fopen ( "Ez", "w");
u (j = 0; j <JE; j ) (
for (i = 0; i <IE, i ) (
fprintf (fp, "% 6.3f", EZ [j]);
)
fprintf (fp, "\ n");
)
fclose (fp);
printf ( "T =% 6.0f \ n", T);
)
)
Díky moc!
Nižšie je uvedený zdrojový kód knihy:
************************************************** *****
/ * Fd2d_3.2.c.TM 2D program s PML * /
#
Include <math.h>
#
Include <stdlib.h>
#
Include <stdio.h>
#
Define IE 140
#
Define JE 140
main ()
(
float ga [CZ] [JE] dz [CZ] [JE], ez [CZ] [JE], Hx [CZ] [JE] hy [CZ] [JE];
int l, n, i, j, ic, jc, nsteps, npml;
float ddx, dt, T, epsz, pi, epsilon, sigma, EAF;
float xn, xxn, xnum, XD, curl_e;
float t0, šírenie, pulz;
float gi2 [CZ], gi3 [CZ];
float gj2 [JE], gj3 [CZ];
float fi1 [CZ], FI2 [CZ], fi3 [JE];
float fj1 [JE], fj2 [JE], fj3 [JE];
float ihx [CZ] [JE], ihy [CZ] [JE];
FILE * fp, * fopen ();
ic = IE/2-20;
jc = JE/2-20;
ddx =, 01; / * Cell veľkosti * /
dt = ddx/6e8; / * Časové kroky * /
epsz = 8.8e-12;
pi = 3.14159;
/ * Inicializovať na pole * /
u (j = 0; j <JE; j ) (
printf ( "% 2d", j);
for (i = 0; i <IE, i ) (
dz [j] = 0.0;
Hx [j] = 0.0;
hy [j] = 0.0;
ihx [j] = 0.0;
ihy [j] = 0.0;
ga [j] = 1.0;
printf ( "% 5.2f", ga [j]);
)
printf ( "\ n");
)
/ * Vypočítajte PML parametre * /
for (i = 0; i <IE, i ) (
gi2 = 1.0;
gi3 = 1.0;
fi1 = 0.0;
FI2 = 1.0;
fi3 = 1.0;
)
u (j = 0; j <IE, j ) (
gj2 [j] = 1.0;
gj3 [j] = 1.0;
fj1 [j] = 0.0;
fj2 [j] = 1.0;
fj3 [j] = 1.0;
)
printf ( "Počet PML bunky ->");
scanf ( "% d", & npml);
for (i = 0; i <= npml, i ) (
xnum = npml - i;
XD = npml;
xxn = xnum / XD;
xn = 0,25 * pow (xxn, 3,0);
printf ( "% d% 7.4f% 7.4f \ n", i, xxn, xn);
gi2 = 1.0 / (1.0 xn);
gi2 [CZ-1-i] = 1.0 / (1.0 xn);
gi3 = (1,0 - xn) / (1,0 xn);
gi3 [IE-i-1] = (1,0 - xn) / (1,0 xn);
xxn = (xnum-.5) / XD;
xn = 0,25 * pow (xxn, 3,0);
fi1 = xn;
fi1 [CZ-2-i] = xn;
FI2 = 1.0 / (1.0 xn);
FI2 [CZ-2-i] = 1.0 / (1.0 xn);
fi3 = (1,0 - xn) / (1,0 xn);
fi3 [CZ-2-i] = (1,0 - xn) / (1,0 xn);
)
u (j = 0; j <= npml j ) (
xnum = npml - j;
XD = npml;
xxn = xnum / XD;
xn = 0,25 * pow (xxn, 3,0);
printf ( "% d% 7.4f% 7.4f \ n", i, xxn, xn);
gj2 [j] = 1.0 / (1.0 xn);
gj2 [JE-1-j] = 1.0 / (1.0 xn);
gj3 [j] = (1,0 - xn) / (1,0 xn);
gj3 [JE-j-1] = (1,0 - xn) / (1,0 xn);
xxn = (xnum-.5) / XD;
xn = 0,25 * pow (xxn, 3,0);
fj1 [j] = xn;
fj1 [JE-2-j] = xn;
fj2 [j] = 1.0 / (1.0 xn);
fj2 [JE-2-j] = 1.0 / (1.0 xn);
fj3 [j] = (1,0 - xn) / (1,0 xn);
fj3 [JE-2-j] = (1,0 - xn) / (1,0 xn);
)
printf ( "gi fi \ n");
for (i = 0; i <IE, i ) (
printf ( "% 2d% 5.2f% 5.2f \ n"
i, gi2 , gi3 ),
printf ( "% 5.2f% 5.2f% 5.2f \ n"
fi1 , FI2 , fi3 );
)
printf ( "GJ FJ \ n");
u (j = 0; j <JE; j ) (
printf ( "% 2d% 5.2f% 5.2f \ n"
j, gj2 [j], gj3 [j]),
printf ( "% 5.2f% 5.2f% 5.2f \ n"
fj1 [j], fj2 [j], fj3 [j]);
)
t0 = 40,0;
šírenia = 12,0;
T = 0;
nsteps = 1;
while (nsteps> 0) (
printf ( "nsteps ->");
scanf ( "% d", & nsteps);
printf ( "% d \ n", nsteps);
k (n = 1, n <= nsteps n ) (
T = T 1;
/ * ---- Štart Hlavná FDTD slučky ---- * /
/ * Vypočítajte Dz pole * /
u (j = 1, j <IE, j ) (
for (i = 1; i <IE, i ) (
dz [j] = gi3 * gj3 [j] * dz [j]
Gi2 * gj2 [j] *. 5 * (hy [j] - hy [i-1] [j]
- Hx [j] Hx [j-1]);
)
)
/ * Sínusové Zdroj * /
/ * Impulz = sin (2 * pi * 1500 * 1e6 * dt * T); * /
pulz = exp (-. 5 * pow ((t-t0) / šírenie, 2.));
dz [IC] [jc] = pulz;
/ * Vypočítajte Ez pole * /
/ * Nechajte Ez okraja na 0, v rámci PML * /
u (j = 1, j <JE-1, j ) (
for (i = 1; i <IE-1, i ) (
EZ [j] = g [j] * dz [j];
)
)
printf ( "% 3f% 6.2f \ n", T, ez [IC] [jc]);
/ * Vypočítajte Hx pole * /
u (j = 0; j <JE-1, j ) (
for (i = 0; i <IE, i ) (
curl_e = EZ [j] - ez [j 1];
ihx [j] = ihx [j] fi1 * curl_e;
Hx [j] = fj3 [j] * Hx [j]
Fj2 [j] *. 5 * (curl_e ihx [j]);
)
)
/ * Vypočítajte Hy pole * /
u (j = 0; j <= JE-1, j ) (
for (i = 0; i <IE-1, i ) (
curl_e = EZ [i 1] [j] - ez [j];
ihy [j] = ihy [j] fj1 [j] * curl_e;
hy [j] = fi3 * hy [j]
FI2 *. 5 * (curl_e ihy [j]);
)
)
)
/ * ---- Koniec hlavnej slučky FDTD ---- * /
u (j = 1, j <JE; j ) (
printf ( "% 2d", j);
for (i = 1; i <= IE; i ) (
printf ( "% 4.1f", EZ [j]);
)
printf ( "\ n");
)
/ *
Zápis E poľa do súboru "Ez" * /
fp = fopen ( "Ez", "w");
u (j = 0; j <JE; j ) (
for (i = 0; i <IE, i ) (
fprintf (fp, "% 6.3f", EZ [j]);
)
fprintf (fp, "\ n");
)
fclose (fp);
printf ( "T =% 6.0f \ n", T);
)
)