-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpi_3D.cpp
445 lines (381 loc) · 16.3 KB
/
mpi_3D.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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#include<bits/stdc++.h>
#include<iostream>
#include<stdlib.h>
#include<fftw3.h>
#include<stdio.h>
#include<complex>
#include<iomanip>
#include<fftw3_mpi.h>
#include<mpi.h>
using namespace std;
int main(int argc,char* argv[])
{
const ptrdiff_t N1,N2,N3;
ptrdiff_t l_N1,l_N2,l_N3,l_s,n1,n2,n3,lsize;
MPI::Init(argc,argv);
fftw_mpi_init();
auto mpisize=MPI::COMM_WORLD.Get_size();
auto mpirank=MPI::COMM_WORLD.Get_rank();
double pi = 3.1428;
double L = 2*pi;
double dx = L/N1;
double dy = L/N2;
double dz = L/N3;
lsize = fftw_mpi_local_size(N1,N2,N1,MPI_COMM_WORLD,&l_N1,&l_N2,&l_s);
double kx;
double ky;
double kz;
double temp;
int Nt = 20;
double time;
double time_max=1;
double time_min=0;
double dt=0.1;
double v = 0.001;
//present components
double *ux = fftw_alloc_double(lsize);
double *uy = fftw_alloc_double(lsize);
double *uz = fftw_alloc_double(lsize);
//old components
double *ux_o = fftw_alloc_double(lsize);
double *uy_o = fftw_alloc_double(lsize);
double *uz_o = fftw_alloc_double(lsize);
double *dx_ux_o = fftw_alloc_double(lsize);
double *dy_ux_o = fftw_alloc_double(lsize);
double *dz_ux_o = fftw_alloc_double(lsize);
double *dx_uy_o = fftw_alloc_double(lsize);
double *dy_uy_o = fftw_alloc_double(lsize);
double *dz_uy_o = fftw_alloc_double(lsize);
double *dx_uz_o = fftw_alloc_double(lsize);
double *dy_uz_o = fftw_alloc_double(lsize);
double *dz_uz_o = fftw_alloc_double(lsize);
double *dxx_ux_o = fftw_alloc_double(lsize);
double *dyy_ux_o = fftw_alloc_double(lsize);
double *dzz_ux_o = fftw_alloc_double(lsize);
double *dxx_uy_o = fftw_alloc_double(lsize);
double *dyy_uy_o = fftw_alloc_double(lsize);
double *dzz_uy_o = fftw_alloc_double(lsize);
double *dxx_uz_o = fftw_alloc_double(lsize);
double *dyy_uz_o = fftw_alloc_double(lsize);
double *dzz_uz_o = fftw_alloc_double(lsize);
//we dont need fourier transforms of x1,x2 and x3 */
double *x1_o = fftw_alloc_double(lsize);
double *x2_o = fftw_alloc_double(lsize);
double *x3_o = fftw_alloc_double(lsize);
/* We will consider initial conditions are given by
ux_o(x,y,z) = (cosx)*(siny)*(cosz)
uy_o(x,y,z) = -(sinx)*(cosy)*(cosz)
uz_o(x,y,z) = (cosx)*sin(y)*sin(z)
* /
/*initialise the functions u_x_o , u_y_o and u_z_o.*/
for(n1=0;n1<l_N1;n1++)
{
for(n2=0;n2<N2;n2++)
{
for(n3=0;n3<N3;n3++)
{
ux_o[(l_s+n1)*n2*N3 + n3] = cos((l_s+n1)*dx)*sin(n2*dy)*cos(n3*dz);
uy_o[(l_s+n1)*n2*N3 + n3] = -sin((l_s+n1)*dx)*cos(n2*dy)*cos(n3*dz);
uz_o[(l_s+n1)*n2*N3 + n3] = cos((l_s+n1)*dx)*sin(n2*dy)*sin(n3*dz);
}
}
}
/* we will now define and allocate space to the fourier transforms of u_x , u_y and u_z */
fftw_complex *f_ux_o = fftw_alloc_complex(lsize) //fourier transform of u_x_o
fftw_complex *f_uy_o = fftw_alloc_complex(lsize); //fourier transform of u_y_o
fftw_complex *f_uz_o = fftw_alloc_complex(lsize); //fourier transform of u_z_o
fftw_complex *f_dx_ux_o = fftw_alloc_complex(lsize);
fftw_complex *f_dy_ux_o = fftw_alloc_complex(lsize);
fftw_complex *f_dz_ux_o = fftw_alloc_complex(lsize);
fftw_complex *f_dx_uy_o = fftw_alloc_complex(lsize);
fftw_complex *f_dy_uy_o = fftw_alloc_complex(lsize);
fftw_complex *f_dz_uy_o = fftw_alloc_complex(lsize);
fftw_complex *f_dx_uz_o = fftw_alloc_complex(lsize);
fftw_complex *f_dy_uz_o = fftw_alloc_complex(lsize);
fftw_complex *f_dz_uz_o = fftw_alloc_complex(lsize);
fftw_complex *f_dxx_ux_o = fftw_alloc_complex(lsize);
fftw_complex *f_dyy_ux_o = fftw_alloc_complex(lsize);
fftw_complex *f_dzz_ux_o = fftw_alloc_complex(lsize);
fftw_complex *f_dxx_uy_o = fftw_alloc_complex(lsize);
fftw_complex *f_dyy_uy_o = fftw_alloc_complex(lsize);
fftw_complex *f_dzz_uy_o = fftw_alloc_complex(lsize);
fftw_complex *f_dxx_uz_o = fftw_alloc_complex(lsize);
fftw_complex *f_dyy_uz_o = fftw_alloc_complex(lsize);
fftw_complex *f_dzz_uz_o = fftw_alloc_complex(lsize);
for(time=time_min+dt;time<=time_max;time=time+dt)
{
/*we have to calculate total 18 terms.Lets calculate the terms in order so that we dont
take confuse or miss any term. We will calculate first all the necessary terms required
to calculate x1 then x2 and x3 respectively.So we require 18 plans. */
fftw_plan a1;
a1 = fftw_plan_dft_r2c_3d(N1,N2,N3,ux_o,f_ux_o,MPI_COMM_WORLD,FFTW_ESTIMATE);
fftw_execute(a1);
fftw_plan a2;
a2 = fftw_plan_dft_r2c_3d(N1,N2,N3,uy_o,f_uy_o,MPI_COMM_WORLD,FFTW_ESTIMATE);
fftw_execute(a2);
fftw_plan a3;
a3 = fftw_plan_dft_r2c_3d(N1,N2,N3,uz_o,f_uz_o,MPI_COMM_WORLD,FFTW_ESTIMATE);
fftw_execute(a3);
/* we have all the fourier transforms of ux_o,uy_o and uz_o. We will now try to find
other terms. */
for(n1=0;n1<l_N1;n1++)
{
for(n2=0;n2<N2;n2++)
{
for(n3=0;n3<N3;n3++)
{
kx = (l_s+n1)*dx;
ky = n2*dy;
kz = n3*dz;
f_dxx_ux_o[(l_s+n1)*n2*N3+n3][0] = -(kx*kx)*(f_ux_o[(l_s+n1)*n2*N3+n3][0]);
f_dxx_ux_o[(l_s+n1)*n2*N3+n3][1] = -(kx*kx)*(f_ux_o[(l_s+n1)*n2*N3+n3][1]);
f_dyy_ux_o[(l_s+n1)*n2*N3+n3][0] = -(ky*ky)*(f_ux_o[(l_s+n1)*n2*N3+n3][0]);
f_dyy_ux_o[(l_s+n1)*n2*N3+n3][1] = -(ky*ky)*(f_ux_o[(l_s+n1)*n2*N3+n3][1]);
f_dzz_ux_o[(l_s+n1)*n2*N3+n3][0] = -(kz*kz)*(f_ux_o[(l_s+n1)*n2*N3+n3][0]);
f_dzz_ux_o[(l_s+n1)*n2*N3+n3][1] = -(kz*kz)*(f_ux_o[(l_s+n1)*n2*N3+n3][1]);
f_dxx_uy_o[(l_s+n1)*n2*N3+n3][0] = -(kx*kx)*(f_uy_o[(l_s+n1)*n2*N3+n3][0]);
f_dxx_uy_o[(l_s+n1)*n2*N3+n3][1] = -(kx*kx)*(f_uy_o[(l_s+n1)*n2*N3+n3][1]);
f_dyy_uy_o[(l_s+n1)*n2*N3+n3][0] = -(ky*ky)*(f_uy_o[(l_s+n1)*n2*N3+n3][0]);
f_dyy_uy_o[(l_s+n1)*n2*N3+n3][1] = -(ky*ky)*(f_uy_o[(l_s+n1)*n2*N3+n3][1]);
f_dzz_uy_o[(l_s+n1)*n2*N3+n3][0] = -(kz*kz)*(f_uy_o[(l_s+n1)*n2*N3+n3][0]);
f_dzz_uy_o[(l_s+n1)*n2*N3+n3][1] = -(kz*kz)*(f_uy_o[(l_s+n1)*n2*N3+n3][1]);
f_dxx_uz_o[(l_s+n1)*n2*N3+n3][0] = -(kx*kx)*(f_uz_o[(l_s+n1)*n2*N3+n3][0]);
f_dxx_uz_o[(l_s+n1)*n2*N3+n3][1] = -(kx*kx)*(f_uz_o[(l_s+n1)*n2*N3+n3][1]);
f_dyy_uz_o[(l_s+n1)*n2*N3+n3][0] = -(ky*ky)*(f_uz_o[(l_s+n1)*n2*N3+n3][0]);
f_dyy_uz_o[(l_s+n1)*n2*N3+n3][1] = -(ky*ky)*(f_uz_o[(l_s+n1)*n2*N3+n3][1]);
f_dzz_uz_o[(l_s+n1)*n2*N3+n3][0] = -(kz*kz)*(f_uz_o[(l_s+n1)*n2*N3+n3][0]);
f_dzz_uz_o[(l_s+n1)*n2*N3+n3][1] = -(kz*kz)*(f_uz_o[(l_s+n1)*n2*N3+n3][1]);
/* now will calculate the single derivative terms*/
/* derivatives of ux*/
f_dx_ux_o[(l_s+n1)*n2*N3+n3][0] = kx*(f_ux_o[(l_s+n1)*n2*N3+n3][0]);
f_dx_ux_o[(l_s+n1)*n2*N3+n3][1] = kx*(f_ux_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dx_ux_o[n1*n2*N3+n3][0];
f_dx_ux_o[(l_s+n1)*n2*N3+n3][0] = -f_dx_ux_o[(l_s+n1)*n2*N3+n3][1];
f_dx_ux_o[(l_s+n1)*n2*N3+n3][1] = temp;
f_dy_ux_o[(l_s+n1)*n2*N3+n3][0] = ky*(f_ux_o[(l_s+n1)*n2*N3+n3][0]);
f_dy_ux_o[(l_s+n1)*n2*N3+n3][1] = ky*(f_ux_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dy_ux_o[n1*n2*N3+n3][0];
f_dy_ux_o[(l_s+n1)*n2*N3+n3][0] = -f_dy_ux_o[(l_s+n1)*n2*N3+n3][1];
f_dy_ux_o[(l_s+n1)*n2*N3+n3][1] = temp;
f_dz_ux_o[(l_s+n1)*n2*N3+n3][0] = kz*(f_ux_o[(l_s+n1)*n2*N3+n3][0]);
f_dz_ux_o[(l_s+n1)*n2*N3+n3][1] = kz*(f_ux_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dz_ux_o[(l_s+n1)*n2*N3+n3][0];
f_dz_ux_o[(l_s+n1)*n2*N3+n3][0] = -f_dz_ux_o[(l_s+n1)*n2*N3+n3][1];
f_dz_ux_o[(l_s+n1)*n2*N3+n3][1] = temp;
/* derivatives of uy */
f_dx_uy_o[(l_s+n1)*n2*N3+n3][0] = kx*(f_uy_o[(l_s+n1)*n2*N3+n3][0]);
f_dx_uy_o[(l_s+n1)*n2*N3+n3][1] = kx*(f_uy_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dx_uy_o[(l_s+n1)*n2*N3+n3][0];
f_dx_uy_o[(l_s+n1)*n2*N3+n3][0] = -f_dx_uy_o[(l_s+n1)*n2*N3+n3][1];
f_dx_uy_o[(l_s+n1)*n2*N3+n3][1] = temp;
f_dy_uy_o[(l_s+n1)*n2*N3+n3][0] = ky*(f_uy_o[(l_s+n1)*n2*N3+n3][0]);
f_dy_uy_o[(l_s+n1)*n2*N3+n3][1] = ky*(f_uy_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dy_uy_o[(l_s+n1)*n2*N3+n3][0];
f_dy_uy_o[(l_s+n1)*n2*N3+n3][0] = -f_dy_uy_o[(l_s+n1)*n2*N3+n3][1];
f_dy_uy_o[(l_s+n1)*n2*N3+n3][1] = temp;
f_dz_uy_o[(l_s+n1)*n2*N3+n3][0] = kz*(f_uy_o[(l_s+n1)*n2*N3+n3][0]);
f_dz_uy_o[(l_s+n1)*n2*N3+n3][1] = kz*(f_uy_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dz_uy_o[(l_s+n1)*n2*N3+n3][0];
f_dz_uy_o[(l_s+n1)*n2*N3+n3][0] = -f_dz_uy_o[(l_s+n1)*n2*N3+n3][1];
f_dz_uy_o[(l_s+n1)*n2*N3+n3][1] = temp;
/* derivatives of uz*/
f_dx_uz_o[(l_s+n1)*n2*N3+n3][0] = kx*(f_uz_o[(l_s+n1)*n2*N3+n3][0]);
f_dx_uz_o[(l_s+n1)*n2*N3+n3][1] = kx*(f_uz_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dx_uz_o[(l_s+n1)*n2*N3+n3][0];
f_dx_uz_o[(l_s+n1)*n2*N3+n3][0] = -f_dx_uz_o[(l_s+n1)*n2*N3+n3][1];
f_dx_uz_o[(l_s+n1)*n2*N3+n3][1] = temp;
f_dy_uz_o[(l_s+n1)*n2*N3+n3][0] = ky*(f_uz_o[(l_s+n1)*n2*N3+n3][0]);
f_dy_uz_o[(l_s+n1)*n2*N3+n3][1] = ky*(f_uz_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dy_uz_o[(l_s+n1)*n2*N3+n3][0];
f_dy_uz_o[(l_s+n1)*n2*N3+n3][0] = -f_dy_uz_o[(l_s+n1)*n2*N3+n3][1];
f_dy_uz_o[(l_s+n1)*n2*N3+n3][1] = temp;
f_dz_uz_o[(l_s+n1)*n2*N3+n3][0] = kz*(f_uz_o[(l_s+n1)*n2*N3+n3][0]);
f_dz_uz_o[(l_s+n1)*n2*N3+n3][1] = kz*(f_uz_o[(l_s+n1)*n2*N3+n3][1]);
temp = f_dz_uz_o[(l_s+n1)*n2*N3+n3][0];
f_dz_uz_o[(l_s+n1)*n2*N3+n3][0] = -f_dz_uz_o[(l_s+n1)*n2*N3+n3][1];
f_dz_uz_o[(l_s+n1)*n2*N3+n3][1] = temp;
}
}
}
/* we have to now take the inverse fourier transforms */
fftw_plan a4 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dxx_ux_o,dxx_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a5 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dyy_ux_o,dyy_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a6 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dzz_ux_o,dzz_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a7 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dxx_uy_o,dxx_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a8 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dyy_uy_o,dyy_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a9 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dzz_uy_o,dzz_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a10 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dxx_uz_o,dxx_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a11 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dyy_uz_o,dyy_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a12 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dzz_uz_o,dzz_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a13 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dx_ux_o,dx_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a14 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dy_ux_o,dy_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a15 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dz_ux_o,dz_ux_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a16 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dx_uy_o,dx_uy_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a17 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dy_uy_o,dy_uy_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a18 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dz_uy_o,dz_uy_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a19 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dx_uz_o,dx_uz_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a20 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dy_uz_o,dy_uz_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
fftw_plan a21 = fftw_mpi_plan_dft_c2r_3d(N1,N2,N3,f_dz_uz_o,dz_uz_o,MPI_COMM_WORLD,
FFTW_ESTIMATE);
/* we have to now execute all these plans one by one. */
fftw_execute(a4);
fftw_execute(a5);
fftw_execute(a6);
fftw_execute(a7);
fftw_execute(a8);
fftw_execute(a9);
fftw_execute(a10);
fftw_execute(a11);
fftw_execute(a12);
fftw_execute(a13);
fftw_execute(a14);
fftw_execute(a15);
fftw_execute(a16);
fftw_execute(a17);
fftw_execute(a18);
fftw_execute(a19);
fftw_execute(a20);
fftw_execute(a21);
/*normalising all the terms obtained by inverse fourier transforms. */
for(int n1=0;n1<N1;n1++)
{
for(int n2=0;n2<N2;n2++)
{
for(int n3=0;n3<N3;n3++)
{
dx_ux_o[(l_s+n1)*n2*N3 + n3] = dx_ux_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dy_ux_o[(l_s+n1)*n2*N3 + n3] = dy_ux_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dz_ux_o[(l_s+n1)*n2*N3 + n3] = dz_ux_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dxx_ux_o[(l_s+n1)*n2*N3 + n3] = dxx_ux_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dyy_ux_o[(l_s+n1)*n2*N3 + n3] = dyy_ux_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dzz_ux_o[(l_s+n1)*n2*N3 + n3] = dzz_ux_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dx_uy_o[(l_s+n1)*n2*N3 + n3] = dx_uy_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dy_uy_o[(l_s+n1)*n2*N3 + n3] = dy_uy_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dz_uy_o[(l_s+n1)*n2*N3 + n3] = dz_uy_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dxx_uy_o[(l_s+n1)*n2*N3 + n3] = dxx_uy_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dyy_uy_o[(l_s+n1)*n2*N3 + n3] = dyy_uy_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dzz_uy_o[(l_s+n1)*n2*N3 + n3] = dzz_uy_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dx_uz_o[(l_s+n1)*n2*N3 + n3] = dx_uz_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dy_uz_o[(l_s+n1)*n2*N3 + n3] = dy_uz_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dz_uz_o[(l_s+n1)*n2*N3 + n3] = dz_uz_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dxx_uz_o[(l_s+n1)*n2*N3 + n3] = dxx_uz_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dyy_uz_o[(l_s+n1)*n2*N3 + n3] = dyy_uz_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
dzz_uz_o[(l_s+n1)*n2*N3 + n3] = dzz_uz_o[(l_s+n1)*n2*N3 + n3]/(float(N1)*float(N2)*float(N3));
}
}
}
/* calculating x1_o , x2_o and x3_o */
for(n1=0;n1<l_N1;n1++)
{
for(n2=0;n2<N2;n2++)
{
for(n3=0;n3<N3;n3++)
{
x1_o[(l_s+n1)*n2*N3+n3] = v*(dxx_ux_o[(l_s+n1)*n2*N3+n3]+
dyy_ux_o[(l_s+n1)*n2*N3+n3]+dzz_ux_o[(l_s+n1)*n2*N3+n3]);
x1_o[(l_s+n1)*n2*N3+n3] = x1_o[(l_s+n1)*n2*N3+n3] -
(ux_o[(l_s+n1)*n2*N3+n3]*dx_ux_o[(l_s+n1)*n2*N3+n3]);
x1_o[(l_s+n1)*n2*N3+n3] = x1_o[(l_s+n1)*n2*N3+n3] -
(uy_o[(l_s+n1)*n2*N3+n3]*dy_ux_o[(l_s+n1)*n2*N3+n3]);
x1_o[(l_s+n1)*n2*N3+n3] = x1_o[(l_s+n1)*n2*N3+n3] -
(uz_o[(l_s+n1)*n2*N3+n3]*dz_ux_o[(l_s+n1)*n2*N3+n3]);
x2_o[(l_s+n1)*n2*N3+n3] = v*(dxx_uy_o[n1*n2*N3+n3]+dyy_uy_o[n1*n2*N3+n3]+
dzz_uy_o[n1*n2*N3+n3]);
x2_o[(l_s+n1)*n2*N3+n3] = x2_o[n1*n2*N3+n3] - (ux_o[n1*n2*N3+n3]*dx_uy_o[n1*n2*N3+n3]);
x2_o[(l_s+n1)*n2*N3+n3] = x2_o[n1*n2*N3+n3] - (uy_o[n1*n2*N3+n3]*dy_uy_o[n1*n2*N3+n3]);
x2_o[(l_s+n1)*n2*N3+n3] = x2_o[n1*n2*N3+n3] - (uz_o[n1*n2*N3+n3]*dz_uy_o[n1*n2*N3+n3]);
x3_o[(l_s+n1)*n2*N3+n3] = v*(dxx_uz_o[(l_s+n1)*n2*N3+n3]+dyy_uz_o[(l_s+n1)*n2*N3+n3]+
dzz_uz_o[(l_s+n1)*n2*N3+n3]);
x3_o[(l_s+n1)*n2*N3+n3] = x3_o[(l_s+n1)*n2*N3+n3] -
(ux_o[(l_s+n1)*n2*N3+n3]*dx_uz_o[(l_s+n1)*n2*N3+n3]);
x3_o[(l_s+n1)*n2*N3+n3] = x3_o[(l_s+n1)*n2*N3+n3] -
(uy_o[(l_s+n1)*n2*N3+n3]*dy_uz_o[(l_s+n1)*n2*N3+n3]);
x3_o[(l_s+n1)*n2*N3+n3] = x3_o[(l_s+n1)*n2*N3+n3] -
(uz_o[(l_s+n1)*n2*N3+n3]*dz_uz_o[(l_s+n1)*n2*N3+n3]);
}
}
}
/*calculating the velocitys at present time */
for(n1=0;n1<l_N1;n1++)
{
for(n2=0;n2<N2;n2++)
{
for(n3=0;n3<N3;n3++)
{
ux[(l_s+n1)*n2*N3+n3] = ux_o[(l_s+n1)*n2*N3+n3] + ((x1_o[(l_s+n1)*n2*N3+n3])*dt);
uy[(l_s+n1)*n2*N3+n3] = uy_o[(l_s+n1)*n2*N3+n3] + ((x2_o[(l_s+n1)*n2*N3+n3])*dt);
uz[(l_s+n1)*n2*N3+n3] = uz_o[(l_s+n1)*n2*N3+n3] + ((x3_o[(l_s+n1)*n2*N3+n3])*dt);
//we can copy all the components into some file here
}
}
}
cout<<"time:"<<time<<endl;
cout<<"n1"<<"\t"<<setw(12)<<"n2"<<"\t"<<setw(12)<<"n3"<<"\t"<<setw(12)<<"ux"<<"\t"<<
setw(12)<<"uy"<<"\t"<<setw(12)<<"uz"<<endl;
for(n1=0;n1<l_N1;n1++)
{
for(n2=0;n2<N2;n2++)
{
for(n3=0;n3<N3;n3++)
{
cout<<n1<<"\t"<<setw(12)<<n2<<"\t"<<setw(12)<<n3<<"\t"<<setw(12)<<ux[(l_s+n1)*n2*N3+n3]
<<"\t"<<setw(12)<<uy[(l_s+n1)*n2*N3+n3]<<"\t"<<setw(12)<<uz[(l_s+n1)*n2*N3+n3]<<endl;
}
}
}
/*assign the present components to the old one's */
for(n1=0;n1<l_N1;n1++)
{
for(n2=0;n2<N2;n2++)
{
for(n3=0;n3<N3;n3++)
{
ux_o[(l_s+n1)*n2*N3+n3] = ux[(l_s+n1)*n2*N3+n3];
uy_o[(l_s+n1)*n2*N3+n3] = uy[(l_s+n1)*n2*N3+n3];
uz_o[(l_s+n1)*n2*N3+n3] = uz[(l_s+n1)*n2*N3+n3];
}
}
}
/* we have to destroy all the plans which we have created till now.*/
fftw_destroy_plan(a1);
fftw_destroy_plan(a2);
fftw_destroy_plan(a3);
fftw_destroy_plan(a4);
fftw_destroy_plan(a5);
fftw_destroy_plan(a6);
fftw_destroy_plan(a7);
fftw_destroy_plan(a8);
fftw_destroy_plan(a9);
fftw_destroy_plan(a10);
fftw_destroy_plan(a11);
fftw_destroy_plan(a12);
fftw_destroy_plan(a13);
fftw_destroy_plan(a14);
fftw_destroy_plan(a15);
fftw_destroy_plan(a16);
fftw_destroy_plan(a17);
fftw_destroy_plan(a18);
fftw_destroy_plan(a19);
fftw_destroy_plan(a20);
fftw_destroy_plan(a21);
}
MPI::finalize();
return 0;
}