CosmoGRaPH v0.0
bssn_macros.h
1 #ifndef BSSN_MACROS
2 #define BSSN_MACROS
3 
4 /*
5  * applying functions to lots of vars
6  */
7 
8 #if USE_Z4c_DAMPING
9  #define Z4c_APPLY_TO_FIELDS(function) \
10  function(theta);
11  #define Z4c_APPLY_TO_FIELDS_ARGS(function, ...) \
12  function(theta, __VA_ARGS__);
13 #else
14  #define Z4c_APPLY_TO_FIELDS(function)
15  #define Z4c_APPLY_TO_FIELDS_ARGS(function, ...)
16 #endif
17 
18 #if USE_BSSN_SHIFT
19  #define BSSN_APPLY_TO_SHIFT(function) \
20  function(beta1); \
21  function(beta2); \
22  function(beta3);
23  #define BSSN_APPLY_TO_SHIFT_ARGS(function, ...) \
24  function(beta1, __VA_ARGS__); \
25  function(beta2, __VA_ARGS__); \
26  function(beta3, __VA_ARGS__);
27  #define BSSN_APPLY_TO_EXP_N(function) \
28  function(expN);
29  #define BSSN_APPLY_TO_EXP_N_ARGS(function, ...) \
30  function(expN, __VA_ARGS__);
31 #else
32  #define BSSN_APPLY_TO_SHIFT(function)
33  #define BSSN_APPLY_TO_SHIFT_ARGS(function, ...)
34  #define BSSN_APPLY_TO_EXP_N(function)
35  #define BSSN_APPLY_TO_EXP_N_ARGS(function, ...)
36 #endif
37 
38 #if USE_GAMMA_DRIVER
39  #define BSSN_APPLY_TO_AUX_B(function) \
40  function(auxB1); \
41  function(auxB2); \
42  function(auxB3);
43  #define BSSN_APPLY_TO_AUX_B_ARGS(function, ...) \
44  function(auxB1, __VA_ARGS__); \
45  function(auxB2, __VA_ARGS__); \
46  function(auxB3, __VA_ARGS__);
47 #else
48  #define BSSN_APPLY_TO_AUX_B(function)
49  #define BSSN_APPLY_TO_AUX_B_ARGS(function, ...)
50 #endif
51 
52 
53 #define BSSN_APPLY_TO_FIELDS_ARGS(function, ...) \
54  function(DIFFgamma11, __VA_ARGS__); \
55  function(DIFFgamma12, __VA_ARGS__); \
56  function(DIFFgamma13, __VA_ARGS__); \
57  function(DIFFgamma22, __VA_ARGS__); \
58  function(DIFFgamma23, __VA_ARGS__); \
59  function(DIFFgamma33, __VA_ARGS__); \
60  function(DIFFphi, __VA_ARGS__); \
61  function(A11, __VA_ARGS__); \
62  function(A12, __VA_ARGS__); \
63  function(A13, __VA_ARGS__); \
64  function(A22, __VA_ARGS__); \
65  function(A23, __VA_ARGS__); \
66  function(A33, __VA_ARGS__); \
67  function(DIFFK, __VA_ARGS__); \
68  function(Gamma1, __VA_ARGS__); \
69  function(Gamma2, __VA_ARGS__); \
70  function(Gamma3, __VA_ARGS__); \
71  function(DIFFalpha, __VA_ARGS__); \
72  Z4c_APPLY_TO_FIELDS_ARGS(function, __VA_ARGS__) \
73  BSSN_APPLY_TO_SHIFT_ARGS(function, __VA_ARGS__) \
74  BSSN_APPLY_TO_AUX_B_ARGS(function, __VA_ARGS__) \
75  BSSN_APPLY_TO_EXP_N_ARGS(function, __VA_ARGS__)
76 
77 #define BSSN_APPLY_TO_FIELDS(function) \
78  function(DIFFgamma11); \
79  function(DIFFgamma12); \
80  function(DIFFgamma13); \
81  function(DIFFgamma22); \
82  function(DIFFgamma23); \
83  function(DIFFgamma33); \
84  function(DIFFphi); \
85  function(A11); \
86  function(A12); \
87  function(A13); \
88  function(A22); \
89  function(A23); \
90  function(A33); \
91  function(DIFFK); \
92  function(Gamma1); \
93  function(Gamma2); \
94  function(Gamma3); \
95  function(DIFFalpha); \
96  Z4c_APPLY_TO_FIELDS(function) \
97  BSSN_APPLY_TO_SHIFT(function) \
98  BSSN_APPLY_TO_AUX_B(function) \
99  BSSN_APPLY_TO_EXP_N(function)
100 
101 #define BSSN_APPLY_TO_SOURCES(function) \
102  function(DIFFr); \
103  function(DIFFS); \
104  function(S1); \
105  function(S2); \
106  function(S3); \
107  function(STF11); \
108  function(STF12); \
109  function(STF13); \
110  function(STF22); \
111  function(STF23); \
112  function(STF33);
113 
114 #if USE_GENERALIZED_NEWTON
115 #define BSSN_APPLY_TO_GEN1_EXTRAS(function) \
116  function(ricci); \
117  function(AijAij); \
118  function(K0); \
119  function(GNricciTF11); \
120  function(GNricciTF22); \
121  function(GNricciTF33); \
122  function(GNricciTF12); \
123  function(GNricciTF13); \
124  function(GNricciTF23); \
125  function(GND2Alpha); \
126  function(GNDiDjRijTFoD2);
127 #else
128 #define BSSN_APPLY_TO_GEN1_EXTRAS(function) \
129  function(ricci); \
130  function(AijAij); \
131  function(K0);
132 #endif
133 
134 
135 #define BSSN_APPLY_TO_IJ_PERMS(function) \
136  function(1, 1); \
137  function(1, 2); \
138  function(1, 3); \
139  function(2, 2); \
140  function(2, 3); \
141  function(3, 3);
142 
143 // apply when the "I" index is special, e.g., d_i g_{jk}
144 #define BSSN_APPLY_TO_IJK_PERMS(function) \
145  function(1, 1, 1); \
146  function(1, 1, 2); \
147  function(1, 1, 3); \
148  function(1, 2, 2); \
149  function(1, 2, 3); \
150  function(1, 3, 3); \
151  function(2, 1, 1); \
152  function(2, 1, 2); \
153  function(2, 1, 3); \
154  function(2, 2, 2); \
155  function(2, 2, 3); \
156  function(2, 3, 3); \
157  function(3, 1, 1); \
158  function(3, 1, 2); \
159  function(3, 1, 3); \
160  function(3, 2, 2); \
161  function(3, 2, 3); \
162  function(3, 3, 3);
163 
164 
165 #define BSSN_ZERO_FIELD(field, reg, idx) \
166  field->_array##reg[idx] = 0.0;
167 
168 #define BSSN_ZERO_ARRAYS(reg, idx) \
169  BSSN_APPLY_TO_FIELDS_ARGS(BSSN_ZERO_FIELD, reg, idx)
170 
171 
172 // macro requires idx to be set
173 #define BSSN_ZERO_GEN1_FIELD(field) \
174  field##_a[idx] = 0.0;
175 
176 // macro requires idx to be set
177 #define BSSN_ZERO_GEN1_EXTRAS() \
178  BSSN_APPLY_TO_GEN1_EXTRAS(BSSN_ZERO_GEN1_FIELD)
179 
180 // macro requires idx to be set
181 #define BSSN_ZERO_SOURCES() \
182  BSSN_APPLY_TO_SOURCES(BSSN_ZERO_GEN1_FIELD)
183 
184 
185 // Initialize all fields
186 #define BSSN_RK_INITIALIZE_FIELD(field) \
187  field->stepInit();
188 
189 #define BSSN_RK_INITIALIZE \
190  BSSN_APPLY_TO_FIELDS(BSSN_RK_INITIALIZE_FIELD)
191 
192 
193 // Evolve all fields
194 #define BSSN_RK_EVOLVE_PT_FIELD(field) \
195  field->_array_c[bd->idx] = ev_##field(bd);
196 
197 #define BSSN_RK_EVOLVE_PT \
198  BSSN_APPLY_TO_FIELDS(BSSN_RK_EVOLVE_PT_FIELD)
199 
200 
201 // Finalize an RK step for all BSSN fields
202 #define BSSN_FINALIZE_K_FIELD(field, n) \
203  field->K##n##Finalize();
204 
205 #define BSSN_FINALIZE_K(n) \
206  BSSN_APPLY_TO_FIELDS_ARGS(BSSN_FINALIZE_K_FIELD, n)
207 
208 
209 // Initialize all fields
210 #define BSSN_SET_DT_FIELD(field, dt) \
211  field->setDt(dt)
212 
213 #define BSSN_SET_DT(dt) \
214  BSSN_APPLY_TO_FIELDS_ARGS(BSSN_SET_DT_FIELD, dt)
215 
216 
217 /*
218  * Aux. variable calculations
219  */
220 
221 #define BSSN_CALCULATE_CHRISTOFFEL(I, J, K) bd->G##I##J##K = 0.5*( \
222  bd->gammai##I##1 * (bd->d##J##g##K##1 + bd->d##K##g##J##1 - bd->d1g##J##K) + \
223  bd->gammai##I##2 * (bd->d##J##g##K##2 + bd->d##K##g##J##2 - bd->d2g##J##K) + \
224  bd->gammai##I##3 * (bd->d##J##g##K##3 + bd->d##K##g##J##3 - bd->d3g##J##K) \
225  )
226 
227 #define BSSN_CALCULATE_CHRISTOFFEL_LOWER(I, J, K) bd->GL##I##J##K = 0.5*( \
228  bd->d##J##g##K##I + bd->d##K##g##J##I - bd->d##I##g##J##K \
229  )
230 
231 #define BSSN_CALCULATE_DGAMMA(I, J, K) bd->d##I##g##J##K = derivative(bd->i, bd->j, bd->k, I, DIFFgamma##J##K->_array_a);
232 
233 #define BSSN_CALCULATE_ACONT(I, J) bd->Acont##I##J = ( \
234  bd->gammai##I##1*bd->gammai##J##1*bd->A11 + bd->gammai##I##2*bd->gammai##J##1*bd->A21 + bd->gammai##I##3*bd->gammai##J##1*bd->A31 \
235  + bd->gammai##I##1*bd->gammai##J##2*bd->A12 + bd->gammai##I##2*bd->gammai##J##2*bd->A22 + bd->gammai##I##3*bd->gammai##J##2*bd->A32 \
236  + bd->gammai##I##1*bd->gammai##J##3*bd->A13 + bd->gammai##I##2*bd->gammai##J##3*bd->A23 + bd->gammai##I##3*bd->gammai##J##3*bd->A33 \
237  );
238 
239 // needs the gamma*ldlphi vars defined:
240 // not actually trace free yet!
241 #define BSSN_CALCULATE_DIDJALPHA(I, J) bd->D##I##D##J##aTF = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFalpha->_array_a) - ( \
242  (bd->G1##I##J + 2.0*( (1==I)*bd->d##J##phi + (1==J)*bd->d##I##phi - bd->gamma##I##J*gammai1ldlphi))*bd->d1a + \
243  (bd->G2##I##J + 2.0*( (2==I)*bd->d##J##phi + (2==J)*bd->d##I##phi - bd->gamma##I##J*gammai2ldlphi))*bd->d2a + \
244  (bd->G3##I##J + 2.0*( (3==I)*bd->d##J##phi + (3==J)*bd->d##I##phi - bd->gamma##I##J*gammai3ldlphi))*bd->d3a \
245  );
246 
247 
248 #define BSSN_CALCULATE_RICCI_UNITARY_TERM1(K, L, I, J) \
249  bd->gammai##K##L*bd->d##K##d##L##g##I##J
250 
251 #define BSSN_CALCULATE_RICCI_UNITARY_TERM2(K, I, J) \
252  bd->gamma##K##I*derivative(bd->i, bd->j, bd->k, J, Gamma##K->_array_a)
253 
254 #define BSSN_CALCULATE_RICCI_UNITARY_TERM3(K, I, J) \
255  bd->Gammad##K*bd->GL##I##J##K
256 
257 #define BSSN_CALCULATE_RICCI_UNITARY_TERM4(K, L, M, I, J) \
258  bd->gammai##L##M*( \
259  bd->G##K##L##I*bd->GL##J##K##M + bd->G##K##L##J*bd->GL##I##K##M \
260  /* symmetrize below because symmetry */ \
261  + 0.5*(bd->G##K##I##M*bd->GL##K##L##J + bd->G##K##J##M*bd->GL##K##L##I) \
262  )
263 
264 #define BSSN_CALCULATE_RICCI_UNITARY(I, J) bd->Uricci##I##J = ( \
265  - 0.5*( \
266  COSMO_SUMMATION_2_ARGS(BSSN_CALCULATE_RICCI_UNITARY_TERM1, I, J) \
267  ) \
268  + 0.5*( \
269  COSMO_SUMMATION_1_ARGS(BSSN_CALCULATE_RICCI_UNITARY_TERM2, I, J) \
270  + COSMO_SUMMATION_1_ARGS(BSSN_CALCULATE_RICCI_UNITARY_TERM2, J, I) \
271  ) \
272  + 0.5*( \
273  COSMO_SUMMATION_1_ARGS(BSSN_CALCULATE_RICCI_UNITARY_TERM3, I, J) \
274  + COSMO_SUMMATION_1_ARGS(BSSN_CALCULATE_RICCI_UNITARY_TERM3, J, I) \
275  ) \
276  + COSMO_SUMMATION_3_ARGS(BSSN_CALCULATE_RICCI_UNITARY_TERM4, I, J) \
277  );
278 
279 #define BSSN_CALCULATE_DIDJGAMMA_PERMS(I, J) \
280  bd->d##I##d##J##g11 = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFgamma11->_array_a); \
281  bd->d##I##d##J##g12 = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFgamma12->_array_a); \
282  bd->d##I##d##J##g13 = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFgamma13->_array_a); \
283  bd->d##I##d##J##g22 = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFgamma22->_array_a); \
284  bd->d##I##d##J##g23 = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFgamma23->_array_a); \
285  bd->d##I##d##J##g33 = double_derivative(bd->i, bd->j, bd->k, I, J, DIFFgamma33->_array_a)
286 
287 
288 /*
289  * Evolution equations for indexed components
290  */
291 
292 #if USE_BSSN_SHIFT
293 #define BSSN_DT_DIFFGAMMAIJ(I, J) ( \
294  - 2.0*bd->alpha*bd->A##I##J \
295  /* + bd->beta1 * bd->d1g##I##J + bd->beta2 * bd->d2g##I##J + bd->beta3 * bd->d3g##I##J \ */ \
296  + upwind_derivative(bd->i, bd->j, bd->k, 1, DIFFgamma##I##J->_array_a, bd->beta1) \
297  + upwind_derivative(bd->i, bd->j, bd->k, 2, DIFFgamma##I##J->_array_a, bd->beta2) \
298  + upwind_derivative(bd->i, bd->j, bd->k, 3, DIFFgamma##I##J->_array_a, bd->beta3) \
299  + bd->gamma##I##1*bd->d##J##beta1 + bd->gamma##I##2*bd->d##J##beta2 + bd->gamma##I##3*bd->d##J##beta3 \
300  + bd->gamma##J##1*bd->d##I##beta1 + bd->gamma##J##2*bd->d##I##beta2 + bd->gamma##J##3*bd->d##I##beta3 \
301  - (2.0/3.0)*bd->gamma##I##J*(bd->d1beta1 + bd->d2beta2 + bd->d3beta3) \
302  )
303 #else
304 #define BSSN_DT_DIFFGAMMAIJ(I, J) ( \
305  - 2.0*bd->alpha*bd->A##I##J \
306  )
307 #endif
308 
309 # define BSSN_DT_AIJ_SECOND_ORDER_AA(I, J) ( \
310  bd->gammai11*bd->A1##I*bd->A1##J + bd->gammai12*bd->A1##I*bd->A2##J + bd->gammai13*bd->A1##I*bd->A3##J \
311  + bd->gammai21*bd->A2##I*bd->A1##J + bd->gammai22*bd->A2##I*bd->A2##J + bd->gammai23*bd->A2##I*bd->A3##J \
312  + bd->gammai31*bd->A3##I*bd->A1##J + bd->gammai32*bd->A3##I*bd->A2##J + bd->gammai33*bd->A3##I*bd->A3##J \
313  )
314 
315 # define BSSN_DT_AIJ_SECOND_ORDER_KA(I, J) ( \
316  (bd->K + 2.0*bd->theta)*bd->A##I##J \
317  )
318 
319 #if USE_BSSN_SHIFT
320 #define BSSN_DT_AIJ(I, J) ( \
321  exp(-4.0*bd->phi)*( bd->alpha*(bd->ricciTF##I##J - 8.0*PI*bd->STF##I##J) - bd->D##I##D##J##aTF ) \
322  + bd->alpha*(BSSN_DT_AIJ_SECOND_ORDER_KA(I,J) - 2.0*BSSN_DT_AIJ_SECOND_ORDER_AA(I,J)) \
323  /* + bd->beta1*derivative(bd->i, bd->j, bd->k, 1, A##I##J->_array_a) \ */ \
324  /* + bd->beta2*derivative(bd->i, bd->j, bd->k, 2, A##I##J->_array_a) \ */ \
325  /* + bd->beta3*derivative(bd->i, bd->j, bd->k, 3, A##I##J->_array_a) \ */ \
326  + upwind_derivative(bd->i, bd->j, bd->k, 1, A##I##J->_array_a, bd->beta1) \
327  + upwind_derivative(bd->i, bd->j, bd->k, 2, A##I##J->_array_a, bd->beta2) \
328  + upwind_derivative(bd->i, bd->j, bd->k, 3, A##I##J->_array_a, bd->beta3) \
329  + bd->A##I##1*bd->d##J##beta1 + bd->A##I##2*bd->d##J##beta2 + bd->A##I##3*bd->d##J##beta3 \
330  + bd->A##J##1*bd->d##I##beta1 + bd->A##J##2*bd->d##I##beta2 + bd->A##J##3*bd->d##I##beta3 \
331  - (2.0/3.0)*bd->A##I##J*(bd->d1beta1 + bd->d2beta2 + bd->d3beta3) \
332  )
333 #else
334 #define BSSN_DT_AIJ(I, J) ( \
335  exp(-4.0*bd->phi)*( bd->alpha*(bd->ricciTF##I##J - 8.0*PI*bd->STF##I##J) - bd->D##I##D##J##aTF ) \
336  + bd->alpha*(BSSN_DT_AIJ_SECOND_ORDER_KA(I,J) - 2.0*BSSN_DT_AIJ_SECOND_ORDER_AA(I,J)) \
337  )
338 #endif
339 
340 #define BSSN_DT_GAMMAI(I) (BSSN_DT_GAMMAI_NOSHIFT(I) + BSSN_DT_GAMMAI_SHIFT(I))
341 
342 #define BSSN_DT_GAMMAI_SECOND_ORDER(I) ( \
343  bd->G##I##11*bd->Acont11 + bd->G##I##22*bd->Acont22 + bd->G##I##33*bd->Acont33 \
344  + 2.0*(bd->G##I##12*bd->Acont12 + bd->G##I##13*bd->Acont13 + bd->G##I##23*bd->Acont23) \
345  + 6.0*(bd->Acont##I##1*bd->d1phi + bd->Acont##I##2*bd->d2phi + bd->Acont##I##3*bd->d3phi) \
346 )
347 
348 #define BSSN_DT_GAMMAI_NOSHIFT(I) ( \
349  - 2.0*(bd->Acont##I##1*bd->d1a + bd->Acont##I##2*bd->d2a + bd->Acont##I##3*bd->d3a) \
350  + 2.0*bd->alpha*( \
351  + BSSN_DT_GAMMAI_SECOND_ORDER(I) \
352  - (1.0/3.0) * ( \
353  2.0*(bd->gammai##I##1*bd->d1K + bd->gammai##I##2*bd->d2K + bd->gammai##I##3*bd->d3K) \
354  + bd->gammai##I##1*bd->d1theta + bd->gammai##I##2*bd->d2theta + bd->gammai##I##3*bd->d3theta \
355  ) \
356  - 2.0*bd->alpha*Z4c_K1_DAMPING_AMPLITUDE*( \
357  bd->Gamma##I - bd->Gammad##I \
358  ) \
359  - 8.0*PI*(bd->gammai##I##1*bd->S1 + bd->gammai##I##2*bd->S2 + bd->gammai##I##3*bd->S3) \
360  ) \
361  )
362 
363 #if USE_BSSN_SHIFT
364 #define BSSN_DT_GAMMAI_SHIFT(I) ( \
365  /* + bd->beta1*derivative(bd->i, bd->j, bd->k, 1, Gamma##I->_array_a) \ */ \
366  /* + bd->beta2*derivative(bd->i, bd->j, bd->k, 2, Gamma##I->_array_a) \ */ \
367  /* + bd->beta3*derivative(bd->i, bd->j, bd->k, 3, Gamma##I->_array_a) \ */ \
368  + upwind_derivative(bd->i, bd->j, bd->k, 1, Gamma##I->_array_a, bd->beta1) \
369  + upwind_derivative(bd->i, bd->j, bd->k, 2, Gamma##I->_array_a, bd->beta2) \
370  + upwind_derivative(bd->i, bd->j, bd->k, 3, Gamma##I->_array_a, bd->beta3) \
371  - bd->Gammad1*bd->d1beta##I - bd->Gammad2*bd->d2beta##I - bd->Gammad3*bd->d3beta##I \
372  + (2.0/3.0) * bd->Gammad##I * (bd->d1beta1 + bd->d2beta2 + bd->d3beta3) \
373  + (1.0/3.0) * ( \
374  bd->gammai##I##1*double_derivative(bd->i, bd->j, bd->k, 1, 1, beta1->_array_a) + bd->gammai##I##1*double_derivative(bd->i, bd->j, bd->k, 2, 1, beta2->_array_a) + bd->gammai##I##1*double_derivative(bd->i, bd->j, bd->k, 3, 1, beta3->_array_a) + \
375  bd->gammai##I##2*double_derivative(bd->i, bd->j, bd->k, 1, 2, beta1->_array_a) + bd->gammai##I##2*double_derivative(bd->i, bd->j, bd->k, 2, 2, beta2->_array_a) + bd->gammai##I##2*double_derivative(bd->i, bd->j, bd->k, 3, 2, beta3->_array_a) + \
376  bd->gammai##I##3*double_derivative(bd->i, bd->j, bd->k, 1, 3, beta1->_array_a) + bd->gammai##I##3*double_derivative(bd->i, bd->j, bd->k, 2, 3, beta2->_array_a) + bd->gammai##I##3*double_derivative(bd->i, bd->j, bd->k, 3, 3, beta3->_array_a) \
377  ) \
378  + ( \
379  bd->gammai11*double_derivative(bd->i, bd->j, bd->k, 1, 1, beta##I->_array_a) + bd->gammai22*double_derivative(bd->i, bd->j, bd->k, 2, 2, beta##I->_array_a) + bd->gammai33*double_derivative(bd->i, bd->j, bd->k, 3, 3, beta##I->_array_a) \
380  + 2.0*(bd->gammai12*double_derivative(bd->i, bd->j, bd->k, 1, 2, beta##I->_array_a) + bd->gammai13*double_derivative(bd->i, bd->j, bd->k, 1, 3, beta##I->_array_a) + bd->gammai23*double_derivative(bd->i, bd->j, bd->k, 2, 3, beta##I->_array_a)) \
381  ) \
382  )
383 #else
384 #define BSSN_DT_GAMMAI_SHIFT(I) 0.0
385 #endif
386 
387 /*
388  * Full metric calcs
389  */
390 
391 // metric derivs
392 
393 #define SET_DKM00(k) bd->d##k##m00 = DKM00(k);
394 #define DKM00(k) \
395  -2.0*bd->alpha*bd->d##k##a \
396  + bd->d##k##m11*bd->beta1*bd->beta1 + bd->d##k##m22*bd->beta2*bd->beta2 + bd->d##k##m33*bd->beta3*bd->beta3 \
397  + 2.0*(bd->d##k##m12*bd->beta1*bd->beta2 + bd->d##k##m13*bd->beta1*bd->beta3 + bd->d##k##m23*bd->beta2*bd->beta3) \
398  + 2.0*exp(4.0*bd->phi)*( \
399  bd->gamma11*bd->d##k##beta1*bd->beta1 + bd->gamma12*bd->d##k##beta2*bd->beta1 + bd->gamma13*bd->d##k##beta3*bd->beta1 \
400  + bd->gamma12*bd->d##k##beta1*bd->beta2 + bd->gamma22*bd->d##k##beta2*bd->beta2 + bd->gamma23*bd->d##k##beta3*bd->beta2 \
401  + bd->gamma13*bd->d##k##beta1*bd->beta3 + bd->gamma23*bd->d##k##beta2*bd->beta3 + bd->gamma33*bd->d##k##beta3*bd->beta3 \
402  );
403 
404 
405 #define SET_DKM0I(k, i) bd->d##k##m0##i = DKM0I(k, i);
406 #define DKM0I(k, i) \
407  exp(4.0*bd->phi)*( \
408  bd->gamma1##i * bd->d##k##beta##1 + bd->gamma2##i * bd->d##k##beta##2 + bd->gamma3##i * bd->d##k##beta##3 \
409  + (bd->d##k##g1##i + 4.0*bd->d##k##phi*bd->gamma1##i) * bd->beta##1 \
410  + (bd->d##k##g2##i + 4.0*bd->d##k##phi*bd->gamma2##i) * bd->beta##2 \
411  + (bd->d##k##g3##i + 4.0*bd->d##k##phi*bd->gamma3##i) * bd->beta##3 \
412  );
413 
414 #define SET_DKMIJ(k, i, j) bd->d##k##m##i##j = DKMIJ(k, i, j);
415 #define DKMIJ(k, i, j) exp(4.0*bd->phi)*(bd->d##k##g##i##j + 4.0*bd->d##k##phi*bd->gamma##i##j);
416 
417 
418 // metric
419 
420 #define SET_M00() bd->m00 = M00();
421 #define M00() \
422  -bd->alpha*bd->alpha + exp(4.0*bd->phi)*( \
423  bd->gamma11*bd->beta1*bd->beta1 + bd->gamma22*bd->beta2*bd->beta2 + bd->gamma33*bd->beta3*bd->beta3 \
424  + 2.0*(bd->gamma12*bd->beta1*bd->beta2 + bd->gamma13*bd->beta1*bd->beta3 + bd->gamma23*bd->beta2*bd->beta3) \
425  );
426 
427 #define SET_M0I(i) bd->m0##i = M0I(i);
428 #define M0I(i) exp(4.0*bd->phi)*(bd->gamma1##i*bd->beta1 + bd->gamma2##i*bd->beta2 + bd->gamma3##i*bd->beta3);
429 
430 #define SET_MIJ(i, j) bd->m##i##j = MIJ(i, j);
431 #define MIJ(i, j) exp(4.0*bd->phi)*(bd->gamma##i##j);
432 
433 // inverse metric
434 
435 #define SET_Mi00() bd->mi00 = Mi00();
436 #define Mi00() -1.0/bd->alpha/bd->alpha;
437 
438 #define SET_Mi0I(i) bd->mi0##i = Mi0I(i);
439 #define Mi0I(i) 1.0/bd->alpha/bd->alpha*bd->beta##i;
440 
441 #define SET_MiIJ(i, j) bd->mi##i##j = MiIJ(i, j);
442 #define MiIJ(i, j) exp(-4.0*bd->phi)*(bd->gamma##i##j) - 1.0/bd->alpha/bd->alpha*bd->beta##i*bd->beta##j;
443 
444 
445 /*
446  * Conversion to ADM quantities for raytracing
447  */
448 #define BSSN_RP_DG(I,J,L) \
449  P*(4.0*bd->gamma##I##J*bd->d##L##phi+ bd->d##L##g##I##J)
450 
451 #define BSSN_RP_DDG(I,J,L,M) \
452  P*( \
453  16.0*bd->gamma##I##J*bd->d##M##phi*bd->d##L##phi \
454  + 4.0*(bd->d##L##g##I##J*bd->d##M##phi + bd->d##M##g##I##J*bd->d##L##phi + bd->gamma##I##J*bd->d##L##d##M##phi) \
455  + bd->d##L##d##M##g##I##J \
456  )
457 
458 #define BSSN_RP_K(I,J) \
459  P*(bd->A##I##J + 1.0/3.0*bd->gamma##I##J*bd->K)
460 
461 #define BSSN_RP_DK(I,J,L) \
462  P*( \
463  4.0*(bd->A##I##J + 1.0/3.0*bd->gamma##I##J*bd->K)*bd->d##L##phi + derivative(bd->i, bd->j, bd->k, L, A##I##J->_array_a) \
464  + 1.0/3.0*bd->K*bd->d##L##g##I##J + 1.0/3.0*bd->gamma##I##J*bd->d##L##K \
465  )
466 
467 #define BSSN_RP_GAMMA(I,J,K) \
468  bd->G##I##J##K + 2.0*( \
469  (I==J ? 1.0 : 0.0)*bd->d##K##phi \
470  + (I==K ? 1.0 : 0.0)*bd->d##J##phi \
471  - bd->gamma##J##K*(bd->gammai##I##1*bd->d1phi + bd->gammai##I##2*bd->d2phi + bd->gammai##I##3*bd->d3phi) \
472  )
473 
474 #define BSSN_RP_GAMMAL(I,J,K) P*( \
475  bd->GL##I##J##K + 2.0*( \
476  bd->gamma##I##J*bd->d##K##phi \
477  + bd->gamma##I##K*bd->d##J##phi \
478  - bd->gamma##J##K*bd->d##I##phi \
479  ) )
480 
481 /*
482  * Constraint calculation macros
483  */
484 
485 // Momentum constraint with index lowered using the conformal metric:
486 // M_I == \bar{gamma}_{IJ} M^J
487 #define BSSN_MI(I) exp(6.0*bd->phi)*( \
488  - 2.0/3.0*bd->d##I##K \
489  /* Note: S_I is lowered with the full metric, not conformal. */ \
490  - 8*PI*(bd->S##I) \
491  - 2.0/3.0*2.0*bd->d##I##theta \
492  + 6.0*( \
493  bd->gammai11*bd->A1##I*bd->d1phi + bd->gammai21*bd->A2##I*bd->d1phi + bd->gammai31*bd->A3##I*bd->d1phi \
494  + bd->gammai12*bd->A1##I*bd->d2phi + bd->gammai22*bd->A2##I*bd->d2phi + bd->gammai32*bd->A3##I*bd->d2phi \
495  + bd->gammai13*bd->A1##I*bd->d3phi + bd->gammai23*bd->A2##I*bd->d3phi + bd->gammai33*bd->A3##I*bd->d3phi \
496  ) + ( \
497  /* (gamma^jk D_j A_ki) */ \
498  bd->gammai11*derivative(bd->i, bd->j, bd->k, 1, A1##I->_array_a) + bd->gammai12*derivative(bd->i, bd->j, bd->k, 2, A1##I->_array_a) + bd->gammai13*derivative(bd->i, bd->j, bd->k, 3, A1##I->_array_a) \
499  + bd->gammai21*derivative(bd->i, bd->j, bd->k, 1, A2##I->_array_a) + bd->gammai22*derivative(bd->i, bd->j, bd->k, 2, A2##I->_array_a) + bd->gammai23*derivative(bd->i, bd->j, bd->k, 3, A2##I->_array_a) \
500  + bd->gammai31*derivative(bd->i, bd->j, bd->k, 1, A3##I->_array_a) + bd->gammai32*derivative(bd->i, bd->j, bd->k, 2, A3##I->_array_a) + bd->gammai33*derivative(bd->i, bd->j, bd->k, 3, A3##I->_array_a) \
501  - bd->Gammad1*bd->A1##I - bd->Gammad2*bd->A2##I - bd->Gammad3*bd->A3##I \
502  - bd->GL11##I*bd->Acont11 - bd->GL21##I*bd->Acont21 - bd->GL31##I*bd->Acont31 \
503  - bd->GL12##I*bd->Acont12 - bd->GL22##I*bd->Acont22 - bd->GL32##I*bd->Acont32 \
504  - bd->GL13##I*bd->Acont13 - bd->GL23##I*bd->Acont23 - bd->GL33##I*bd->Acont33 \
505  ) \
506  )
507 
508 #define BSSN_MI_SCALE(I) exp(6.0*bd->phi)*( \
509  std::abs(2.0/3.0*bd->d##I##K) \
510  /* Note: S_I is lowered with the full metric, not conformal. */ \
511  + std::abs(8*PI*(bd->S##I)) \
512  + std::abs(2.0/3.0*2.0*bd->d##I##theta) \
513  + 6.0*std::abs( \
514  bd->gammai11*bd->A1##I*bd->d1phi + bd->gammai21*bd->A2##I*bd->d1phi + bd->gammai31*bd->A3##I*bd->d1phi \
515  + bd->gammai12*bd->A1##I*bd->d2phi + bd->gammai22*bd->A2##I*bd->d2phi + bd->gammai32*bd->A3##I*bd->d2phi \
516  + bd->gammai13*bd->A1##I*bd->d3phi + bd->gammai23*bd->A2##I*bd->d3phi + bd->gammai33*bd->A3##I*bd->d3phi \
517  ) + std::abs( \
518  /* (gamma^jk D_j A_ki) */ \
519  bd->gammai11*derivative(bd->i, bd->j, bd->k, 1, A1##I->_array_a) + bd->gammai12*derivative(bd->i, bd->j, bd->k, 2, A1##I->_array_a) + bd->gammai13*derivative(bd->i, bd->j, bd->k, 3, A1##I->_array_a) \
520  + bd->gammai21*derivative(bd->i, bd->j, bd->k, 1, A2##I->_array_a) + bd->gammai22*derivative(bd->i, bd->j, bd->k, 2, A2##I->_array_a) + bd->gammai23*derivative(bd->i, bd->j, bd->k, 3, A2##I->_array_a) \
521  + bd->gammai31*derivative(bd->i, bd->j, bd->k, 1, A3##I->_array_a) + bd->gammai32*derivative(bd->i, bd->j, bd->k, 2, A3##I->_array_a) + bd->gammai33*derivative(bd->i, bd->j, bd->k, 3, A3##I->_array_a) \
522  - bd->Gammad1*bd->A1##I - bd->Gammad2*bd->A2##I - bd->Gammad3*bd->A3##I \
523  - bd->GL11##I*bd->Acont11 - bd->GL21##I*bd->Acont21 - bd->GL31##I*bd->Acont31 \
524  - bd->GL12##I*bd->Acont12 - bd->GL22##I*bd->Acont22 - bd->GL32##I*bd->Acont32 \
525  - bd->GL13##I*bd->Acont13 - bd->GL23##I*bd->Acont23 - bd->GL33##I*bd->Acont33 \
526  ) \
527  )
528 
529 
530 #define BSSN_GI_CALC(I) \
531  bd->Gamma##I - bd->gammai11*bd->G##I##11 - bd->gammai22*bd->G##I##22 - bd->gammai33*bd->G##I##33 \
532  - 2.0*(bd->gammai12*bd->G##I##12 + bd->gammai13*bd->G##I##13 + bd->gammai23*bd->G##I##23);
533 
534 #define BSSN_GI_SCALE(I) \
535  std::abs(bd->Gamma##I) + std::abs(bd->gammai11*bd->G##I##11 - bd->gammai22*bd->G##I##22 - bd->gammai33*bd->G##I##33 \
536  - 2.0*(bd->gammai12*bd->G##I##12 + bd->gammai13*bd->G##I##13 + bd->gammai23*bd->G##I##23));
537 
538 
539 #define BSSN_NORMALIZE_STDEV(C) \
540  stdev_##C = sqrt(stdev_##C/(POINTS-1.0)); \
541  stdev_##C##_scaled = sqrt(stdev_##C##_scaled/(POINTS-1.0));
542 
543 #define BSSN_NORMALIZE_MEAN(C) \
544  mean_##C /= POINTS; \
545  mean_##C##_scaled /= POINTS;
546 
547 #define BSSN_INITIALIZE_CONSTRAINT_STAT_VARS(C) \
548  real_t mean_##C = 0.0, stdev_##C = 0.0, max_##C = 0.0; \
549  real_t mean_##C##_scale = 0.0; \
550  real_t mean_##C##_scaled = 0.0, stdev_##C##_scaled = 0.0,\
551  max_##C##_scaled = 0.0;
552 
553 #define BSSN_STORE_CONSTRAINT_STAT_VARS(C) \
554  C##_values[0] = mean_##C; \
555  C##_values[1] = stdev_##C; \
556  C##_values[2] = max_##C; \
557  C##_values[3] = mean_##C##_scale; \
558  C##_values[4] = mean_##C##_scaled; \
559  C##_values[5] = stdev_##C##_scaled; \
560  C##_values[6] = max_##C##_scaled;
561 
562 #define BSSN_COMPUTE_CONSTRAINT_STAT_VARS(C, calcfn, scalefn) \
563  real_t C##_val = calcfn(&bd); \
564  real_t C##_scale = scalefn(&bd); \
565  real_t C##_scaled = C##_val/C##_scale;
566 
567 #define BSSN_COMPUTE_CONSTRAINT_STAT_VARS_VEC(C, calcfn, scalefn) \
568  real_t C##_val = sqrt( pw2(calcfn(&bd, 1)) + pw2(calcfn(&bd, 2)) + pw2(calcfn(&bd, 3)) ); \
569  real_t C##_scale = sqrt( pw2(scalefn(&bd, 1)) + pw2(scalefn(&bd, 2)) + pw2(scalefn(&bd, 3)) ); \
570  real_t C##_scaled = C##_val/C##_scale;
571 
572 #define BSSN_COMPUTE_CONSTRAINT_MEAN_VARS(C) \
573  mean_##C += C##_val; \
574  mean_##C##_scale += C##_scale; \
575  mean_##C##_scaled += C##_scaled;
576 
577 #define BSSN_COMPUTE_CONSTRAINT_STDEV_VARS(C) \
578  stdev_##C += pw2(C##_val - mean_##C); \
579  stdev_##C##_scaled += pw2(C##_scaled - mean_##C##_scaled);
580 
581 #define BSSN_COMPUTE_CONSTRAINT_MAXES(C) \
582  if(fabs(C##_val) > max_##C) \
583  max_##C = fabs(C##_val); \
584  if(fabs(C##_scaled) > max_##C##_scaled) \
585  max_##C##_scaled = fabs(C##_scaled);
586 
587 /*
588  * Enforce standard ordering of indexes for tensor components
589  */
590 
591 // actual fields:
592 #define A21 A12
593 #define A31 A13
594 #define A32 A23
595 
596 #define DIFFgamma21 DIFFgamma12
597 #define DIFFgamma31 DIFFgamma13
598 #define DIFFgamma32 DIFFgamma23
599 #define DIFFgammai21 DIFFgammai12
600 #define DIFFgammai31 DIFFgammai13
601 #define DIFFgammai32 DIFFgammai23
602 
603 // local variables:
604 // non-difference metric
605 #define gamma21 gamma12
606 #define gamma31 gamma13
607 #define gamma32 gamma23
608 
609 // inverse metric
610 #define gammai21 gammai12
611 #define gammai31 gammai13
612 #define gammai32 gammai23
613 
614 // ricci tensor
615 #define ricciTF21 ricciTF12
616 #define ricciTF31 ricciTF13
617 #define ricciTF32 ricciTF23
618 #define ricci21 ricci12
619 #define ricci31 ricci13
620 #define ricci32 ricci23
621 
622 // covariant double-derivatives of phi
623 #define D2D1phi D1D2phi
624 #define D3D1phi D1D3phi
625 #define D3D2phi D2D3phi
626 
627 // covariant double-derivatives of alpha
628 #define D2D1aTF D1D2aTF
629 #define D3D1aTF D1D3aTF
630 #define D3D2aTF D2D3aTF
631 
632 // Inverse ext. curvature
633 #define Acont21 Acont12
634 #define Acont31 Acont13
635 #define Acont32 Acont23
636 
637 // christoffel symbols
638 #define G121 G112
639 #define G131 G113
640 #define G132 G123
641 #define G221 G212
642 #define G231 G213
643 #define G232 G223
644 #define G321 G312
645 #define G331 G313
646 #define G332 G323
647 
648 // lower christoffel symbols
649 #define GL121 GL112
650 #define GL131 GL113
651 #define GL132 GL123
652 #define GL221 GL212
653 #define GL231 GL213
654 #define GL232 GL223
655 #define GL321 GL312
656 #define GL331 GL313
657 #define GL332 GL323
658 
659 // Metric derivatives
660 #define d1g21 d1g12
661 #define d1g31 d1g13
662 #define d1g32 d1g23
663 #define d2g21 d2g12
664 #define d2g31 d2g13
665 #define d2g32 d2g23
666 #define d3g21 d3g12
667 #define d3g31 d3g13
668 #define d3g32 d3g23
669 
670 // second derivatives of the metric
671 // bad metric indices
672 #define d1d1g21 d1d1g12
673 #define d1d1g31 d1d1g13
674 #define d1d1g32 d1d1g23
675 #define d1d2g21 d1d2g12
676 #define d1d2g31 d1d2g13
677 #define d1d2g32 d1d2g23
678 #define d1d3g21 d1d3g12
679 #define d1d3g31 d1d3g13
680 #define d1d3g32 d1d3g23
681 #define d2d2g21 d2d2g12
682 #define d2d2g31 d2d2g13
683 #define d2d2g32 d2d2g23
684 #define d2d3g21 d2d3g12
685 #define d2d3g31 d2d3g13
686 #define d2d3g32 d2d3g23
687 #define d3d3g21 d3d3g12
688 #define d3d3g31 d3d3g13
689 #define d3d3g32 d3d3g23
690 // bad derivative indices
691 #define d2d1g11 d1d2g11
692 #define d2d1g12 d1d2g12
693 #define d2d1g13 d1d2g13
694 #define d2d1g22 d1d2g22
695 #define d2d1g23 d1d2g23
696 #define d2d1g33 d1d2g33
697 #define d3d1g11 d1d3g11
698 #define d3d1g12 d1d3g12
699 #define d3d1g13 d1d3g13
700 #define d3d1g22 d1d3g22
701 #define d3d1g23 d1d3g23
702 #define d3d1g33 d1d3g33
703 #define d3d2g11 d2d3g11
704 #define d3d2g12 d2d3g12
705 #define d3d2g13 d2d3g13
706 #define d3d2g22 d2d3g22
707 #define d3d2g23 d2d3g23
708 #define d3d2g33 d2d3g33
709 // bad in both indices
710 #define d2d1g21 d1d2g12
711 #define d2d1g31 d1d2g13
712 #define d2d1g32 d1d2g23
713 #define d3d1g21 d1d3g12
714 #define d3d1g31 d1d3g13
715 #define d3d1g32 d1d3g23
716 #define d3d2g21 d2d3g12
717 #define d3d2g31 d2d3g13
718 #define d3d2g32 d2d3g23
719 
720 // Full Metric
721 #define m10 m01
722 #define m20 m02
723 #define m30 m03
724 #define m21 m12
725 #define m31 m13
726 #define m32 m23
727 
728 // Full Metric derivatives
729 #define d1m10 d1m01
730 #define d1m20 d1m02
731 #define d1m30 d1m03
732 #define d1m21 d1m12
733 #define d1m31 d1m13
734 #define d1m32 d1m23
735 #define d2m10 d2m01
736 #define d2m20 d2m02
737 #define d2m30 d2m03
738 #define d2m21 d2m12
739 #define d2m31 d2m13
740 #define d2m32 d2m23
741 #define d3m10 d3m01
742 #define d3m20 d3m02
743 #define d3m30 d3m03
744 #define d3m21 d3m12
745 #define d3m31 d3m13
746 #define d3m32 d3m23
747 
748 // source terms
749 #define S21 S12
750 #define S31 S13
751 #define S32 S23
752 
753 #define STF21 STF12
754 #define STF31 STF13
755 #define STF32 STF23
756 
757 #if USE_GENERALIZED_NEWTON
758 #define ricciTF21 ricciTF12
759 #define ricciTF31 ricciTF13
760 #define ricciTF32 ricciTF23
761 
762 #define GNTensor21 GNTensor12
763 #define GNTensor31 GNTensor13
764 #define GNTensor32 GNTensor23
765 
766 #define GNTensor21_a GNTensor12_a
767 #define GNTensor31_a GNTensor13_a
768 #define GNTensor32_a GNTensor23_a
769 
770 
771 #endif
772 
773 #endif