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