-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Magpylib version
4.x (Latest)
What happened?
Issue :
When computing the magnetic B field right in the centre of a Halbach octupole that has been spatially rotated, the result blows up.
The expected magnetics field should be zero though.
Code example :
The octupole is made of 32 individual CylinderSegment
, distributed circularly.
The following code example build such octupole, with z as the axis of symmetry.
The B field vector is then computed for values distributed along the z axis. The result is close to zero, as expected.
However, rotating the same octupole around the y axis, then computing the B field vector for values distributed along the x axis (the new axis of symmetry), and the B field amplitude blows up to unphysical values.
Precisions and tests :
-
Using the
magpy
routinerotate_from_angax
or thescipyspatial.transform.Rotation
routinefrom_rotvec
provide similar results -
Strangely, playing with the radii, height, or magnetization of the disc segments doesn't change the position at which the B field explodes. It is always located around 50mm before or after the centre of the octupole, along the axis of symetry.
-
The issue only appears when computing the magnetic field on the symmetry axis. Outside, the results between both orientations are similar.
Code example
import magpylib as magpy
import numpy as np
from scipy.spatial.transform import Rotation as R
from matplotlib import pyplot as plt
def buildOctupole():
N = 32 # number of Segments
phi = 360/N # angle between semgents
r1 = 1
r2 = 2
z = 1 # heigh of segment
M = 1 # Magnetization
octupole = magpy.Collection()
for deg in np.arange(0, 360, phi):
rad = np.deg2rad(deg)
magnetization = (M*np.cos(5*rad), M*np.sin(5*rad), 0)
dimension = (r1, r2, z, deg-phi/2, deg+phi/2)
position = (0, 0, 0)
orientation = None # R.from_rotvec((0, 90, 0), degrees=True)
color = 'rgb(%i, %i, %i)' % tuple(np.random.randint(0, 255, 3))
segment = magpy.magnet.CylinderSegment(magnetization, dimension, position, orientation=orientation, style={'color':color})
octupole.add(segment)
return octupole
octupole = buildOctupole()
zline = np.zeros((100, 3))
zline[:, 2] = np.linspace(-100, 100, zline.shape[0])
B_zline = octupole.getB(zline)
xline = np.zeros((100, 3))
xline[:, 0] = np.linspace(-100, 100, xline.shape[0])
B_xline = octupole.rotate_from_angax(90, axis='y',anchor=0).getB(xline)
octupole.show()
plt.plot(zline[:, 2], np.abs(B_zline), label=("|Bx| z axis", "|By| z axis", "|Bz| z axis"))
plt.plot(xline[:, 0], np.abs(B_xline), label=("|Bx| x axis", "|By| x axis", "|Bz| x axis"), ls="--")
plt.yscale("log")
plt.ylabel("log(|B|)")
plt.xlabel("x | z")
plt.legend()
plt.show()
Additional context
- Ubuntu 22,
- python 3.10.6
- magpy 4.2.0
- numpy 1.24.2
- scipy 1.8.1