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
示例#2
0
d = 5           #distance magnet to center of tilt
thMAX = 15      #maximal joystick tilt angle

# define figure
fig = plt.figure(figsize=(7,6))
ax = plt.axes(projection='3d')
cm = plt.get_cmap("jet") #colormap

# set tilt angle
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))
示例#3
0
# sample definition

demagnetizing_factor = 1/3             # sphere
volume = 4 / 3 * pi * (4 / 1000) ** 3  # V sphere r=4mm [m3]
M_saturation = 1.400e6                 # Ms Co room temperature [A/m]

sample = {'demagnetizing_factor': demagnetizing_factor,
          'volume': volume,
          'M_saturation': M_saturation}


# magnet collection definition

m1 = Cylinder(mag=[0, 0, 1300],  # 1300mT of magnetization along z axis
              dim=[10, 20],      # 10mm diameter, 20mm height
              pos=[0, 0, -20])   # center is at z = -20mm

m2 = Cylinder(mag=[0, 0, 1300],  # 1300mT of magnetization along z axis
              dim=[10, 20],      # 10mm diameter, 20mm height
              pos=[0, 0, 20])    # center is at z = 20mm

both = Collection(m1, m2)        # arrangement with both magnets


# magnet collection visualisation

displaySystem(both, suppress=True)


# 3D plot of B and F in a 3D space
示例#4
0
# taken from https://magpylib.readthedocs.io/en/latest/_pages/2_guideExamples/

import numpy as np
import matplotlib.pyplot as plt
from magpylib.source.magnet import Cylinder
import magpylib as magpy

# create collection of two magnets
s1 = Cylinder(mag=[0,0,1000], dim=[5,5])
s2 = Cylinder(mag=[0,0,-1000], dim=[2,6])
c = magpy.Collection(s1,s2)

# create positions
xs = np.linspace(-8,8,100)
zs = np.linspace(-6,6,100)
posis = [[x,0,z] for z in zs for x in xs]

# calculate field and amplitude
B = [c.getB(pos) for pos in posis]
Bs = np.array(B).reshape([100,100,3]) #reshape
Bamp = np.linalg.norm(Bs,axis=2)

# define figure with a 2d and a 3d axis
fig = plt.figure(figsize=(8,4))
ax1 = fig.add_subplot(121,projection='3d')
ax2 = fig.add_subplot(122)

# add displaySystem on ax1
magpy.displaySystem(c,subplotAx=ax1,suppress=True)
ax1.view_init(elev=75)
示例#5
0
import numpy as np
import math
import matplotlib.pyplot as plt
from magpylib.source.magnet import Cylinder
from magpylib.source.current import Circular
from magpylib import Collection 

TURNS = 15
s = 91
LENGTH = 3
CURRENT = 1

# create magnets
s2 = Cylinder(mag=(0,0,500), dim=(3,5))
coil1 = [Circular(curr=CURRENT,dim=LENGTH,pos=[0,0,z]) for z in np.linspace(-3,3,TURNS)]

# create collection 
c1 = Collection(coil1)

xs = np.linspace(0, 0,6)
ys = np.linspace(0, 0,6)
zs = np.linspace(-9, 9, s)
F_POS = np.array([(x,y,z) for x in xs for y in ys for z in zs])

B = c1.getB(F_POS)[:s]
mags = [ math.sqrt(sum(i**2 for i in x)) for x in B ]
z_pos = [d for d in zs]
derivative = np.diff(mags)/np.diff(zs)
print(mags)

示例#6
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]))
示例#7
0
# taken from https://magpylib.readthedocs.io/en/latest/_pages/2_guideExamples/

import numpy as np
import matplotlib.pyplot as plt
from magpylib.source.magnet import Box, Cylinder
from magpylib import Collection, displaySystem

# create magnets
s1 = Box(mag=(0, 0, 600), dim=(3, 3, 3), pos=(-4, 0, 3))
s2 = Cylinder(mag=(0, 0, 500), dim=(3, 5))

# create collection
c = Collection(s1, s2)

# manipulate magnets individually
s1.rotate(45, (0, 1, 0), anchor=(0, 0, 0))
s2.move((5, 0, -4))

# manipulate collection
c.move((-2, 0, 0))

# calculate B-field on a grid
xs = np.linspace(-10, 10, 33)
zs = np.linspace(-10, 10, 44)
POS = np.array([(x, 0, z) for z in zs for x in xs])
Bs = c.getB(POS).reshape(44, 33, 3)  #<--VECTORIZED

# create figure
fig = plt.figure(figsize=(9, 5))
ax1 = fig.add_subplot(121, projection='3d')  # 3D-axis
ax2 = fig.add_subplot(122)  # 2D-axis
示例#8
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]))
示例#9
0
from magpylib.source.magnet import Cylinder
import matplotlib.pyplot as plt
import numpy as np
import magpylib.math as math

#system parameters
D, H = 5, 4  #magnet dimension
M0 = 1200  #magnet magnetization amplitude
gap = 3  #airgap
d = 5  #distance magnet to center of tilt
thMAX = 15  #maximal joystick tilt angle

#create magnet
s = Cylinder(dim=[D, H], mag=[0, 0, M0])

#initial central magnet position
p0 = [0, 0, H / 2 + gap]

#generate rotation axes
axes = [[np.cos(phi), np.sin(phi), 0]
        for phi in np.linspace(0, 2 * np.pi, 180)]

#generate a type2 INPUT
INPUT = []
for th in np.linspace(1, thMAX, 30):

    #rotation of the magnet position outwards
    posis = [
        math.rotatePosition(p0, th, ax, anchor=[0, 0, gap + H + d])
        for ax in axes
    ]