Chombo + EB  3.2
SPACE.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 #ifndef _SPACE_H_
12 #define _SPACE_H_
13 
14 #ifdef HAVE_CONFIG_H
15 #include <autoconfig.H>
16 #endif
17 
18 #ifdef CH_LANG_CC
19 # include "MayDay.H"
20 #endif
21 
22 # include "CH_assert.H"
23 
24 #include "NamespaceHeader.H"
25 
26 #if !defined(CH_LANG_FORT) || defined(CH_LANG_CC)
27 
28 /**
29  The SpaceDim C++ integer constant specifies the dimension of the
30  Chombo library to be built. It is initialized to the value of
31  the macro CH_SPACEDIM. Hence it will have one of the values 1, 2, or 3.
32 
33  C++ code that depends on the dimensionality of the problem that
34  you're trying to solve should be cast in terms of this constant,
35  instead of the CH_SPACEDIM macro, if possible, as constants are
36  visible to debuggers while macros are not.
37 */
38  const int SpaceDim = CH_SPACEDIM;
39 #endif
40 
41 #ifdef DOXYGEN
42 /** \defgroup macros Chombo Macros
43  */
44 
45 /**
46 @ingroup macros
47 compile-time cpp macro that controls the dimensionality of
48  the Chombo package. */
49 #define CH_SPACEDIM
50 #undef CH_SPACEDIM
51 #define CH_SPACEDIM 3
52 #endif
53 
54 #if ! defined(CH_SPACEDIM)
55 #error CH_SPACEDIM must be defined
56 #endif
57 
58 #if (CH_SPACEDIM < 1 || CH_SPACEDIM > 6)
59 #error CH_SPACEDIM must be either 1, 2, 3, 4, 5, or 6
60 #endif
61 
62 #ifdef DOXYGEN
63 #undef CH_SPACEDIM
64 #endif
65 
66 #include "NamespaceFooter.H"
67 
68 #endif
69 #ifdef CH_LANG_CC
70 // That matches the include guard. The rest of this file is all macros
71 // whose definitions depend on CH_SPACEDIM. In CH_MULTIDIM mode, we want
72 // to rescan these macros after every time CH_SPACEDIM has changed.
73 // Of course, if CH_MULTIDIM is not defined, we want to scan just once.
74 #endif
75 
76 #ifndef LAST_SPACE_H_SPACEDIM
77 #define LAST_SPACE_H_SPACEDIM 0
78 #endif
79 
80 #if CH_SPACEDIM != LAST_SPACE_H_SPACEDIM
81 #undef LAST_SPACE_H_SPACEDIM
82 
83 #ifdef D_EXPR6
84 #undef D_EXPR
85 #undef D_DECL
86 #undef D_TERM
87 #undef D_INVTERM
88 #undef D_SELECT
89 #undef D_EXPR6
90 #undef D_DECL6
91 #undef D_TERM6
92 #undef D_INVTERM6
93 #undef D_SELECT6
94 #endif
95 
96 #if CH_SPACEDIM==1
97 # define D_EXPR(a,b,c) ((void)((a),0))
98 # define D_DECL(a,b,c) a
99 # define D_TERM(a,b,c) a
100 # define D_INVTERM(a,b,c) a
101 # define D_SELECT(a,b,c) a
102 # define D_EXPR6(a,b,c,d,e,f) ((void)((a),0))
103 # define D_DECL6(a,b,c,d,e,f) a
104 # define D_TERM6(a,b,c,d,e,f) a
105 # define D_INVTERM6(a,b,c,d,e,f) a
106 # define D_SELECT6(a,b,c,d,e,f) a
107 # define LAST_SPACE_H_SPACEDIM 1
108 
109 #elif CH_SPACEDIM==2
110 # define D_EXPR(a,b,c) ((void)((a),(b),0))
111 # define D_DECL(a,b,c) a,b
112 # define D_TERM(a,b,c) a b
113 # define D_INVTERM(a,b,c) b a
114 # define D_SELECT(a,b,c) b
115 # define D_EXPR6(a,b,c,d,e,f) ((void)((a),(b),0))
116 # define D_DECL6(a,b,c,d,e,f) a,b
117 # define D_TERM6(a,b,c,d,e,f) a b
118 # define D_INVTERM6(a,b,c,d,e,f) b a
119 # define D_SELECT6(a,b,c,d,e,f) b
120 # define LAST_SPACE_H_SPACEDIM 2
121 
122 #elif CH_SPACEDIM==3
123 #ifdef DOXYGEN
124 /**
125 @ingroup macros
126 
127  The D_EXPR(a,b,c) macro expands to a comma expression that will
128  evaluate SpaceDim of its arguments, counting from the left; i.e.
129  CH_SPACEDIM==1 implies only `a' is evaluated, CH_SPACEDIM==2
130  implies both `a' and `b', and CH_SPACEDIM==3 implies all three
131  arguments are evaluated. This macro can be used to enhance
132  the portability of code that works with structures whose size
133  depends on CH_SPACEDIM.
134 
135  For example:
136 
137  D_EXPR(vect[0] *= s, vect[1] *= s, vect[2] *= s);
138 
139  More explicitly, this macro evaluates to one of
140 
141  ((void)((a),0))
142 
143  ((void)((a),(b),0))
144 
145  ((void)((a),(b),(c),0))
146 
147  corresponding to CH_SPACEDIM values of 1, 2, or 3.
148 */
149 #endif
150 # define D_EXPR(a,b,c) ((void)((a),(b),(c),0))
151 # define D_EXPR6(a,b,c,d,e,f) ((void)((a),(b),(c),0))
152 
153 #ifdef DOXYGEN
154 /**
155 @ingroup macros
156 
157  The D_DECL(a,b,c) macro expands to a comma-separated list of
158  1, 2, or all 3 of the arguments of the call, depending on the
159  value of CH_SPACEDIM. This can be used to write portable
160  function calls that depend on 1, 2, or 3 arguments, corresponding
161  to the value of CH_SPACEDIM.
162 
163  For example:
164 
165  return IntVect(D_DECL(p[0] + s, p[1] + s, p[2] + s));
166 
167  More explicitly, this macro evaluates to one of
168 
169  a
170 
171  a,b
172 
173  a,b,c
174 
175  corresponding to CH_SPACEDIM values of 1, 2, or 3.
176 */
177 #endif
178 # define D_DECL(a,b,c) a,b,c
179 # define D_DECL6(a,b,c,d,e,f) a,b,c
180 
181 #ifdef DOXYGEN
182 /**
183 @ingroup macros
184  define D_TERM(a,b,c) a b c
185 
186  More explicitly, this macro evaluates to one of
187 
188  a
189 
190  a b
191 
192  a b c
193 
194  corresponding to CH_SPACEDIM values of 1, 2, or 3.
195 
196  handy for situations like:
197 
198  Real norm = sqrt(D_TERM(u[0]*u[0],+u[1]*u[1],+u[2]*u[2]));
199 */
200 #endif
201 # define D_TERM(a,b,c) a b c
202 # define D_TERM6(a,b,c,d,e,f) a b c
203 
204 #ifdef DOXYGEN
205 /**
206 @ingroup macros
207  define D_INVTERM(a,b,c) c b a
208 
209  More explicitly, this macro evaluates to one of
210 
211  a
212 
213  b a
214 
215  c b a
216 
217  corresponding to CH_SPACEDIM values of 1, 2, or 3.
218 
219  handy for situations like declaring nested loops where you want (a)
220  to be the innermost or last for loop statement:
221 
222  {
223  D_INVTERM(
224  for (int i0 = 0; i0 != n0; ++i0)
225  {
226  data[(i2*n1 + i1)*n0 + i0] = val;
227  },
228  for (int i1 = 0; i1 != n1; ++i1) {,
229  for (int i2 = 0; i2 != n2; ++i2) {)
230  D_TERM(},},})
231 */
232 #endif
233 # define D_INVTERM(a,b,c) c b a
234 # define D_INVTERM6(a,b,c,d,e,f) c b a
235 
236 #ifdef DOXYGEN
237 /**
238 @ingroup macros
239  define D_SELECT(a,b,c) a b c
240 
241  More explicitly, this macro evaluates to one of
242 
243  a
244 
245  b
246 
247  c
248 
249  corresponding to CH_SPACEDIM values of 1, 2, or 3.
250 */
251 #endif
252 # define D_SELECT(a,b,c) c
253 # define D_SELECT6(a,b,c,d,e,f) c
254 
255 # define LAST_SPACE_H_SPACEDIM 3
256 
257 #ifdef DOXYGEN
258 /** higher-dimensional (up to 6D) extensions of the original macros
259  (note that the original macros are no longer defined once dim>3)
260  */
261 #endif
262 #elif CH_SPACEDIM==4
263 # define D_EXPR6(a,b,c,d,e,f) ((void)((a),(b),(c),(d),0))
264 # define D_DECL6(a,b,c,d,e,f) a,b,c,d
265 # define D_TERM6(a,b,c,d,e,f) a b c d
266 # define D_INVTERM6(a,b,c,d,e,f) d c b a
267 # define D_SELECT6(a,b,c,d,e,f) d
268 # define LAST_SPACE_H_SPACEDIM 4
269 
270 #elif CH_SPACEDIM==5
271 # define D_EXPR6(a,b,c,d,e,f) ((void)((a),(b),(c),(d),(e),0))
272 # define D_DECL6(a,b,c,d,e,f) a,b,c,d,e
273 # define D_TERM6(a,b,c,d,e,f) a b c d e
274 # define D_INVTERM6(a,b,c,d,e,f) e d c b a
275 # define D_SELECT6(a,b,c,d,e,f) e
276 # define LAST_SPACE_H_SPACEDIM 5
277 
278 #elif CH_SPACEDIM==6
279 # define D_EXPR6(a,b,c,d,e,f) ((void)((a),(b),(c),(d),(e),(f),0))
280 # define D_DECL6(a,b,c,d,e,f) a,b,c,d,e,f
281 # define D_TERM6(a,b,c,d,e,f) a b c d e f
282 # define D_INVTERM6(a,b,c,d,e,f) f e d c b a
283 # define D_SELECT6(a,b,c,d,e,f) f
284 # define LAST_SPACE_H_SPACEDIM 6
285 
286 #else /* matches elif CH_SPACEDIM==3 */
287 // note that D_TERM, D_DECL, D_EXPR, D_SELECT are not defined for DIM>3
288 # define LAST_SPACE_H_SPACEDIM CH_SPACEDIM
289 #endif
290 #endif /* matches CH_SPACEDIM != LAST_SPACE_H_SPACEDIM */
#define CH_SPACEDIM
Definition: SPACE.H:51
const int SpaceDim
Definition: SPACE.H:38