Submodule: mfs.sources¶
Magnetic field sources
Overview¶
Single magnets
|
A representation of a single circular EM coil. |
|
A representation of a single rectangular EM coil. |
|
A representation of a rectangular permanent magnet. |
Combined magnets
|
A generic pair of coils. |
Base magnet class
|
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
phireturn phi in radians
phi_degreturn phi in degrees
thetareturn Theta in radians
theta_degReturn 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
rDashin 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: floatfull spacing between closest coils along yDash axis
spatially distributed: boolShould the programme calculate for each loop independently, or approximate by placing all coils in the same place?
axial layers: intnumber of new layers further out along the yDash axis
axial spacing: floatdistance between centres of layers in the axial direction
radial layers: intnumber of new layers further out away from yDash axis
radial spacing: floatdistance between centres of layers in the radial direction
configuration: strValid entries are
ahh,hhand some variations
shape: strValid entries are variations on
circ,circular,rectangular,r, etc
Required parameters for either
RectangularCoilorCircularCoil(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
phireturn phi in radians
phi_degreturn phi in degrees
thetareturn Theta in radians
theta_degReturn 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
rDashin 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 positioniin the string onto the axis dimensioni. For example,projection="zxy"will projectglobal 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
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
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
rDashin 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
rin 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 positioniin the string onto the axis dimensioni. For example,projection="zxy"will projectglobal 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
axDashayDashazDash
All three parameters are the FULL lengths of the magnet, in the x’, y’, z’ frame, in metres
- theta: float
Rotation of the
xDash-yDashaxis around the Z axis in degrees- phi: float
Rotation of the
yDash-zDashaxis 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
yDashas the axis of magnetisation- Attributes
phireturn phi in radians
phi_degreturn phi in degrees
thetareturn Theta in radians
theta_degReturn 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
rDashin 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 positioniin the string onto the axis dimensioni. For example,projection="zxy"will projectglobal 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 alongxDashaxisazDash: float Full length of coil alongzDashaxis
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
yDashas the principle axis, and notZDue to Python zero-indexing arrays, the use of
(-1)**alphachanges slightly
- Attributes
phireturn phi in radians
phi_degreturn phi in degrees
thetareturn Theta in radians
theta_degReturn 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
rDashin the Dashed co-ordinate frame