What is Magpylib ?¶
- Python package for calculating 3D static magnetic fields of magnets (e.g. Cuboids, Cylinders, Spheres, …), line currents (e.g. straight or loops) and other sources (e.g. Dipoles).
- The fields are computed using analytical solutions which makes the computation very fast (fully vectorized)
- The field computation is coupled to a geometry interface (position, orientation, paths) which makes it convenient to determine relative motion between sources and observers.
When can you use Magpylib ?¶
The analytical solutions are exact when there is no material response. In permanent magnets, when (remanent) permeabilities are below the error is typically below 1% (long magnet shapes are better, large distance from magnet is better). For more details check out the physics section.
Magpylib is at its best when dealing with air-coils (no eddy currents) and high grade permanent magnet assemblies (Ferrite, NdFeB, SmCo or similar materials).
Quickstart¶
Install Magpylib with pip or conda:
> pip install magpylib
.
> conda install magpylib
.
This Example code calculates the magnetic field of a cylindrical magnet.
import magpylib as mag3
s = mag3.magnet.Cylinder(magnetization=(0,0,350), dimension=(4,5))
observer_pos = (4,4,4)
print(s.getB(observer_pos))
# Output: [ 5.08641867 5.08641867 -0.60532983]
A cylinder shaped permanent magnet with diameter and height of 4 and 5 millimeter, respectively, is created in a global coordinate system with cylinder axis parallel to the z-axis and geometric magnet center in the origin. The magnetization is homogeneous and points in z-direction with an amplitude of 350 millitesla. The magnetic field is calculated in units of millitesla at the observer position (4,4,4) in units of millimeter.