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