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