torus_solver.fieldline

torus_solver.fieldline.trace_field_line(B_fn, r0, *, step_size, n_steps, normalize=True, eps=1e-12)[source]

Trace a single magnetic field line using fixed-step RK4.

The integration variable is an arbitrary “time” parameter. If normalize=True, we trace the unit vector b = B / norm(B) so the step size is roughly a spatial arc length (in meters if coordinates are meters).

B_fn must accept points of shape (…,3) and return B of shape (…,3).

Return type:

Array

Parameters:
  • B_fn (Callable[[Array], Array])

  • r0 (Array)

  • step_size (float)

  • n_steps (int)

  • normalize (bool)

  • eps (float)

torus_solver.fieldline.trace_field_lines(B_fn, r0, *, step_size, n_steps, normalize=True, eps=1e-12)[source]

Vectorized field-line tracing for a batch of initial points (N,3).

Return type:

Array

Parameters:
  • B_fn (Callable[[Array], Array])

  • r0 (Array)

  • step_size (float)

  • n_steps (int)

  • normalize (bool)

  • eps (float)

torus_solver.fieldline.trace_field_lines_batch(B_fn, r0, *, step_size, n_steps, normalize=True, eps=1e-12)[source]

Trace multiple field lines in one lax.scan (faster than vmap-of-scan).

r0 has shape (N,3). B_fn must accept (N,3) and return (N,3).

Returns an array of shape (n_steps+1, N, 3).

Return type:

Array

Parameters:
  • B_fn (Callable[[Array], Array])

  • r0 (Array)

  • step_size (float)

  • n_steps (int)

  • normalize (bool)

  • eps (float)