kharma icon indicating copy to clipboard operation
kharma copied to clipboard

KHARMA does not initialize B in all ghost faces correctly

Open bprather opened this issue 1 year ago • 0 comments

When computing magnetic field from the vector potential, KHARMA misses the last (4th) ghost zone/face. From a single-block 2D Bondi problem with vertical field, values on face 1:

>>> f['cons.fB'][0, 0, 0, 20, :]
array([0.04219514, 0.04219514, 0.04219514, 0.04219514, 0.04219514,
       ...
       1.74109976, 1.82962478, 0.        ])

The last face should have a value, and is being either computed incorrectly or fails to be output. Interestingly, the trivial index increase one might think would solve this does not -- perhaps because A is not initialized correctly on the last edge, even when the indexes would indicate it should.

Also interesting, though not surprising, is a corruption in the last X2 face in the radial direction:

>>> f['cons.fB'][0, 1, 0, 20, :]
array([-0.07287638, -0.07287638, -0.07287638, -0.07287638, -0.07287638,
       ...
       -1.53135878, 33.94290305,  0.        ])

This time the last value should be zero, as there is no N+1 X2 face as there is an X1 face. However, the last true face is corrupted, with a clearly incorrect value compared to the face just interior.

Since there seems to be no harm in the index changes I've made, and they seem to be prerequisites to solve this, I'll open a PR to stable. But I think the easiest way to do a true accounting here is to make the vector potential A a true edge-centered field, and get the indices directly from the relevant locations and domains, rather than by adding 1 here and there & hoping as we do now.

@hyerincho first reported this & might have a better idea how to fix it in dev. Otherwise I'll put it off to test when we move A to being a field, which will enable synchronization & easier indices and would replace any current solution, anyway.

bprather avatar Feb 09 '24 18:02 bprather