微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微波和射频技术 > 电磁仿真讨论 > A question about 1D_FDTD

A question about 1D_FDTD

时间:03-31 整理:3721RD 点击:
Hi~I run the 1D_FDTD code of the book named ELECTROMAGNETIC SIMULATION UING THE FDTD METHOD. But the result of calculation is wrong~
[url=../imgqa/eboard/EM/EM-eycgj5u3o14.jpg][img]../imgqa/eboard/EM/EM-eycgj5u3o14.jpg[/

I want to know why?

This is the code:
/*1D FDTD simulation in free space*/
#include<math.h>
#include<stdlib.h>
#include<stdio.h>

#define KE 200

main()
{
float ex[KE], hy[KE];
int n, k, kc, ke, NSTEPS;
float T;
float t0, spread, pulse;
FILE *fp; //, *fopen();

/*Initialize*/
for (k=1; k<KE; k++)
{
ex[k] = 0;
hy[k] = 0;
}

kc = KE/2; //Center of the problem space
t0 = 40.0; //Center of the incident pulse
spread = 12; //Width of the incident pulse
T = 0;
NSTEPS = 1;

while(NSTEPS > 0)
{
printf("NSTEPS -->"); //NSTEPS is the number of times the main loop has executed
scanf("%d", &NSTEPS);
printf("%d\n", NSTEPS);
n = 0;
for (n=1; n<=NSTEPS; n++)
{
T = T+1;
//Main FDTD Loop
/*Calculate the Ex field*/
for ( k=1; k < KE; k++)
{
ex[k] = ex[k]+ 0.5*( hy[k-1] - hy[k] );
}
//Put a Gaussian pulse in the middle
pulse = exp(-5*(pow((t0-T)/spread, 2.0 )));
ex[kc] = pulse;
printf( " %5.1f %6.2f \n", t0 - T, ex[kc] );
//Calculate the Hy field
for (k=0; k<KE-1; k++)
{
hy[k] = hy[k] + 0.5* (ex[k] - ex[k+1] );
}
}
//End of the Main loop
//At the end of the calculation ,print out the Ex and Hy fields
for (k=1; k<=KE; k++)
{
printf("%3d %6f %6.2f\n", k, ex[k], hy[k]);
}

//Write the E field out to a file "Ex"
fp = fopen("Ex.dat","w");
for (k=1; k<=KE; k++)
{
fprintf(fp, "%d %6.2f \n",k, ex[k]);
}
fclose(fp);

//Write the H field out to a file "Hy"
fp = fopen("Hy.dat","w");
for (k=1; k<=KE; k++)
{
fprintf(fp, "%d %6.2f \n", k, hy[k]);
}
fclose(fp);
printf("T= %5.0f\n",T);
}

}

Added after 1 minutes:

[url=../imgqa/eboard/EM/EM-kpeslvsn4qn.jpg][img]../imgqa/eboard/EM/EM-kpeslvsn4qn.jpg[/

hi
i think matlab is beeter than c for fdtd method and the out put is good for matlab
c is more sensetive for errors if u want matlab code 1 D send me u email and i will send it to u
best regard

@learnerlcy: you might want to describe what is wrong (what result you expected etc.)
also, the code in Sullivan has many bugs/does not always compile/is badly designed.
The best advice I can give is: try to understand the FDTD equations and then try to
implement them from scratch in a programming language of your choice.

@aaea3: visualization etc. may be easier in matlab. But if you have larger models then
running time might increase by 1 or 2 orders of magnitude when using matlab instead
of C (in C you can also be more memory efficient).

Hi

I am also facing problem with this set of code in C. When the program is compiled, it does not shows the same result as in the book. It seems that the iteration is only ran once when the pulse is at the center. Does anyone here knows where is problem in this code.

Thanks

You might want to

1) add the code you are using
2) show the output you get
3) say what exactly you think is wrong

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top