CosmoGRaPH v0.0
cosmo_macros.h
1 #ifndef COSMO_MACROS
2 #define COSMO_MACROS
3 
4 
5 /************************************************/
6 /* Variables that can be changed at compilation */
7 /* time using, eg, the -D option for gcc. */
8 /************************************************/
9 
10 // simulation size
11 // Code runs much slower with global N (slow indexing?)
12 #ifndef COSMO_N
13  #define COSMO_N 16
14 #endif
15 #ifndef NX
16  #define NX COSMO_N
17 #endif
18 #ifndef NY
19  #define NY COSMO_N
20 #endif
21 #ifndef NZ
22  #define NZ COSMO_N
23 #endif
24 #define POINTS ((NX)*(NY)*(NZ))
25 
26 // physical box size (in units of the initial Hubble^-1 scale)
27 // eg; L = H_LEN_FRAC = N*dx
28 #ifndef H_LEN_FRAC
29  #define H_LEN_FRAC 0.5
30 #endif
31 
32 // compile using reference integrator?
33 #ifndef USE_REFERENCE_FRW
34  #define USE_REFERENCE_FRW true
35 #endif
36 
37 // Stencil order
38 #ifndef STENCIL_ORDER
39  #define STENCIL_ORDER 8
40 #endif
41 
42 // evolve shift as well? (if not, assumed to be zero)
43 #ifndef USE_BSSN_SHIFT
44  #define USE_BSSN_SHIFT false
45 #endif
46 
47 // Gamma-driver gauge settings (must turn on bssn_shift as well)
48 #ifndef USE_GAMMA_DRIVER
49  #define USE_GAMMA_DRIVER false
50 #endif
51 
52 // Generalized Newtonian gauge setting
53 #ifndef USE_GENERALIZED_NEWTON
54  #define USE_GENERALIZED_NEWTON false
55 #endif
56 
57 // Long doubles?
58 #ifndef USE_LONG_DOUBLES
59 # define USE_LONG_DOUBLES false
60 #endif
61 
62 // Optionally exclude some second-order terms
63 #ifndef EXCLUDE_SECOND_ORDER_SMALL
64  #define EXCLUDE_SECOND_ORDER_SMALL false
65 #endif
66 #ifndef EXCLUDE_SECOND_ORDER_FRW
67  #define EXCLUDE_SECOND_ORDER_FRW false
68 #endif
69 
70 // Optionally compile without raytracing, multigrid classes
71 #ifndef USE_MULTIGRID
72  #define USE_MULTIGRID true
73 #endif
74 #ifndef USE_COSMOTRACE
75  #define USE_COSMOTRACE true
76 #endif
77 
78 //Potential types
79 #ifndef USE_COSMO_CONST_POTENTIAL
80  #define USE_COSMO_CONST_POTENTIAL true
81  #ifndef COSMO_CONST
82  #define COSMO_CONST 0.0003
83  #endif
84 #endif
85 
86 /*****************************************/
87 /* Additional variable/macro definitions */
88 /*****************************************/
89 
90 // not really tested:
91 #ifndef USE_Z4c_DAMPING
92 # define USE_Z4c_DAMPING false
93 #endif
94 #if USE_Z4c_DAMPING
95 # define Z4c_K1_DAMPING_AMPLITUDE 0.5
96 # define Z4c_K2_DAMPING_AMPLITUDE 0.1
97 #else
98 # define Z4c_K1_DAMPING_AMPLITUDE 0.0
99 # define Z4c_K2_DAMPING_AMPLITUDE 0.0
100 #endif
101 
102 #define STENCIL_CONCATENATOR(function, order) function ## order
103 #define STENCIL_EVALUATOR(function, order) STENCIL_CONCATENATOR(function, order)
104 #define STENCIL_ORDER_FUNCTION(function) STENCIL_EVALUATOR(function, STENCIL_ORDER)
105 
106 #define PI (4.0*atan(1.0))
107 #define SIGN(x) (((x) < 0.0) ? -1 : ((x) > 0.0))
108 #define pw2(x) ((x)*(x))
109 #define C_RE(c) ((c)[0])
110 #define C_IM(c) ((c)[1])
111 #define ROUND_2_IDXT(f) ((idx_t)(f >= 0.0 ? (f + 0.5) : (f - 0.5)))
112 
113 #define RESTRICT __restrict__
114 
115 // standard index, implementing periodic boundary conditions
116 #define INDEX(i,j,k) ( ((i+4*NX)%(NX))*(NY)*(NZ) + ((j+4*NY)%(NY))*(NZ) + (k+4*NZ)%(NZ) )
117 // indexing without periodicity
118 #define NP_INDEX(i,j,k) ((NZ)*(NY)*(i) + (NZ)*(j) + (k))
119 // indexing of flux arrays; indexes cell boundaries with 'd' = 1,2,3, using periodic BCs
120 #define F_INDEX(i,j,k,d) ( ((i+NX)%(NX))*(NY)*(NZ)*3 + ((j+NY)%(NY))*(NZ)*3 + (k+NZ)%(NZ)*3 + (d+2)%3 )
121 // non-periodic indexing of flux arrays; indexes cell boundaries with 'd' = 1,2,3
122 #define F_NP_INDEX(i,j,k,d) ( (NZ)*(NY)*(i)*3 + (NZ)*(j)*3 + (k)*3 + (d+2)%3 )
123 
124 // index with variable grid resolution
125 #define H_INDEX(i,j,k,nx,ny,nz) (((i+nx)%(nx))*(ny)*(nz) + ((j+ny)%(ny))*(nz) + (k+(nz))%(nz))
126 
127 // map spatial (i,j) to array index
128 #define aIDX(i,j) ( i <= j ? (7-i)*i/2 - 4 + j : (7-j)*j/2 - 4 + i )
129 // map spatial (i) to array index
130 #define iIDX(i) ( i - 1 )
131 
132 
133 #define LOOP3(i,j,k) \
134  for(i=0; i<NX; ++i) \
135  for(j=0; j<NY; ++j) \
136  for(k=0; k<NZ; ++k)
137 
138 #define AREA_LOOP(j,k) \
139  for(j=0; j<NY; ++j) \
140  for(k=0; k<NZ; ++k)
141 
142 #define DECLARE_REAL_T(name) real_t name
143 
144 // structure to store 27 immediately adjacent points
145 #define DECLARE_ADJACENT_REAL_T(name) real_t name##_adj[3][3][3]
146 // structure to store "faces" 2 points away (6 of them; _ext[dimension (x,y,z)][direction (-,+)])
147 #define DECLARE_ADJ_ADJACENT_REAL_T(name) real_t name##_adj_ext[3][2]
148 
149 
150 // RK4 method, using 4 "registers". One for the "_p"revious step data, one
151 // for the data being "_a"ctively used for calculation, one for the
152 // Runge-Kutta "_c"oefficient being calculated, and lastly the "_f"inal
153 // result of the calculation.
154 #define RK4_ARRAY_ADDMAP(name) \
155  fields[#name "_a"] = & name->_array_a; \
156  fields[#name "_c"] = & name->_array_c; \
157  fields[#name "_p"] = & name->_array_p; \
158  fields[#name "_f"] = & name->_array_f
159 
160 #define RK4_ARRAY_CREATE(name) \
161  register_t * name
162 
163 #define RK4_ARRAY_ALLOC(name) \
164  name = new register_t(); \
165  name->init(NX, NY, NZ, dt)
166 
167 #define RK4_ARRAY_DELETE(name) \
168  delete name
169 
170 #define RK4_SET_LOCAL_VALUES(name) \
171  bd->name = name->_array_a[bd->idx];
172 
173 // A GEN1 method; just declares one register.
174 // Sets up an "_a" (active) register.
175 #define GEN1_ARRAY_ADDMAP(name) \
176  fields[#name "_a"] = &name##_a
177 
178 #define GEN1_ARRAY_CREATE(name) \
179  arr_t name##_a
180 
181 #define GEN1_ARRAY_ALLOC(name) \
182  name##_a.init(NX, NY, NZ)
183 
184 #define GEN1_ARRAY_DELETE(name)
185 
186 #define GEN1_SET_LOCAL_VALUES(name) \
187  bd->name = name##_a[bd->idx];
188 
189 
190 // macros for summing
191 #define COSMO_SUMMATION_1(MACRO) \
192  ( MACRO(1) + MACRO(2) + MACRO(3) )
193 
194 #define COSMO_SUMMATION_1_ARGS(MACRO, ...) \
195  ( MACRO(1, __VA_ARGS__) + MACRO(2, __VA_ARGS__) + MACRO(3, __VA_ARGS__) )
196 
197 #define COSMO_SUMMATION_2(MACRO) ( \
198  MACRO(1, 1) + MACRO(1, 2) + MACRO(1, 3) \
199  + MACRO(2, 1) + MACRO(2, 2) + MACRO(2, 3) \
200  + MACRO(3, 1) + MACRO(3, 2) + MACRO(3, 3) \
201  )
202 
203 #define COSMO_SUMMATION_2_ARGS(MACRO, ...) ( \
204  MACRO(1, 1, __VA_ARGS__) + MACRO(1, 2, __VA_ARGS__) + MACRO(1, 3, __VA_ARGS__) \
205  + MACRO(2, 1, __VA_ARGS__) + MACRO(2, 2, __VA_ARGS__) + MACRO(2, 3, __VA_ARGS__) \
206  + MACRO(3, 1, __VA_ARGS__) + MACRO(3, 2, __VA_ARGS__) + MACRO(3, 3, __VA_ARGS__) \
207  )
208 
209 #define COSMO_SUMMATION_3(MACRO) ( \
210  MACRO(1, 1, 1) + MACRO(1, 1, 2) + MACRO(1, 1, 3) \
211  + MACRO(1, 2, 1) + MACRO(1, 2, 2) + MACRO(1, 2, 3) \
212  + MACRO(1, 3, 1) + MACRO(1, 3, 2) + MACRO(1, 3, 3) \
213  + MACRO(2, 1, 1) + MACRO(2, 1, 2) + MACRO(2, 1, 3) \
214  + MACRO(2, 2, 1) + MACRO(2, 2, 2) + MACRO(2, 2, 3) \
215  + MACRO(2, 3, 1) + MACRO(2, 3, 2) + MACRO(2, 3, 3) \
216  + MACRO(3, 1, 1) + MACRO(3, 1, 2) + MACRO(3, 1, 3) \
217  + MACRO(3, 2, 1) + MACRO(3, 2, 2) + MACRO(3, 2, 3) \
218  + MACRO(3, 3, 1) + MACRO(3, 3, 2) + MACRO(3, 3, 3) \
219  )
220 
221 #define COSMO_SUMMATION_3_ARGS(MACRO, ...) ( \
222  MACRO(1, 1, 1, __VA_ARGS__) + MACRO(1, 1, 2, __VA_ARGS__) + MACRO(1, 1, 3, __VA_ARGS__) \
223  + MACRO(1, 2, 1, __VA_ARGS__) + MACRO(1, 2, 2, __VA_ARGS__) + MACRO(1, 2, 3, __VA_ARGS__) \
224  + MACRO(1, 3, 1, __VA_ARGS__) + MACRO(1, 3, 2, __VA_ARGS__) + MACRO(1, 3, 3, __VA_ARGS__) \
225  + MACRO(2, 1, 1, __VA_ARGS__) + MACRO(2, 1, 2, __VA_ARGS__) + MACRO(2, 1, 3, __VA_ARGS__) \
226  + MACRO(2, 2, 1, __VA_ARGS__) + MACRO(2, 2, 2, __VA_ARGS__) + MACRO(2, 2, 3, __VA_ARGS__) \
227  + MACRO(2, 3, 1, __VA_ARGS__) + MACRO(2, 3, 2, __VA_ARGS__) + MACRO(2, 3, 3, __VA_ARGS__) \
228  + MACRO(3, 1, 1, __VA_ARGS__) + MACRO(3, 1, 2, __VA_ARGS__) + MACRO(3, 1, 3, __VA_ARGS__) \
229  + MACRO(3, 2, 1, __VA_ARGS__) + MACRO(3, 2, 2, __VA_ARGS__) + MACRO(3, 2, 3, __VA_ARGS__) \
230  + MACRO(3, 3, 1, __VA_ARGS__) + MACRO(3, 3, 2, __VA_ARGS__) + MACRO(3, 3, 3, __VA_ARGS__) \
231  )
232 
233 #endif