Skip to content

Commit 6cab954

Browse files
committed
Add check that flux is conserved
1 parent 68ffe3c commit 6cab954

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

zoidberg/zoidberg.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def get_metric(grid, magnetic_field):
237237
metric["g_yy"][:, yindex, :] *= (Bmag[:, yindex, :] / By) ** 2
238238
metric["gyy"][:, yindex, :] *= (By / Bmag[:, yindex, :]) ** 2
239239

240-
return metric, Bmag, pressure
240+
# B * J / sqrt(g22)
241+
BJg = Bmag * np.sqrt(metric["g_xx"] * metric["g_zz"] - metric["g_xz"] ** 2)
242+
243+
return metric, Bmag, pressure, BJg
241244

242245

243246
class MapWriter:
@@ -273,6 +276,7 @@ def __init__(
273276
self.is_open = False
274277
self.create = create
275278

279+
self.BJg = None
276280
self.grid = None
277281
self.field = None
278282
self.metric_done = False
@@ -373,7 +377,7 @@ def _write_metric(self):
373377
if self.metric_done:
374378
return
375379

376-
metric, Bmag, pressure = get_metric(self.grid, self.field)
380+
metric, Bmag, pressure, self.BJg = get_metric(self.grid, self.field)
377381

378382
# Add Rxy, Bxy
379383
metric["Bxy"] = Bmag
@@ -450,7 +454,17 @@ def _write_par_metric(self, maps, nslice, ypar):
450454
yperiodic=yperiodic,
451455
)
452456

453-
par_metric, _, _ = get_metric(par_grid, self.field)
457+
par_metric, _, _, par_BJg = get_metric(par_grid, self.field)
458+
459+
if self.BJg is not None and self.BJg.shape[0] > 4:
460+
mymax = np.max(np.abs(par_BJg / self.BJg - 1)[2:-2], axis=(0, 2))
461+
if np.max(mymax) > 1e-6:
462+
print(
463+
"FluxError",
464+
np.max(np.abs(par_BJg / self.BJg - 1)[2:-2], axis=(0, 2)),
465+
)
466+
ysel = np.argmax(mymax)
467+
454468
if not self.new_names:
455469
par_metric = update_metric_names(par_metric)
456470

0 commit comments

Comments
 (0)