Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shiftField_lex.cpp
Go to the documentation of this file.
1 
15 #include "shiftField_lex.h"
16 
17 
18 //====================================================================
19 void ShiftField_lex::backward(Field& v, const Field& w,
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 //====================================================================
40 void ShiftField_lex::forward(Field& v, const Field& w,
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 //====================================================================
61 void ShiftField_lex::backward(Field& v, const Field& w,
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 //====================================================================
80 void ShiftField_lex::forward(Field& v, const Field& w,
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 
113  Field *wt = new Field(Nin, Nvol / Nx, Nex);
114  Field *vt = new Field(Nin, Nvol / Nx, Nex);
115 
116  for (int t = 0; t < Nt; t++) {
117  for (int z = 0; z < Nz; z++) {
118  for (int y = 0; y < Ny; y++) {
119  int s2 = y + Ny * (z + Nz * t);
120  // bulk
121  for (int x = 0; x < Nx - 1; x++) {
122  int ix = idx.site(x, y, z, t);
123  int px = idx.site(x + 1, y, z, t);
124  for (int ex = 0; ex < Nex; ex++) {
125  for (int in = 0; in < Nin; in++) {
126  v->set(in, ix, ex, w->cmp(in, px, ex));
127  }
128  }
129  }
130  // boundary (x=Nx-1)
131  int ix = idx.site(Nx - 1, y, z, t);
132  int px = idx.site(0, y, z, t);
133  for (int in = 0; in < Nin; in++) {
134  for (int ex = 0; ex < Nex; ex++) {
135  wt->set(in, s2, ex, bc2 * w->cmp(in, px, ex));
136  }
137  }
138  }
139  }
140  }
141 
142  int size = Nin * (Nvol / Nx) * Nex;
143  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 0, 1, 0);
144 
145  for (int t = 0; t < Nt; t++) {
146  for (int z = 0; z < Nz; z++) {
147  for (int y = 0; y < Ny; y++) {
148  int s2 = y + Ny * (z + Nz * t);
149  // boundary (x=Nx-1)
150  int ix = idx.site(Nx - 1, y, z, t);
151  int px = idx.site(0, y, z, t);
152  for (int in = 0; in < Nin; in++) {
153  for (int ex = 0; ex < Nex; ex++) {
154  v->set(in, ix, ex, vt->cmp(in, s2, ex));
155  }
156  }
157  }
158  }
159  }
160 
161  delete vt;
162  delete wt;
163 }
164 
165 
166 //====================================================================
167 void ShiftField_lex::up_y(Field *v, const Field *w, const int bc)
168 {
169  double bc2;
170 
171  if (Communicator::ipe(1) == 0) {
172  bc2 = bc;
173  } else {
174  bc2 = 1.0;
175  }
176 
177  int Nin = w->nin();
178  int Nex = w->nex();
179  int Nvol = w->nvol();
180 
181  Field *wt = new Field(Nin, Nvol / Ny, Nex);
182  Field *vt = new Field(Nin, Nvol / Ny, Nex);
183 
184  for (int t = 0; t < Nt; t++) {
185  for (int z = 0; z < Nz; z++) {
186  for (int x = 0; x < Nx; x++) {
187  int s2 = x + Nx * (z + Nz * t);
188 
189  // bulk
190  for (int y = 0; y < Ny - 1; y++) {
191  int ix = idx.site(x, y, z, t);
192  int px = idx.site(x, y + 1, z, t);
193  for (int ex = 0; ex < Nex; ex++) {
194  for (int in = 0; in < Nin; in++) {
195  v->set(in, ix, ex, w->cmp(in, px, ex));
196  }
197  }
198  }
199 
200  // boundary (y=Ny-1)
201  int ix = idx.site(x, Ny - 1, z, t);
202  int px = idx.site(x, 0, z, t);
203  for (int in = 0; in < Nin; in++) {
204  for (int ex = 0; ex < Nex; ex++) {
205  wt->set(in, s2, ex, bc2 * w->cmp(in, px, ex));
206  }
207  }
208  }
209  }
210  }
211 
212  int size = Nin * (Nvol / Ny) * Nex;
213  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 1, 1, 1);
214 
215  for (int t = 0; t < Nt; t++) {
216  for (int z = 0; z < Nz; z++) {
217  for (int x = 0; x < Nx; x++) {
218  int s2 = x + Nx * (z + Nz * t);
219 
220  // boundary (y=Ny-1)
221  int ix = idx.site(x, Ny - 1, z, t);
222  int px = idx.site(x, 0, z, t);
223  for (int in = 0; in < Nin; in++) {
224  for (int ex = 0; ex < Nex; ex++) {
225  v->set(in, ix, ex, vt->cmp(in, s2, ex));
226  }
227  }
228  }
229  }
230  }
231 
232  delete vt;
233  delete wt;
234 }
235 
236 
237 //====================================================================
238 void ShiftField_lex::up_z(Field *v, const Field *w, const int bc)
239 {
240  double bc2;
241 
242  if (Communicator::ipe(2) == 0) {
243  bc2 = bc;
244  } else {
245  bc2 = 1.0;
246  }
247 
248  int Nin = w->nin();
249  int Nex = w->nex();
250  int Nvol = w->nvol();
251 
252  Field *wt = new Field(Nin, Nvol / Nz, Nex);
253  Field *vt = new Field(Nin, Nvol / Nz, Nex);
254 
255  for (int t = 0; t < Nt; t++) {
256  for (int y = 0; y < Ny; y++) {
257  for (int x = 0; x < Nx; x++) {
258  int s2 = x + Nx * (y + Ny * t);
259 
260  // bulk
261  for (int z = 0; z < Nz - 1; z++) {
262  int ix = idx.site(x, y, z, t);
263  int px = idx.site(x, y, z + 1, t);
264  for (int ex = 0; ex < Nex; ex++) {
265  for (int in = 0; in < Nin; in++) {
266  v->set(in, ix, ex, w->cmp(in, px, ex));
267  }
268  }
269  }
270 
271  // boundary (z=Nz-1)
272  int ix = idx.site(x, y, Nz - 1, t);
273  int px = idx.site(x, y, 0, t);
274  for (int in = 0; in < Nin; in++) {
275  for (int ex = 0; ex < Nex; ex++) {
276  wt->set(in, s2, ex, bc2 * w->cmp(in, px, ex));
277  }
278  }
279  }
280  }
281  }
282 
283  int size = Nin * (Nvol / Nz) * Nex;
284  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 2, 1, 2);
285 
286  for (int t = 0; t < Nt; t++) {
287  for (int y = 0; y < Ny; y++) {
288  for (int x = 0; x < Nx; x++) {
289  int s2 = x + Nx * (y + Ny * t);
290 
291  // boundary (z=Nz-1)
292  int ix = idx.site(x, y, Nz - 1, t);
293  int px = idx.site(x, y, 0, t);
294  for (int in = 0; in < Nin; in++) {
295  for (int ex = 0; ex < Nex; ex++) {
296  v->set(in, ix, ex, vt->cmp(in, s2, ex));
297  }
298  }
299  }
300  }
301  }
302 
303  delete vt;
304  delete wt;
305 }
306 
307 
308 //====================================================================
309 void ShiftField_lex::up_t(Field *v, const Field *w, const int bc)
310 {
311  double bc2;
312 
313  if (Communicator::ipe(3) == 0) {
314  bc2 = bc;
315  } else {
316  bc2 = 1.0;
317  }
318 
319  int Nin = w->nin();
320  int Nex = w->nex();
321  int Nvol = w->nvol();
322 
323  Field *wt = new Field(Nin, Nvol / Nt, Nex);
324  Field *vt = new Field(Nin, Nvol / Nt, Nex);
325 
326  for (int z = 0; z < Nz; z++) {
327  for (int y = 0; y < Ny; y++) {
328  for (int x = 0; x < Nx; x++) {
329  int s2 = x + Nx * (y + Ny * z);
330 
331  // bulk
332  for (int t = 0; t < Nt - 1; t++) {
333  int ix = idx.site(x, y, z, t);
334  int px = idx.site(x, y, z, t + 1);
335  for (int ex = 0; ex < Nex; ex++) {
336  for (int in = 0; in < Nin; in++) {
337  v->set(in, ix, ex, w->cmp(in, px, ex));
338  }
339  }
340  }
341 
342  // boundary (t=Nt-1)
343  int ix = idx.site(x, y, z, Nt - 1);
344  int px = idx.site(x, y, z, 0);
345  for (int ex = 0; ex < Nex; ex++) {
346  for (int in = 0; in < Nin; in++) {
347  wt->set(in, s2, ex, bc2 * w->cmp(in, px, ex));
348  }
349  }
350  }
351  }
352  }
353 
354  int size = Nin * (Nvol / Nt) * Nex;
355  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 3, 1, 3);
356 
357  for (int z = 0; z < Nz; z++) {
358  for (int y = 0; y < Ny; y++) {
359  for (int x = 0; x < Nx; x++) {
360  int s2 = x + Nx * (y + Ny * z);
361 
362  // boundary (t=Nt-1)
363  int ix = idx.site(x, y, z, Nt - 1);
364  int px = idx.site(x, y, z, 0);
365  for (int ex = 0; ex < Nex; ex++) {
366  for (int in = 0; in < Nin; in++) {
367  v->set(in, ix, ex, vt->cmp(in, s2, ex));
368  }
369  }
370  }
371  }
372  }
373 
374  delete vt;
375  delete wt;
376 }
377 
378 
379 //====================================================================
380 void ShiftField_lex::dn_x(Field *v, const Field *w, const int bc)
381 {
382  double bc2;
383 
384  if (Communicator::ipe(0) == 0) {
385  bc2 = bc;
386  } else {
387  bc2 = 1.0;
388  }
389 
390  int Nin = w->nin();
391  int Nex = w->nex();
392  int Nvol = w->nvol();
393 
394  Field *wt = new Field(Nin, Nvol / Nx, Nex);
395  Field *vt = new Field(Nin, Nvol / Nx, Nex);
396 
397  for (int t = 0; t < Nt; t++) {
398  for (int z = 0; z < Nz; z++) {
399  for (int y = 0; y < Ny; y++) {
400  int s2 = y + Ny * (z + Nz * t);
401 
402  // bulk
403  for (int x = 1; x < Nx; x++) {
404  int ix = idx.site(x, y, z, t);
405  int px = idx.site(x - 1, y, z, t);
406  for (int ex = 0; ex < Nex; ex++) {
407  for (int in = 0; in < Nin; in++) {
408  v->set(in, ix, ex, w->cmp(in, px, ex));
409  }
410  }
411  }
412  // boundary (x=0)
413  //int ix = idx.site(0 ,y,z,t);
414  int px = idx.site(Nx - 1, y, z, t);
415  for (int in = 0; in < Nin; in++) {
416  for (int ex = 0; ex < Nex; ex++) {
417  wt->set(in, s2, ex, w->cmp(in, px, ex));
418  }
419  }
420  }
421  }
422  }
423 
424  int size = Nin * (Nvol / Nx) * Nex;
425  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 0, -1, 4);
426 
427  for (int t = 0; t < Nt; t++) {
428  for (int z = 0; z < Nz; z++) {
429  for (int y = 0; y < Ny; y++) {
430  int s2 = y + Ny * (z + Nz * t);
431  // boundary (x=0)
432  int ix = idx.site(0, y, z, t);
433  //int px = idx.site(Nx-1,y,z,t);
434  for (int in = 0; in < Nin; in++) {
435  for (int ex = 0; ex < Nex; ex++) {
436  v->set(in, ix, ex, bc2 * vt->cmp(in, s2, ex));
437  }
438  }
439  }
440  }
441  }
442 
443  delete vt;
444  delete wt;
445 }
446 
447 
448 //====================================================================
449 void ShiftField_lex::dn_y(Field *v, const Field *w, const int bc)
450 {
451  double bc2;
452 
453  if (Communicator::ipe(1) == 0) {
454  bc2 = bc;
455  } else {
456  bc2 = 1.0;
457  }
458 
459  int Nin = w->nin();
460  int Nex = w->nex();
461  int Nvol = w->nvol();
462 
463  Field *wt = new Field(Nin, Nvol / Ny, Nex);
464  Field *vt = new Field(Nin, Nvol / Ny, Nex);
465 
466  for (int t = 0; t < Nt; t++) {
467  for (int z = 0; z < Nz; z++) {
468  for (int x = 0; x < Nx; x++) {
469  int s2 = x + Nx * (z + Nz * t);
470 
471  // bulk
472  for (int y = 1; y < Ny; y++) {
473  int ix = idx.site(x, y, z, t);
474  int px = idx.site(x, y - 1, z, t);
475  for (int ex = 0; ex < Nex; ex++) {
476  for (int in = 0; in < Nin; in++) {
477  v->set(in, ix, ex, w->cmp(in, px, ex));
478  }
479  }
480  }
481  // boundary (y=0)
482  int ix = idx.site(x, 0, z, t);
483  int px = idx.site(x, Ny - 1, z, t);
484  for (int in = 0; in < Nin; in++) {
485  for (int ex = 0; ex < Nex; ex++) {
486  wt->set(in, s2, ex, w->cmp(in, px, ex));
487  }
488  }
489  }
490  }
491  }
492 
493  int size = Nin * (Nvol / Ny) * Nex;
494  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 1, -1, 5);
495 
496  for (int t = 0; t < Nt; t++) {
497  for (int z = 0; z < Nz; z++) {
498  for (int x = 0; x < Nx; x++) {
499  int s2 = x + Nx * (z + Nz * t);
500 
501  // boundary (y=0)
502  int ix = idx.site(x, 0, z, t);
503  int px = idx.site(x, Ny - 1, z, t);
504  for (int in = 0; in < Nin; in++) {
505  for (int ex = 0; ex < Nex; ex++) {
506  v->set(in, ix, ex, bc2 * vt->cmp(in, s2, ex));
507  }
508  }
509  }
510  }
511  }
512 
513  delete vt;
514  delete wt;
515 }
516 
517 
518 //====================================================================
519 void ShiftField_lex::dn_z(Field *v, const Field *w, const int bc)
520 {
521  double bc2;
522 
523  if (Communicator::ipe(2) == 0) {
524  bc2 = bc;
525  } else {
526  bc2 = 1.0;
527  }
528 
529  int Nin = w->nin();
530  int Nex = w->nex();
531  int Nvol = w->nvol();
532 
533  Field *wt = new Field(Nin, Nvol / Nz, Nex);
534  Field *vt = new Field(Nin, Nvol / Nz, Nex);
535 
536  for (int t = 0; t < Nt; t++) {
537  for (int y = 0; y < Ny; y++) {
538  for (int x = 0; x < Nx; x++) {
539  int s2 = x + Nx * (y + Ny * t);
540 
541  // bulk
542  for (int z = 1; z < Nz; z++) {
543  int ix = idx.site(x, y, z, t);
544  int px = idx.site(x, y, z - 1, t);
545  for (int ex = 0; ex < Nex; ex++) {
546  for (int in = 0; in < Nin; in++) {
547  v->set(in, ix, ex, w->cmp(in, px, ex));
548  }
549  }
550  }
551  // boundary (z=0)
552  int ix = idx.site(x, y, 0, t);
553  int px = idx.site(x, y, Nz - 1, t);
554  for (int in = 0; in < Nin; in++) {
555  for (int ex = 0; ex < Nex; ex++) {
556  wt->set(in, s2, ex, w->cmp(in, px, ex));
557  }
558  }
559  }
560  }
561  }
562 
563  int size = Nin * (Nvol / Nz) * Nex;
564  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 2, -1, 6);
565 
566  for (int t = 0; t < Nt; t++) {
567  for (int y = 0; y < Ny; y++) {
568  for (int x = 0; x < Nx; x++) {
569  int s2 = x + Nx * (y + Ny * t);
570 
571  // boundary (z=0)
572  int ix = idx.site(x, y, 0, t);
573  int px = idx.site(x, y, Nz - 1, t);
574  for (int in = 0; in < Nin; in++) {
575  for (int ex = 0; ex < Nex; ex++) {
576  v->set(in, ix, ex, bc2 * vt->cmp(in, s2, ex));
577  }
578  }
579  }
580  }
581  }
582 
583  delete vt;
584  delete wt;
585 }
586 
587 
588 //====================================================================
589 void ShiftField_lex::dn_t(Field *v, const Field *w, const int bc)
590 {
591  double bc2;
592 
593  if (Communicator::ipe(3) == 0) {
594  bc2 = bc;
595  } else {
596  bc2 = 1.0;
597  }
598 
599  int Nin = w->nin();
600  int Nex = w->nex();
601  int Nvol = w->nvol();
602 
603  Field *wt = new Field(Nin, Nvol / Nt, Nex);
604  Field *vt = new Field(Nin, Nvol / Nt, Nex);
605 
606  for (int z = 0; z < Nz; z++) {
607  for (int y = 0; y < Ny; y++) {
608  for (int x = 0; x < Nx; x++) {
609  int s2 = x + Nx * (y + Ny * z);
610 
611  // bulk
612  for (int t = 1; t < Nt; t++) {
613  int ix = idx.site(x, y, z, t);
614  int px = idx.site(x, y, z, t - 1);
615  for (int ex = 0; ex < Nex; ex++) {
616  for (int in = 0; in < Nin; in++) {
617  v->set(in, ix, ex, w->cmp(in, px, ex));
618  }
619  }
620  }
621  // boundary (t=0)
622  int ix = idx.site(x, y, z, 0);
623  int px = idx.site(x, y, z, Nt - 1);
624  for (int ex = 0; ex < Nex; ex++) {
625  for (int in = 0; in < Nin; in++) {
626  wt->set(in, s2, ex, w->cmp(in, px, ex));
627  }
628  }
629  }
630  }
631  }
632 
633  int size = Nin * (Nvol / Nt) * Nex;
634  Communicator::exchange(size, vt->ptr(0), wt->ptr(0), 3, -1, 7);
635 
636  for (int z = 0; z < Nz; z++) {
637  for (int y = 0; y < Ny; y++) {
638  for (int x = 0; x < Nx; x++) {
639  int s2 = x + Nx * (y + Ny * z);
640 
641  // boundary (t=0)
642  int ix = idx.site(x, y, z, 0);
643  int px = idx.site(x, y, z, Nt - 1);
644  for (int ex = 0; ex < Nex; ex++) {
645  for (int in = 0; in < Nin; in++) {
646  v->set(in, ix, ex, bc2 * vt->cmp(in, s2, ex));
647  }
648  }
649  }
650  }
651  }
652 
653  delete vt;
654  delete wt;
655 }
656 
657 
658 //====================================================================
659 //============================================================END=====
void up_t(Field *, const Field *, const int bc)
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:128
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:53
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
double cmp(const int jin, const int site, const int jex) const
Definition: field.h:108
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)