Basic functionality

Just compute the field

The most fundamental functionality of the library - compute the field (B in [mT], H in [kA/m]) of a source (here Cylinder magnet) at the observer position (1,2,3).

from magpylib.magnet import Cylinder

src = Cylinder(magnetization=(222, 333, 444), dimension=(2, 2))
B = src.getB((1, 2, 3))
print(B)
[2.52338575 6.12608223 9.49772059]

Field values of a path

In this example the field B in [mT] of the Cylinder magnet is evaluated for a moving observer, rotating 360° with 45° steps around the source along the z-axis and a radius of 5[mm].

from magpylib.magnet import Cylinder
from magpylib import Sensor

src = Cylinder(magnetization=(222, 333, 444), dimension=(2, 2))
sens = Sensor(position=(5, 0, 0)).rotate_from_angax(
    [45] * 8, "z", anchor=(0, 0, 0), start=0, increment=True
)
B = sens.getB(src)
print(B)
[[ 3.10333764 -0.31222382 -1.74482112]
 [ 2.63326931  0.88310231 -1.74482112]
 [ 0.62066753  1.56111908 -1.74482112]
 [-1.75551287  1.32465347 -1.74482112]
 [-3.10333764  0.31222382 -1.74482112]
 [-2.63326931 -0.88310231 -1.74482112]
 [-0.62066753 -1.56111908 -1.74482112]
 [ 1.75551287 -1.32465347 -1.74482112]]