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