Exemplo n.º 1
0
def test_vectorMagnetCylinder():

    MAG = np.array([[0, 0, -44], [0, 0, 55], [11, 22, 33], [-14, 25, 36],
                    [17, -28, 39], [-10, -21, 32], [0, 12, 23], [0, -14, 25],
                    [16, 0, 27], [-18, 0, 29]])
    POSM = np.ones([10, 3])
    POSO = MAG * 0.1 * np.array([.8, -1, -1.3]) + POSM
    DIM = np.ones([10, 2])

    Bv = getBv_magnet('cylinder', MAG, DIM, POSM, POSO)

    Bc = []
    for mag, posM, posO, dim in zip(MAG, POSM, POSO, DIM):
        pm = Cylinder(mag, dim, posM)
        Bc += [pm.getB(posO)]
    Bc = np.array(Bc)

    assert np.amax(abs(Bv - Bc)) < 1e-15

    # inside cylinder testing and iterDia

    MAG = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 1], [1, 0, 1],
                    [1, 1, 0], [1, 1, 1]])
    POSO = np.zeros([7, 3]) - .1
    DIM = np.ones([7, 2])
    POSM = np.zeros([7, 3])

    Bv = getBv_magnet('cylinder', MAG, DIM, POSM, POSO, Nphi0=11)

    Bc = []
    for mag, posM, posO, dim in zip(MAG, POSM, POSO, DIM):
        pm = Cylinder(mag, dim, posM, iterDia=11)
        Bc += [pm.getB(posO)]
    Bc = np.array(Bc)

    assert np.amax(abs(Bv - Bc)) < 1e-15
Exemplo n.º 2
0
for th in np.linspace(1,thMAX,30):
    
    # store fields here
    Bs = np.zeros([181,3])

    # create magnet for joystick in center position
    s = Cylinder(dim=[D,H],mag=[0,0,M0],pos=[0,0,H/2+gap])
    
    # set joystick tilt th
    s.rotate(th,[0,1,0],anchor=[0,0,gap+H+d])
    
    # rotate joystick for fixed tilt
    for i in range(181):
        
        # calculate field (sensor at [0,0,0]) and store in Bs
        Bs[i] = s.getB([0,0,0])
        
        # rotate magnet to next position
        s.rotate(2,[0,0,1],anchor=[0,0,0])

    # plot fields
    ax.plot(Bs[:,0],Bs[:,1],Bs[:,2],color=cm(th/15))

# annotate
ax.set(
       xlabel = 'Bx [mT]',
       ylabel = 'By [mT]',
       zlabel = 'Bz [mT]')

# display
plt.show()
Exemplo n.º 3
0
from magpylib.source.magnet import Box, Cylinder, Sphere

# Simuate a N38 5 * 5 *5 mm
#https://www.leeyed.com/rare_earth_magnet.html
s_Box = Box(mag=(0, 0, 1220), dim=(5, 5, 5), pos=(0, 0, -2.5))
s_Cylinder = Cylinder(mag=(0, 0, 1220),
                      dim=(5, 5),
                      pos=(0.0, 0.0, -2.5),
                      angle=0.0,
                      axis=(0.0, 0.0, 1.0),
                      iterDia=50)
s_Sphere = Sphere(mag=(0.0, 0.0, 1220),
                  dim=5.0,
                  pos=(0.0, 0.0, -2.5),
                  angle=0.0,
                  axis=(0.0, 0.0, 1.0))

print(s_Box.getB([0, 0, 5]))
print(s_Cylinder.getB([0, 0, 5]))
print(s_Sphere.getB([0, 0, 5]))
Exemplo n.º 4
0
# taken from https://magpylib.readthedocs.io/en/latest/_pages/2_guideExamples/

from magpylib.source.magnet import Cylinder

s = Cylinder( mag = [0,0,350], dim = [4,5])

print(s.getB([4,4,4]))