-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdomain.c
418 lines (383 loc) · 22.6 KB
/
domain.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/* 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 : domain.c
* Last Modified : Thu 20 Mar 2014 10:20:51 PM EDT
*/
#include "tools.h"
#include "h5io.h"
#include "mem.h"
#include "domain.h"
double ***epsilon;
double d_tx;
double d_ty;
double d_tz;
int x, y, z;
int setup_domain (char *file_name)
{
int partition_index;
char attr_name[30];
int boundary_type;
int status;
status = h5_get_attr(file_name, "settings", "domain_size_x", &total_x);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "domain_size_y", &total_y);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "domain_size_z", &total_z);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "boundaries", "abc_thickness", &abc_size);
inspect(status, "fail to get h5 attributes");
/* fill region data */
for (partition_index = 1; partition_index < 7; partition_index++)
{
sprintf(attr_name, "boundary_%01d", partition_index);
status = h5_get_attr(file_name, "boundaries", attr_name, &boundary_type);
inspect(status, "fail to get h5 attributes");
partition_data[partition_index].boundary_type = boundary_type;
if (boundary_type == boundary_pml)
partition_data[partition_index].thickness = abc_size;
else
partition_data[partition_index].thickness = 0;
}
/* main grid */
partition_data[partition_main].x_start = partition_data[partition_x0].thickness;
partition_data[partition_main].x_stop = total_x - partition_data[partition_x1].thickness;
partition_data[partition_main].y_start = partition_data[partition_y0].thickness;
partition_data[partition_main].y_stop = total_y - partition_data[partition_y1].thickness;
partition_data[partition_main].z_start = partition_data[partition_z0].thickness;
partition_data[partition_main].z_stop = total_z - partition_data[partition_z1].thickness;
partition_data[partition_main].size_x = partition_data[partition_main].x_stop - partition_data[partition_main].x_start;
partition_data[partition_main].size_y = partition_data[partition_main].y_stop - partition_data[partition_main].y_start;
partition_data[partition_main].size_z = partition_data[partition_main].z_stop - partition_data[partition_main].z_start;
/* region 1 z0 */
partition_data[partition_z0].x_start = 0;
partition_data[partition_z0].x_stop = total_x;
partition_data[partition_z0].y_start = 0;
partition_data[partition_z0].y_stop = total_y;
partition_data[partition_z0].z_start = 0;
partition_data[partition_z0].z_stop = partition_data[partition_z0].thickness;
partition_data[partition_z0].size_x = partition_data[partition_z0].x_stop - partition_data[partition_z0].x_start;
partition_data[partition_z0].size_y = partition_data[partition_z0].y_stop - partition_data[partition_z0].y_start;
partition_data[partition_z0].size_z = partition_data[partition_z0].z_stop - partition_data[partition_z0].z_start;
/* region 2 z1 */
partition_data[partition_z1].x_start = 0;
partition_data[partition_z1].x_stop = total_x;
partition_data[partition_z1].y_start = 0;
partition_data[partition_z1].y_stop = total_y;
partition_data[partition_z1].z_start = total_z - partition_data[partition_z1].thickness;
partition_data[partition_z1].z_stop = total_z;
partition_data[partition_z1].size_x = partition_data[partition_z1].x_stop - partition_data[partition_z1].x_start;
partition_data[partition_z1].size_y = partition_data[partition_z1].y_stop - partition_data[partition_z1].y_start;
partition_data[partition_z1].size_z = partition_data[partition_z1].z_stop - partition_data[partition_z1].z_start;
/* region 3 x0 */
partition_data[partition_x0].x_start = 0;
partition_data[partition_x0].x_stop = partition_data[partition_x0].thickness;
partition_data[partition_x0].y_start = 0;
partition_data[partition_x0].y_stop = total_y;
partition_data[partition_x0].z_start = 0;
partition_data[partition_x0].z_stop = total_z;
partition_data[partition_x0].size_x = partition_data[partition_x0].x_stop - partition_data[partition_x0].x_start;
partition_data[partition_x0].size_y = partition_data[partition_x0].y_stop - partition_data[partition_x0].y_start;
partition_data[partition_x0].size_z = partition_data[partition_x0].z_stop - partition_data[partition_x0].z_start;
/* region 4 x1 */
partition_data[partition_x1].x_start = total_x - partition_data[partition_x1].thickness;
partition_data[partition_x1].x_stop = total_x;
partition_data[partition_x1].y_start = 0;
partition_data[partition_x1].y_stop = total_y;
partition_data[partition_x1].z_start = 0;
partition_data[partition_x1].z_stop = total_z;
partition_data[partition_x1].size_x = partition_data[partition_x1].x_stop - partition_data[partition_x1].x_start;
partition_data[partition_x1].size_y = partition_data[partition_x1].y_stop - partition_data[partition_x1].y_start;
partition_data[partition_x1].size_z = partition_data[partition_x1].z_stop - partition_data[partition_x1].z_start;
/* region 5 y0 */
partition_data[partition_y0].x_start = 0;
partition_data[partition_y0].x_stop = total_x;
partition_data[partition_y0].y_start = 0;
partition_data[partition_y0].y_stop = partition_data[partition_y0].thickness;
partition_data[partition_y0].z_start = 0;
partition_data[partition_y0].z_stop = total_z;
partition_data[partition_y0].size_x = partition_data[partition_y0].x_stop - partition_data[partition_y0].x_start;
partition_data[partition_y0].size_y = partition_data[partition_y0].y_stop - partition_data[partition_y0].y_start;
partition_data[partition_y0].size_z = partition_data[partition_y0].z_stop - partition_data[partition_y0].z_start;
/* region 6 y1 */
partition_data[partition_y1].x_start = 0;
partition_data[partition_y1].x_stop = total_x;
partition_data[partition_y1].y_start = total_y - partition_data[partition_y1].thickness;
partition_data[partition_y1].y_stop = total_y;
partition_data[partition_y1].z_start = 0;
partition_data[partition_y1].z_stop = total_z;
partition_data[partition_y1].size_x = partition_data[partition_y1].x_stop - partition_data[partition_y1].x_start;
partition_data[partition_y1].size_y = partition_data[partition_y1].y_stop - partition_data[partition_y1].y_start;
partition_data[partition_y1].size_z = partition_data[partition_y1].z_stop - partition_data[partition_y1].z_start;
return 1;
}
int setup_fields (char* file_name)
{
int status;
double ***temp;
status = h5_get_attr(file_name, "settings", "mode", &mode);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "EPSILON0", &EPSILON0);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "MU0", &MU0);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "C0", &C0);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "d_x", &d_x);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "d_y", &d_y);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "d_z", &d_z);
inspect(status, "fail to get h5 attributes");
status = h5_get_attr(file_name, "settings", "d_t", &d_t);
inspect(status, "fail to get h5 attributes");
d_tx = d_t / d_x;
d_ty = d_t / d_y;
d_tz = d_t / d_z;
switch (mode)
{
case (mode_full):
ex = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ex, "fail to allocate memory for field ex");
ey = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ey, "fail to allocate memory for field ey");
ez = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ez, "fail to allocate memory for field ez");
hx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hx, "fail to allocate memory for field hx");
hy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hy, "fail to allocate memory for field hy");
hz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hz, "fail to allocate memory for field hz");
dx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dx, "fail to allocate memory for field dx");
dy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dy, "fail to allocate memory for field dy");
dz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dz, "fail to allocate memory for field dz");
bx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bx, "fail to allocate memory for field bx");
by = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(by, "fail to allocate memory for field by");
bz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bz, "fail to allocate memory for field bz");
dipole_ex = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ex, "fail to allocate memory for field dipole_ex");
dipole_ey = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ey, "fail to allocate memory for field dipole_ey");
dipole_ez = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ez, "fail to allocate memory for field dipole_ez");
dipole_hx = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hx, "fail to allocate memory for field dipole_hx");
dipole_hy = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hy, "fail to allocate memory for field dipole_hy");
dipole_hz = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hz, "fail to allocate memory for field dipole_hz");
break;
case (mode_tmx):
ex = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ex, "fail to allocate memory for field ex");
hy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hy, "fail to allocate memory for field hy");
hz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hz, "fail to allocate memory for field hz");
dx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dx, "fail to allocate memory for field dx");
by = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(by, "fail to allocate memory for field by");
bz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bz, "fail to allocate memory for field bz");
dipole_ex = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ex, "fail to allocate memory for field dipole_ex");
dipole_hy = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hy, "fail to allocate memory for field dipole_hy");
dipole_hz = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hz, "fail to allocate memory for field dipole_hz");
break;
case (mode_tmy):
ey = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ey, "fail to allocate memory for field ey");
hx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hx, "fail to allocate memory for field hx");
hz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hz, "fail to allocate memory for field hz");
dy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dy, "fail to allocate memory for field dy");
bx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bx, "fail to allocate memory for field bx");
bz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bz, "fail to allocate memory for field bz");
dipole_ey = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ey, "fail to allocate memory for field dipole_ey");
dipole_hx = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hx, "fail to allocate memory for field dipole_hx");
dipole_hz = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hz, "fail to allocate memory for field dipole_hz");
break;
case (mode_tmz):
ez = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ez, "fail to allocate memory for field ez");
hx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hx, "fail to allocate memory for field hx");
hy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hy, "fail to allocate memory for field hy");
dz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dz, "fail to allocate memory for field dz");
bx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bx, "fail to allocate memory for field bx");
by = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(by, "fail to allocate memory for field by");
dipole_ez = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ez, "fail to allocate memory for field dipole_ez");
dipole_hx = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hx, "fail to allocate memory for field dipole_hx");
dipole_hy = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hy, "fail to allocate memory for field dipole_hy");
break;
case (mode_tex):
hx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hx, "fail to allocate memory for field hx");
ey = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ey, "fail to allocate memory for field ey");
ez = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ez, "fail to allocate memory for field ez");
bx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bx, "fail to allocate memory for field bx");
dy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dy, "fail to allocate memory for field dy");
dz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dz, "fail to allocate memory for field dz");
dipole_hx = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hx, "fail to allocate memory for field dipole_hx");
dipole_ey = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ey, "fail to allocate memory for field dipole_ey");
dipole_ez = (double ***)mem3(type_double, total_x, total_y , total_z);
inspect(dipole_ez, "fail to allocate memory for field dipole_ez");
break;
case (mode_tey):
hy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hy, "fail to allocate memory for field hy");
ex = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ex, "fail to allocate memory for field ex");
ez = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ez, "fail to allocate memory for field ez");
by = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(by, "fail to allocate memory for field by");
dx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dx, "fail to allocate memory for field dx");
dz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dz, "fail to allocate memory for field dz");
dipole_hy = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hy, "fail to allocate memory for field dipole_hy");
dipole_ex = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ex, "fail to allocate memory for field dipole_ex");
dipole_ez = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ez, "fail to allocate memory for field dipole_ez");
break;
case (mode_tez):
hz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(hz, "fail to allocate memory for field hz");
ex = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ex, "fail to allocate memory for field ex");
ey = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(ey, "fail to allocate memory for field ey");
bz = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(bz, "fail to allocate memory for field bz");
dx = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dx, "fail to allocate memory for field dx");
dy = (double ***)mem3(type_double, total_x + 1, total_y + 1, total_z + 1);
inspect(dy, "fail to allocate memory for field dy");
dipole_hz = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_hz, "fail to allocate memory for field dipole_hz");
dipole_ex = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ex, "fail to allocate memory for field dipole_ex");
dipole_ey = (double ***)mem3(type_double, total_x, total_y, total_z);
inspect(dipole_ey, "fail to allocate memory for field dipole_ey");
break;
}
epsilon = (double ***)mem3(type_double, total_x, total_y, total_z);
temp = (double ***)h5_load3(file_name, "/materials/epsilon", total_x, total_y, total_z);
inspect(temp, "fail to load hdf5 dataset");
for (z = 0; z < total_z; z++)
for (y = 0; y < total_y; y++)
for (x = 0; x < total_x; x++)
{
epsilon[x][y][z] = temp[x][y][z] * EPSILON0;
}
return 1;
}
int get_partition(int x, int y, int z)
{
if (in_partition_y0(x, y, z)) return partition_y0;
if (in_partition_y1(x, y, z)) return partition_y1;
if (in_partition_x0(x, y, z)) return partition_x0;
if (in_partition_x1(x, y, z)) return partition_x1;
if (in_partition_z0(x, y, z)) return partition_z0;
if (in_partition_z1(x, y, z)) return partition_z1;
return partition_main;
}
int in_partition_x0(int x, int y, int z)
{
if ( x >= partition_data[partition_x0].x_start && x < partition_data[partition_x0].x_stop
&& y >= partition_data[partition_x0].y_start && y < partition_data[partition_x0].y_stop
&& z >= partition_data[partition_x0].z_start && z < partition_data[partition_x0].z_stop)
return 1;
return 0;
}
int in_partition_x1(int x, int y, int z)
{
if ( x >= partition_data[partition_x1].x_start && x < partition_data[partition_x1].x_stop
&& y >= partition_data[partition_x1].y_start && y < partition_data[partition_x1].y_stop
&& z >= partition_data[partition_x1].z_start && z < partition_data[partition_x1].z_stop)
return 1;
return 0;
}
int in_partition_y0(int x, int y, int z)
{
if ( x >= partition_data[partition_y0].x_start && x < partition_data[partition_y0].x_stop
&& y >= partition_data[partition_y0].y_start && y < partition_data[partition_y0].y_stop
&& z >= partition_data[partition_y0].z_start && z < partition_data[partition_y0].z_stop)
return 1;
return 0;
}
int in_partition_y1(int x, int y, int z)
{
if ( x >= partition_data[partition_y1].x_start && x < partition_data[partition_y1].x_stop
&& y >= partition_data[partition_y1].y_start && y < partition_data[partition_y1].y_stop
&& z >= partition_data[partition_y1].z_start && z < partition_data[partition_y1].z_stop)
return 1;
return 0;
}
int in_partition_z0(int x, int y, int z)
{
if ( x >= partition_data[partition_z0].x_start && x < partition_data[partition_z0].x_stop
&& y >= partition_data[partition_z0].y_start && y < partition_data[partition_z0].y_stop
&& z >= partition_data[partition_z0].z_start && z < partition_data[partition_z0].z_stop)
return 1;
return 0;
}
int in_partition_z1(int x, int y, int z)
{
if ( x >= partition_data[partition_z1].x_start && x < partition_data[partition_z1].x_stop
&& y >= partition_data[partition_z1].y_start && y < partition_data[partition_z1].y_stop
&& z >= partition_data[partition_z1].z_start && z < partition_data[partition_z1].z_stop)
return 1;
return 0;
}
int in_partition_main(int x, int y, int z)
{
if ( x >= partition_data[partition_main].x_start && x < partition_data[partition_main].x_stop
&& y >= partition_data[partition_main].y_start && y < partition_data[partition_main].y_stop
&& z >= partition_data[partition_main].z_start && z < partition_data[partition_main].z_stop)
return 1;
return 0;
}