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