-
Notifications
You must be signed in to change notification settings - Fork 8
/
fdtd1d.c
43 lines (31 loc) · 1.03 KB
/
fdtd1d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Bare-bones 1D FDTD simulation with a hard source. */
#include <stdio.h>
#include <math.h>
#define SIZE 400
int main()
{
double ez[SIZE] = {0.}, hy[SIZE] = {0.}, imp0 = 377.0, epsR[SIZE];
int qTime, maxTime = 400, mm;
double sourcePeakTime = 30, sourceSdv = 7, sourceSigma;
int sensorLocation = 250;
sourceSigma = 2 * sourceSdv * sourceSdv;
for (mm = 0; mm < SIZE; mm++) epsR[mm] = 1.0;
/* uncomment next line to insert glass slab */
// for (mm = 150; mm < 200; mm++) epsR[mm] = 4.7;
/* do time stepping */
for (qTime = 0; qTime < maxTime; qTime++) {
/* update magnetic field */
for (mm = 0; mm < SIZE - 1; mm++)
hy[mm] = hy[mm] + (ez[mm + 1] - ez[mm]) / imp0;
/* update electric field */
for (mm = 1; mm < SIZE; mm++)
ez[mm] = ez[mm] + (hy[mm] - hy[mm - 1]) * imp0 / epsR[mm];
/* hardwire a source node */
if (qTime < sourceSigma)
ez[0] = exp(-(qTime - sourcePeakTime)*(qTime - sourcePeakTime) / sourceSigma);
else
ez[0] = 0.0;
printf("%g\n", ez[sensorLocation]);
} /* end of time-stepping */
return 0;
}