desc.magnetic_fields.field_line_integrate

class desc.magnetic_fields.field_line_integrate(r0, z0, phis, field, params=None, source_grid=None, rtol=1e-08, atol=1e-08, max_steps=None, min_step_size=1e-08, solver=Tsit5(), bounds_R=(0, inf), bounds_Z=(-inf, inf), use_precomputed_source=True, chunk_size=None, bs_chunk_size=None, options=None, return_aux=False)Source

Trace field lines by integration, using diffrax package.

Parameters:
  • r0 (array-like) – initial starting coordinates for r,z on phi=phis[0] plane

  • z0 (array-like) – initial starting coordinates for r,z on phi=phis[0] plane

  • phis (array-like) – geometric toroidal angle values to output r,z at. Can be strictly increasing or decreasing, but must be monotonic.

  • field (MagneticField) – source of magnetic field to integrate

  • params (dict, optional) – parameters passed to field

  • source_grid (Grid, optional) – Collocation points used to discretize source field.

  • rtol (float) – relative and absolute tolerances for PID stepsize controller. Not used if stepsize_controller is provided.

  • atol (float) – relative and absolute tolerances for PID stepsize controller. Not used if stepsize_controller is provided.

  • max_steps (int) – maximum number of steps for the integration. Defaults to abs((phis[-1] - phis[0]) * 1000)

  • min_step_size (float) – minimum step size (in phi) that the integration can take. default is 1e-8

  • solver (diffrax.Solver) – diffrax Solver object to use in integration, defaults to Tsit5(), a RK45 explicit solver

  • bounds_R (tuple of (float,float), optional) – R bounds for field line integration bounding box. Trajectories that leave this box will be stopped, and NaN returned for points outside the box. Defaults to (0, np.inf)

  • bounds_Z (tuple of (float,float), optional) – Z bounds for field line integration bounding box. Trajectories that leave this box will be stopped, and NaN returned for points outside the box. Defaults to (-np.inf, np.inf)

  • use_precomputed_source (bool, optional) – Precompute the Biot-Savart source data (positions, tangents and currents) once before the integration, so that each ODE step only evaluates the Biot-Savart kernel from the merged sources instead of recomputing the constant geometry information. This is usually much faster. Set to False to evaluate the field the standard way. Only used if underlying field implements the precomputation via _as_precomputed_source method. Default is True.

  • chunk_size (int or None) – Chunk of field lines to trace at once. If None, traces all at once. Defaults to None.

  • bs_chunk_size (int or None) – Chunk size to use when evaluating Biot-Savart for the magnetic field. If None, evaluates all the source grid points at once. Defaults to None.

  • options (dict, optional) – Additional arguments to pass to the diffrax diffeqsolve.

  • return_aux (bool, optional) – Whether to return auxiliary information from the integrator. If True, will return a tuple (r, z, aux) where aux consists stats and result from diffrax.diffeqsolve. Defaults to False.

Returns:

r, z (ndarray) – arrays of r and z coordinates of the field line, corresponding to the input phis