-
Notifications
You must be signed in to change notification settings - Fork 7
/
global.fieldmacros.h
395 lines (281 loc) · 20.2 KB
/
global.fieldmacros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// divB=0 related macros
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if(NEWMETRICSTORAGE==1)
#if(MCOORD!=CARTMINKMETRIC)
// e.g. MYGDET(i,j,k,CENT)
// GODMARK: assumes field EOMs have WHICHEOM==WITHGDET or NOGDETB?=0
#define MYGDET(i,j,k,p) (GLOBALMETMACP1A0(compgeom,p,i,j,k).gdet)
#else
#define MYGDET(i,j,k,p) (GLOBALMETMACP1A0(compgeom,p,0,0,0).gdet)
#endif
#else // old method
#if(MCOORD!=CARTMINKMETRIC)
// e.g. MYGDET(i,j,k,CENT)
#define MYGDET(i,j,k,p) (GLOBALMETMACP1A0(gdet,p,i,j,k_))
#else
#define MYGDET(i,j,k,p) (GLOBALMETMACP1A0(gdet,p,0,0,0))
#endif
#endif // end if old method
/////////////////////////////////
//
// below 4 macros used for vpot2field() in initbase.c
#define FgCORN(F,i,j,k) (MAC(F,i,j,k))
// AVG_x functions that average in x direction
// typically operates on CORN1,2,3 quantities to get face quantities
#define AVGCORN_1(F,i,j,k) (0.5*(FgCORN(F,ip1mac(i),j,k) + FgCORN(F,i,j,k) ))
#define AVGCORN_2(F,i,j,k) (0.5*(FgCORN(F,i,jp1mac(j),k) + FgCORN(F,i,j,k) ))
#define AVGCORN_3(F,i,j,k) (0.5*(FgCORN(F,i,j,kp1mac(k)) + FgCORN(F,i,j,k) ))
// do-nothing functions
#define NOAVGCORN_1(F,i,j,k) (FgCORN(F,i,j,k))
#define NOAVGCORN_2(F,i,j,k) (FgCORN(F,i,j,k))
#define NOAVGCORN_3(F,i,j,k) (FgCORN(F,i,j,k))
///////////////////////////////
//
// below macros are similar to those farther below for divb, but no gdet stuff
#define FgN(F,i,j,k,pl) (MACP0A1(F,i,j,k,pl))
// AVGN_x functions that average in x direction
// typically operates on centered quantities to get face quantities OR on face quantities to get edge quantities
#define AVGN_1(F,i,j,k,pl) (0.5*(FgN(F,i,j,k,pl) + FgN(F,im1mac(i),j,k,pl) ))
#define AVGN_2(F,i,j,k,pl) (0.5*(FgN(F,i,j,k,pl) + FgN(F,i,jm1mac(j),k,pl) ))
#define AVGN_3(F,i,j,k,pl) (0.5*(FgN(F,i,j,k,pl) + FgN(F,i,j,km1mac(k),pl) ))
#define NOAVGN_1(F,i,j,k,pl) (FgN(F,i,j,k,pl))
#define NOAVGN_2(F,i,j,k,pl) (FgN(F,i,j,k,pl))
#define NOAVGN_3(F,i,j,k,pl) (FgN(F,i,j,k,pl))
// just average of 4 quantities that eventually lives on (0.5,0,0) (i.e. CORN1)
#define AVGN_for1(F,i,j,k,pl) (0.5*(AVGN_2(F,i,j,k,pl)+AVGN_2(F,i,j,km1mac(k),pl))) // 2 and 3 directions averaged
// lives on (0,0.5,0) (i.e. CORN2)
#define AVGN_for2(F,i,j,k,pl) (0.5*(AVGN_1(F,i,j,k,pl)+AVGN_1(F,i,j,km1mac(k),pl))) // 1 and 3 directions averaged
// lives on (0,0,0.5) (i.e. CORN3)
#define AVGN_for3(F,i,j,k,pl) (0.5*(AVGN_2(F,i,j,k,pl)+AVGN_2(F,im1mac(i),j,k,pl))) // 1 and 2 directions averaged
#define NOAVGN_for1(F,i,j,k,pl) (NOAVGN_1(F,i,j,k,pl))
#define NOAVGN_for2(F,i,j,k,pl) (NOAVGN_2(F,i,j,k,pl))
#define NOAVGN_for3(F,i,j,k,pl) (NOAVGN_3(F,i,j,k,pl))
///////////////////////////////
//
// below macros are similar to those farther below for divb, but no gdet stuff
#define absFgN(F,i,j,k,pl) (fabs(MACP0A1(F,i,j,k,pl)))
// AVGN_x functions that average in x direction
// typically operates on centered quantities to get face quantities OR on face quantities to get edge quantities
#define absAVGN_1(F,i,j,k,pl) (0.5*(absFgN(F,i,j,k,pl) + absFgN(F,im1mac(i),j,k,pl) ))
#define absAVGN_2(F,i,j,k,pl) (0.5*(absFgN(F,i,j,k,pl) + absFgN(F,i,jm1mac(j),k,pl) ))
#define absAVGN_3(F,i,j,k,pl) (0.5*(absFgN(F,i,j,k,pl) + absFgN(F,i,j,km1mac(k),pl) ))
#define absNOAVGN_1(F,i,j,k,pl) (absFgN(F,i,j,k,pl))
#define absNOAVGN_2(F,i,j,k,pl) (absFgN(F,i,j,k,pl))
#define absNOAVGN_3(F,i,j,k,pl) (absFgN(F,i,j,k,pl))
// just average of 4 quantities that eventually lives on (0.5,0,0) (i.e. CORN1)
#define absAVGN_for1(F,i,j,k,pl) (0.5*(absAVGN_2(F,i,j,k,pl)+absAVGN_2(F,i,j,km1mac(k),pl))) // 2 and 3 directions averaged
// lives on (0,0.5,0) (i.e. CORN2)
#define absAVGN_for2(F,i,j,k,pl) (0.5*(absAVGN_1(F,i,j,k,pl)+absAVGN_1(F,i,j,km1mac(k),pl))) // 1 and 3 directions averaged
// lives on (0,0,0.5) (i.e. CORN3)
#define absAVGN_for3(F,i,j,k,pl) (0.5*(absAVGN_2(F,i,j,k,pl)+absAVGN_2(F,im1mac(i),j,k,pl))) // 1 and 2 directions averaged
#define absNOAVGN_for1(F,i,j,k,pl) (absNOAVGN_1(F,i,j,k,pl))
#define absNOAVGN_for2(F,i,j,k,pl) (absNOAVGN_2(F,i,j,k,pl))
#define absNOAVGN_for3(F,i,j,k,pl) (absNOAVGN_3(F,i,j,k,pl))
//////////////////////////////////////////
//
// below macros used for divb definition (with gdet)
#define Fg(F,i,j,k,pl) (MACP0A1(F,i,j,k,pl)*MYGDET(i,j,k,CENT))
#define Fgface(F,i,j,k,pl) (MACP0A1(F,i,j,k,pl)*MYGDET(i,j,k,FACE1+pl-B1)) // assumes B1,B2,B3 in order for pl GODMARK
// AVG_x functions that average in x direction (includes geometry)
// typically operates on centered quantities to get face quantities OR on face quantities to get edge quantities
#define AVG_1(F,i,j,k,pl) (0.5*(Fg(F,i,j,k,pl) + Fg(F,im1mac(i),j,k,pl) ))
#define AVG_2(F,i,j,k,pl) (0.5*(Fg(F,i,j,k,pl) + Fg(F,i,jm1mac(j),k,pl) ))
#define AVG_3(F,i,j,k,pl) (0.5*(Fg(F,i,j,k,pl) + Fg(F,i,j,km1mac(k),pl) ))
#define NOAVG_1(F,i,j,k,pl) (Fg(F,i,j,k,pl))
#define NOAVG_2(F,i,j,k,pl) (Fg(F,i,j,k,pl))
#define NOAVG_3(F,i,j,k,pl) (Fg(F,i,j,k,pl))
#define NOAVGFACE_1(F,i,j,k,pl) (Fgface(F,i,j,k,pl))
#define NOAVGFACE_2(F,i,j,k,pl) (Fgface(F,i,j,k,pl))
#define NOAVGFACE_3(F,i,j,k,pl) (Fgface(F,i,j,k,pl))
// just average of 4 quantities that eventually lives on (0.5,0,0) (i.e. CORN1)
#define AVG_for1(F,i,j,k,pl) (0.5*(AVG_2(F,i,j,k,pl)+AVG_2(F,i,j,km1mac(k),pl))) // 2 and 3 directions averaged
// lives on (0,0.5,0) (i.e. CORN2)
#define AVG_for2(F,i,j,k,pl) (0.5*(AVG_1(F,i,j,k,pl)+AVG_1(F,i,j,km1mac(k),pl))) // 1 and 3 directions averaged
// lives on (0,0,0.5) (i.e. CORN3)
#define AVG_for3(F,i,j,k,pl) (0.5*(AVG_2(F,i,j,k,pl)+AVG_2(F,im1mac(i),j,k,pl))) // 1 and 2 directions averaged
#define NOAVG_for1(F,i,j,k,pl) (NOAVG_1(F,i,j,k,pl))
#define NOAVG_for2(F,i,j,k,pl) (NOAVG_2(F,i,j,k,pl))
#define NOAVG_for3(F,i,j,k,pl) (NOAVG_3(F,i,j,k,pl))
#define NOAVGFACE_for1(F,i,j,k,pl) (NOAVGFACE_1(F,i,j,k,pl))
#define NOAVGFACE_for2(F,i,j,k,pl) (NOAVGFACE_2(F,i,j,k,pl))
#define NOAVGFACE_for3(F,i,j,k,pl) (NOAVGFACE_3(F,i,j,k,pl))
///////////////////////////////////////////
//
// below macros used for divb definition (with gdet)
#define absFg(F,i,j,k,pl) (fabs(MACP0A1(F,i,j,k,pl)*MYGDET(i,j,k,CENT)))
#define absFgface(F,i,j,k,pl) (fabs(MACP0A1(F,i,j,k,pl)*MYGDET(i,j,k,FACE1+pl-B1))) // assumes B1,B2,B3 in order for pl GODMARK
// absAVG_x functions that average in x direction
// typically operates on centered quantities to get face quantities OR on face quantities to get edge quantities
#define absAVG_1(F,i,j,k,pl) (0.5*(absFg(F,i,j,k,pl) + absFg(F,im1mac(i),j,k,pl) ))
#define absAVG_2(F,i,j,k,pl) (0.5*(absFg(F,i,j,k,pl) + absFg(F,i,jm1mac(j),k,pl) ))
#define absAVG_3(F,i,j,k,pl) (0.5*(absFg(F,i,j,k,pl) + absFg(F,i,j,km1mac(k),pl) ))
#define absAVGFACE_1(F,i,j,k,pl) (0.5*(absFgface(F,i,j,k,pl) + absFgface(F,im1mac(i),j,k,pl) ))
#define absAVGFACE_2(F,i,j,k,pl) (0.5*(absFgface(F,i,j,k,pl) + absFgface(F,i,jm1mac(j),k,pl) ))
#define absAVGFACE_3(F,i,j,k,pl) (0.5*(absFgface(F,i,j,k,pl) + absFgface(F,i,j,km1mac(k),pl) ))
// absAVG_x functions that average in x direction
// typically operates on centered quantities to get face quantities OR on face quantities to get edge quantities
#define absNOAVG_1(F,i,j,k,pl) (absFg(F,i,j,k,pl))
#define absNOAVG_2(F,i,j,k,pl) (absFg(F,i,j,k,pl))
#define absNOAVG_3(F,i,j,k,pl) (absFg(F,i,j,k,pl))
#define absNOAVGFACE_1(F,i,j,k,pl) (absFgface(F,i,j,k,pl))
#define absNOAVGFACE_2(F,i,j,k,pl) (absFgface(F,i,j,k,pl))
#define absNOAVGFACE_3(F,i,j,k,pl) (absFgface(F,i,j,k,pl))
// just average of 4 quantities that eventually lives on (0.5,0,0) (i.e. CORN1)
#define absAVG_for1(F,i,j,k,pl) (0.5*(absAVG_2(F,i,j,k,pl)+absAVG_2(F,i,j,km1mac(k),pl))) // 2 and 3 directions averaged
// lives on (0,0.5,0) (i.e. CORN2)
#define absAVG_for2(F,i,j,k,pl) (0.5*(absAVG_1(F,i,j,k,pl)+absAVG_1(F,i,j,km1mac(k),pl))) // 1 and 3 directions averaged
// lives on (0,0,0.5) (i.e. CORN3)
#define absAVG_for3(F,i,j,k,pl) (0.5*(absAVG_2(F,i,j,k,pl)+absAVG_2(F,im1mac(i),j,k,pl))) // 1 and 2 directions averaged
#define absNOAVG_for1(F,i,j,k,pl) (absAVG_1(F,i,j,k,pl))
#define absNOAVG_for2(F,i,j,k,pl) (absAVG_2(F,i,j,k,pl))
#define absNOAVG_for3(F,i,j,k,pl) (absAVG_3(F,i,j,k,pl))
#define absNOAVGFACE_for1(F,i,j,k,pl) (absAVGFACE_1(F,i,j,k,pl))
#define absNOAVGFACE_for2(F,i,j,k,pl) (absAVGFACE_2(F,i,j,k,pl))
#define absNOAVGFACE_for3(F,i,j,k,pl) (absAVGFACE_3(F,i,j,k,pl))
// #define DIVBCONDITION(p,i,j)
// if((i>=-1)&&(j>=-1)&&(startpos[2]+j!=0)&&(startpos[2]+j!=N2TOT))
//#define DIVBCONDITION(p,i,j) if((startpos[1]+i>0)&&(startpos[2]+j>0)&&(startpos[1]+i<totalsize[1])&&(startpos[2]+j<totalsize[2]))
//#define DIVBCONDITION(p,i,j) if((startpos[1]+i!=0)&&(startpos[1]+i!=totalsize[1])&&(startpos[2]+j!=0)&&(startpos[2]+j!=totalsize[2]))
// only needed for polar axis condition
//GODMARK
//#define DIVBCONDITION(p,i,j,k) if((startpos[2]+j!=0)&&(startpos[2]+j!=totalsize[2]))
// GODMARK: No, need for all boundaries
//#define DIVBCONDITION(p,i,j,k) if(((startpos[1]+i!=0)&&(startpos[1]+i!=totalsize[1]) || (!N1NOT1))&&((startpos[2]+j!=0)&&(startpos[2]+j!=totalsize[2]) || (!N2NOT1))&&((startpos[3]+k!=0)&&(startpos[3]+k!=totalsize[3]) || (!N3NOT1)))
// only consider within bounds or ignore condition if no such dimension
#define DIVBCDIR1 ((i >= -N1BND+1 && i <= N1 - 1 + N1BND - 1) || (!N1NOT1))
#define DIVBCDIR2 ((j >= -N2BND+1 && j <= N2 - 1 + N2BND - 1) || (!N2NOT1))
#define DIVBCDIR3 ((k >= -N3BND+1 && k <= N3 - 1 + N3BND - 1) || (!N3NOT1))
#define DIVBCONDITION(p,i,j,k) if(DIVBCDIR1&&DIVBCDIR2&&DIVBCDIR3)
//#define DIVBCONDITION(p,i,j,k) if(1)
///////////////////////////////////
//
// FLUXCTTOTH DIVB
//
////////////////////////////////////
//(startpos[2]+j!=0)&&(startpos[2]+j!=totalsize[2])&&(startpos[3]+k!=0)&&(startpos[3]+k!=totalsize[3])
/////////////////////
// PRMITIVE quantity
// the below lines results in quantity at TRUE CORNER
#define DIVBDIFFFLUXCTTOTHPRIMx(p,i,j,k) (AVG_for1(p,i,j,k,B1)-AVG_for1(p,im1mac(i),j,k,B1))
#define DIVBDIFFFLUXCTTOTHPRIMy(p,i,j,k) (AVG_for2(p,i,j,k,B2)-AVG_for2(p,i,jm1mac(j),k,B2))
#define DIVBDIFFFLUXCTTOTHPRIMz(p,i,j,k) (AVG_for3(p,i,j,k,B3)-AVG_for3(p,i,j,km1mac(k),B3))
//#define DIVBNORMFLUXCTTOTHPRIMx(p,i,j,k) (AVG_for1(p,i,j,k,B1)+AVG_for1(p,im1mac(i),j,k,B1))
//#define DIVBNORMFLUXCTTOTHPRIMy(p,i,j,k) (AVG_for2(p,i,j,k,B2)+AVG_for2(p,i,jm1mac(j),k,B2))
//#define DIVBNORMFLUXCTTOTHPRIMz(p,i,j,k) (AVG_for3(p,i,j,k,B3)+AVG_for3(p,i,j,km1mac(k),B3))
#define DIVBNORMFLUXCTTOTHPRIMx(p,i,j,k) (absAVG_for1(p,i,j,k,B1)+absAVG_for1(p,im1mac(i),j,k,B1))
#define DIVBNORMFLUXCTTOTHPRIMy(p,i,j,k) (absAVG_for2(p,i,j,k,B2)+absAVG_for2(p,i,jm1mac(j),k,B2))
#define DIVBNORMFLUXCTTOTHPRIMz(p,i,j,k) (absAVG_for3(p,i,j,k,B3)+absAVG_for3(p,i,j,km1mac(k),B3))
// the below as dividing by too many \detg's since MYGDET in division and inside B
//#define DIVBNORMFLUXCTTOTHPRIM(p,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(THIRD*MYGDET(i,j,k,CORNT)*fabs(DIVBNORMFLUXCTTOTHPRIMx(p,i,j,k)+DIVBNORMFLUXCTTOTHPRIMy(p,i,j,k)+DIVBNORMFLUXCTTOTHPRIMz(p,i,j,k)) +SMALL))
// removed MYGDET at corner. This 1) removes issue with dividing by 0 and 2) is correct since DIVBNORMFLUXCTTOTHPRIM already has gdet
//#define DIVBNORMFLUXCTTOTHPRIM(p,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(THIRD*fabs(DIVBNORMFLUXCTTOTHPRIMx(p,i,j,k)+DIVBNORMFLUXCTTOTHPRIMy(p,i,j,k)+DIVBNORMFLUXCTTOTHPRIMz(p,i,j,k)) +SMALL))
#define DIVBNORMFLUXCTTOTHPRIM(p,i,j,k) (1.0/(fabs(DIVBNORMFLUXCTTOTHPRIMx(p,i,j,k)/dx[1]+DIVBNORMFLUXCTTOTHPRIMy(p,i,j,k)/dx[2]+DIVBNORMFLUXCTTOTHPRIMz(p,i,j,k)/dx[3]) +SMALL))
#define DIVBFLUXCTTOTHPRIM(p,i,j,k) (( \
DIVBDIFFFLUXCTTOTHPRIMx(p,i,j,k)/dx[1] + DIVBDIFFFLUXCTTOTHPRIMy(p,i,j,k)/dx[2] + DIVBDIFFFLUXCTTOTHPRIMz(p,i,j,k)/dx[3] \
)*(DIVBNORMFLUXCTTOTHPRIM(p,i,j,k)))
/////////////////////
// CONSERVED quantity
// the below lines results in quantity at TRUE CORNER
#define DIVBDIFFFLUXCTTOTHx(U,i,j,k) (AVGN_for1(U,i,j,k,B1)-AVGN_for1(U,im1mac(i),j,k,B1))
#define DIVBDIFFFLUXCTTOTHy(U,i,j,k) (AVGN_for2(U,i,j,k,B2)-AVGN_for2(U,i,jm1mac(j),k,B2))
#define DIVBDIFFFLUXCTTOTHz(U,i,j,k) (AVGN_for3(U,i,j,k,B3)-AVGN_for3(U,i,j,km1mac(k),B3))
//#define DIVBNORMFLUXCTTOTHx(U,i,j,k) (AVGN_for1(U,i,j,k,B1)+AVGN_for1(U,im1mac(i),j,k,B1))
//#define DIVBNORMFLUXCTTOTHy(U,i,j,k) (AVGN_for2(U,i,j,k,B2)+AVGN_for2(U,i,jm1mac(j),k,B2))
//#define DIVBNORMFLUXCTTOTHz(U,i,j,k) (AVGN_for3(U,i,j,k,B3)+AVGN_for3(U,i,j,km1mac(k),B3))
#define DIVBNORMFLUXCTTOTHx(U,i,j,k) (absAVGN_for1(U,i,j,k,B1)+absAVGN_for1(U,im1mac(i),j,k,B1))
#define DIVBNORMFLUXCTTOTHy(U,i,j,k) (absAVGN_for2(U,i,j,k,B2)+absAVGN_for2(U,i,jm1mac(j),k,B2))
#define DIVBNORMFLUXCTTOTHz(U,i,j,k) (absAVGN_for3(U,i,j,k,B3)+absAVGN_for3(U,i,j,km1mac(k),B3))
// the below as dividing by too many \detg's since MYGDET in division and inside B
//#define DIVBNORMFLUXCTTOTH(U,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(THIRD*MYGDET(i,j,k,CORNT)*fabs(DIVBNORMFLUXCTTOTHx(U,i,j,k)+DIVBNORMFLUXCTTOTHy(U,i,j,k)+DIVBNORMFLUXCTTOTHz(U,i,j,k)) +SMALL))
// removed MYGDET at corner. This 1) removes issue with dividing by 0 and 2) is correct since DIVBNORMFLUXCTTOTH already has gdet
//#define DIVBNORMFLUXCTTOTH(U,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(THIRD*fabs(DIVBNORMFLUXCTTOTHx(U,i,j,k)+DIVBNORMFLUXCTTOTHy(U,i,j,k)+DIVBNORMFLUXCTTOTHz(U,i,j,k)) +SMALL))
#define DIVBNORMFLUXCTTOTH(U,i,j,k) (1.0/(fabs(DIVBNORMFLUXCTTOTHx(U,i,j,k)/dx[1]+DIVBNORMFLUXCTTOTHy(U,i,j,k)/dx[2]+DIVBNORMFLUXCTTOTHz(U,i,j,k)/dx[3]) +SMALL))
#define DIVBFLUXCTTOTH(U,i,j,k) (( \
DIVBDIFFFLUXCTTOTHx(U,i,j,k)/dx[1] + DIVBDIFFFLUXCTTOTHy(U,i,j,k)/dx[2] + DIVBDIFFFLUXCTTOTHz(U,i,j,k)/dx[3] \
)*(DIVBNORMFLUXCTTOTH(U,i,j,k)))
///////////////////////////////////
//
// FLUXCTSTAG DIVB (divb sits at center and assume p here is located at FACE)
//
///////////////////////////////////
//////////////////////
// CONSERVED quantity
// as input for divb calculation (otherwise have to change MYGDET so doesn't always use CENT
// the below lines results in quantity at CENT
#define DIVBDIFFFLUXCTSTAGx(U,i,j,k) (NOAVGN_for1(U,ip1mac(i),j,k,B1)-NOAVGN_for1(U,i,j,k,B1))
#define DIVBDIFFFLUXCTSTAGy(U,i,j,k) (NOAVGN_for2(U,i,jp1mac(j),k,B2)-NOAVGN_for2(U,i,j,k,B2))
#define DIVBDIFFFLUXCTSTAGz(U,i,j,k) (NOAVGN_for3(U,i,j,kp1mac(k),B3)-NOAVGN_for3(U,i,j,k,B3))
#define DIVBNORMFLUXCTSTAGx(U,i,j,k) (absNOAVGN_for1(U,ip1mac(i),j,k,B1)+absNOAVGN_for1(U,i,j,k,B1))
#define DIVBNORMFLUXCTSTAGy(U,i,j,k) (absNOAVGN_for2(U,i,jp1mac(j),k,B2)+absNOAVGN_for2(U,i,j,k,B2))
#define DIVBNORMFLUXCTSTAGz(U,i,j,k) (absNOAVGN_for3(U,i,j,kp1mac(k),B3)+absNOAVGN_for3(U,i,j,k,B3))
//#define DIVBNORMFLUXCTSTAG(U,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(THIRD*fabs(DIVBNORMFLUXCTSTAGx(U,i,j,k)+DIVBNORMFLUXCTSTAGy(U,i,j,k)+DIVBNORMFLUXCTSTAGz(U,i,j,k)) +SMALL))
#define DIVBNORMFLUXCTSTAG(U,i,j,k) (1.0/(fabs(DIVBNORMFLUXCTSTAGx(U,i,j,k)/dx[1]+DIVBNORMFLUXCTSTAGy(U,i,j,k)/dx[2]+DIVBNORMFLUXCTSTAGz(U,i,j,k)/dx[3]) +SMALL))
#define DIVBFLUXCTSTAG(U,i,j,k) (( \
DIVBDIFFFLUXCTSTAGx(U,i,j,k)/dx[1] + DIVBDIFFFLUXCTSTAGy(U,i,j,k)/dx[2] + DIVBDIFFFLUXCTSTAGz(U,i,j,k)/dx[3] \
)*(DIVBNORMFLUXCTSTAG(U,i,j,k)))
/////////////////////
// PRMITIVE quantity
// as input for divb calculation (otherwise have to change MYGDET so doesn't always use CENT
// the below lines results in quantity at CENT
#define DIVBDIFFFLUXCTSTAGPRIMx(p,i,j,k) (NOAVGFACE_for1(p,ip1mac(i),j,k,B1)-NOAVGFACE_for1(p,i,j,k,B1))
#define DIVBDIFFFLUXCTSTAGPRIMy(p,i,j,k) (NOAVGFACE_for2(p,i,jp1mac(j),k,B2)-NOAVGFACE_for2(p,i,j,k,B2))
#define DIVBDIFFFLUXCTSTAGPRIMz(p,i,j,k) (NOAVGFACE_for3(p,i,j,kp1mac(k),B3)-NOAVGFACE_for3(p,i,j,k,B3))
#define DIVBNORMFLUXCTSTAGPRIMx(p,i,j,k) (absNOAVGFACE_for1(p,ip1mac(i),j,k,B1)+absNOAVGFACE_for1(p,i,j,k,B1))
#define DIVBNORMFLUXCTSTAGPRIMy(p,i,j,k) (absNOAVGFACE_for2(p,i,jp1mac(j),k,B2)+absNOAVGFACE_for2(p,i,j,k,B2))
#define DIVBNORMFLUXCTSTAGPRIMz(p,i,j,k) (absNOAVGFACE_for3(p,i,j,kp1mac(k),B3)+absNOAVGFACE_for3(p,i,j,k,B3))
//#define DIVBNORMFLUXCTSTAGPRIM(p,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(THIRD*fabs(DIVBNORMFLUXCTSTAGPRIMx(p,i,j,k)+DIVBNORMFLUXCTSTAGPRIMy(p,i,j,k)+DIVBNORMFLUXCTSTAGPRIMz(p,i,j,k)) +SMALL))
// keep like-dimensional things together
#define DIVBNORMFLUXCTSTAGPRIM(p,i,j,k) (1.0/(fabs(DIVBNORMFLUXCTSTAGPRIMx(p,i,j,k)/dx[1]+DIVBNORMFLUXCTSTAGPRIMy(p,i,j,k)/dx[2]+DIVBNORMFLUXCTSTAGPRIMz(p,i,j,k)/dx[3]) +SMALL))
#define DIVBFLUXCTSTAGPRIM(p,i,j,k) (( \
DIVBDIFFFLUXCTSTAGPRIMx(p,i,j,k)/dx[1] + DIVBDIFFFLUXCTSTAGPRIMy(p,i,j,k)/dx[2] + DIVBDIFFFLUXCTSTAGPRIMz(p,i,j,k)/dx[3] \
)*(DIVBNORMFLUXCTSTAGPRIM(p,i,j,k)))
///////////////////////////////////
//
// FLUXCD DIVB
//
///////////////////////////////////
/////////////////////
// CONSERVED quantity
// FLUXCD divb lives at CENT
#define DIVBNORMFLUXCD(p,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(MYGDET(i,j,k,CENT)*fabs( \
Fg(p,ip1mac(i),j,k,B1) + Fg(p,im1mac(i),j,k,B1) \
+Fg(p,i,jp1mac(j),k,B2) + Fg(p,i,jm1mac(j),k,B2) \
+Fg(p,i,j,kp1mac(k),B3) + Fg(p,i,j,km1mac(k),B3) \
)+SMALL))
#define DIVBFLUXCD(p,i,j,k) (0.5*( \
(Fg(p,ip1mac(i),j,k,B1) - Fg(p,im1mac(i),j,k,B1))/dx[1] \
+(Fg(p,i,jp1mac(j),k,B2) - Fg(p,i,jm1mac(j),k,B2))/dx[2] \
+(Fg(p,i,j,kp1mac(k),B3) - Fg(p,i,j,km1mac(k),B3))/dx[3] \
)*DIVBNORMFLUXCD(p,i,j,k))
/////////////////////
// PRMITIVE quantity
// FLUXCD divb lives at CENT
#define DIVBNORMFLUXCDPRIM(p,i,j,k) (MAX(MAX(dx[1],dx[2]),dx[3])/(MYGDET(i,j,k,CENT)*fabs( \
FgN(p,ip1mac(i),j,k,B1) + FgN(p,im1mac(i),j,k,B1) \
+FgN(p,i,jp1mac(j),k,B2) + FgN(p,i,jm1mac(j),k,B2) \
+FgN(p,i,j,kp1mac(k),B3) + FgN(p,i,j,km1mac(k),B3) \
)+SMALL))
#define DIVBFLUXCDPRIM(p,i,j,k) (0.5*( \
(FgN(p,ip1mac(i),j,k,B1) - FgN(p,im1mac(i),j,k,B1))/dx[1] \
+(FgN(p,i,jp1mac(j),k,B2) - FgN(p,i,jm1mac(j),k,B2))/dx[2] \
+(FgN(p,i,j,kp1mac(k),B3) - FgN(p,i,j,km1mac(k),B3))/dx[3] \
)*DIVBNORMFLUXCDPRIM(p,i,j,k))
///////////////////////////////////
//
// SETTING MACROS for all divb methods
//
///////////////////////////////////
// poles defined as divb=0, can't divide due to singularity (could use
// volume regularization)
#define SETFDIVBFLUXCTTOTH(divb,U,i,j,k) {DIVBCONDITION(U,i,j,k){ divb = fabs(DIVBFLUXCTTOTHPRIM(U,i,j,k)) ;} else divb = 0.;}
#define SETFDIVBFLUXCTTOTHPRIM(divb,p,i,j,k) {DIVBCONDITION(p,i,j,k){ divb = fabs(DIVBFLUXCTTOTHPRIM(p,i,j,k)) ;} else divb = 0.;}
#define SETFDIVBFLUXCTSTAG(divb,U,i,j,k) {DIVBCONDITION(U,i,j,k){ divb = fabs(DIVBFLUXCTSTAG(U,i,j,k)) ;} else divb = 0.;}
#define SETFDIVBFLUXCTSTAGPRIM(divb,p,i,j,k) {DIVBCONDITION(p,i,j,k){ divb = fabs(DIVBFLUXCTSTAGPRIM(p,i,j,k)) ;} else divb = 0.;}
#define SETFDIVBFLUXCD(divb,U,i,j,k) {DIVBCONDITION(U,i,j,k){ divb = fabs(DIVBFLUXCD(U,i,j,k)) ;} else divb = 0.;}
#define SETFDIVBFLUXCDPRIM(divb,p,i,j,k) {DIVBCONDITION(p,i,j,k){ divb = fabs(DIVBFLUXCDPRIM(p,i,j,k)) ;} else divb = 0.;}
//#define SETFDIVB(divb,p,i,j,k) SETFDIVBFLUXCT(divb,p,i,j,k)