What is Magpylib ?

What is Magpylib ?

  • Python package for calculating 3D static magnetic fields of magnets, currents and other sources.

  • The fields are computed using analytical solutions (very fast computations, simple geometries and superpositions thereof).

  • The field computation is coupled to a geometry interface (position, orientation, paths) which makes it convenient to model relative positioning between sources and observers.

source fundamentals

Quickstart

Install Magpylib with pip or conda:

pip install magpylib

or

conda install magpylib

This Example code calculates the magnetic field of a cylindrical magnet.

import magpylib as magpy
s = magpy.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.

Library Docstrings: