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