-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathezfdtd.c
187 lines (155 loc) · 4.82 KB
/
ezfdtd.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* NOTE: This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bugs can be reported to Yu Zhang <[email protected]>.
*
* File Name : ezfdtd.c
* Last Modified : Sun 07 Oct 2012 12:41:45 AM EDT
*/
#include "tools.h"
#include "classical.h"
#include "domain.h"
#include "ade.h"
#include "h5io.h"
#include "excitation.h"
#include "probes.h"
#include "step.h"
#include "mur.h"
#include "pml.h"
#include "cpml.h"
#include "dft.h"
/* mode */
unsigned int mode;
unsigned int pml_type;
/* constants */
double MU0;
double C0;
double EPSILON0;
/* discretization */
double d_x;
double d_y;
double d_z;
double d_t;
/* simulation time */
unsigned int total_timesteps;
/* grid size */
unsigned int abc_size;
unsigned int total_x;
unsigned int total_y;
unsigned int total_z;
unsigned int main_length_x;
unsigned int main_length_y;
unsigned int main_length_z;
/* the fields */
double ***ex;
double ***ey;
double ***ez;
double ***dx;
double ***dy;
double ***dz;
double ***bx;
double ***by;
double ***bz;
double ***hx;
double ***hy;
double ***hz;
/* the exciation sources */
double ***dipole_ex;
double ***dipole_ey;
double ***dipole_ez;
double ***dipole_hx;
double ***dipole_hy;
double ***dipole_hz;
/* domain partition */
DomainData partition_data[7];
static void compute (int time_index)
{
get_h();
apply_hhards(time_index);
get_e();
update_mur();
apply_ehards(time_index);
apply_pmc();
}
int main (int argc, char** argv)
{
char *input_file_name;
char *output_file_name;
int time_index;
int status;
int verbosity;
check(argc > 1, "less than two arguments; exit !");
input_file_name = argv[1];
output_file_name = argv[2];
status = h5_set_file(output_file_name);
check(status, "fail to create h5 output files");
status = h5_get_attr(input_file_name, "settings", "number_of_timesteps", &total_timesteps);
check(status, "fail to get h5 attributes");
status = h5_get_attr(input_file_name, "settings", "verbosity", &verbosity);
check(status && verbosity >= 0, "fail to get h5 attributes");
status = h5_get_attr(input_file_name, "boundaries", "pml_type", &pml_type);
check(status, "fail to get h5 attributes");
status = setup_domain(input_file_name);
check(status, "fail to setup domain");
status = setup_fields(input_file_name);
check(status, "fail to setup fields");
status = setup_mur();
check(status, "fail to setup abc_mur");
status = setup_classical(input_file_name);
check(status, "fail to setup classical mode");
if (verbosity > 0) printf("setup classical ... DONE\n");
if (classical != 1)
{
status = setup_ade(input_file_name);
check(status, "fail to setup ade");
}
if (pml_type != 0)
{
status = setup_cpml(input_file_name);
check(status, "fail to setup cpml");
if (verbosity > 0) printf("setup cpml ... DONE\n");
}
else
{
status = setup_pml(input_file_name);
check(status, "fail to setup pml");
if (verbosity > 0) printf("setup pml ... DONE\n");
}
status = setup_input_ports(input_file_name);
check(status, "fail to setup input ports");
if (verbosity > 0) printf("setup excitation ... DONE\n");
status = setup_point_sources(input_file_name);
check(status, "fail to setup point sources");
if (verbosity > 0) printf("setup point sources ... DONE\n");
status = setup_hards(input_file_name);
check(status, "fail to setup hards");
if (verbosity > 0) printf("setup hard sources ... DONE \n");
status = setup_output_ports(input_file_name);
check(status, "fail to setup output ports");
if (verbosity > 0) printf("setup probes ... DONE\n");
status = setup_planes(input_file_name, output_file_name);
check(status, "fail to setup planes");
if (verbosity > 0) printf("setup animations ... DONE\n");
status = setup_dft(input_file_name);
check(status, "fail to setup dft");
if (verbosity > 0) printf("setup DFT ... DONE\n");
for (time_index = 0; time_index < total_timesteps; time_index++)
{
if (verbosity > 0 && time_index%verbosity == 0) printf("Time Index %06d:\n", time_index);
excite(time_index);
compute(time_index);
update_ports(time_index);
update_dft(time_index);
update_planes(output_file_name, time_index);
}
write_ports(output_file_name);
write_dft(output_file_name);
exit(EXIT_SUCCESS);
}