Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

A question about 1D_FDTD

Status
Not open for further replies.

learnerlcy

Newbie level 1
Newbie level 1
Joined
Nov 15, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Xian
Activity points
1,303
Hi~I run the 1D_FDTD code of the book named ELECTROMAGNETIC SIMULATION UING THE FDTD METHOD. But the result of calculation is wrong~
http://obrazki.elektroda.pl/13_1258255028_thumb.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);
}

}

[size=2][color=#999999]Added after 1 minutes:[/color][/size]

[url=http://obrazki.elektroda.pl/53_1258255246.jpg][img]http://obrazki.elektroda.pl/53_1258255246_thumb.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
 

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top