bluemira.equilibria.coils._field

Coil and coil grouping objects

Classes

CoilGroupFieldsMixin

CoilGroup magnetic fields mixin.

CoilSetFieldsMixin

CoilSet magnetic fields mixin.

CoilFieldsMixin

Coil magnetic fields mixin.

Module Contents

class bluemira.equilibria.coils._field.CoilGroupFieldsMixin(*, psi_analytic: bool = False, Bx_analytic: bool = True, Bz_analytic: bool = True)

CoilGroup magnetic fields mixin.

Add field calculation mechanics to coilgroups

Parameters:
  • psi_analytic (bool)

  • Bx_analytic (bool)

  • Bz_analytic (bool)

__slots__ = ('_Bx_analytic', '_Bz_analytic', '_einsum_str', '_psi_analytic', '_quad_dx', '_quad_dz',...
_psi_analytic = False
_Bx_analytic = True
_Bz_analytic = True
dB_d(x: float | numpy.ndarray, z: float | numpy.ndarray)

dB_d of Coilset

Parameters:
  • x (float | numpy.ndarray) – The x values at which to calculate the dB_d response

  • z (float | numpy.ndarray) – The z values at which to calculate the dB_d response

  • @je-cook (# TODO)

  • sum_coils (#)

  • coils (# sum over)

  • control (#)

  • only (# operations on control coils)

Returns:

Differential of magnetic field

dB_d_response(x: float | numpy.ndarray, z: float | numpy.ndarray)

Unit dB_d of Coilset

Parameters:
  • x (float | numpy.ndarray) – The x values at which to calculate the dB_d response

  • z (float | numpy.ndarray) – The z values at which to calculate the dB_d response

  • @je-cook (# TODO)

  • sum_coils (#)

  • coils (# sum over)

  • control (#)

  • only (# operations on control coils)

Returns:

Differential of magnetic field response

psi(x: float | numpy.ndarray, z: float | numpy.ndarray)

Calculate poloidal flux at (x, z)

Parameters:
  • x (float | numpy.ndarray)

  • z (float | numpy.ndarray)

psi_response(x, z)
Bx(x: float | numpy.ndarray, z: float | numpy.ndarray)

Calculate radial magnetic field Bx at (x, z)

Parameters:
  • x (float | numpy.ndarray)

  • z (float | numpy.ndarray)

Bx_response(x: float | numpy.ndarray, z: float | numpy.ndarray) float | numpy.ndarray

Calculate the radial magnetic field response at (x, z) due to a unit current. Green’s functions are used outside the coil, and a semianalytic method is used for the field inside the coil.

Parameters:
  • x (float | numpy.ndarray) – The x values at which to calculate the Bx response

  • z (float | numpy.ndarray) – The z values at which to calculate the Bx response

Returns:

The radial magnetic field response at the x, z coordinates.

Return type:

float | numpy.ndarray

Bz(x: float | numpy.ndarray, z: float | numpy.ndarray) float | numpy.ndarray

Calculate vertical magnetic field Bz at (x, z)

Parameters:
  • x (float | numpy.ndarray)

  • z (float | numpy.ndarray)

Return type:

float | numpy.ndarray

Bz_response(x: float | numpy.ndarray, z: float | numpy.ndarray) float | numpy.ndarray

Calculate the vertical magnetic field response at (x, z) due to a unit current. Green’s functions are used outside the coil, and a semianalytic method is used for the field inside the coil.

Parameters:
  • x (float | numpy.ndarray) – The x values at which to calculate the Bz response

  • z (float | numpy.ndarray) – The z values at which to calculate the Bz response

Returns:

The vertical magnetic field response at the x, z coordinates.

Return type:

float | numpy.ndarray

Bp(x: float | numpy.ndarray, z: float | numpy.ndarray)

Calculate poloidal magnetic field Bp at (x, z)

Notes

\[B_p = \sqrt{B_x^2 + B_z^2}\]

where B_x and B_z are the x and z components of the magnetic field.

Parameters:
  • x (float | numpy.ndarray)

  • z (float | numpy.ndarray)

F(eqcoil: bluemira.equilibria.coils._grouping.CoilGroup) numpy.ndarray

Calculate the force response at the coil centre including the coil self-force.

\[ \mathbf{F} = \mathbf{j}\times \mathbf{B} F_x = IB_z+\dfrac{\mu_0I^2}{4\pi X}\textrm{ln}\bigg(\dfrac{8X}{r_c}-1+\xi/2\bigg) F_z = -IBx\]
Returns:

The force response

Parameters:

eqcoil (bluemira.equilibria.coils._grouping.CoilGroup)

Return type:

numpy.ndarray

control_F(coil_grp: bluemira.equilibria.coils._grouping.CoilGroup) numpy.ndarray

Calculates the coil mutual force

\(Fz_{i,j}=-2\pi X_i\mathcal{G}(X_j,Z_j,X_i,Z_i)\)

Returns:

The Green’s matrix element for the coil mutual force.

Parameters:

coil_grp (bluemira.equilibria.coils._grouping.CoilGroup)

Return type:

numpy.ndarray

_stored_greens(green: float | numpy.ndarray)

Quickly calculate plasma psi, Bx or Bz from Greens functions and current

Parameters:

green (float | numpy.ndarray)

_mix_control_method(x: float | numpy.ndarray, z: float | numpy.ndarray, greens_func: collections.abc.Callable, semianalytic_func: collections.abc.Callable, *, disable_analytic: bool = False) float | numpy.ndarray

Boiler-plate helper function to mixed the Green’s function responses with the semi-analytic function responses, as a function of position outside/inside the coil boundary.

Parameters:
  • x (float | numpy.ndarray) – The x values at which to calculate the response at

  • z (float | numpy.ndarray) – The z values at which to calculate the response at

  • greens_func (collections.abc.Callable) – greens function

  • semianalytic_func (collections.abc.Callable) – semianalytic function

  • disable_analytic (bool)

Returns:

Mixed control response

Return type:

float | numpy.ndarray

_combined_control(inside: numpy.ndarray, x: float | numpy.ndarray, z: float | numpy.ndarray, greens_func: collections.abc.Callable, semianalytic_func: collections.abc.Callable) float | numpy.ndarray

Combine semianalytic and greens function calculation of [psi, Bx, Bz]

Used for situation where there are calculation points both inside and outside the coil boundaries.

Parameters:
  • inside (numpy.ndarray) – array of if the point is inside a coil

  • x (float | numpy.ndarray) – The x values at which to calculate the response at

  • z (float | numpy.ndarray) – The z values at which to calculate the response at

  • greens_func (collections.abc.Callable) – greens function

  • semianalytic_func (collections.abc.Callable) – semianalytic function

Returns:

Combined control response

Return type:

float | numpy.ndarray

_points_inside_coil(x: float | numpy.array, z: float | numpy.array, *, atol: float = X_TOLERANCE) numpy.ndarray

Determine which points lie inside or on the coil boundary.

Parameters:
  • x (float | numpy.array) – The x coordinates to check

  • z (float | numpy.array) – The z coordinates to check

  • atol (float) – Add an offset, to ensure points very near the edge are counted as being on the edge of a coil

Returns:

The Boolean array of point indices inside/outside the coil boundary

Return type:

numpy.ndarray

_response_greens(greens: collections.abc.Callable, x: numpy.ndarray, z: numpy.ndarray, *, split: bool = False, _quad_x: numpy.ndarray | None = None, _quad_z: numpy.ndarray | None = None, _quad_weight: numpy.ndarray | None = None) float | numpy.ndarray

Calculate [psi, Bx, Bz] response at (x, z) due to a unit current using Green’s functions.

Parameters:
  • greens (collections.abc.Callable) – greens function

  • x (numpy.ndarray) – The x values at which to calculate the response at

  • z (numpy.ndarray) – The z values at which to calculate the response at

  • split (bool) – Flag for if :meth:_combined_control is used

  • _quad_x (numpy.ndarray | None) – :meth:_combined_control x positions

  • _quad_z (numpy.ndarray | None) – :meth:_combined_control z positions

  • _quad_weight (numpy.ndarray | None) – :meth:_combined_control weighting

Returns:

Greens response

Return type:

float | numpy.ndarray

_response_analytical(semianalytic: collections.abc.Callable, x: numpy.ndarray, z: numpy.ndarray, *, split: bool = False, coil_x: numpy.ndarray | None = None, coil_z: numpy.ndarray | None = None, coil_dx: numpy.ndarray | None = None, coil_dz: numpy.ndarray | None = None) numpy.ndarray

Calculate [psi, Bx, Bz] response at (x, z) due to a unit current using semi-analytic method.

Parameters:
  • semianalytic (collections.abc.Callable) – semianalytic function

  • x (numpy.ndarray) – The x values at which to calculate the response at

  • z (numpy.ndarray) – The z values at which to calculate the response at

  • split (bool) – Flag for if :meth:_combined_control is used

  • coil_x (numpy.ndarray | None) – :meth:_combined_control x positions

  • coil_z (numpy.ndarray | None) – :meth:_combined_control z positions

  • coil_dx (numpy.ndarray | None) – :meth:_combined_control x positions

  • coil_dz (numpy.ndarray | None) – :meth:_combined_control z positions

Returns:

Analytical response

Return type:

numpy.ndarray

class bluemira.equilibria.coils._field.CoilSetFieldsMixin(*, psi_analytic: bool = False, Bx_analytic: bool = True, Bz_analytic: bool = True)

Bases: CoilGroupFieldsMixin

Inheritance diagram of bluemira.equilibria.coils._field.CoilSetFieldsMixin

CoilSet magnetic fields mixin.

Adjust output of coilgroup field calculations dealing with control coils or summing over coils

Parameters:
  • psi_analytic (bool)

  • Bx_analytic (bool)

  • Bz_analytic (bool)

__slots__ = ()
psi(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = True, control: bool = False) numpy.ndarray

Psi of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the psi response

  • z (numpy.ndarray) – The z values at which to calculate the psi response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Poloidal magnetic flux density

Return type:

numpy.ndarray

Bx(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = True, control: bool = False) numpy.ndarray

Bx of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the Bx response

  • z (numpy.ndarray) – The z values at which to calculate the Bx response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Radial magnetic field

Return type:

numpy.ndarray

Bz(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = True, control: bool = False) numpy.ndarray

Bz of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the Bz response

  • z (numpy.ndarray) – The z values at which to calculate the Bz response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Vertical magnetic field

Return type:

numpy.ndarray

dB_d(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = True, control: bool = False) numpy.ndarray

dB_d of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the dB_d response

  • z (numpy.ndarray) – The z values at which to calculate the dB_d response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Return type:

Differential of magnetic field

psi_response(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = False, control: bool = False) numpy.ndarray

Unit psi of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the psi response

  • z (numpy.ndarray) – The z values at which to calculate the psi response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Psi response

Return type:

numpy.ndarray

Bx_response(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = False, control: bool = False) numpy.ndarray

Unit Bx of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the Bx response

  • z (numpy.ndarray) – The z values at which to calculate the Bx response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Bx response

Return type:

numpy.ndarray

Bz_response(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = False, control: bool = False) numpy.ndarray

Unit Bz of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the Bz response

  • z (numpy.ndarray) – The z values at which to calculate the Bz response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Bz response

Return type:

numpy.ndarray

dB_d_response(x: numpy.ndarray, z: numpy.ndarray, *, sum_coils: bool = False, control: bool = False) numpy.ndarray

Unit dB_d of Coilset

Parameters:
  • x (numpy.ndarray) – The x values at which to calculate the dB_d response

  • z (numpy.ndarray) – The z values at which to calculate the dB_d response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Differential of magnetic field response

Return type:

numpy.ndarray

control_F(coil_grp: bluemira.equilibria.coils._grouping.CoilGroup, *, control: bool = False) numpy.ndarray

Calculate the coil mutual force

\(Fz_{i,j}=-2\pi X_i\mathcal{G}(X_j,Z_j,X_i,Z_i)\)

Parameters:
Returns:

the Green’s matrix element for the coil mutual force.

Return type:

numpy.ndarray

_stored_greens(bgreen: numpy.ndarray, *, sum_coils: bool = True, control: bool = False) numpy.ndarray

Uses the Greens mapped dict to quickly compute the Bx,Bz or psi

Parameters:
  • bgreen (numpy.ndarray) – The unit Bx response

  • sum_coils (bool) – sum over coils

  • control (bool) – operations on control coils only

Returns:

Cached Greens response

Return type:

numpy.ndarray

class bluemira.equilibria.coils._field.CoilFieldsMixin(*, psi_analytic: bool = False, Bx_analytic: bool = True, Bz_analytic: bool = True)

Bases: CoilGroupFieldsMixin

Inheritance diagram of bluemira.equilibria.coils._field.CoilFieldsMixin

Coil magnetic fields mixin.

Add field calculation mechanics to Coils

Parameters:
  • psi_analytic (bool)

  • Bx_analytic (bool)

  • Bz_analytic (bool)

__slots__ = ()
_points_inside_coil(x: float | numpy.array, z: float | numpy.array, *, atol: float = X_TOLERANCE) numpy.ndarray

Determine which points lie inside or on the coil boundary.

Parameters:
  • x (float | numpy.array) – The x values to check

  • z (float | numpy.array) – The z values to check

  • atol (float) – Add an offset, to ensure points very near the edge are counted as being on the edge of a coil

Returns:

The Boolean array of point indices inside/outside the coil boundary

Return type:

numpy.ndarray

_combined_control(inside: numpy.ndarray, x: numpy.ndarray, z: numpy.ndarray, greens_func: collections.abc.Callable, semianalytic_func: collections.abc.Callable)

Combine semianalytic and greens function calculation of magnetic field

Used for situation where there are calculation points both inside and outside the coil boundaries.

Parameters:
  • inside (numpy.ndarray) – array of if the point is inside a coil

  • x (numpy.ndarray) – The x values at which to calculate the response at

  • z (numpy.ndarray) – The z values at which to calculate the response at

  • greens_func (collections.abc.Callable) – greens function

  • semianalytic_func (collections.abc.Callable) – semianalytic function

Returns:

Combined response

_response_analytical(semianalytic: collections.abc.Callable, x: numpy.ndarray, z: numpy.ndarray, *_args, **_kwargs) numpy.ndarray

Calculate [psi, Bx, Bz] response at (x, z) due to a unit current using semi-analytic method.

Parameters:
  • semianalytic (collections.abc.Callable) – semianalytic function

  • x (numpy.ndarray) – The x values at which to calculate the response at

  • z (numpy.ndarray) – The z values at which to calculate the response at

Returns:

Analytical response

Return type:

numpy.ndarray