Submodule: mfs.sources

Magnetic field sources

Overview

Single magnets

mfs.sources.CircularCoil(strength, rDash, …)

A representation of a single circular EM coil.

mfs.sources.RectangularCoil(strength, rDash, …)

A representation of a single rectangular EM coil.

mfs.sources.PermanentMagnet(strength, rDash, …)

A representation of a rectangular permanent magnet.

Combined magnets

mfs.sources.CoilPair(I, rDash, dimsDash, …)

A generic pair of coils.

Base magnet class

mfs.sources.Magnet(rDash, dimsDash[, theta, phi])

A representation of a generic magnetic field source (e.g.

Detailed Documentation

This file implements magnetic field calculations arising from several possible magnetic sources. You can create a combination of permanent magnets, straight wires and circular or rectangular coils (in either Helmholtz or Anti-helmholtz configuration).

Each magnet is created in its own co-ordinate frame, r’=(x’, y’, z’), which is rotated from the laboratory frame by two angles, theta (rotation around Z) and phi (rotation around X).

Functions are provided for visualising the position of each magnet in various projections.

class mfs.sources.CircularCoil(strength, rDash, dimsDash, theta, phi=0)

A representation of a single circular EM coil. The coil is defined as having its origin at rDash=(x’,y’,z’) and its axis along the yDash axis. A positive current flowing results in a field which, at the coil origin, points along the positive yDash direction.

This class mmodels a single loop of wire. For an approximation of multiple loops, increase the current. For an accurate simulation of a spatially distributed buncdle of wires, there exists a shortcut in the CoilPair class, but no shortcut for a spatially distributed single coil

Parameters
I: float

Current flowing through coil

rDash: 3 element list or array

Position of origin of coil

dimsDash: dict

Dictionary of parameters. Required parameters for a circular coil are

  • radius: float

Attributes
phi

return phi in radians

phi_deg

return phi in degrees

theta

return Theta in radians

theta_deg

Return Theta in degrees

Methods

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

get_B_field(r)

Calculate the vector B field at a given position r in the lab frame B(r) = B(x, y, z)

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

rotate_to_dashed_frame(r)

Angular rotation from the lab frame to the Dashed co-ordinate frame

rotate_to_normal_frame(rDash)

Angular rotation from the Dashed co-ordinate frame to the lab frame

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

Parameters
rDash: np.ndarray

A vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

Returns
np.ndarray

The vector B field at position rDash in the Dashed co-ordinate frame

class mfs.sources.CoilPair(I, rDash, dimsDash, theta, phi)

A generic pair of coils. They can both be circular or rectangular, and either Helmholtz or Anti-Helmholtz.

Parameters
I: float

Current flowing through coils

rDash: 3 entry list or array

Origin of coils in Dash co-ordinate frame

dimsDash: dict

Dictionary of coil pair parameters.

  • full spacing: float

    full spacing between closest coils along yDash axis

  • spatially distributed: bool

    Should the programme calculate for each loop independently, or approximate by placing all coils in the same place?

  • axial layers: int

    number of new layers further out along the yDash axis

  • axial spacing: float

    distance between centres of layers in the axial direction

  • radial layers: int

    number of new layers further out away from yDash axis

  • radial spacing: float

    distance between centres of layers in the radial direction

  • configuration: str

    Valid entries are ahh, hh and some variations

  • shape: str

    Valid entries are variations on circ, circular, rectangular, r, etc

  • Required parameters for either RectangularCoil or CircularCoil (see the documentaiton for those classes)

theta: float

Rotation of Dash frame around Z axis

phi: float

Rotation of Dash frame around X axis

Attributes
phi

return phi in radians

phi_deg

return phi in degrees

theta

return Theta in radians

theta_deg

Return Theta in degrees

Methods

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

get_B_field(r)

Calculate the vector B field at a given position r in the lab frame B(r) = B(x, y, z)

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

rotate_to_dashed_frame(r)

Angular rotation from the lab frame to the Dashed co-ordinate frame

rotate_to_normal_frame(rDash)

Angular rotation from the Dashed co-ordinate frame to the lab frame

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

Parameters
rDash: np.ndarray

A vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

Returns
np.ndarray

The vector B field at position rDash in the Dashed co-ordinate frame

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

If the axes are 2D, it will only plot the outline of the magnet as projected by the projection keyword. For example, a coil in the XY plane will appear to be a line with the projection xy

If the axes are 3d, then all 3 dimensions will be plotted.

Parameters
axes: matplotlib.axes._subplots.AxesSubplot
The pyplot axis on which the outline will be drawn. Can be produced by, e.g.

fig, axes = plt.subplots()

projection: str

The projection of the global frame onto the axes, in the form of a string such as xyz. Maps the global frame dimension at position i in the string onto the axis dimension i. For example, projection="zxy" will project

  • global dimension z onto axes dimension x

  • global dimension x onto axes dimension y

  • global dimension y onto axes projection z

class mfs.sources.Magnet(rDash, dimsDash, theta=0, phi=0)

A representation of a generic magnetic field source (e.g. permanent magnet, solenoid etc). The magnet is defined in its own co-ordinate axis r'=(x',y',z'), rotated with respect to the lab frame by theta and phi.

The angular convention used here is as follows

  • Theta is the azimuthal angle

  • Phi is the polar angle

This means that

  • If Phi=0°, values of Theta correspond to a rotation of the XY plane around the Z axis.

  • At Theta=90°, Phi=0°, the positive xDash axis is aligned along the positive Y axis

  • If Theta=0°, values of Phi correspond to a rotation of the YZ plane around the X axis

  • At Theta=0°, Phi=90°, the positive zDash axis is aligned along the positive Y axis

Specific kinds of magnets extend this class to calculate the exact form of the magnetic field arising.

Attributes
phi

return phi in radians

phi_deg

return phi in degrees

theta

return Theta in radians

theta_deg

Return Theta in degrees

Methods

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

get_B_field(r)

Calculate the vector B field at a given position r in the lab frame B(r) = B(x, y, z)

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

rotate_to_dashed_frame(r)

Angular rotation from the lab frame to the Dashed co-ordinate frame

rotate_to_normal_frame(rDash)

Angular rotation from the Dashed co-ordinate frame to the lab frame

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

Parameters
rDash: np.ndarray

A vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

Returns
np.ndarray

The vector B field at position rDash in the Dashed co-ordinate frame

get_B_field(r)

Calculate the vector B field at a given position r in the lab frame B(r) = B(x, y, z)

Parameters
r: np.ndarray

A vector in the lab frame: r = (x, y, z)

Returns
np.ndarray

The vector B field at position r in the laboratory frame

property phi

return phi in radians

property phi_deg

return phi in degrees

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

If the axes are 2D, it will only plot the outline of the magnet as projected by the projection keyword. For example, a coil in the XY plane will appear to be a line with the projection xy

If the axes are 3d, then all 3 dimensions will be plotted.

Parameters
axes: matplotlib.axes._subplots.AxesSubplot
The pyplot axis on which the outline will be drawn. Can be produced by, e.g.

fig, axes = plt.subplots()

projection: str

The projection of the global frame onto the axes, in the form of a string such as xyz. Maps the global frame dimension at position i in the string onto the axis dimension i. For example, projection="zxy" will project

  • global dimension z onto axes dimension x

  • global dimension x onto axes dimension y

  • global dimension y onto axes projection z

rotate_to_dashed_frame(r)

Angular rotation from the lab frame to the Dashed co-ordinate frame

Parameters
r: np.ndarray

A vector in the lab frame: r = (x, y, z)

Returns
np.ndarray

The vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

rotate_to_normal_frame(rDash)

Angular rotation from the Dashed co-ordinate frame to the lab frame

Parameters
r: np.ndarray

A vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

Returns
np.ndarray

The vector in the lab frame: r = (x, y, z)

property theta

return Theta in radians

property theta_deg

Return Theta in degrees

class mfs.sources.PermanentMagnet(strength, rDash, dimsDash, theta, phi=0)

A representation of a rectangular permanent magnet. The magnet is defined in its own co-ordinate system, (x', y', z'), with the centre of the magnet at rDash and magnetisation M aligned parallel to the y’ axis.

dimsDash is a dictionary containing the keys axDash, ayDash, azDash. These are the FULL lengths of the magnet in the x’d, y’, z’ directions

Parameters
strength: float

The magnetisation of the magnet, in Tesla per metre

rDash: list

The origin of the magnet in the Dashed co-ordinate frame

dimsDash: dict

Dictionary of parameters. The required parameters for a permanent magnet are

  • axDash

  • ayDash

  • azDash

All three parameters are the FULL lengths of the magnet, in the x’, y’, z’ frame, in metres

theta: float

Rotation of the xDash-yDash axis around the Z axis in degrees

phi: float

Rotation of the yDash-zDash axis around the X axis in degrees

References

https://link.springer.com/content/pdf/10.1007%2FBF01573988.pdf

This function implements the approach taken by Metzger in Archiv fur Elektrotechnik 59 (1977) 229-242, with one change - selecting yDash as the axis of magnetisation

Attributes
phi

return phi in radians

phi_deg

return phi in degrees

theta

return Theta in radians

theta_deg

Return Theta in degrees

Methods

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

get_B_field(r)

Calculate the vector B field at a given position r in the lab frame B(r) = B(x, y, z)

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

rotate_to_dashed_frame(r)

Angular rotation from the lab frame to the Dashed co-ordinate frame

rotate_to_normal_frame(rDash)

Angular rotation from the Dashed co-ordinate frame to the lab frame

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

Parameters
rDash: np.ndarray

A vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

Returns
np.ndarray

The vector B field at position rDash in the Dashed co-ordinate frame

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

If the axes are 2D, it will only plot the outline of the magnet as projected by the projection keyword. For example, a coil in the XY plane will appear to be a line with the projection xy

If the axes are 3d, then all 3 dimensions will be plotted.

Parameters
axes: matplotlib.axes._subplots.AxesSubplot
The pyplot axis on which the outline will be drawn. Can be produced by, e.g.

fig, axes = plt.subplots()

projection: str

The projection of the global frame onto the axes, in the form of a string such as xyz. Maps the global frame dimension at position i in the string onto the axis dimension i. For example, projection="zxy" will project

  • global dimension z onto axes dimension x

  • global dimension x onto axes dimension y

  • global dimension y onto axes projection z

class mfs.sources.RectangularCoil(strength, rDash, dimsDash, theta, phi)

A representation of a single rectangular EM coil. The coil is defined as having its origin at rDash=(x’,y’,z’) and its axis along the yDash axis. A positive current flowing results in a field which, at the coil origin, points along the positive yDash direction.

Parameters
strength: float

Current flowing through coil

rDash: 3 element list or array

Position of origin of coil in the coil frame

dimsDash: dict

Dictionary of parameters. Required parameters for a rectangular coil are

  • axDash: float Full length of coil along xDash axis

  • azDash: float Full length of coil along zDash axis

References

https://dx.doi.org/10.6028%2Fjres.105.045

Equations for the Magnetic Field produced by One or More Rectangular Loops of Wire in the Same Plane (Misiakin)

J Res Natl Inst Stand Technol. 2000 Jul-Aug; 105(4): 557–564

Two slight changes from the paper

  • consistent with the other sources in this file, to choose yDash as the principle axis, and not Z

  • Due to Python zero-indexing arrays, the use of (-1)**alpha changes slightly

Attributes
phi

return phi in radians

phi_deg

return phi in degrees

theta

return Theta in radians

theta_deg

Return Theta in degrees

Methods

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

get_B_field(r)

Calculate the vector B field at a given position r in the lab frame B(r) = B(x, y, z)

plot_magnet_position(axes, projection)

Plot the outline of the magnet on the provided axes

rotate_to_dashed_frame(r)

Angular rotation from the lab frame to the Dashed co-ordinate frame

rotate_to_normal_frame(rDash)

Angular rotation from the Dashed co-ordinate frame to the lab frame

get_BDash_field(rDash)

Calculate the vector B field at a given position rDash in the Dashed frame B(rDash) = B(xDash, yDash, zDash)

Parameters
rDash: np.ndarray

A vector in the Dashed co-ordinate frame: rDash = (xDash, yDash, zDash)

Returns
np.ndarray

The vector B field at position rDash in the Dashed co-ordinate frame