Magnets#
Common Interface#
All magnet types in PyMagba share a common interface for computing magnetic fields and geometric properties.
- property position: ArrayLike3
Position of the object [x, y, z] in meters.
- property orientation: scipy.spatial.transform.Rotation
Orientation as a scipy.spatial.transform.Rotation object.
- translate(translation)
Translate the object by a displacement vector.
- Parameters:
translation (ArrayLike3) – Displacement [dx, dy, dz] in meters.
- rotate(rot)
Rotate the object about its own origin.
- Parameters:
rot (Rotation | ArrayLike4) – Rotation to apply. Can be a scipy.spatial.transform.Rotation object or a unit quaternion as a list.
- rotate_anchor(rot, anchor)
Rotate the object about an arbitrary anchor point.
- Parameters:
rot (Rotation | ArrayLike4) – Rotation to apply.
anchor (ArrayLike3) – Anchor point [x, y, z] in meters about which to rotate.
- compute_B(points)
Compute the magnetic flux density B at a batch of observer points.
- Parameters:
points (numpy.ndarray) – Array of shape (N, 3) containing the observer positions [x, y, z] in meters.
- Returns:
Array of shape (N, 3) with the [Bx, By, Bz] field vectors in Tesla at each observer point.
- Return type:
numpy.ndarray
Available Magnets#
CylinderMagnet#
- class pymagba.magnets.CylinderMagnet(position=None, orientation=None, diameter=1.0, height=1.0, polarization=None)[source]#
Uniformly magnetized cylindrical magnet.
All dimensions are in SI units (meters, Tesla).
- Parameters:
position (
ArrayLike3, optional) – Center of the cylinder [x, y, z] in meters. Defaults to [0.0, 0.0, 0.0].orientation (
PyRotation, optional) – Orientation as a unit quaternion [x, y, z, w] or a scipy.spatial.transform.Rotation object. Defaults to identity.diameter (
float, optional) – Cylinder diameter in meters. Must be positive. Defaults to 1.0.height (
float, optional) – Cylinder height in meters. Must be positive. Defaults to 1.0.polarization (
ArrayLike3, optional) – Remanence polarization vector [Bx, By, Bz] in Tesla. Defaults to [0.0, 0.0, 0.0].
Examples
from pymagba.magnets import CylinderMagnet from scipy.spatial.transform import Rotation magnet = CylinderMagnet( position=[0.0, 0.0, 0.0], orientation=Rotation.from_euler('x', 90, degrees=True), diameter=0.01, height=0.02, polarization=[0.0, 0.0, 1.0], )
References
Caciagli, Alessio, et al. “Exact Expression for the Magnetic Field of a Finite Cylinder with Arbitrary Uniform Magnetization.” Journal of Magnetism and Magnetic Materials 456 (2018): 423-432. https://doi.org/10.1016/j.jmmm.2018.02.003
Derby, Norman, and Stanislaw Olbert. “Cylindrical Magnets and Ideal Solenoids.” American Journal of Physics 78, no. 3 (2010): 229-235. https://doi.org/10.1119/1.3256157
CuboidMagnet#
- class pymagba.magnets.CuboidMagnet(position=None, orientation=None, dimensions=None, polarization=None)[source]#
Uniformly magnetized cuboid magnet.
All dimensions are in SI units (meters, Tesla).
- Parameters:
position (
ArrayLike3, optional) – Center of the cuboid [x, y, z] in meters. Defaults to [0.0, 0.0, 0.0].orientation (
PyRotation, optional) – Orientation as a unit quaternion [x, y, z, w] or a scipy.spatial.transform.Rotation object. Defaults to identity.dimensions (
ArrayLike3, optional) – Side lengths [dx, dy, dz] in meters. Defaults to [1.0, 1.0, 1.0].polarization (
ArrayLike3, optional) – Remanence polarization vector [Bx, By, Bz] in Tesla. Defaults to [0.0, 0.0, 0.0].
Examples
from pymagba.magnets import CuboidMagnet from scipy.spatial.transform import Rotation magnet = CuboidMagnet( position=[0.0, 0.0, 0.0], orientation=Rotation.from_euler('z', 45, degrees=True), dimensions=[0.01, 0.01, 0.02], polarization=[0.0, 0.0, 1.0], )
References
Ortner, Michael, and Lucas Gabriel Coliado Bandeira. “Magpylib: A Free Python Package for Magnetic Field Computation.” SoftwareX 11 (2020): 100466. https://doi.org/10.1016/j.softx.2020.100466
Dipole#
- class pymagba.magnets.Dipole(position=None, orientation=None, moment=None)[source]#
Magnetic dipole source.
Models a point magnetic dipole - a useful approximation for small magnets at distances much greater than their physical size.
- Parameters:
position (
ArrayLike3, optional) – Position of the dipole [x, y, z] in meters. Defaults to [0.0, 0.0, 0.0].orientation (
PyRotation, optional) – Orientation as a unit quaternion [x, y, z, w] or a scipy.spatial.transform.Rotation object. Defaults to identity.moment (
ArrayLike3, optional) – Magnetic dipole moment vector [mx, my, mz] in A·m². Defaults to [0.0, 0.0, 0.0].
Examples
from pymagba.magnets import Dipole dipole = Dipole( position=[0.0, 0.0, 0.0], moment=[0.0, 0.0, 1.0], )
References
Ortner, Michael, and Lucas Gabriel Coliado Bandeira. “Magpylib: A Free Python Package for Magnetic Field Computation.” SoftwareX 11 (2020): 100466. https://doi.org/10.1016/j.softx.2020.100466
SourceCollection#
- class pymagba.magnets.SourceCollection(sources=None, position=None, orientation=None)[source]#
A group of magnetic sources that can be transformed and queried as a unit.
SourceCollection wraps a SourceAssembly from Magba, combining multiple magnetic sources (CylinderMagnet, CuboidMagnet, or Dipole) into a single object with its own pose. Transformations applied to the collection move all child sources relative to the collection’s reference frame.
- Parameters:
sources (
list[Source], optional) – Iterable of magnetic sources to include. Each element must be a CylinderMagnet, CuboidMagnet, or Dipole. Defaults to None.
Examples
from pymagba.magnets import CylinderMagnet, CuboidMagnet, Dipole, SourceCollection import numpy as np m1 = CylinderMagnet( position=[0.005, 0.0, 0.0], diameter=0.01, height=0.02, polarization=[0.0, 0.0, 1.0], ) m2 = CuboidMagnet( position=[-0.005, 0.0, 0.0], dimensions=[0.01, 0.01, 0.01], polarization=[0.0, 0.0, -1.0], ) collection = SourceCollection([m1, m2]) points = np.array([[0.0, 0.0, 0.05]]) B = collection.compute_B(points) # shape (1, 3) B = collection.compute_B(points) # shape (1, 3)