예제 #1
0
mag_field_y = 0
mag_field_z = 0

pos_x = (dis + mag_size_x/2*2)/2
pos_z = - mag_size_z/2

# create magnets
sL = Box(mag=(mag_field_x,mag_field_y,mag_field_z), dim=(mag_size_x,mag_size_y,mag_size_z), pos=(-pos_x,0,pos_z))
sL_1 = Box(mag=(mag_field_x,mag_field_y,mag_field_z), dim=(mag_size_x,mag_size_y,mag_size_z), pos=(-pos_x,0,pos_z))
sL_2 = Box(mag=(mag_field_x,mag_field_y,mag_field_z), dim=(mag_size_x,mag_size_y,mag_size_z), pos=(-pos_x,0,pos_z))
sR = Box(mag=(mag_field_x,mag_field_y,mag_field_z), dim=(mag_size_x,mag_size_y,mag_size_z), pos=(pos_x,0,pos_z))
sR_1 = Box(mag=(mag_field_x,mag_field_y,mag_field_z), dim=(mag_size_x,mag_size_y,mag_size_z), pos=(pos_x,0,pos_z))
sR_2 = Box(mag=(mag_field_x,mag_field_y,mag_field_z), dim=(mag_size_x,mag_size_y,mag_size_z), pos=(pos_x,0,pos_z))

#move copy bos
sL_1.move((-mag_size_x,0,0))
sR_1.move((mag_size_x,0,0))
sL_2.move((-2*mag_size_x,0,0))
sR_2.move((2*mag_size_x,0,0))

# create collection
c = Collection(sL,sL_1,sL_2,sR,sR_1,sR_2)

# 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))
예제 #2
0
from magpylib.source.magnet import Box
import magpylib as magpy
from numpy import array

#fixed magnet parameters
M = [0, 0, 1]  #magnetization
D = [2, 2, 2]  #dimension

# Translation of magnets can be realized in several ways
s1 = Box(mag=M, dim=D, pos=[-4, 0, 4])

s2 = Box(mag=M, dim=D, pos=[-2, 0, 4])
s2.move([0, 0, -2])

s3 = Box(mag=M, dim=D, pos=[0, 0, 4])
s3.move([0, 0, -2])
s3.move([0, 0, -2])

s4 = Box(mag=M, dim=D, pos=[2, 0, 4])
s4.setPosition([2, 0, -2])

s5 = Box(mag=M, dim=D, pos=[4, 0, 4])
s5.position = array([4, 0, 0])

#collection
c = magpy.Collection(s1, s2, s3, s4, s5)

#display collection
fig = c.displaySystem()
fig.set_size_inches(6, 6)