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