-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdump_types_vec.cpp
executable file
·350 lines (297 loc) · 10.4 KB
/
dump_types_vec.cpp
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
#include "dumps.h"
#include "solver.h"
dump_type_empty_class :: ~dump_type_empty_class()
{
fclose(dumpfid);
}
void dump_type_empty_class :: init_dumpfile(FILE* optfid, int i)
{
char filenamebuf[200];
load_namednumstringn(optfid, "DUMP_FILENAME", filenamebuf, i, 200, false);
if (ISMASTER)
printf("\nInitializing dump file %s (tN=%d, xN=%d, yN=%d, zN=%d)...", filenamebuf, tN, xN, yN, zN);
init_dumpfile(filenamebuf);
if (ISMASTER) {printf("Done."); }
}
void dump_type_empty_class :: init_dumpfile(const char* filename)
{
const char dumpstandard_name[] = "UDF1.0";
int float_size = sizeof(float_type);
if (ISMASTER)
{
dumpfid = fopen(filename, "wb");
if (!dumpfid)
{
printf("\nvoid dump_type_empty_class :: init_dumpfile: Unable to open file %s for writing.",filename);
perror("Unable to open file!"); fflush(stdout);
throw "void dump_type_empty_class :: init_dumpfile : Unable to open file!";
}
fwrite(dumpstandard_name, sizeof(char), strlen(dumpstandard_name)+1, dumpfid);
fwrite(&float_size, sizeof(int), 1, dumpfid);
fwrite(&iscomplex, sizeof(int), 1, dumpfid);
fwrite(&tN, sizeof(int), 1, dumpfid);
fwrite(&xN, sizeof(int), 1, dumpfid);
fwrite(&yN, sizeof(int), 1, dumpfid);
fwrite(&zN, sizeof(int), 1, dumpfid);
fclose(dumpfid);
}
#ifdef __ENABLE_MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
dumpfid=fopen(filename, "r+b");
header_ofs = sizeof(char)*(strlen(dumpstandard_name)+1) + 6*sizeof(int);
}
void dump_type_empty_class :: dump()
{
dump_noflush();
fflush(dumpfid);
}
void dump_type_empty_class :: dump_write(void* buf)
{
size_t ofs = header_ofs;
if (iscomplex) ofs += fileofs()*sizeof(f_complex); else ofs += fileofs()*sizeof(float_type);
fseeko(dumpfid, ofs, SEEK_SET);
if (iscomplex) fwrite(buf, sizeof(f_complex) , piece_size, dumpfid);
else fwrite(buf, sizeof(float_type), piece_size, dumpfid);
}
dump_type_full_class :: dump_type_full_class(FILE* fid, int num)
{
xN = N_X; yN=N_Y; zN=N_Z; tN=2*N_T;
piece_size = xN*tN*MY_NY;
iscomplex = 1;
init_dumpfile(fid, num);
}
size_t dump_type_full_class :: fileofs()
{
return tN*xN*(yN*((size_t)n_Z) + ((size_t)MY_NYstart));
}
void dump_type_full_class :: dump_noflush()
{
fftw(FFT_BWPLAN_T, N_X*MY_NY, (fftwt_complex*)FIELD, 2,2*N_T, (fftwt_complex*)BIGBUFFER1, 2,2*N_T);
fftw(FFT_BWPLAN_T, N_X*MY_NY, (fftwt_complex*)(FIELD+1), 2,2*N_T, (fftwt_complex*)(BIGBUFFER1+1), 2,2*N_T); fftwt_Nnormalize(2*N_X*MY_NY, BIGBUFFER1);
dump_write(BIGBUFFER1);
}
dump_type_maxI_class :: dump_type_maxI_class(FILE* fid, int num)
{
xN = N_X; yN=N_Y; zN=N_Z; tN=1;
piece_size = xN*MY_NY;
iscomplex = 0;
init_dumpfile(fid, num);
wfilter = (f_complex*)malloc_ch(2*sizeof(f_complex)*N_T);
char filtertype[100]; load_namednumstringn(fid, "FILTER_TYPE", filtertype, num, 100, "true", "NO");
create_wfilter(wfilter, filtertype);
}
dump_type_maxI_class :: ~dump_type_maxI_class()
{
free(wfilter);
}
size_t dump_type_maxI_class :: fileofs()
{
return xN*(yN*n_Z+MY_NYstart);
}
void dump_type_maxI_class :: dump_noflush()
{
float_type* buf = (float_type*)BIGBUFFER1;
for(int ny=0; ny<MY_NY; ny++) for(int nx=0; nx<N_X; nx++)
{
int ofs = 2*N_T*(nx+N_X*ny);
for(int nw=0; nw<2*N_T; nw++) NL_SMALLBUFFER1[nw]=FIELD[ofs+nw]*wfilter[nw];
fftw(FFT_BWPLAN_T, 2, (fftwt_complex*)NL_SMALLBUFFER1, 2, 1, (fftwt_complex*)(BIGBUFFER1+ofs), 2, 1);
}
fftwt_Nnormalize(2*N_X*MY_NY, BIGBUFFER1);
for(int ny=0; ny<MY_NY; ny++) for(int nx=0; nx<N_X; nx++)
{
float_type maxI=0;
for(int nt=0; nt<N_T; nt++)
{
int ofs = 2*(nt + N_T*(nx+N_X*ny)); maxI = max(maxI, abs2(BIGBUFFER1[ofs])+abs2(BIGBUFFER1[ofs+1]));
}
buf[nx+N_X*ny] = maxI;
}
dump_write(buf);
}
void dump_type_flux_class :: dump_noflush()
{
// TODO: Compare results for frequency- and time-domain integration
float_type* buf = (float_type*)BIGBUFFER1;
for(int ny=0; ny<MY_NY; ny++) for(int nx=0; nx<N_X; nx++)
{
int ofs = 2*N_T*(nx+N_X*ny);
for(int nw=0; nw<2*N_T; nw++) NL_SMALLBUFFER1[nw]=FIELD[ofs+nw]*wfilter[nw];
fftw(FFT_BWPLAN_T, 1, (fftwt_complex*)NL_SMALLBUFFER1, 1, N_T, (fftwt_complex*)(BIGBUFFER1+ofs), 1, N_T);
}
fftwt_Nnormalize(N_X*MY_NY, BIGBUFFER1);
for(int ny=0; ny<MY_NY; ny++) for(int nx=0; nx<N_X; nx++)
{
float_type f=0;
for(int nt=0; nt<2*N_T; nt++)
{
int ofs = nt + N_T*(nx+N_X*ny); f+=abs2(BIGBUFFER1[ofs]);
}
buf[nx+N_X*ny] = f*TSTEP;
}
dump_write(buf);
}
void dump_type_ysection_class :: init_ny(FILE* optfid, int num)
{
ny = load_namednumint(optfid, "DUMP_NY", num, true, N_Y/2);
ny -= MY_NYstart; if (0 <= ny && ny < MY_NY) mydump=true; else mydump=false;
}
dump_type_ysection_class :: dump_type_ysection_class(FILE* optfid, int num)
{
tN=2*N_T; xN = N_X; yN=1; zN=N_Z;
piece_size=tN*xN; iscomplex=1;
init_dumpfile(optfid, num);
init_ny(optfid, num);
}
size_t dump_type_ysection_class :: fileofs()
{
return piece_size*n_Z;
}
void dump_type_ysection_class :: dump_noflush()
{
if (mydump)
{
fftw(FFT_BWPLAN_T, N_X, (fftwt_complex*)FIELD+2*N_T*N_X*ny, 2,2*N_T, (fftwt_complex*)BIGBUFFER1, 2,2*N_T);
fftw(FFT_BWPLAN_T, N_X, (fftwt_complex*)FIELD+2*N_T*N_X*ny+1, 2,2*N_T, (fftwt_complex*)BIGBUFFER1+1, 2,2*N_T);
fftwt_Nnormalize(N_X, BIGBUFFER1);
dump_write(BIGBUFFER1);
}
}
dump_type_ysection_maxI_class :: dump_type_ysection_maxI_class(FILE* optfid, int num)
{
throw "TODO: vector version";
tN=1; xN = N_X; yN=1; zN=N_Z;
piece_size=xN; iscomplex=0;
init_dumpfile(optfid, num);
init_ny(optfid, num);
wfilter = (f_complex*)malloc_ch(sizeof(f_complex)*N_T);
char filtertype[100]; load_namednumstringn(optfid, "FILTER_TYPE", filtertype, num, 100, "true", "NO");
create_wfilter(wfilter, filtertype);
}
dump_type_ysection_maxI_class :: ~dump_type_ysection_maxI_class()
{
free(wfilter);
}
void dump_type_ysection_maxI_class :: dump_noflush()
{
if (mydump)
{
float_type* buf = (float_type*)BIGBUFFER1;
fftw(FFT_BWPLAN_T, N_X, (fftwt_complex*)FIELD+N_T*N_X*ny, 1,N_T, (fftwt_complex*)BIGBUFFER1, 1,N_T); fftwt_Nnormalize(N_X, BIGBUFFER1);
for (int nx=0; nx<N_X; nx++)
{
float_type maxI = 0;
for (int nt=0; nt<N_T; nt++) maxI=max(maxI, abs2(BIGBUFFER1[nt+N_T*nx]));
buf[nx] = maxI;
}
dump_write(buf);
}
}
void dump_type_ysection_flux_class :: dump_noflush()
{
if (mydump)
{
float_type* buf = (float_type*)BIGBUFFER1;
fftw(FFT_BWPLAN_T, N_X, (fftwt_complex*)FIELD+N_T*N_X*ny, 1,N_T, (fftwt_complex*)BIGBUFFER1, 1,N_T); fftwt_Nnormalize(N_X, BIGBUFFER1);
for (int nx=0; nx<N_X; nx++)
{
float_type f = 0;
for (int nt=0; nt<N_T; nt++) f+=abs2(BIGBUFFER1[nt+N_T*nx]);
buf[nx] = f*TSTEP;
}
dump_write(buf);
}
}
dump_type_full_plasma_class :: dump_type_full_plasma_class(FILE* fid, int num)
{
throw "TODO: vector version";
xN = N_X; yN=N_Y; zN=N_Z; tN=N_T;
piece_size = xN*tN*MY_NY;
iscomplex = 0;
init_dumpfile(fid, num);
}
void dump_type_full_plasma_class :: dump_noflush()
{
float_type* b1 = (float_type*)BIGBUFFER1;
float_type* nlb1 = (float_type*)NL_SMALLBUFFER1;
fftw(FFT_BWPLAN_T, N_X*MY_NY, (fftwt_complex*)FIELD, 1, N_T, (fftwt_complex*)BIGBUFFER1, 1,N_T); fftwt_Nnormalize(N_X*MY_NY, BIGBUFFER1);
//The following code appears somewhat weird, since it takes field values from BIGBUFFER 1
// and calculates plasma density also in BIGBUFFER1. However, this allows to save the memory space
// required and not to use BIGBUFFER2, which contains field x-y Fourier transform and should not be modified.
calculate_plasmadensity_small_2float(BIGBUFFER1, nlb1); memcpy(b1, nlb1, N_T*sizeof(float_type));
calculate_plasmadensity_2float(BIGBUFFER1+N_T, b1+N_T, N_X*MY_NY-1);
dump_write(BIGBUFFER2);
}
dump_type_plasma_max_class :: dump_type_plasma_max_class(FILE* optfid, int num)
{
throw "TODO: vector version";
xN=N_X; yN=N_Y; tN=1; zN=N_Z;
piece_size = xN*tN*MY_NY;
iscomplex = 0;
init_dumpfile(optfid, num);
}
void dump_type_plasma_max_class :: dump_noflush()
{
throw "TODO: vector version";
float_type* b1 = (float_type*)BIGBUFFER1;
float_type* nlb = (float_type*)NL_SMALLBUFFER1;
fftw(FFT_BWPLAN_T, N_X*MY_NY, (fftwt_complex*)FIELD, 1, N_T, (fftwt_complex*)BIGBUFFER1, 1,N_T); fftwt_Nnormalize(N_X*MY_NY, BIGBUFFER1);
calculate_maxplasmadensity_2float(BIGBUFFER1, (float_type*)BIGBUFFER1, N_X*MY_NY);
/*for (int ny=0; ny<MY_NY; ny++)
for (int nx=0; nx<N_X; nx++)
{
float_type maxro = 0;
int ofs1 = (nx+N_X*ny);
calculate_plasmadensity_small_2float(BIGBUFFER1 + N_T*ofs1, nlb);
for (int nt=0; nt<N_T; nt++) maxro = max(maxro, nlb[nt]);
b1[ofs1] = maxro;
}*/
dump_write(b1);
}
dump_type_ysection_plasma_class :: dump_type_ysection_plasma_class(FILE* optfid, int num)
{
throw "TODO: vector version";
tN=N_T; xN = N_X; yN=1; zN=N_Z;
piece_size=tN*xN; iscomplex=0;
init_dumpfile(optfid, num);
ny = load_namednumint(optfid, "DUMP_NY", num, true, N_Y/2);
ny -= MY_NYstart; if (0 <= ny && ny < MY_NY) mydump=true; else mydump=false;
}
void dump_type_ysection_plasma_class :: dump_noflush()
{
if (mydump)
{
float_type* b = (float_type*)BIGBUFFER1;
//float_type* nlb = (float_type*)NL_SMALLBUFFER1;
fftw(FFT_BWPLAN_T, N_X, (fftwt_complex*)FIELD+N_T*N_X*ny, 1,N_T, (fftwt_complex*)BIGBUFFER1, 1,N_T); fftwt_Nnormalize(N_X, BIGBUFFER1);
//calculate_plasmadensity_small_2float(BIGBUFFER1, nlb); memcpy(b, nlb, N_T*sizeof(float_type));
calculate_plasmadensity_2float(BIGBUFFER1, b, N_X);
dump_write(b);
}
}
dump_type_ysection_plasma_max_class :: dump_type_ysection_plasma_max_class(FILE* optfid, int num)
{
throw "TODO: vector version";
tN=1; xN = N_X; yN=1; zN=N_Z;
piece_size=tN*xN; iscomplex=0;
init_dumpfile(optfid, num);
init_ny(optfid, num);
}
void dump_type_ysection_plasma_max_class :: dump_noflush()
{
if (mydump)
{
float_type* b = (float_type*)BIGBUFFER1;
float_type* nlb = (float_type*)NL_SMALLBUFFER1;
fftw(FFT_BWPLAN_T, N_X, (fftwt_complex*)FIELD+N_T*N_X*ny, 1,N_T, (fftwt_complex*)BIGBUFFER1, 1,N_T); fftwt_Nnormalize(N_X, BIGBUFFER1);
for (int nx=0; nx<N_X; nx++)
{
float_type maxro = 0;
calculate_plasmadensity_small_2float(BIGBUFFER1+N_T*nx, nlb);
for (int nt=0; nt<N_T; nt++) maxro = max(maxro, nlb[nt]);
b[nx]=maxro;
}
dump_write(b);
}
}