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