Preview:
def div_clean(grid, B, tolerance):
  # Compute the divergence of the magnetic field
  divB = compute_divergence(B)

  # Identify points where the divergence exceeds the tolerance
  error_points = [i for i in range(len(grid)) if abs(divB[i]) > tolerance]

  # Adjust the magnetic field at these points using the Powell-Eyink scheme
  for i in error_points:
    B[i] = powell_eyink(B[i], divB[i])
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter