Bridge++  Ver. 1.3.x
shiftField_lex_imp.cpp
Go to the documentation of this file.
1 
15 #include "shiftField_lex.h"
16 
17 #include <vector>
18 
19 #include "bridgeIO.h"
20 using Bridge::vout;
21 
22 //====================================================================
24  const int mu)
25 {
26  int bc = 1;
27 
28  if (mu == 0) { // x-direction
29  up_x(&v, &w, bc);
30  } else if (mu == 1) {
31  up_y(&v, &w, bc);
32  } else if (mu == 2) {
33  up_z(&v, &w, bc);
34  } else if (mu == 3) {
35  up_t(&v, &w, bc);
36  } else {
37  vout.crucial("Shift_Field_lex: parameter error, wrong parameter\n");
38  exit(EXIT_FAILURE);
39  }
40 }
41 
42 
43 //====================================================================
45  const int mu)
46 {
47  int bc = 1;
48 
49  if (mu == 0) {
50  dn_x(&v, &w, bc);
51  } else if (mu == 1) {
52  dn_y(&v, &w, bc);
53  } else if (mu == 2) {
54  dn_z(&v, &w, bc);
55  } else if (mu == 3) {
56  dn_t(&v, &w, bc);
57  } else {
58  vout.crucial("Shift_Field_lex: parameter error, wrong parameter\n");
59  exit(EXIT_FAILURE);
60  }
61 }
62 
63 
64 //====================================================================
66  const int bc, const int mu)
67 {
68  if (mu == 0) { // x-direction
69  up_x(&v, &w, bc);
70  } else if (mu == 1) {
71  up_y(&v, &w, bc);
72  } else if (mu == 2) {
73  up_z(&v, &w, bc);
74  } else if (mu == 3) {
75  up_t(&v, &w, bc);
76  } else {
77  vout.crucial("Shift_Field_lex: parameter error, wrong parameter\n");
78  exit(EXIT_FAILURE);
79  }
80 }
81 
82 
83 //====================================================================
85  const int bc, const int mu)
86 {
87  if (mu == 0) {
88  dn_x(&v, &w, bc);
89  } else if (mu == 1) {
90  dn_y(&v, &w, bc);
91  } else if (mu == 2) {
92  dn_z(&v, &w, bc);
93  } else if (mu == 3) {
94  dn_t(&v, &w, bc);
95  } else {
96  vout.crucial("Shift_Field_lex: parameter error, wrong parameter\n");
97  exit(EXIT_FAILURE);
98  }
99 }
100 
101 
102 //====================================================================
103 void ShiftField_lex::up_x(Field *v, const Field *w, const int bc)
104 {
105  double bc2;
106 
107  if (Communicator::ipe(0) == 0) {
108  bc2 = bc;
109  } else {
110  bc2 = 1.0;
111  }
112 
113  int Nin = w->nin();
114  int Nex = w->nex();
115  int Nvol = w->nvol();
116  int Nvol2 = Nvol / Nx;
117 
118  double *vp = v->ptr(0);
119  const double *wp = w->ptr(0);
120 
121  std::vector<double> wt(Nin * Nvol2 * Nex);
122  std::vector<double> vt(Nin * Nvol2 * Nex);
123 
124  for (int s2 = 0; s2 < Ny * Nz * Nt; s2++) {
125  // bulk
126  for (int x = 0; x < Nx - 1; x++) {
127  int ix = x + Nx * s2;
128  int px = ix + 1;
129  for (int ex = 0; ex < Nex; ex++) {
130  for (int in = 0; in < Nin; in++) {
131  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
132  }
133  }
134  }
135 
136  // boundary (x=Nx-1)
137  int px = Nx * s2;
138  // int ix = Nx - 1 + px;
139  for (int ex = 0; ex < Nex; ex++) {
140  for (int in = 0; in < Nin; in++) {
141  wt[in + Nin * (s2 + Nvol2 * ex)] = bc2 * wp[in + Nin * (px + Nvol * ex)];
142  }
143  }
144  }
145 
146  int size = Nin * Nvol2 * Nex;
147  Communicator::exchange(size, &vt[0], &wt[0], 0, 1, 0);
148 
149  for (int s2 = 0; s2 < Ny * Nz * Nt; s2++) {
150  // boundary (x=Nx-1)
151  int px = Nx * s2;
152  int ix = Nx - 1 + px;
153  for (int in = 0; in < Nin; in++) {
154  for (int ex = 0; ex < Nex; ex++) {
155  vp[in + Nin * (ix + Nvol * ex)] = vt[in + Nin * (s2 + Nvol2 * ex)];
156  }
157  }
158  }
159 }
160 
161 
162 //====================================================================
163 void ShiftField_lex::dn_x(Field *v, const Field *w, const int bc)
164 {
165  double bc2;
166 
167  if (Communicator::ipe(0) == 0) {
168  bc2 = bc;
169  } else {
170  bc2 = 1.0;
171  }
172 
173  int Nin = w->nin();
174  int Nex = w->nex();
175  int Nvol = w->nvol();
176  int Nvol2 = Nvol / Nx;
177 
178  double *vp = v->ptr(0);
179  const double *wp = w->ptr(0);
180 
181  std::vector<double> wt(Nin * Nvol2 * Nex);
182  std::vector<double> vt(Nin * Nvol2 * Nex);
183 
184  for (int s2 = 0; s2 < Ny * Nz * Nt; s2++) {
185  // bulk
186  for (int x = 1; x < Nx; x++) {
187  int ix = x + Nx * s2;
188  int px = ix - 1;
189  for (int ex = 0; ex < Nex; ex++) {
190  for (int in = 0; in < Nin; in++) {
191  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
192  }
193  }
194  }
195 
196  // boundary (x=0)
197  int px = Nx - 1 + Nx * s2;
198  for (int ex = 0; ex < Nex; ex++) {
199  for (int in = 0; in < Nin; in++) {
200  wt[in + Nin * (s2 + Nvol2 * ex)] = wp[in + Nin * (px + Nvol * ex)];
201  }
202  }
203  }
204 
205  int size = Nin * Nvol2 * Nex;
206  Communicator::exchange(size, &vt[0], &wt[0], 0, -1, 4);
207 
208  for (int s2 = 0; s2 < Ny * Nz * Nt; s2++) {
209  // boundary (x=0)
210  int ix = Nx * s2;
211  for (int ex = 0; ex < Nex; ex++) {
212  for (int in = 0; in < Nin; in++) {
213  vp[in + Nin * (ix + Nvol * ex)] = bc2 * vt[in + Nin * (s2 + Nvol2 * ex)];
214  }
215  }
216  }
217 }
218 
219 
220 //====================================================================
221 void ShiftField_lex::up_y(Field *v, const Field *w, const int bc)
222 {
223  double bc2;
224 
225  if (Communicator::ipe(1) == 0) {
226  bc2 = bc;
227  } else {
228  bc2 = 1.0;
229  }
230 
231  int Nin = w->nin();
232  int Nex = w->nex();
233  int Nvol = w->nvol();
234  int Nvol2 = Nvol / Ny;
235 
236  double *vp = v->ptr(0);
237  const double *wp = w->ptr(0);
238 
239  std::vector<double> wt(Nin * Nvol2 * Nex);
240  std::vector<double> vt(Nin * Nvol2 * Nex);
241 
242  for (int zt = 0; zt < Nz * Nt; zt++) {
243  for (int x = 0; x < Nx; x++) {
244  int s1 = x + Nx * Ny * zt;
245  int s2 = x + Nx * zt;
246 
247  // bulk
248  for (int y = 0; y < Ny - 1; y++) {
249  int ix = s1 + Nx * y;
250  int px = ix + Nx;
251  for (int ex = 0; ex < Nex; ex++) {
252  for (int in = 0; in < Nin; in++) {
253  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
254  }
255  }
256  }
257 
258  // boundary (y=Ny-1)
259  int px = s1;
260  for (int ex = 0; ex < Nex; ex++) {
261  for (int in = 0; in < Nin; in++) {
262  wt[in + Nin * (s2 + Nvol2 * ex)] = bc2 * wp[in + Nin * (px + Nvol * ex)];
263  }
264  }
265  }
266  }
267 
268  int size = Nin * Nvol2 * Nex;
269  Communicator::exchange(size, &vt[0], &wt[0], 1, 1, 1);
270 
271  for (int zt = 0; zt < Nz * Nt; zt++) {
272  for (int x = 0; x < Nx; x++) {
273  int s1 = x + Nx * Ny * zt;
274  int s2 = x + Nx * zt;
275 
276  // boundary (y=Ny-1)
277  int ix = s1 + Nx * (Ny - 1);
278  for (int ex = 0; ex < Nex; ex++) {
279  for (int in = 0; in < Nin; in++) {
280  vp[in + Nin * (ix + Nvol * ex)] = vt[in + Nin * (s2 + Nvol2 * ex)];
281  }
282  }
283  }
284  }
285 }
286 
287 
288 //====================================================================
289 void ShiftField_lex::dn_y(Field *v, const Field *w, const int bc)
290 {
291  double bc2;
292 
293  if (Communicator::ipe(1) == 0) {
294  bc2 = bc;
295  } else {
296  bc2 = 1.0;
297  }
298 
299  int Nin = w->nin();
300  int Nex = w->nex();
301  int Nvol = w->nvol();
302  int Nvol2 = Nvol / Ny;
303 
304  double *vp = v->ptr(0);
305  const double *wp = w->ptr(0);
306 
307  std::vector<double> wt(Nin * Nvol2 * Nex);
308  std::vector<double> vt(Nin * Nvol2 * Nex);
309 
310  for (int zt = 0; zt < Nz * Nt; zt++) {
311  for (int x = 0; x < Nx; x++) {
312  int s1 = x + Nx * Ny * zt;
313  int s2 = x + Nx * zt;
314 
315  // bulk
316  for (int y = 1; y < Ny; y++) {
317  int ix = s1 + Nx * y;
318  int px = ix - Nx;
319  for (int ex = 0; ex < Nex; ex++) {
320  for (int in = 0; in < Nin; in++) {
321  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
322  }
323  }
324  }
325 
326  // boundary (y=0)
327  int px = s1 + Nx * (Ny - 1);
328  for (int ex = 0; ex < Nex; ex++) {
329  for (int in = 0; in < Nin; in++) {
330  wt[in + Nin * (s2 + Nvol2 * ex)] = wp[in + Nin * (px + Nvol * ex)];
331  }
332  }
333  }
334  }
335 
336  int size = Nin * Nvol2 * Nex;
337  Communicator::exchange(size, &vt[0], &wt[0], 1, -1, 5);
338 
339  for (int zt = 0; zt < Nz * Nt; zt++) {
340  for (int x = 0; x < Nx; x++) {
341  int s1 = x + Nx * Ny * zt;
342  int s2 = x + Nx * zt;
343 
344  // boundary (y=0)
345  int ix = s1;
346  for (int ex = 0; ex < Nex; ex++) {
347  for (int in = 0; in < Nin; in++) {
348  vp[in + Nin * (ix + Nvol * ex)] = bc2 * vt[in + Nin * (s2 + Nvol2 * ex)];
349  }
350  }
351  }
352  }
353 }
354 
355 
356 //====================================================================
357 void ShiftField_lex::up_z(Field *v, const Field *w, const int bc)
358 {
359  double bc2;
360 
361  if (Communicator::ipe(2) == 0) {
362  bc2 = bc;
363  } else {
364  bc2 = 1.0;
365  }
366 
367  int Nin = w->nin();
368  int Nex = w->nex();
369  int Nvol = w->nvol();
370  int Nvol2 = Nvol / Nz;
371 
372  double *vp = v->ptr(0);
373  const double *wp = w->ptr(0);
374 
375  std::vector<double> wt(Nin * Nvol2 * Nex);
376  std::vector<double> vt(Nin * Nvol2 * Nex);
377 
378  for (int t = 0; t < Nt; t++) {
379  for (int xy = 0; xy < Nx * Ny; xy++) {
380  int s1 = xy + Nx * Ny * Nz * t;
381  int s2 = xy + Nx * Ny * t;
382 
383  // bulk
384  for (int z = 0; z < Nz - 1; z++) {
385  int ix = s1 + Nx * Ny * z;
386  int px = ix + Nx * Ny;
387  for (int ex = 0; ex < Nex; ex++) {
388  for (int in = 0; in < Nin; in++) {
389  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
390  }
391  }
392  }
393 
394  // boundary (z=Nz-1)
395  int px = s1;
396  for (int ex = 0; ex < Nex; ex++) {
397  for (int in = 0; in < Nin; in++) {
398  wt[in + Nin * (s2 + Nvol2 * ex)] = bc2 * wp[in + Nin * (px + Nvol * ex)];
399  }
400  }
401  }
402  }
403 
404  int size = Nin * (Nvol / Nz) * Nex;
405  Communicator::exchange(size, &vt[0], &wt[0], 2, 1, 2);
406 
407  for (int t = 0; t < Nt; t++) {
408  for (int xy = 0; xy < Nx * Ny; xy++) {
409  int s1 = xy + Nx * Ny * Nz * t;
410  int s2 = xy + Nx * Ny * t;
411 
412  // boundary (z=Nz-1)
413  int ix = s1 + Nx * Ny * (Nz - 1);
414  for (int ex = 0; ex < Nex; ex++) {
415  for (int in = 0; in < Nin; in++) {
416  vp[in + Nin * (ix + Nvol * ex)] = vt[in + Nin * (s2 + Nvol2 * ex)];
417  }
418  }
419  }
420  }
421 }
422 
423 
424 //====================================================================
425 void ShiftField_lex::dn_z(Field *v, const Field *w, const int bc)
426 {
427  double bc2;
428 
429  if (Communicator::ipe(2) == 0) {
430  bc2 = bc;
431  } else {
432  bc2 = 1.0;
433  }
434 
435  int Nin = w->nin();
436  int Nex = w->nex();
437  int Nvol = w->nvol();
438  int Nvol2 = Nvol / Nz;
439 
440  double *vp = v->ptr(0);
441  const double *wp = w->ptr(0);
442 
443  std::vector<double> wt(Nin * Nvol2 * Nex);
444  std::vector<double> vt(Nin * Nvol2 * Nex);
445 
446  for (int t = 0; t < Nt; t++) {
447  for (int xy = 0; xy < Nx * Ny; xy++) {
448  int s1 = xy + Nx * Ny * Nz * t;
449  int s2 = xy + Nx * Ny * t;
450 
451  // bulk
452  for (int z = 1; z < Nz; z++) {
453  int ix = s1 + Nx * Ny * z;
454  int px = ix - Nx * Ny;
455  for (int ex = 0; ex < Nex; ex++) {
456  for (int in = 0; in < Nin; in++) {
457  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
458  }
459  }
460  }
461  // boundary (z=0)
462  int px = s1 + Nx * Ny * (Nz - 1);
463  for (int in = 0; in < Nin; in++) {
464  for (int ex = 0; ex < Nex; ex++) {
465  wt[in + Nin * (s2 + Nvol2 * ex)] = wp[in + Nin * (px + Nvol * ex)];
466  }
467  }
468  }
469  }
470 
471  int size = Nin * Nvol2 * Nex;
472  Communicator::exchange(size, &vt[0], &wt[0], 2, -1, 6);
473 
474  for (int t = 0; t < Nt; t++) {
475  for (int xy = 0; xy < Nx * Ny; xy++) {
476  int s1 = xy + Nx * Ny * Nz * t;
477  int s2 = xy + Nx * Ny * t;
478 
479  // boundary (z=0)
480  int ix = s1;
481  for (int in = 0; in < Nin; in++) {
482  for (int ex = 0; ex < Nex; ex++) {
483  vp[in + Nin * (ix + Nvol * ex)] = bc2 * vt[in + Nin * (s2 + Nvol2 * ex)];
484  }
485  }
486  }
487  }
488 }
489 
490 
491 //====================================================================
492 void ShiftField_lex::up_t(Field *v, const Field *w, const int bc)
493 {
494  double bc2;
495 
496  if (Communicator::ipe(3) == 0) {
497  bc2 = bc;
498  } else {
499  bc2 = 1.0;
500  }
501 
502  int Nin = w->nin();
503  int Nex = w->nex();
504  int Nvol = w->nvol();
505  int Nvol2 = Nvol / Nt;
506 
507  double *vp = v->ptr(0);
508  const double *wp = w->ptr(0);
509 
510  std::vector<double> wt(Nin * Nvol2 * Nex);
511  std::vector<double> vt(Nin * Nvol2 * Nex);
512 
513  for (int s2 = 0; s2 < Nx * Ny * Nz; s2++) {
514  // bulk
515  for (int t = 0; t < Nt - 1; t++) {
516  int ix = s2 + Nx * Ny * Nz * t;
517  int px = ix + Nx * Ny * Nz;
518  for (int ex = 0; ex < Nex; ex++) {
519  for (int in = 0; in < Nin; in++) {
520  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
521  }
522  }
523  }
524 
525  // boundary (t=Nt-1)
526  int px = s2;
527  for (int ex = 0; ex < Nex; ex++) {
528  for (int in = 0; in < Nin; in++) {
529  wt[in + Nin * (s2 + Nvol2 * ex)] = bc2 * wp[in + Nin * (px + Nvol * ex)];
530  }
531  }
532  }
533 
534  int size = Nin * Nvol2 * Nex;
535  Communicator::exchange(size, &vt[0], &wt[0], 3, 1, 3);
536 
537  for (int s2 = 0; s2 < Nx * Ny * Nz; s2++) {
538  // boundary (t=Nt-1)
539  int ix = s2 + Nx * Ny * Nz * (Nt - 1);
540  for (int ex = 0; ex < Nex; ex++) {
541  for (int in = 0; in < Nin; in++) {
542  vp[in + Nin * (ix + Nvol * ex)] = vt[in + Nin * (s2 + Nvol2 * ex)];
543  }
544  }
545  }
546 }
547 
548 
549 //====================================================================
550 void ShiftField_lex::dn_t(Field *v, const Field *w, const int bc)
551 {
552  double bc2;
553 
554  if (Communicator::ipe(3) == 0) {
555  bc2 = bc;
556  } else {
557  bc2 = 1.0;
558  }
559 
560  int Nin = w->nin();
561  int Nex = w->nex();
562  int Nvol = w->nvol();
563  int Nvol2 = Nvol / Nt;
564 
565  double *vp = v->ptr(0);
566  const double *wp = w->ptr(0);
567 
568  std::vector<double> wt(Nin * Nvol2 * Nex);
569  std::vector<double> vt(Nin * Nvol2 * Nex);
570 
571  for (int s2 = 0; s2 < Nx * Ny * Nz; s2++) {
572  // bulk
573  for (int t = 1; t < Nt; t++) {
574  int ix = s2 + Nx * Ny * Nz * t;
575  int px = ix - Nx * Ny * Nz;
576  for (int ex = 0; ex < Nex; ex++) {
577  for (int in = 0; in < Nin; in++) {
578  vp[in + Nin * (ix + Nvol * ex)] = wp[in + Nin * (px + Nvol * ex)];
579  }
580  }
581  }
582  // boundary (t=0)
583  int px = s2 + Nx * Ny * Nz * (Nt - 1);
584  for (int ex = 0; ex < Nex; ex++) {
585  for (int in = 0; in < Nin; in++) {
586  wt[in + Nin * (s2 + Nvol2 * ex)] = wp[in + Nin * (px + Nvol * ex)];
587  }
588  }
589  }
590 
591  int size = Nin * Nvol2 * Nex;
592  Communicator::exchange(size, &vt[0], &wt[0], 3, -1, 7);
593 
594  for (int s2 = 0; s2 < Nx * Ny * Nz; s2++) {
595  // boundary (t=0)
596  int ix = s2;
597  for (int ex = 0; ex < Nex; ex++) {
598  for (int in = 0; in < Nin; in++) {
599  vp[in + Nin * (ix + Nvol * ex)] = bc2 * vt[in + Nin * (s2 + Nvol2 * ex)];
600  }
601  }
602  }
603 }
604 
605 
606 //====================================================================
607 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:278
void up_t(Field *, const Field *, const int bc)
const double * ptr(const int jin, const int site, const int jex) const
Definition: field.h:133
Container of Field-type object.
Definition: field.h:39
int nvol() const
Definition: field.h:116
void dn_t(Field *, const Field *, const int bc)
static int ipe(const int dir)
logical coordinate of current proc.
void dn_y(Field *, const Field *, const int bc)
int nin() const
Definition: field.h:115
void up_y(Field *, const Field *, const int bc)
static int exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag)
receive array of double from upstream specified by idir and ipm, and send array to downstream...
void backward(Field &, const Field &, const int mu)
int nex() const
Definition: field.h:117
void dn_z(Field *, const Field *, const int bc)
void crucial(const char *format,...)
Definition: bridgeIO.cpp:48
void up_x(Field *, const Field *, const int bc)
void dn_x(Field *, const Field *, const int bc)
void up_z(Field *, const Field *, const int bc)
void forward(Field &, const Field &, const int mu)