Chombo + EB  3.0
BaseFabMacros.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // note that DIM>3 versions of these macros require that the "BoxIterator.H"
12 // is included in the file calling the macros
13 
14 // Can't use ordinary include guards here or multidim won't work. So instead
15 // we do something fancier, with LAST_BASEFABMACROS_H_SPACEDIM:
16 //#ifndef _BASEFABMACROS_H_
17 //#define _BASEFABMACROS_H_
18 
19 #ifndef LAST_BASEFABMACROS_H_SPACEDIM
20 #define LAST_BASEFABMACROS_H_SPACEDIM 0
21 #endif
22 #if CH_SPACEDIM != LAST_BASEFABMACROS_H_SPACEDIM
23 #undef LAST_BASEFABMACROS_H_SPACEDIM
24 // #endif is at bottom of file.
25 
26 #include "SPACE.H"
27 #if CH_SPACEDIM > 3
28 #include "BoxIterator.H"
29 #endif
30 
31 
32 #ifdef DOXYGEN
33 #define CH_SPACEDIM 1
34 #endif
35 
36 //
37 // CH_MULTIDIM stuff
38 //
39 #ifdef ForAllThisCPencil
40 # undef ForAllThisCPencil
41 # undef ForAllThisPencil
42 # undef ForAllXBPencil
43 # undef ForAllXBNNnoindx
44 # undef ForAllXBNN
45 # undef ForAllXCBNN
46 # undef ForAllThisBNN
47 # undef ForAllThisCBNN
48 # undef ForAllThisBNNXC
49 # undef ForAllThisCBNNXC
50 # undef ForAllThisBNNXCBN
51 # undef ForAllThisBNNXCBNYCBN
52 # undef ForAllRevXBNYCBNNN
53 # undef EndFor
54 # undef EndForTX
55 # undef EndForPencil
56 #endif
57 
58 #if CH_SPACEDIM == 1
59 # define ForAllThisCPencil ForAllThisCPencil1
60 # define ForAllThisPencil ForAllThisPencil1
61 # define ForAllXBPencil ForAllXBPencil1
62 # define ForAllXBNN ForAllXBNN1
63 # define ForAllXBNNnoindx ForAllXBNNnoindx1
64 # define ForAllXCBNN ForAllXCBNN1
65 # define ForAllThisBNN ForAllThisBNN1
66 # define ForAllThisCBNN ForAllThisCBNN1
67 # define ForAllThisBNNXC ForAllThisBNNXC1
68 # define ForAllThisCBNNXC ForAllThisCBNNXC1
69 # define ForAllThisBNNXCBN ForAllThisBNNXCBN1
70 # define ForAllThisBNNXCBNYCBN ForAllThisBNNXCBNYCBN1
71 # define ForAllRevXBNYCBNNN ForAllRevXBNYCBNNN1
72 # define EndFor EndFor1
73 # define EndForTX EndForTX1
74 # define EndForPencil EndForPencil1
75 # define LAST_BASEFABMACROS_H_SPACEDIM 1
76 #endif
77 #if CH_SPACEDIM == 2
78 # define ForAllThisCPencil ForAllThisCPencil2
79 # define ForAllThisPencil ForAllThisPencil2
80 # define ForAllXBPencil ForAllXBPencil2
81 # define ForAllXBNN ForAllXBNN2
82 # define ForAllXBNNnoindx ForAllXBNNnoindx2
83 # define ForAllXCBNN ForAllXCBNN2
84 # define ForAllThisBNN ForAllThisBNN2
85 # define ForAllThisCBNN ForAllThisCBNN2
86 # define ForAllThisBNNXC ForAllThisBNNXC2
87 # define ForAllThisCBNNXC ForAllThisCBNNXC2
88 # define ForAllThisBNNXCBN ForAllThisBNNXCBN2
89 # define ForAllThisBNNXCBNYCBN ForAllThisBNNXCBNYCBN2
90 # define ForAllRevXBNYCBNNN ForAllRevXBNYCBNNN2
91 # define EndFor EndFor2
92 # define EndForTX EndForTX2
93 # define EndForPencil EndForPencil2
94 # define LAST_BASEFABMACROS_H_SPACEDIM 2
95 #endif
96 #if CH_SPACEDIM == 3
97 # define ForAllThisCPencil ForAllThisCPencil3
98 # define ForAllThisPencil ForAllThisPencil3
99 # define ForAllXBPencil ForAllXBPencil3
100 # define ForAllXBNN ForAllXBNN3
101 # define ForAllXBNNnoindx ForAllXBNNnoindx3
102 # define ForAllXCBNN ForAllXCBNN3
103 # define ForAllThisBNN ForAllThisBNN3
104 # define ForAllThisCBNN ForAllThisCBNN3
105 # define ForAllThisBNNXC ForAllThisBNNXC3
106 # define ForAllThisCBNNXC ForAllThisCBNNXC3
107 # define ForAllThisBNNXCBN ForAllThisBNNXCBN3
108 # define ForAllThisBNNXCBNYCBN ForAllThisBNNXCBNYCBN3
109 # define ForAllRevXBNYCBNNN ForAllRevXBNYCBNNN3
110 # define EndFor EndFor3
111 # define EndForTX EndForTX3
112 # define EndForPencil EndForPencil3
113 # define LAST_BASEFABMACROS_H_SPACEDIM 3
114 #endif
115 
116 #if CH_SPACEDIM > 3
117 # define ForAllThisCPencil ForAllThisCPencilHiDim
118 # define ForAllThisPencil ForAllThisPencilHiDim
119 # define ForAllXBPencil ForAllXBPencilHiDim
120 # define ForAllXBNN ForAllXBNNHiDim
121 # define ForAllXBNNnoindx ForAllXBNNnoindxHiDim
122 # define ForAllXCBNN ForAllXCBNNHiDim
123 # define ForAllThisBNN ForAllThisBNNHiDim
124 # define ForAllThisCBNN ForAllThisCBNNHiDim
125 # define ForAllThisBNNXC ForAllThisBNNXCHiDim
126 # define ForAllThisCBNNXC ForAllThisCBNNXCHiDim
127 # define ForAllThisBNNXCBN ForAllThisBNNXCBNHiDim
128 # define ForAllThisBNNXCBNYCBN ForAllThisBNNXCBNYCBNHiDim
129 # define ForAllRevXBNYCBNNN ForAllRevXBNYCBNNNHiDim
130 # define EndFor EndForHiDim
131 # define EndForTX EndForTXHiDim
132 # define EndForPencil EndForPencilHiDim
133 # define LAST_BASEFABMACROS_H_SPACEDIM HiDim
134 #endif
135 
136 #if (CH_SPACEDIM == 1)
137 
138 /**
139 @ingroup macros
140 
141  The macro ForAllThisPencil(T,b,ns,nc) is intended to facilitate efficient
142  looping over the contents of BaseFabs and objects derived from BaseFab.
143  Special attention has been paid to make it work efficiently on vector
144  supercomputers.
145 
146  This macro acts upon the BaseFab *this. Instead of iterating over the
147  entire Box b, it iterates over components starting at component ns and
148  ending at component ns+nc-1, in all directions except the first coordinate
149  direction. The user must iterate over the first coordinate direction within
150  the ForAllThisPencil loop. The macro creates two internal reference
151  variables; thisR that references the first element in the pencil, and
152  thisLen that gives the length of the pencil. The first argument of the
153  macro is a type: the type contained in the BaseFab that is being iterated
154  over.
155 
156  We can rewrite the code illustrated in `ForAllThisBNN' in this form:
157 
158 \code
159  template <class T>
160  void BaseFab<T>::performSetVal(const T val, const Box bx, int ns, int nc)
161  {
162  CH_assert(domain.contains(bx));
163  ForAllThisPencil(T,bx,ns,nc)
164  {
165  T* dog = &thisR;
166  for (int i = 0; i < thisLen; i++)
167  dog[i] = val;
168  } EndForPencil
169  }
170 \endcode
171 
172  Looping macro mnemonics:
173 
174  This stands for the current object
175 
176  C for a const
177 
178  X stands for a BaseFab
179 
180  B for a Box
181 
182  N for an int
183 */
184 #define ForAllThisPencil1(T,b,ns,nc) \
185  { \
186  CH_assert(contains(b)); \
187  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
188  const int *_th_plo = this->loVect(); \
189  const IntVect _th_plen = this->size(); \
190  const int *_b_lo = (b).loVect(); \
191  const IntVect _b_len = (b).size(); \
192  T* _th_p = this->m_dptr; \
193  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
194  { \
195  const int nR = _n; (int&)nR += 0; \
196  T *_th_pp = _th_p \
197  + ((_b_lo[0] - _th_plo[0]) \
198  + _n * _th_plen[0]); \
199  T &thisR = * _th_pp; \
200  const int thisLen = _b_len[0]; \
201 
202 /** @ingroup macros
203  Same as ForAllThisPencil, except that it operates on the
204  the argument BaseFab passed in. added by bvs, 05/27/99
205 */
206 #define ForAllXBPencil1(T,x,b,ns,nc) \
207  { \
208  CH_assert(x.contains(b)); \
209  CH_assert((ns) >= 0 && (ns) + (nc) <= x.nComp()); \
210  const int *_th_plo = x.loVect(); \
211  const IntVect _th_plen = x.size(); \
212  const int *_b_lo = (b).loVect(); \
213  const IntVect _b_len = (b).size(); \
214  T* _th_p = x.dataPtr(); \
215  for (int nR = (ns); nR < (ns)+(nc); ++nR) \
216  { \
217  T * xR = _th_p \
218  + ((_b_lo[0] - _th_plo[0]) \
219  + nR * _th_plen[0]); \
220  const int thisLen = _b_len[0];
221 
222 /** @ingroup macros
223  The macro ForAllThisCPencil(T,b,ns,nc) is intended to facilitate efficient
224  looping over the contents of BaseFabs and objects derived from BaseFab.
225  Special attention has been paid to make it work efficiently on vector
226  supercomputers.
227 
228  This is the constant version of ForAllThisPencil; i.e. it works when the
229  underlying BaseFab is constant.
230 
231  Looping macro mnemonics:
232 
233  This stands for the current object
234 
235  C for a const
236 
237  X stands for a BaseFab
238 
239  B for a Box
240 
241  N for an int
242 */
243 #define ForAllThisCPencil1(T,b,ns,nc) \
244  { \
245  CH_assert(this->contains(b)); \
246  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
247  const int *_th_plo = this->loVect(); \
248  const IntVect _th_plen = this->size(); \
249  const int *_b_lo = (b).loVect(); \
250  const IntVect _b_len = (b).size(); \
251  const T* _th_p = this->m_dptr; \
252  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
253  { \
254  int nR = _n; nR += 0; \
255  const T *_th_pp = _th_p \
256  + ((_b_lo[0] - _th_plo[0]) \
257  + _n * _th_plen[0]); \
258  const T &thisR = * _th_pp; \
259  const int thisLen = _b_len[0];
260 
261 /** @ingroup macros
262  The macro ForAllXBNN(T,x,b,ns,nc) is intended to facilitate efficient
263  looping over the contents of BaseFabs and objects derived from BaseFab.
264  Special attention has been paid to make it work efficiently on vector
265  supercomputers.
266 
267  This macro acts upon the BaseFab x where the loop runs over the points in
268  the Box b and over components starting at ns and ending at ns+nc-1. The
269  first argument of the macro is a type: the type contained in the BaseFab
270  that is being iterated over. The reference variable is xR, where x
271  is literally replaced by the macros second argument. Thus an expression
272  ForAllXBNN(int,dog,...) would have a reference variable dogR of type int.
273 
274  Looping macro mnemonics:
275 
276  This stands for the current object
277 
278  C for a const
279 
280  X stands for a BaseFab
281 
282  B for a Box
283 
284  N for an int
285 */
286 #define ForAllXBNN1(T,x,b,ns,nc) \
287  { \
288  CH_assert(x.contains(b)); \
289  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
290  const int *_x_plo = (x).loVect(); \
291  const IntVect _x_plen = (x).size(); \
292  const int *_b_lo = (b).loVect(); \
293  const IntVect _b_len = (b).size(); \
294  T* _x_p = (x) .dataPtr(); \
295  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
296  { \
297  const int nR = _n; (int&)nR += 0; \
298  T *_x_pp = _x_p \
299  + ((_b_lo[0] - _x_plo[0]) \
300  + _n * _x_plen[0]); \
301  for (int _i = 0; _i < _b_len[0]; ++_i, ++_x_pp) \
302  { \
303  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
304  T &x##R = * _x_pp;
305 
306 // undocumented interface
307 // Same as ForALLXBNN() except the index variables are not declared.
308 // Of course, this assumes they aren't used in the loop.
309 // This exists only for LevelFluxRegister.cpp, to eliminate the annoying
310 // 'unused variable' compiler warning msgs.
311 // dbs Apr2004
312 #define ForAllXBNNnoindx1(T,x,b,ns,nc) \
313  { \
314  CH_assert(x.contains(b)); \
315  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
316  const int *_x_plo = (x).loVect(); \
317  const IntVect _x_plen = (x).size(); \
318  const int *_b_lo = (b).loVect(); \
319  const IntVect _b_len = (b).size(); \
320  T* _x_p = (x) .dataPtr(); \
321  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
322  { \
323  T *_x_pp = _x_p \
324  + ((_b_lo[0] - _x_plo[0]) \
325  + _n * _x_plen[0]); \
326  for (int _i = 0; _i < _b_len[0]; ++_i, ++_x_pp) \
327  { \
328  T &x##R = * _x_pp;
329 
330 /** @ingroup macros
331  The macro ForAllXCBNN(T,x,b,ns,nc) is intended to facilitate efficient
332  looping over the contents of BaseFabs and objects derived from BaseFab.
333  Special attention has been paid to make it work efficiently on vector
334  supercomputers.
335 
336  This is the constant version of ForAllXBNN; i.e. it works when the
337  underlying BaseFab is constant.
338 
339  Looping macro mnemonics:
340 
341  This stands for the current object
342 
343  C for a const
344 
345  X stands for a BaseFab
346 
347  B for a Box
348 
349  N for an int
350 */
351 #define ForAllXCBNN1(T,x,b,ns,nc) \
352  { \
353  CH_assert(x.contains(b)); \
354  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
355  const int *_x_plo = (x).loVect(); \
356  const IntVect _x_plen = (x).size(); \
357  const int *_b_lo = (b).loVect(); \
358  const IntVect _b_len = (b).size(); \
359  const T* _x_p = (x).dataPtr(); \
360  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
361  { \
362  const int nR = _n; (int&)nR += 0; \
363  const T *_x_pp = _x_p \
364  + ((_b_lo[0] - _x_plo[0]) \
365  + _n * _x_plen[0]); \
366  for (int _i = 0; _i < _b_len[0]; ++_i) \
367  { \
368  const int iR = _i + _b_lo[0]; (int&) iR += 0; \
369  const T & x##R = _x_pp[_i];
370 
371 /** @ingroup macros
372  The ForAllThisBNN(T,b,ns,nc) macro is intended to facilitate efficient
373  looping over the contents of BaseFabs and objects derived from BaseFab.
374  Special attention has been paid to make it work efficiently on vector
375  supercomputers.
376 
377  This macro performs the loop over the current object (*this) where the loop
378  runs over the points in the Box b and over components starting at ns and
379  ending at ns+nc-1. The first argument of the macro is a type: the type
380  contained in the BaseFab that is being iterated over. The reference
381  variable is thisR.
382 
383  For example:
384 \code
385  template<class T>
386  void
387  BaseFab<T>::performSetVal (const T val, const Box bx, int ns, int num)
388  {
389  CH_assert(domain.contains(bx));
390  ForAllThisBNN(T,bx,ns,num)
391  {
392  thisR = val;
393  } EndFor
394  }
395 \endcode
396 
397  Looping macro mnemonics:
398 
399  This stands for the current object
400 
401  C for a const
402 
403  X stands for a BaseFab
404 
405  B for a Box
406 
407  N for an int
408 */
409 #define ForAllThisBNN1(T,b,ns,nc) \
410  { \
411  CH_assert(this->contains(b)); \
412  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
413  const int *_th_plo = this->loVect(); \
414  const IntVect _th_plen = this->size(); \
415  const int *_b_lo = (b).loVect(); \
416  const IntVect _b_len = (b).size(); \
417  T* _th_p = this->m_dptr; \
418  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
419  { \
420  int nR = _n; nR += 0; \
421  T *_th_pp = _th_p \
422  + ((_b_lo[0] - _th_plo[0]) \
423  + _n * _th_plen[0]); \
424  for (int _i = 0; _i < _b_len[0]; ++_i, ++_th_pp) \
425  { \
426  int iR = _i + _b_lo[0]; iR += 0; \
427  T &thisR = * _th_pp;
428 
429 /** @ingroup macros
430  The macro ForAllThisCBNN(T,b,ns,nc) is intended to facilitate efficient
431  looping over the contents of BaseFabs and objects derived from BaseFab.
432  Special attention has been paid to make it work efficiently on vector
433  supercomputers.
434 
435  This is the constant version of ForAllThisBNN; i.e. it works when the
436  underlying BaseFab is constant.
437 
438  Looping macro mnemonics:
439 
440  This stands for the current object
441 
442  C for a const
443 
444  X stands for a BaseFab
445 
446  B for a Box
447 
448  N for an int
449 */
450 #define ForAllThisCBNN1(T,b,ns,nc) \
451  { \
452  CH_assert(this->contains(b)); \
453  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
454  const int *_th_plo = this->loVect(); \
455  const IntVect _th_plen = this->size(); \
456  const int *_b_lo = (b).loVect(); \
457  const IntVect _b_len = (b).size(); \
458  const T* _th_p = this->m_dptr; \
459  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
460  { \
461  const int nR = _n; (int&)nR += 0; \
462  const T *_th_pp = _th_p \
463  + ((_b_lo[0] - _th_plo[0]) \
464  + _n * _th_plen[0]); \
465  for (int _i = 0; _i < _b_len[0]; ++_i) \
466  { \
467  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
468  const T &thisR = _th_pp[_i];
469 
470 /** @ingroup macros
471  The macro ForAllThisBNNXC(T,b,ns,nc,x,nss) is intended to facilitate
472  efficient looping over the contents of BaseFabs and objects derived from
473  BaseFab. Special attention has been paid to make it work efficiently on
474  vector supercomputers.
475 
476  This macro acts upon the BaseFab *this and in addition is able to utiliize
477  values in the const BaseFab x. The loop runs over the points in the Box b
478  and over components starting at ns and ending at ns+nc-1. The reference
479  variables are thisR and xR, respectively. As usual the x in xR is replaced
480  by the macro's fifth argument. The sixth argument nss is the number of the
481  argument in x that corresponds to the ns argument in *this.
482 
483  Looping macro mnemonics:
484 
485  This stands for the current object
486 
487  C for a const
488 
489  X stands for a BaseFab
490 
491  B for a Box
492 
493  N for an int
494 */
495 #define ForAllThisBNNXC1(T,b,ns,nc,x,nss) \
496  { \
497  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
498  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
499  Box _subbox_((x).box()); \
500  _subbox_ &= this->box(); \
501  _subbox_ &= b; \
502  if (!_subbox_.isEmpty()) \
503  { \
504  const int *_th_plo = this->loVect(); \
505  const IntVect _th_plen = this->size(); \
506  const int *_x_plo = (x).loVect(); \
507  const IntVect _x_plen = (x).size(); \
508  const int *_subbox_lo = _subbox_.loVect(); \
509  const IntVect _subbox_len = _subbox_.size(); \
510  T* _th_p = dataPtr(ns); \
511  const T* _x_p = (x).dataPtr(nss); \
512  for (int _n = 0; _n < (nc); ++_n) \
513  { \
514  int nR = _n; nR += 0; \
515  T *_th_pp = _th_p \
516  + ((_subbox_lo[0] - _th_plo[0]) \
517  + _n * _th_plen[0]); \
518  const T *_x_pp = _x_p \
519  + ((_subbox_lo[0] - _x_plo[0]) \
520  + _n * _x_plen[0]); \
521  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
522  { \
523  int iR = _i + _subbox_lo[0]; iR += 0; \
524  T &thisR = * _th_pp; \
525  const T & x##R = _x_pp[_i];
526 
527 #define ForAllThisCBNNXC1(T,b,ns,nc,x,nss) \
528  { \
529  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
530  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
531  Box _subbox_((x).box()); \
532  _subbox_ &= this->box(); \
533  _subbox_ &= b; \
534  if (!_subbox_.isEmpty()) \
535  { \
536  const int *_th_plo = this->loVect(); \
537  const IntVect _th_plen = this->size(); \
538  const int *_x_plo = (x).loVect(); \
539  const IntVect _x_plen = (x).size(); \
540  const int *_subbox_lo = _subbox_.loVect(); \
541  const IntVect _subbox_len = _subbox_.size(); \
542  const T* _th_p = this->dataPtr(ns); \
543  const T* _x_p = (x).dataPtr(nss); \
544  for (int _n = 0; _n < (nc); ++_n) \
545  { \
546  int nR = _n; nR += 0; \
547  const T *_th_pp = _th_p \
548  + ((_subbox_lo[0] - _th_plo[0]) \
549  + _n * _th_plen[0]); \
550  const T *_x_pp = _x_p \
551  + ((_subbox_lo[0] - _x_plo[0]) \
552  + _n * _x_plen[0]); \
553  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
554  { \
555  int iR = _i + _subbox_lo[0]; iR += 0; \
556  const T &thisR = * _th_pp; \
557  const T & x##R = _x_pp[_i];
558 
559 /** @ingroup macros
560  The macro ForAllThisBNNXCBN(T,b,ns,nc,x,bx,nss) is intended to facilitate
561  efficient looping over the contents of BaseFabs and objects derived from
562  BaseFab. Special attention has been paid to make it work efficiently on
563  vector supercomputers.
564 
565  This macro acts upon the BaseFab *this and in addition is able to utiliize
566  values in the const BaseFab x. The loop runs over the points in the
567  Box b with components starting at ns and ending at ns+nc-1. The reference
568  variables are thisR and xR, respectively. As usual the x in xR is replaced
569  by the macro's fifth argument. The sixth argument nss is the number of the
570  argument in x that corresponds to the ns argument in *this. Box bx must
571  be the same size as this->box() intersected with b.
572 
573  Looping macro mnemonics:
574 
575  This stands for the current object
576 
577  C for a const
578 
579  X stands for a BaseFab
580 
581  B for a Box
582 
583  N for an int
584 */
585 #define ForAllThisBNNXCBN1(T,b,ns,nc,x,bx,nss) \
586  { \
587  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
588  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
589  CH_assert(bx.sameSize((b))); \
590  if (!((b).isEmpty())) \
591  { \
592  const int *_th_plo = this->loVect(); \
593  const IntVect _th_plen = this->size(); \
594  const int *_x_plo = (x).loVect(); \
595  const IntVect _x_plen = (x).size(); \
596  const int *_subbox_lo = (b).loVect(); \
597  const IntVect _subbox_len = (b).size(); \
598  const int *_bx_lo = (bx).loVect(); \
599  T* _th_p = this->dataPtr(ns); \
600  const T* _x_p = (x).dataPtr(nss); \
601  for (int _n = 0; _n < (nc); ++_n) \
602  { \
603  int nR = _n + ns; nR += 0; \
604  int n##x##R = _n + nss; n##x##R += 0; \
605  T *_th_pp = _th_p \
606  + ((_subbox_lo[0] - _th_plo[0]) \
607  + _n * _th_plen[0]); \
608  const T *_x_pp = _x_p \
609  + ((_bx_lo[0] - _x_plo[0]) \
610  + _n * _x_plen[0]); \
611  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
612  { \
613  int iR = _i + _subbox_lo[0]; iR += 0; \
614  int i##x##R = _i + _bx_lo[0]; i##x##R += 0; \
615  T &thisR = * _th_pp; \
616  const T & x##R = _x_pp[_i];
617 
618 /** @ingroup macros
619  The macro ForAllThisBNNXCBNYCBN(T,b,ns,nc,x,bx,nsx,y,by,nsy) is intended to
620  facilitate efficient looping over the contents of BaseFabs and objects
621  derived from BaseFab. Special attention has been paid to make it work
622  efficiently on vector supercomputers.
623 
624  This macro acts upon the BaseFab *this and in addition is able to utiliize
625  values in the const BaseFab x and const BaseFab y. The loop runs over the
626  points in the intersection of Box b with components starting at ns and
627  ending at ns+nc-1. The reference variables are thisR, xR, and yR
628  respectively. As usual the x in xR is replaced by the macro's fifth argument
629  and likewise for the y in yR. The seventh argument nsx is the number of the
630  argument in x that corresponds to the ns argument in *this, and the eighth
631  argument nsy is the number of the argument in y that corresponds to the ns
632  argument in *this. Boxes bx and by must be the same size as this->box()
633  intersected with b.
634 
635  Looping macro mnemonics:
636 
637  This stands for the current object
638 
639  C for a const
640 
641  X stands for a BaseFab
642 
643  B for a Box
644 
645  N for an int
646 */
647 #define ForAllThisBNNXCBNYCBN1(T,b,ns,nc,x,bx,nsx,y,by,nsy) \
648  { \
649  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
650  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
651  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
652  Box _subbox_ = this->box(); \
653  _subbox_ &= b; \
654  CH_assert((bx).sameSize(_subbox_)); \
655  CH_assert((by).sameSize(_subbox_)); \
656  if (!_subbox_.isEmpty()) \
657  { \
658  const int *_th_plo = this->loVect(); \
659  const IntVect _th_plen = this->size(); \
660  const int *_x_plo = (x).loVect(); \
661  const IntVect _x_plen = (x).size(); \
662  const int *_y_plo = (y).loVect(); \
663  const IntVect _y_plen = (y).size(); \
664  const int *_subbox_lo = _subbox_.loVect(); \
665  const IntVect _subbox_len = _subbox_.size(); \
666  const int *_bx_lo = (bx).loVect(); \
667  const int *_by_lo = (by).loVect(); \
668  T* _th_p = this->dataPtr(ns); \
669  const T* _x_p = (x).dataPtr(nsx); \
670  const T* _y_p = (y).dataPtr(nsy); \
671  for (int _n = 0; _n < (nc); ++_n) \
672  { \
673  int nR = _n + ns; nR += 0; \
674  int n##x##R = _n + nsx; n##x##R += 0; \
675  int n##y##R = _n + nsy; n##y##R += 0; \
676  T *_th_pp = _th_p \
677  + ((_subbox_lo[0] - _th_plo[0]) \
678  + _n * _th_plen[0]); \
679  const T *_x_pp = _x_p \
680  + ((_bx_lo[0] - _x_plo[0]) \
681  + _n * _x_plen[0]); \
682  const T *_y_pp = _y_p \
683  + ((_by_lo[0] - _y_plo[0]) \
684  + _n * _y_plen[0]); \
685  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
686  { \
687  int iR = _i + _subbox_lo[0]; iR += 0; \
688  int i##x##R = _i + _bx_lo[0]; i##x##R += 0; \
689  int i##y##R = _i + _by_lo[0]; i##y##R += 0; \
690  T &thisR = * _th_pp; \
691  const T & x##R = _x_pp[_i]; \
692  const T & y##R = _y_pp[_i];
693 
694 #define ForAllRevXBNYCBNNN1(T,x,bx,nsx,y,by,nsy,nc,ri) \
695  { \
696  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
697  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
698  CH_assert((x).contains(bx)); \
699  CH_assert((y).contains(by)); \
700  CH_assert((bx).sameSize(by)); \
701  const int *_x_plo = (x).loVect(); \
702  const IntVect _x_plen = (x).size(); \
703  const int *_y_plo = (y).loVect(); \
704  const IntVect _y_plen = (y).size(); \
705  const IntVect _len = (bx).size(); \
706  const int *_bx_lo = (bx).loVect(); \
707  const int *_by_lo = (by).loVect(); \
708  T* _x_p = (x).dataPtr(nsx); \
709  const T* _y_p = (y).dataPtr(nsy); \
710  for (int _n = 0; _n < (nc); ++_n) \
711  { \
712  int n##x##R = _n + nsx; n##x##R += 0; \
713  int n##y##R = _n + nsy; n##y##R += 0; \
714  int _ix = 0; \
715  T *_x_pp = _x_p \
716  + ((_bx_lo[0] - _x_plo[0]) + _len[0] - 1 \
717  + _n * _x_plen[0]); \
718  const T *_y_pp = _y_p \
719  + ((_by_lo[0] - _y_plo[0]) \
720  + _n * _y_plen[0]); \
721  for (int _i = 0; _i < _len[0]; ++_i, --_ix) \
722  { \
723  T & x##R = _x_pp[_ix]; \
724  const T & y##R = _y_pp[_i];
725 
726 /** @ingroup macros
727  The macro EndForTX must be used to end all ForAllThisBNNXC,
728  ForAllThisBNNXCBN and ForAllThisBNNXCBNYCBN looping constructs.
729 */
730 #define EndForTX1 \
731  } \
732  } \
733  } \
734  }
735 
736 /** @ingroup macros
737  The macro EndFor must be used to end all ForAllXBNN, ForAllXCBNN,
738  ForAllThisBNN, and ForAllThisCBNN looping constructs.
739 */
740 #define EndFor1 \
741  } \
742  } \
743  }
744 
745 /** @ingroup macros
746  The macro EndForPencil must be used to end ForAll*Pencil looping constructs.
747 */
748 #define EndForPencil1 \
749  } \
750  }
751 
752 #elif (CH_SPACEDIM == 2)
753 
754 #define ForAllThisCPencil2(T,b,ns,nc) \
755  { \
756  CH_assert(contains(b)); \
757  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
758  const int *_th_plo = this->loVect(); \
759  const IntVect _th_plen = this->size(); \
760  const int *_b_lo = (b).loVect(); \
761  const IntVect _b_len = (b).size(); \
762  const T* _th_p = this->m_dptr; \
763  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
764  { \
765  int nR = _n; nR += 0; \
766  for (int _j = 0; _j < _b_len[1]; ++_j) \
767  { \
768  const int jR = _j + _b_lo[1]; \
769  const T *_th_pp = _th_p \
770  + ((_b_lo[0] - _th_plo[0]) \
771  + _th_plen[0]*( \
772  (jR - _th_plo[1]) \
773  + _n * _th_plen[1])); \
774  const T &thisR = * _th_pp; \
775  const int thisLen = _b_len[0];
776 
777 #define ForAllThisPencil2(T,b,ns,nc) \
778  { \
779  CH_assert(this->contains(b)); \
780  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
781  const int *_th_plo = this->loVect(); \
782  const IntVect _th_plen = this->size(); \
783  const int *_b_lo = (b).loVect(); \
784  const IntVect _b_len = (b).size(); \
785  T* _th_p = this->m_dptr; \
786  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
787  { \
788  const int nR = _n; (int&)nR += 0; \
789  for (int _j = 0; _j < _b_len[1]; ++_j) \
790  { \
791  const int jR = _j + _b_lo[1]; (int&)jR += 0; \
792  T *_th_pp = _th_p \
793  + ((_b_lo[0] - _th_plo[0]) \
794  + _th_plen[0]*( \
795  (jR - _th_plo[1]) \
796  + _n * _th_plen[1])); \
797  T &thisR = * _th_pp; \
798  const int thisLen = _b_len[0]; \
799 
800 #define ForAllXBPencil2(T,x,b,ns,nc) \
801  { \
802  CH_assert((x).contains(b)); \
803  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
804  const int *_th_plo = (x).loVect(); \
805  const IntVect _th_plen =(x).size(); \
806  const int *_b_lo = (b).loVect(); \
807  const IntVect _b_len = (b).size(); \
808  T* _th_p = (x) .dataPtr(); \
809  for (int nR = (ns); nR < (ns)+(nc); ++nR) \
810  { \
811  for (int _j = 0; _j < _b_len[1]; ++_j) \
812  { \
813  const int jR = _j + _b_lo[1]; (int&)jR += 0; \
814  T *xR = _th_p \
815  + ((_b_lo[0] - _th_plo[0]) \
816  + _th_plen[0]*( \
817  (jR - _th_plo[1]) \
818  + nR * _th_plen[1])); \
819  const int thisLen = _b_len[0]; \
820 
821 #define ForAllXBNN2(T,x,b,ns,nc) \
822  { \
823  CH_assert((x).contains(b)); \
824  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
825  const int *_x_plo = (x).loVect(); \
826  const IntVect _x_plen = (x).size(); \
827  const int *_b_lo = (b).loVect(); \
828  const IntVect _b_len = (b).size(); \
829  T* _x_p = (x) .dataPtr(); \
830  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
831  { \
832  const int nR = _n; (int&)nR += 0; \
833  for (int _j = 0; _j < _b_len[1]; ++_j) \
834  { \
835  const int jR = _j + _b_lo[1]; (int&)jR += 0; \
836  T *_x_pp = _x_p \
837  + ((_b_lo[0] - _x_plo[0]) \
838  + _x_plen[0]*( \
839  (jR - _x_plo[1]) \
840  + _n * _x_plen[1])); \
841  for (int _i = 0; _i < _b_len[0]; ++_i, ++_x_pp) \
842  { \
843  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
844  T &x##R = * _x_pp;
845 
846 #define ForAllXBNNnoindx2(T,x,b,ns,nc) \
847  { \
848  CH_assert((x).contains(b)); \
849  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
850  const int *_x_plo = (x).loVect(); \
851  const IntVect _x_plen = (x).size(); \
852  const int *_b_lo = (b).loVect(); \
853  const IntVect _b_len = (b).size(); \
854  T* _x_p = (x) .dataPtr(); \
855  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
856  { \
857  for (int _j = 0; _j < _b_len[1]; ++_j) \
858  { \
859  const int jR = _j + _b_lo[1]; \
860  T *_x_pp = _x_p \
861  + ((_b_lo[0] - _x_plo[0]) \
862  + _x_plen[0]*( \
863  (jR - _x_plo[1]) \
864  + _n * _x_plen[1])); \
865  for (int _i = 0; _i < _b_len[0]; ++_i, ++_x_pp) \
866  { \
867  T &x##R = * _x_pp;
868 
869 #define ForAllXCBNN2(T,x,b,ns,nc) \
870  { \
871  CH_assert(x.contains(b)); \
872  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
873  const int *_x_plo = (x).loVect(); \
874  const IntVect _x_plen = (x).size(); \
875  const int *_b_lo = (b).loVect(); \
876  const IntVect _b_len = (b).size(); \
877  const T* _x_p = (x).dataPtr(); \
878  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
879  { \
880  const int nR = _n; (int&)nR += 0; \
881  for (int _j = 0; _j < _b_len[1]; ++_j) \
882  { \
883  const int jR = _j + _b_lo[1]; \
884  const T *_x_pp = _x_p \
885  + ((_b_lo[0] - _x_plo[0]) \
886  + _x_plen[0]*( \
887  (jR - _x_plo[1]) \
888  + _n * _x_plen[1])); \
889  for (int _i = 0; _i < _b_len[0]; ++_i) \
890  { \
891  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
892  const T & x##R = _x_pp[_i];
893 
894 #define ForAllThisBNN2(T,b,ns,nc) \
895  { \
896  CH_assert(this->contains(b)); \
897  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
898  const int *_th_plo = this->loVect(); \
899  const IntVect _th_plen = this->size(); \
900  const int *_b_lo = (b).loVect(); \
901  const IntVect _b_len = (b).size(); \
902  T* _th_p = this->m_dptr; \
903  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
904  { \
905  int nR = _n; nR += 0; \
906  for (int _j = 0; _j < _b_len[1]; ++_j) \
907  { \
908  const int jR = _j + _b_lo[1]; \
909  T *_th_pp = _th_p \
910  + ((_b_lo[0] - _th_plo[0]) \
911  + _th_plen[0]*( \
912  (jR - _th_plo[1]) \
913  + _n * _th_plen[1])); \
914  for (int _i = 0; _i < _b_len[0]; ++_i, ++_th_pp) \
915  { \
916  int iR = _i + _b_lo[0]; iR += 0; \
917  T &thisR = * _th_pp;
918 
919 #define ForAllThisCBNN2(T,b,ns,nc) \
920  { \
921  CH_assert(this->contains(b)); \
922  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
923  const int *_th_plo = this->loVect(); \
924  const IntVect _th_plen = this->size(); \
925  const int *_b_lo = (b).loVect(); \
926  const IntVect _b_len = (b).size(); \
927  const T* _th_p = this->m_dptr; \
928  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
929  { \
930  const int nR = _n; (int&)nR += 0; \
931  for (int _j = 0; _j < _b_len[1]; ++_j) \
932  { \
933  const int jR = _j + _b_lo[1]; (int&)jR+=0;; \
934  const T *_th_pp = _th_p \
935  + ((_b_lo[0] - _th_plo[0]) \
936  + _th_plen[0]*( \
937  (_j + _b_lo[1] - _th_plo[1]) \
938  + _n * _th_plen[1])); \
939  for (int _i = 0; _i < _b_len[0]; ++_i) \
940  { \
941  const int iR = _i + _b_lo[0]; (int&)iR +=0; \
942  const T &thisR = _th_pp[_i];
943 
944 #define ForAllThisBNNXC2(T,b,ns,nc,x,nss) \
945  { \
946  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
947  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
948  Box _subbox_((x).box()); \
949  _subbox_ &= this->box(); \
950  _subbox_ &= b; \
951  if (!_subbox_.isEmpty()) \
952  { \
953  const int *_th_plo = this->loVect(); \
954  const IntVect _th_plen = this->size(); \
955  const int *_x_plo = (x).loVect(); \
956  const IntVect _x_plen = (x).size(); \
957  const int *_subbox_lo = _subbox_.loVect(); \
958  const IntVect _subbox_len = _subbox_.size(); \
959  T* _th_p = this->dataPtr(ns); \
960  const T* _x_p = (x).dataPtr(nss); \
961  for (int _n = 0; _n < (nc); ++_n) \
962  { \
963  int nR = _n; nR += 0; \
964  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
965  { \
966  const int jR = _j + _subbox_lo[1]; \
967  T *_th_pp = _th_p \
968  + ((_subbox_lo[0] - _th_plo[0]) \
969  + _th_plen[0]*( \
970  (jR - _th_plo[1]) \
971  + _n * _th_plen[1])); \
972  const T *_x_pp = _x_p \
973  + ((_subbox_lo[0] - _x_plo[0]) \
974  + _x_plen[0]*( \
975  (jR - _x_plo[1]) \
976  + _n * _x_plen[1])); \
977  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
978  { \
979  int iR = _i + _subbox_lo[0]; iR += 0; \
980  T &thisR = * _th_pp; \
981  const T & x##R = _x_pp[_i];
982 
983 #define ForAllThisCBNNXC2(T,b,ns,nc,x,nss) \
984  { \
985  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
986  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
987  Box _subbox_((x).box()); \
988  _subbox_ &= this->box(); \
989  _subbox_ &= b; \
990  if (!_subbox_.isEmpty()) \
991  { \
992  const int *_th_plo = this->loVect(); \
993  const IntVect _th_plen = this->size(); \
994  const int *_x_plo = (x).loVect(); \
995  const IntVect _x_plen = (x).size(); \
996  const int *_subbox_lo = _subbox_.loVect(); \
997  const IntVect _subbox_len = _subbox_.size(); \
998  const T* _th_p = this->dataPtr(ns); \
999  const T* _x_p = (x).dataPtr(nss); \
1000  for (int _n = 0; _n < (nc); ++_n) \
1001  { \
1002  int nR = _n; nR += 0; \
1003  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1004  { \
1005  const int jR = _j + _subbox_lo[1]; \
1006  const T *_th_pp = _th_p \
1007  + ((_subbox_lo[0] - _th_plo[0]) \
1008  + _th_plen[0]*( \
1009  (jR - _th_plo[1]) \
1010  + _n * _th_plen[1])); \
1011  const T *_x_pp = _x_p \
1012  + ((_subbox_lo[0] - _x_plo[0]) \
1013  + _x_plen[0]*( \
1014  (jR - _x_plo[1]) \
1015  + _n * _x_plen[1])); \
1016  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
1017  { \
1018  int iR = _i + _subbox_lo[0]; iR += 0; \
1019  const T &thisR = * _th_pp; \
1020  const T & x##R = _x_pp[_i];
1021 
1022 #define ForAllThisBNNXCBN2(T,b,ns,nc,x,bx,nss) \
1023  { \
1024  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1025  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1026  CH_assert(bx.sameSize((b))); \
1027  if (!((b).isEmpty())) \
1028  { \
1029  const int *_th_plo = this->loVect(); \
1030  const IntVect _th_plen = this->size(); \
1031  const int *_x_plo = (x).loVect(); \
1032  const IntVect _x_plen = (x).size(); \
1033  const int *_subbox_lo = (b).loVect(); \
1034  const IntVect _subbox_len = (b).size(); \
1035  const int *_bx_lo = (bx).loVect(); \
1036  T* _th_p = this->dataPtr(ns); \
1037  int nR = ns; int n##x##R = nss; \
1038  const T* _x_p = (x).dataPtr(nss); \
1039  for (int _n = 0; _n < (nc); ++_n, ++nR, ++n##x##R ) \
1040  { \
1041  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1042  { \
1043  const int jR = _j + _subbox_lo[1]; \
1044  const int j##x##R = _j + _bx_lo[1]; \
1045  T *_th_pp = _th_p \
1046  + ((_subbox_lo[0] - _th_plo[0]) \
1047  + _th_plen[0]*( \
1048  (jR - _th_plo[1]) \
1049  + _n * _th_plen[1])); \
1050  const T *_x_pp = _x_p \
1051  + ((_bx_lo[0] - _x_plo[0]) \
1052  + _x_plen[0]*( \
1053  (j##x##R - _x_plo[1]) \
1054  + _n * _x_plen[1])); \
1055  int iR = _subbox_lo[0]; int i##x##R = _bx_lo[0]; \
1056  for (int _i = 0; _i < _subbox_len[0]; \
1057  ++_i, ++_th_pp, ++_x_pp, ++iR, ++i##x##R) \
1058  { \
1059  T &thisR = * _th_pp; \
1060  const T & x##R = * _x_pp;
1061 
1062 #define ForAllThisBNNXCBNYCBN2(T,b,ns,nc,x,bx,nsx,y,by,nsy) \
1063  { \
1064  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1065  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
1066  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
1067  Box _subbox_ = this->box(); \
1068  _subbox_ &= b; \
1069  CH_assert((bx).sameSize(_subbox_)); \
1070  CH_assert((by).sameSize(_subbox_)); \
1071  if (!_subbox_.isEmpty()) \
1072  { \
1073  const int *_th_plo = this->loVect(); \
1074  const IntVect _th_plen = this->size(); \
1075  const int *_x_plo = (x).loVect(); \
1076  const IntVect _x_plen = (x).size(); \
1077  const int *_y_plo = (y).loVect(); \
1078  const IntVect _y_plen = (y).size(); \
1079  const int *_subbox_lo = _subbox_.loVect(); \
1080  const IntVect _subbox_len = _subbox_.size(); \
1081  const int *_bx_lo = (bx).loVect(); \
1082  const int *_by_lo = (by).loVect(); \
1083  T* _th_p = this->dataPtr(ns); \
1084  const T* _x_p = (x).dataPtr(nsx); \
1085  const T* _y_p = (y).dataPtr(nsy); \
1086  for (int _n = 0; _n < (nc); ++_n) \
1087  { \
1088  int nR = _n + ns; nR += 0; \
1089  int n##x##R = _n + nsx; n##x##R += 0; \
1090  int n##y##R = _n + nsy; n##y##R += 0; \
1091  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1092  { \
1093  const int jR = _j + _subbox_lo[1]; \
1094  const int j##x##R = _j + _bx_lo[1]; \
1095  const int j##y##R = _j + _by_lo[1]; \
1096  T *_th_pp = _th_p \
1097  + ((_subbox_lo[0] - _th_plo[0]) \
1098  + _th_plen[0]*( \
1099  (jR - _th_plo[1]) \
1100  + _n * _th_plen[1])); \
1101  const T *_x_pp = _x_p \
1102  + ((_bx_lo[0] - _x_plo[0]) \
1103  + _x_plen[0]*( \
1104  (j##x##R - _x_plo[1]) \
1105  + _n * _x_plen[1])); \
1106  const T *_y_pp = _y_p \
1107  + ((_by_lo[0] - _y_plo[0]) \
1108  + _y_plen[0]*( \
1109  (j##y##R - _y_plo[1]) \
1110  + _n * _y_plen[1])); \
1111  for (int _i = 0; _i < _subbox_len[0]; ++_i, ++_th_pp) \
1112  { \
1113  int iR = _i + _subbox_lo[0]; iR += 0; \
1114  int i##x##R = _i + _bx_lo[0]; i##x##R += 0; \
1115  int i##y##R = _i + _by_lo[0]; i##y##R += 0; \
1116  T &thisR = * _th_pp; \
1117  const T & x##R = _x_pp[_i]; \
1118  const T & y##R = _y_pp[_i];
1119 
1120 #define ForAllRevXBNYCBNNN2(T,x,bx,nsx,y,by,nsy,nc,ir) \
1121  { \
1122  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
1123  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
1124  CH_assert((ir) >= 0 && (ir) < SpaceDim); \
1125  CH_assert((x).contains(bx)); \
1126  CH_assert((y).contains(by)); \
1127  CH_assert((bx).sameSize(by)); \
1128  const int *_x_plo = (x).loVect(); \
1129  const IntVect _x_plen = (x).size(); \
1130  const int *_y_plo = (y).loVect(); \
1131  const int *_y_plen = (y).size(); \
1132  const int *_bx_lo = (bx).loVect(); \
1133  const int *_by_lo = (by).loVect(); \
1134  const IntVect _len = (bx).size(); \
1135  T* _x_p = (x).dataPtr(nsx); \
1136  const T* _y_p = (y).dataPtr(nsy); \
1137  for (int _n = 0; _n < (nc); ++_n) \
1138  { \
1139  int n##x##R = _n + nsx; n##x##R += 0; \
1140  int n##y##R = _n + nsy; n##y##R += 0; \
1141  for (int _j = 0; _j < _len[1]; ++_j) \
1142  { \
1143  const int j##x##R = _j + _bx_lo[1]; \
1144  const int jrev##x##R = _len[1]-1-_j + _bx_lo[1]; \
1145  const int j##y##R = _j + _by_lo[1]; \
1146  T *_x_pp; \
1147  int _ix = 0; \
1148  int _istrd; \
1149  if (ir == 0) \
1150  { \
1151  _x_pp = _x_p \
1152  + ((_bx_lo[0] - _x_plo[0]) + _len[0] - 1 \
1153  + _x_plen[0]*( \
1154  (j##x##R - _x_plo[1]) \
1155  + _n * _x_plen[1])); \
1156  _istrd = -1; \
1157  } \
1158  else \
1159  { \
1160  _x_pp = _x_p \
1161  + ((_bx_lo[0] - _x_plo[0]) \
1162  + _x_plen[0]*( \
1163  (jrev##x##R - _x_plo[1]) \
1164  + _n * _x_plen[1])); \
1165  _istrd = 1; \
1166  } \
1167  const T *_y_pp = _y_p \
1168  + ((_by_lo[0] - _y_plo[0]) \
1169  + _y_plen[0]*( \
1170  (j##y##R - _y_plo[1]) \
1171  + _n * _y_plen[1])); \
1172  int _x_rev = _len[0]-1; _x_rev += 0; \
1173  for (int _i = 0; _i < _len[0]; ++_i, _ix+=_istrd) \
1174  { \
1175  T & x##R = _x_pp[_ix]; \
1176  const T & y##R = _y_pp[_i];
1177 
1178 #define EndFor2 \
1179  } \
1180  } \
1181  } \
1182  }
1183 
1184 #define EndForTX2 \
1185  } \
1186  } \
1187  } \
1188  } \
1189  }
1190 
1191 #define EndForPencil2 \
1192  } \
1193  } \
1194  }
1195 
1196 #elif (CH_SPACEDIM == 3)
1197 
1198 #define ForAllThisCPencil3(T,b,ns,nc) \
1199  { \
1200  CH_assert(this->contains(b)); \
1201  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1202  const int *_th_plo = this->loVect(); \
1203  const IntVect _th_plen = this->size(); \
1204  const int *_b_lo = (b).loVect(); \
1205  const IntVect _b_len = (b).size(); \
1206  const T* _th_p = this->m_dptr; \
1207  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1208  { \
1209  int nR = _n; nR += 0; \
1210  for (int _k = 0; _k < _b_len[2]; ++_k) \
1211  { \
1212  const int kR = _k + _b_lo[2]; \
1213  for (int _j = 0; _j < _b_len[1]; ++_j) \
1214  { \
1215  const int jR = _j + _b_lo[1]; \
1216  const T *_th_pp = _th_p \
1217  + ((_b_lo[0] - _th_plo[0]) \
1218  + _th_plen[0]*( \
1219  (jR - _th_plo[1]) \
1220  + _th_plen[1]*( \
1221  (kR - _th_plo[2]) \
1222  + _n * _th_plen[2]))); \
1223  const T &thisR = * _th_pp; \
1224  const int thisLen = _b_len[0];
1225 
1226 #define ForAllThisPencil3(T,b,ns,nc) \
1227  { \
1228  CH_assert(this->contains(b)); \
1229  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1230  const int *_th_plo = this->loVect(); \
1231  const IntVect _th_plen = this->size(); \
1232  const int *_b_lo = (b).loVect(); \
1233  const IntVect _b_len = (b).size(); \
1234  T* _th_p = this->m_dptr; \
1235  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1236  { \
1237  const int nR = _n; (int&)nR += 0; \
1238  for (int _k = 0; _k < _b_len[2]; ++_k) \
1239  { \
1240  const int kR = _k + _b_lo[2]; \
1241  for (int _j = 0; _j < _b_len[1]; ++_j) \
1242  { \
1243  const int jR = _j + _b_lo[1]; \
1244  T *_th_pp = _th_p \
1245  + ((_b_lo[0] - _th_plo[0]) \
1246  + _th_plen[0]*( \
1247  (jR - _th_plo[1]) \
1248  + _th_plen[1]*( \
1249  (kR - _th_plo[2]) \
1250  + _n * _th_plen[2]))); \
1251  T &thisR = * _th_pp; \
1252  const int thisLen = _b_len[0]; \
1253 
1254 #define ForAllXBPencil3(T,x,b,ns,nc) \
1255  { \
1256  CH_assert((x).contains(b)); \
1257  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1258  const int *_th_plo = (x).loVect(); \
1259  const IntVect _th_plen = (x).size(); \
1260  const int *_b_lo = (b).loVect(); \
1261  const IntVect _b_len = (b).size(); \
1262  T* _th_p = (x) .dataPtr(); \
1263  for (int nR = (ns); nR < (ns)+(nc); ++nR) \
1264  { \
1265  for (int _k = 0; _k < _b_len[2]; ++_k) \
1266  { \
1267  const int kR = _k + _b_lo[2]; \
1268  for (int _j = 0; _j < _b_len[1]; ++_j) \
1269  { \
1270  const int jR = _j + _b_lo[1]; \
1271  T *xR = _th_p \
1272  + ((_b_lo[0] - _th_plo[0]) \
1273  + _th_plen[0]*( \
1274  (jR - _th_plo[1]) \
1275  + _th_plen[1]*( \
1276  (kR - _th_plo[2]) \
1277  + nR * _th_plen[2]))); \
1278  const int thisLen = _b_len[0];
1279 
1280 #define ForAllXBNN3(T,x,b,ns,nc) \
1281  { \
1282  CH_assert(x.contains(b)); \
1283  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1284  const int *_x_plo = (x).loVect(); \
1285  const IntVect _x_plen = (x).size(); \
1286  const int *_b_lo = (b).loVect(); \
1287  const IntVect _b_len = (b).size(); \
1288  T* _x_p = (x) .dataPtr(); \
1289  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1290  { \
1291  const int nR = _n; (int&)nR += 0; \
1292  for (int _k = 0; _k < _b_len[2]; ++_k) \
1293  { \
1294  const int kR = _k + _b_lo[2]; \
1295  for (int _j = 0; _j < _b_len[1]; ++_j) \
1296  { \
1297  const int jR = _j + _b_lo[1]; \
1298  T *_x_pp = _x_p \
1299  + ((_b_lo[0] - _x_plo[0]) \
1300  + _x_plen[0]*( \
1301  (jR - _x_plo[1]) \
1302  + _x_plen[1]*( \
1303  (kR - _x_plo[2]) \
1304  + _n * _x_plen[2]))); \
1305  for (int _i = 0; _i < _b_len[0]; ++_i, ++_x_pp) \
1306  { \
1307  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
1308  T &x##R = * _x_pp;
1309 
1310 #define ForAllXBNNnoindx3(T,x,b,ns,nc) \
1311  { \
1312  CH_assert(x.contains(b)); \
1313  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1314  const int *_x_plo = (x).loVect(); \
1315  const IntVect _x_plen = (x).size(); \
1316  const int *_b_lo = (b).loVect(); \
1317  const IntVect _b_len = (b).size(); \
1318  T* _x_p = (x) .dataPtr(); \
1319  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1320  { \
1321  for (int _k = 0; _k < _b_len[2]; ++_k) \
1322  { \
1323  const int kR = _k + _b_lo[2]; \
1324  for (int _j = 0; _j < _b_len[1]; ++_j) \
1325  { \
1326  const int jR = _j + _b_lo[1]; \
1327  T *_x_pp = _x_p \
1328  + ((_b_lo[0] - _x_plo[0]) \
1329  + _x_plen[0]*( \
1330  (jR - _x_plo[1]) \
1331  + _x_plen[1]*( \
1332  (kR - _x_plo[2]) \
1333  + _n * _x_plen[2]))); \
1334  for (int _i = 0; _i < _b_len[0]; ++_i, ++_x_pp) \
1335  { \
1336  T &x##R = * _x_pp;
1337 
1338 #define ForAllXCBNN3(T,x,b,ns,nc) \
1339  { \
1340  CH_assert(x.contains(b)); \
1341  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1342  const int *_x_plo = (x).loVect(); \
1343  const IntVect _x_plen = (x).size(); \
1344  const int *_b_lo = (b).loVect(); \
1345  const IntVect _b_len = (b).size(); \
1346  const T* _x_p = (x).dataPtr(); \
1347  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1348  { \
1349  const int nR = _n; (int&)nR += 0; \
1350  for (int _k = 0; _k < _b_len[2]; ++_k) \
1351  { \
1352  const int kR = _k + _b_lo[2]; \
1353  for (int _j = 0; _j < _b_len[1]; ++_j) \
1354  { \
1355  const int jR = _j + _b_lo[1]; \
1356  const T *_x_pp = _x_p \
1357  + ((_b_lo[0] - _x_plo[0]) \
1358  + _x_plen[0]*( \
1359  (jR - _x_plo[1]) \
1360  + _x_plen[1]*( \
1361  (kR - _x_plo[2]) \
1362  + _n * _x_plen[2]))); \
1363  for (int _i = 0; _i < _b_len[0]; ++_i) \
1364  { \
1365  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
1366  const T & x##R = _x_pp[_i];
1367 
1368 #define ForAllThisBNN3(T,b,ns,nc) \
1369  { \
1370  CH_assert(this->contains(b)); \
1371  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1372  const int *_th_plo = this->loVect(); \
1373  const IntVect _th_plen = this->size(); \
1374  const int *_b_lo = (b).loVect(); \
1375  const IntVect _b_len = (b).size(); \
1376  T* _th_p = this->m_dptr; \
1377  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1378  { \
1379  int nR = _n; nR += 0; \
1380  for (int _k = 0; _k < _b_len[2]; ++_k) \
1381  { \
1382  const int kR = _k + _b_lo[2]; \
1383  for (int _j = 0; _j < _b_len[1]; ++_j) \
1384  { \
1385  const int jR = _j + _b_lo[1]; \
1386  T *_th_pp = _th_p \
1387  + ((_b_lo[0] - _th_plo[0]) \
1388  + _th_plen[0]*( \
1389  (jR - _th_plo[1]) \
1390  + _th_plen[1]*( \
1391  (kR - _th_plo[2]) \
1392  + _n * _th_plen[2]))); \
1393  for (int _i = 0; _i < _b_len[0]; ++_i, ++_th_pp) \
1394  { \
1395  int iR = _i + _b_lo[0]; iR += 0; \
1396  T &thisR = * _th_pp;
1397 
1398 #define ForAllThisCBNN3(T,b,ns,nc) \
1399  { \
1400  CH_assert(this->contains(b)); \
1401  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1402  const int *_th_plo = this->loVect(); \
1403  const IntVect _th_plen = this->size(); \
1404  const int *_b_lo = (b).loVect(); \
1405  const IntVect _b_len = (b).size(); \
1406  const T* _th_p = this->m_dptr; \
1407  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1408  { \
1409  const int nR = _n; (int&)nR += 0; \
1410  for (int _k = 0; _k < _b_len[2]; ++_k) \
1411  { \
1412  const int kR = _k + _b_lo[2]; \
1413  for (int _j = 0; _j < _b_len[1]; ++_j) \
1414  { \
1415  const int jR = _j + _b_lo[1]; \
1416  const T *_th_pp = _th_p \
1417  + ((_b_lo[0] - _th_plo[0]) \
1418  + _th_plen[0]*( \
1419  (jR - _th_plo[1]) \
1420  + _th_plen[1]*( \
1421  (kR - _th_plo[2]) \
1422  + _n * _th_plen[2]))); \
1423  for (int _i = 0; _i < _b_len[0]; ++_i) \
1424  { \
1425  const int iR = _i + _b_lo[0]; (int&)iR += 0; \
1426  const T &thisR = _th_pp[_i];
1427 
1428 #define ForAllThisBNNXC3(T,b,ns,nc,x,nss) \
1429  { \
1430  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1431  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1432  Box _subbox_((x).box()); \
1433  _subbox_ &= this->box(); \
1434  _subbox_ &= b; \
1435  if (!_subbox_.isEmpty()) \
1436  { \
1437  const int *_th_plo = this->loVect(); \
1438  const IntVect _th_plen = this->size(); \
1439  const int *_x_plo = (x).loVect(); \
1440  const IntVect _x_plen = (x).size(); \
1441  const int *_subbox_lo = _subbox_.loVect(); \
1442  const IntVect _subbox_len = _subbox_.size(); \
1443  T* _th_p = this->dataPtr(ns); \
1444  const T* _x_p = (x).dataPtr(nss); \
1445  for (int _n = 0; _n < (nc); ++_n) \
1446  { \
1447  int nR = _n; nR += 0; \
1448  for (int _k = 0; _k < _subbox_len[2]; ++_k) \
1449  { \
1450  const int kR = _k + _subbox_lo[2]; \
1451  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1452  { \
1453  const int jR = _j + _subbox_lo[1]; \
1454  T *_th_pp = _th_p \
1455  + ((_subbox_lo[0] - _th_plo[0]) \
1456  + _th_plen[0]*( \
1457  (jR - _th_plo[1]) \
1458  + _th_plen[1]*( \
1459  (kR - _th_plo[2]) \
1460  + _n * _th_plen[2]))); \
1461  const T *_x_pp = _x_p \
1462  + ((_subbox_lo[0] - _x_plo[0]) \
1463  + _x_plen[0]*( \
1464  (jR - _x_plo[1]) \
1465  + _x_plen[1]*( \
1466  (kR - _x_plo[2]) \
1467  + _n * _x_plen[2]))); \
1468  for (int _i = 0; _i < _subbox_len[0]; \
1469  ++_i, ++_th_pp) \
1470  { \
1471  int iR = _i + _subbox_lo[0]; iR += 0; \
1472  T &thisR = * _th_pp; \
1473  const T & x##R = _x_pp[_i];
1474 
1475 #define ForAllThisCBNNXC3(T,b,ns,nc,x,nss) \
1476  { \
1477  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1478  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1479  Box _subbox_((x).box()); \
1480  _subbox_ &= this->box(); \
1481  _subbox_ &= b; \
1482  if (!_subbox_.isEmpty()) \
1483  { \
1484  const int *_th_plo = this->loVect(); \
1485  const IntVect _th_plen = this->size(); \
1486  const int *_x_plo = (x).loVect(); \
1487  const IntVect _x_plen = (x).size(); \
1488  const int *_subbox_lo = _subbox_.loVect(); \
1489  const IntVect _subbox_len = _subbox_.size(); \
1490  const T* _th_p = this->dataPtr(ns); \
1491  const T* _x_p = (x).dataPtr(nss); \
1492  for (int _n = 0; _n < (nc); ++_n) \
1493  { \
1494  int nR = _n; nR += 0; \
1495  for (int _k = 0; _k < _subbox_len[2]; ++_k) \
1496  { \
1497  const int kR = _k + _subbox_lo[2]; \
1498  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1499  { \
1500  const int jR = _j + _subbox_lo[1]; \
1501  const T *_th_pp = _th_p \
1502  + ((_subbox_lo[0] - _th_plo[0]) \
1503  + _th_plen[0]*( \
1504  (jR - _th_plo[1]) \
1505  + _th_plen[1]*( \
1506  (kR - _th_plo[2]) \
1507  + _n * _th_plen[2]))); \
1508  const T *_x_pp = _x_p \
1509  + ((_subbox_lo[0] - _x_plo[0]) \
1510  + _x_plen[0]*( \
1511  (jR - _x_plo[1]) \
1512  + _x_plen[1]*( \
1513  (kR - _x_plo[2]) \
1514  + _n * _x_plen[2]))); \
1515  for (int _i = 0; _i < _subbox_len[0]; \
1516  ++_i, ++_th_pp) \
1517  { \
1518  int iR = _i + _subbox_lo[0]; iR += 0; \
1519  const T &thisR = * _th_pp; \
1520  const T & x##R = _x_pp[_i];
1521 
1522 #define ForAllThisBNNXCBN3(T,b,ns,nc,x,bx,nss) \
1523  { \
1524  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1525  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1526  CH_assert((bx).sameSize((b))); \
1527  if (!((b).isEmpty())) \
1528  { \
1529  const int *_th_plo = this->loVect(); \
1530  const IntVect _th_plen = this->size(); \
1531  const int *_x_plo = (x).loVect(); \
1532  const IntVect _x_plen = (x).size(); \
1533  const int *_subbox_lo = (b).loVect(); \
1534  IntVect _subbox_len = (b).size(); \
1535  const int *_bx_lo = (bx).loVect(); \
1536  T* _th_p = this->dataPtr(ns); \
1537  const T* _x_p = (x).dataPtr(nss); \
1538  for (int _n = 0; _n < (nc); ++_n) \
1539  { \
1540  int nR = _n + ns; nR += 0; \
1541  int n##x##R = _n + nss; n##x##R += 0; \
1542  for (int _k = 0; _k < _subbox_len[2]; ++_k) \
1543  { \
1544  const int kR = _k + _subbox_lo[2]; \
1545  const int k##x##R = _k + _bx_lo[2]; \
1546  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1547  { \
1548  const int jR = _j + _subbox_lo[1]; \
1549  const int j##x##R = _j + _bx_lo[1]; \
1550  T *_th_pp = _th_p \
1551  + ((_subbox_lo[0] - _th_plo[0]) \
1552  + _th_plen[0]*( \
1553  (jR - _th_plo[1]) \
1554  + _th_plen[1]*( \
1555  (kR - _th_plo[2]) \
1556  + _n * _th_plen[2]))); \
1557  const T *_x_pp = _x_p \
1558  + ((_bx_lo[0] - _x_plo[0]) \
1559  + _x_plen[0]*( \
1560  (j##x##R - _x_plo[1]) \
1561  + _x_plen[1]*( \
1562  (k##x##R - _x_plo[2]) \
1563  + _n * _x_plen[2]))); \
1564  for (int _i = 0; _i < _subbox_len[0]; \
1565  ++_i, ++_th_pp) \
1566  { \
1567  int iR = _i + _subbox_lo[0]; iR += 0; \
1568  int i##x##R = _i + _bx_lo[0]; i##x##R += 0; \
1569  T &thisR = * _th_pp; \
1570  const T & x##R = _x_pp[_i];
1571 
1572 #define ForAllThisBNNXCBNYCBN3(T,b,ns,nc,x,bx,nsx,y,by,nsy) \
1573  { \
1574  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1575  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
1576  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
1577  Box _subbox_(this->box()); \
1578  _subbox_ &= b; \
1579  CH_assert((bx).sameSize(_subbox_)); \
1580  CH_assert((by).sameSize(_subbox_)); \
1581  if (!_subbox_.isEmpty()) \
1582  { \
1583  const int *_th_plo = this->loVect(); \
1584  const IntVect _th_plen = this->size(); \
1585  const int *_x_plo = (x).loVect(); \
1586  const IntVect _x_plen = (x).size(); \
1587  const int *_y_plo = (y).loVect(); \
1588  const IntVect _y_plen = (y).size(); \
1589  const int *_subbox_lo = _subbox_.loVect(); \
1590  const IntVect _subbox_len = _subbox_.size(); \
1591  const int *_bx_lo = (bx).loVect(); \
1592  const int *_by_lo = (by).loVect(); \
1593  T* _th_p = this->dataPtr(ns); \
1594  const T* _x_p = (x).dataPtr(nsx); \
1595  const T* _y_p = (y).dataPtr(nsy); \
1596  for (int _n = 0; _n < (nc); ++_n) \
1597  { \
1598  int nR = _n + ns; nR += 0; \
1599  int n##x##R = _n + nsx; n##x##R += 0; \
1600  int n##y##R = _n + nsy; n##y##R += 0; \
1601  for (int _k = 0; _k < _subbox_len[2]; ++_k) \
1602  { \
1603  const int kR = _k + _subbox_lo[2]; \
1604  const int k##x##R = _k + _bx_lo[2]; \
1605  const int k##y##R = _k + _by_lo[2]; \
1606  for (int _j = 0; _j < _subbox_len[1]; ++_j) \
1607  { \
1608  const int jR = _j + _subbox_lo[1]; \
1609  const int j##x##R = _j + _bx_lo[1]; \
1610  const int j##y##R = _j + _by_lo[1]; \
1611  T *_th_pp = _th_p \
1612  + ((_subbox_lo[0] - _th_plo[0]) \
1613  + _th_plen[0]*( \
1614  (jR - _th_plo[1]) \
1615  + _th_plen[1]*( \
1616  (kR - _th_plo[2]) \
1617  + _n * _th_plen[2]))); \
1618  const T *_x_pp = _x_p \
1619  + ((_bx_lo[0] - _x_plo[0]) \
1620  + _x_plen[0]*( \
1621  (j##x##R - _x_plo[1]) \
1622  + _x_plen[1]*( \
1623  (k##x##R - _x_plo[2]) \
1624  + _n * _x_plen[2]))); \
1625  const T *_y_pp = _y_p \
1626  + ((_by_lo[0] - _y_plo[0]) \
1627  + _y_plen[0]*( \
1628  (j##y##R - _y_plo[1]) \
1629  + _y_plen[1]*( \
1630  (k##y##R - _y_plo[2]) \
1631  + _n * _y_plen[2]))); \
1632  for (int _i = 0; _i < _subbox_len[0]; \
1633  ++_i, ++_th_pp) \
1634  { \
1635  int iR = _i + _subbox_lo[0]; iR += 0; \
1636  int i##x##R = _i + _bx_lo[0]; i##x##R += 0; \
1637  int i##y##R = _i + _by_lo[0]; i##y##R += 0; \
1638  T &thisR = * _th_pp; \
1639  const T & x##R = _x_pp[_i]; \
1640  const T & y##R = _y_pp[_i];
1641 
1642 #define ForAllRevXBNYCBNNN3(T,x,bx,nsx,y,by,nsy,nc,ir) \
1643  { \
1644  CH_assert((ir) >= 0 && (ir) < SpaceDim); \
1645  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
1646  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
1647  CH_assert((x).contains(bx)); \
1648  CH_assert((y).contains(by)); \
1649  CH_assert((bx).sameSize(by)); \
1650  const int *_x_plo = (x).loVect(); \
1651  const IntVect _x_plen = (x).size(); \
1652  const int *_y_plo = (y).loVect(); \
1653  intVect _y_plen = (y).size(); \
1654  const int *_bx_lo = (bx).loVect(); \
1655  const int *_by_lo = (by).loVect(); \
1656  const IntVect _len = (bx).size(); \
1657  T* _x_p = (x).dataPtr(nsx); \
1658  const T* _y_p = (y).dataPtr(nsy); \
1659  for (int _n = 0; _n < (nc); ++_n) \
1660  { \
1661  int n##x##R = _n + nsx; n##x##R += 0; \
1662  int n##y##R = _n + nsy; n##y##R += 0; \
1663  for (int _k = 0; _k < _len[2]; ++_k) \
1664  { \
1665  const int k##x##R = _k + _bx_lo[2]; \
1666  const int krev##x##R = _len[2]-1-_k + _bx_lo[2]; \
1667  const int k##y##R = _k + _by_lo[2]; \
1668  for (int _j = 0; _j < _len[1]; ++_j) \
1669  { \
1670  const int j##x##R = _j + _bx_lo[1]; \
1671  const int jrev##x##R = _len[1]-1-_j + _bx_lo[1]; \
1672  const int j##y##R = _j + _by_lo[1]; \
1673  T *_x_pp; \
1674  int _ix = 0; \
1675  int _istrd = 1; \
1676  if (ir == 0) \
1677  { \
1678  _x_pp = _x_p \
1679  + ((_bx_lo[0] - _x_plo[0]) + _len[0]-1 \
1680  + _x_plen[0]*( \
1681  (j##x##R - _x_plo[1]) \
1682  + _x_plen[1]*( \
1683  (k##x##R - _x_plo[2]) \
1684  + _n * _x_plen[2]))); \
1685  _istrd = -1; \
1686  } \
1687  else if (ir == 1) \
1688  { \
1689  _x_pp = _x_p \
1690  + ((_bx_lo[0] - _x_plo[0]) \
1691  + _x_plen[0]*( \
1692  (jrev##x##R - _x_plo[1]) \
1693  + _x_plen[1]*( \
1694  (k##x##R - _x_plo[2]) \
1695  + _n * _x_plen[2]))); \
1696  } \
1697  else \
1698  { \
1699  _x_pp = _x_p \
1700  + ((_bx_lo[0] - _x_plo[0]) \
1701  + _x_plen[0]*( \
1702  (j##x##R - _x_plo[1]) \
1703  + _x_plen[1]*( \
1704  (krev##x##R - _x_plo[2]) \
1705  + _n * _x_plen[2]))); \
1706  } \
1707  const T *_y_pp = _y_p \
1708  + ((_by_lo[0] - _y_plo[0]) \
1709  + _y_plen[0]*( \
1710  (j##y##R - _y_plo[1]) \
1711  + _y_plen[1]*( \
1712  (k##y##R - _y_plo[2]) \
1713  + _n * _y_plen[2]))); \
1714  for (int _i = 0; _i < _len[0]; ++_i, _ix += _istrd) \
1715  { \
1716  T & x##R = _x_pp[_ix]; \
1717  const T & y##R = _y_pp[_i];
1718 
1719 #define EndFor3 \
1720  } \
1721  } \
1722  } \
1723  } \
1724  }
1725 
1726 #define EndForTX3 \
1727  } \
1728  } \
1729  } \
1730  } \
1731  } \
1732  }
1733 
1734 #define EndForPencil3 \
1735  } \
1736  } \
1737  } \
1738  }
1739 
1740 #elif (CH_SPACEDIM > 3)
1741 
1742 #define ForAllThisCPencilHiDim(T,b,ns,nc) \
1743  { \
1744  CH_assert(this->contains(b)); \
1745  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1746  const IntVect _b_len = (b).size(); \
1747  Box _pencil_box(b); \
1748  _pencil_box.setBig(0,b.smallEnd(0)); \
1749  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1750  { \
1751  int nR = _n; nR += 0; \
1752  BoxIterator _bit( _pencil_box ); \
1753  for (_bit.begin(); _bit.ok(); ++_bit) \
1754  { \
1755  IntVect _iv = _bit(); \
1756  const T &thisR = this->operator()(_iv,_n); \
1757  const int thisLen = _b_len[0]; \
1758  int jR = _iv[1]; jR += 0; \
1759  int kR = _iv[2]; kR += 0;
1760 
1761 #define ForAllThisPencilHiDim(T,b,ns,nc) \
1762  { \
1763  CH_assert(this->contains(b)); \
1764  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1765  const IntVect _b_len = (b).size(); \
1766  Box _pencil_box(b); \
1767  _pencil_box.setBig(0,b.smallEnd(0)); \
1768  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1769  { \
1770  const int nR = _n; \
1771  BoxIterator _bit( _pencil_box ); \
1772  for (_bit.begin(); _bit.ok(); ++_bit) \
1773  { \
1774  IntVect _iv = _bit(); \
1775  T &thisR = this->operator()(_iv,nR); \
1776  const int thisLen = _b_len[0]; \
1777  int jR = _iv[1]; jR += 0; \
1778  int kR = _iv[2]; kR += 0;
1779 
1780 #define ForAllXBPencilHiDim(T,x,b,ns,nc) \
1781  { \
1782  CH_assert((x).contains(b)); \
1783  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1784  const IntVect _b_len = (b).size(); \
1785  Box _pencil_box(b); \
1786  _pencil_box.setBig(0,b.smallEnd(0)); \
1787  for (int nR = (ns); nR < (ns)+(nc); ++nR) \
1788  { \
1789  BoxIterator _bit( _pencil_box ); \
1790  for (_bit.begin(); _bit.ok(); ++_bit) \
1791  { \
1792  IntVect _iv = _bit(); \
1793  T *xR = &(x).operator()(_iv,nR); \
1794  const int thisLen = _b_len[0]; \
1795  int jR = _iv[1]; jR += 0; \
1796  int kR = _iv[2]; kR += 0;
1797 
1798 #define ForAllXBNNHiDim(T,x,b,ns,nc) \
1799  { \
1800  CH_assert(x.contains(b)); \
1801  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1802  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1803  { \
1804  const int nR = _n; (int&)nR += 0; \
1805  BoxIterator _bit( (b) ); \
1806  for (_bit.begin(); _bit.ok(); ++_bit) \
1807  { \
1808  IntVect _iv = _bit(); \
1809  T &x##R = (x)(_iv,nR); \
1810  T *_x_pp = &x##R; _x_pp += 0; \
1811  int iR = _iv[0]; iR += 0; \
1812  int jR = _iv[1]; jR += 0; \
1813  int kR = _iv[2]; kR += 0;
1814 
1815 
1816 #define ForAllXBNNnoindxHiDim(T,x,b,ns,nc) \
1817  { \
1818  CH_assert(x.contains(b)); \
1819  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1820  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1821  { \
1822  BoxIterator _bit( (b) ); \
1823  for (_bit.begin(); _bit.ok(); ++_bit) \
1824  { \
1825  IntVect _iv = _bit(); \
1826  T& x##R = (x)(_iv,_n); \
1827  int iR = _iv[0]; iR += 0; \
1828  int jR = _iv[1]; jR += 0; \
1829  int kR = _iv[2]; kR += 0;
1830 
1831 #define ForAllXCBNNHiDim(T,x,b,ns,nc) \
1832  { \
1833  CH_assert(x.contains(b)); \
1834  CH_assert((ns) >= 0 && (ns) + (nc) <= (x).nComp()); \
1835  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1836  { \
1837  const int nR = _n; \
1838  BoxIterator _bit( (b) ); \
1839  for (_bit.begin(); _bit.ok(); ++_bit) \
1840  { \
1841  IntVect _iv = _bit(); \
1842  const T & x##R = (x)(_iv, nR); \
1843  const T *_x_pp = &x##R; _x_pp += 0; \
1844  const int iR = _iv[0]; (int&)iR += 0; \
1845  const int jR = _iv[1]; (int&)jR += 0; \
1846  const int kR = _iv[2]; (int&)kR += 0;
1847 
1848 
1849 #define ForAllThisBNNHiDim(T,b,ns,nc) \
1850  { \
1851  CH_assert(this->contains(b)); \
1852  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1853  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1854  { \
1855  int nR = _n; nR += 0; \
1856  BoxIterator _bit( (b)); \
1857  for (_bit.begin(); _bit.ok(); ++_bit) \
1858  { \
1859  IntVect _iv = _bit(); \
1860  T &thisR = this->operator()(_iv,nR); \
1861  int iR = _iv[0]; iR += 0; \
1862  int jR = _iv[1]; jR += 0; \
1863  int kR = _iv[2]; kR += 0;
1864 
1865 
1866 #define ForAllThisCBNNHiDim(T,b,ns,nc) \
1867  { \
1868  CH_assert(this->contains(b)); \
1869  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1870  for (int _n = (ns); _n < (ns)+(nc); ++_n) \
1871  { \
1872  const int nR = _n; \
1873  BoxIterator _bit( (b) ); \
1874  for (_bit.begin(); _bit.ok(); ++_bit) \
1875  { \
1876  IntVect _iv = _bit(); \
1877  const T &thisR = this->operator()(_iv,nR); \
1878  const int iR = _iv[0]; (int&)iR +=0; \
1879  const int jR = _iv[1]; (int&)jR +=0; \
1880  const int kR = _iv[2]; (int&)kR +=0;
1881 
1882 #define ForAllThisBNNXCHiDim(T,b,ns,nc,x,nss) \
1883  { \
1884  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1885  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1886  Box _subbox_((x).box()); \
1887  _subbox_ &= this->box(); \
1888  _subbox_ &= b; \
1889  if (!_subbox_.isEmpty()) \
1890  { \
1891  for (int _n = 0; _n < (nc); ++_n) \
1892  { \
1893  int nR = _n; nR += 0; \
1894  BoxIterator _bit(_subbox_); \
1895  for (_bit.begin(); _bit.ok(); ++_bit) \
1896  { \
1897  IntVect _iv = _bit(); \
1898  T &thisR = this->operator()(_iv, ns+nR); \
1899  const T & x##R = (x)(_iv, nss+nR); \
1900  const int iR = _iv[0]; (int&)iR += 0; \
1901  const int jR = _iv[1]; (int&)jR += 0; \
1902  const int kR = _iv[2]; (int&)kR += 0;
1903 
1904 #define ForAllThisCBNNXCHiDim(T,b,ns,nc,x,nss) \
1905  { \
1906  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1907  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1908  Box _subbox_((x).box()); \
1909  _subbox_ &= this->box(); \
1910  _subbox_ &= b; \
1911  if (!_subbox_.isEmpty()) \
1912  { \
1913  for (int _n = 0; _n < (nc); ++_n) \
1914  { \
1915  int nR = _n; nR += 0; \
1916  BoxIterator _bit(_subbox_); \
1917  for (_bit.begin(); _bit.ok(); ++_bit) \
1918  { \
1919  IntVect _iv = _bit(); \
1920  const T &thisR = this->operator()(_iv,ns+nR); \
1921  const T & x##R = (x)(_iv,nss+nR); \
1922  const int iR = _iv[0]; (int&)iR += 0; \
1923  const int jR = _iv[1]; (int&)jR += 0; \
1924  const int kR = _iv[2]; (int&)kR += 0;
1925 
1926 #define ForAllThisBNNXCBNHiDim(T,b,ns,nc,x,bx,nss) \
1927  { \
1928  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1929  CH_assert((nss) >= 0 && (nss) + (nc) <= (x).nComp()); \
1930  CH_assert((bx).sameSize((b))); \
1931  if (!((b).isEmpty())) \
1932  { \
1933  for (int _n = 0; _n < (nc); ++_n) \
1934  { \
1935  int nR = _n + ns; nR += 0; \
1936  int n##x##R = _n + nss; n##x##R += 0; \
1937  BoxIterator this_Bit( (b) ); \
1938  IntVect _bxOffset = bx.smallEnd() - b.smallEnd(); \
1939  for (this_Bit.begin(); this_Bit.ok(); ++this_Bit) \
1940  { \
1941  IntVect _thisIV = this_Bit(); \
1942  IntVect _xIV = _thisIV + _bxOffset; \
1943  T &thisR = this->operator()(_thisIV, nR); \
1944  const T & x##R = (x)(_xIV,n##x##R); \
1945  int iR = _xIV[0]; iR += 0; \
1946  int jR = _xIV[1]; jR += 0; \
1947  int kR = _xIV[2]; kR += 0;
1948 
1949 
1950 #define ForAllThisBNNXCBNYCBNHiDim(T,b,ns,nc,x,bx,nsx,y,by,nsy) \
1951  { \
1952  CH_assert((ns) >= 0 && (ns) + (nc) <= this->nComp()); \
1953  CH_assert((nsx) >= 0 && (nsx) + (nc) <= (x).nComp()); \
1954  CH_assert((nsy) >= 0 && (nsy) + (nc) <= (y).nComp()); \
1955  Box _subbox_(this->box()); \
1956  _subbox_ &= b; \
1957  CH_assert((bx).sameSize(_subbox_)); \
1958  CH_assert((by).sameSize(_subbox_)); \
1959  if (!_subbox_.isEmpty()) \
1960  { \
1961  for (int _n = 0; _n < (nc); ++_n) \
1962  { \
1963  int nR = _n + ns; nR += 0; \
1964  int n##x##R = _n + nsx; n##x##R += 0; \
1965  int n##y##R = _n + nsy; n##y##R += 0; \
1966  BoxIterator _thisBit(_subbox_); \
1967  IntVect _xOffset = bx.smallEnd() - _subbox_.smallEnd(); \
1968  IntVect _yOffset = by.smallEnd() - _subbox_.smallEnd(); \
1969  for (_thisBit.begin(); _thisBit.ok(); ++_thisBit) \
1970  { \
1971  IntVect _thisIV = _thisBit(); \
1972  IntVect _xIV = _thisIV + _xOffset; \
1973  IntVect _yIV = _thisIV + _yOffset; \
1974  T &thisR = this->operator()(_thisIV,nR); \
1975  const T & x##R = (x)(_xIV,n##x##R); \
1976  const T & y##R = (y)(_yIV,n##y##R); \
1977  int iR = _thisIV[0]; iR += 0; \
1978  int jR = _thisIV[1]; jR += 0; \
1979  int kR = _thisIV[2]; kR += 0;
1980 
1981 
1982 #define EndForHiDim \
1983  } \
1984  } \
1985  }
1986 
1987 #define EndForTXHiDim \
1988  } \
1989  } \
1990  } \
1991  }
1992 
1993 #define EndForPencilHiDim \
1994  } \
1995  } \
1996  }
1997 
1998 #endif
1999 /** @ingroup macros
2000  The Macro ForAllXPencil is a shortened version of ForAllXBPencil
2001  where the box is defaulted to the entire domain the the
2002  components run over all components of x
2003  */
2004 #define ForAllXPencil(T,x) ForAllXBPencil(T,x,((x).box()),0,((x).nComp()))
2005 
2006 /** @ingroup macros
2007  The macro ForAllX(T,x) is a shortened form of `ForAllXBNN' where the Box
2008  defaults to the domain of x and the components run over all the components
2009  of x.
2010 */
2011 #define ForAllX(T,x) ForAllXBNN(T,x,((x).box()),0,((x).nComp()))
2012 
2013 /** @ingroup macros
2014  The macro ForAllXC(T,x) is the constant form of ForAllX(T,x).
2015 */
2016 #define ForAllXC(T,x) ForAllXCBNN(T,x,((x).box()),0,((x).nComp()))
2017 
2018 /** @ingroup macros
2019  The macro ForAllXB(T,x,b) is a shortened form of `ForAllXBNN'
2020  where the components run over all the components of x.
2021 */
2022 #define ForAllXB(T,x,b) ForAllXBNN(T,x,(b),0,(x).nComp())
2023 
2024 /** @ingroup macros
2025  The macro ForAllXBC(T,x,b) is the constant form of ForAllXB(T,x,b).
2026 */
2027 #define ForAllXBC(T,x,b) ForAllXCBNN(T,x,(b),0,(x).nComp())
2028 
2029 /** @ingroup macros
2030  The macro ForAllThis(T) is a shortened form of `ForAllThisBNN' where the Box
2031  defaults to the domain of x and the components run over all the components
2032  of x.
2033 */
2034 #define ForAllThis(T) ForAllThisBNN(T,this->m_domain,0,this->nComp())
2035 
2036 /** @ingroup macros
2037  The macro ForAllThisC(T) is the constant form of ForAllThis(T).
2038 */
2039 #define ForAllThisC(T) ForAllThisCBNN(T,this->m_domain,0,this->nComp())
2040 
2041 /** @ingroup macros
2042  The macro ForAllThisB(T,b) is a shortened form of `ForAllThisBNN'
2043  where the components run over all the components of x.
2044 */
2045 #define ForAllThisB(T,b) ForAllThisBNN(T,(b),0,this->nComp())
2046 
2047 /** @ingroup macros
2048  The macro ForAllThisCB(T,b) is the constant form of ForAllThisB(T,b).
2049 */
2050 #define ForAllThisCB(T,b) ForAllThisCBNN(T,(b),0,this->nComp())
2051 
2052 /** @ingroup macros
2053  The macro ForAllThisNN(T,ns,nc) is a shortened form of `ForAllThisBNN'
2054  where the Box defaults to the domain of *this.
2055 */
2056 #define ForAllThisNN(T,ns,nc) ForAllThisBNN(T,this->m_domain,ns,nc)
2057 
2058 /** @ingroup macros
2059  The macro ForAllThisXC(T,x) is a shortened form of `ForAllThisBNNXC'
2060  where the Box defaults to the domain of *this and the components run over
2061  all the components of *this.
2062 */
2063 #define ForAllThisXC(T,x) ForAllThisBNNXC(T,this->m_domain,0,this->nComp(),x,0)
2064 
2065 #ifdef DOXYGEN
2066 #undef CH_SPACEDIM
2067 #endif /* Doxygen */
2068 
2069 #endif // matches CH_SPACEDIM != LAST_BASEFABMACROS_H_SPACEDIM