예제 #1
0
def test_vectorCurrentCircular():

    I = np.ones([10])
    D = np.ones([10]) * 4
    Pm = np.zeros([10, 3])
    Po = np.array([[0, 0, 1], [0, 0, -1], [1, 1, 0], [1, -1, 0], [-1, -1, 0],
                   [-1, 1, 0], [5, 5, 0], [5, -5, 0], [-5, -5, 0], [-5, 5, 0]])

    Bc = []
    for i, d, pm, po in zip(I, D, Pm, Po):
        s = Circular(curr=i, dim=d, pos=pm)
        Bc += [s.getB(po)]
    Bc = np.array(Bc)

    Bv = getBv_current('circular', I, D, Pm, Po)

    assert np.amax(abs(Bc - Bv)) < 1e-10
예제 #2
0
from magpylib import Collection
from magpylib.source.current import Circular
from numpy import linspace

#windings of three parts of a coil at x/y = 0/0
coil1a = [Circular(curr=1,dim=3,pos=[0,0,z]) for z in linspace( -3,-1,20)]
coil1b = [Circular(curr=1,dim=3,pos=[0,0,z]) for z in linspace( -1, 1,20)]
coil1c = [Circular(curr=1,dim=3,pos=[0,0,z]) for z in linspace(  1, 3,20)]

#create collection and manipulate step by step
c1 = Collection(coil1a)
c1.move([-1,-1,0])
c1.addSources(coil1b)
c1.move([-1,-1,0])
c1.addSources(coil1c)
c1.move([-1,-1,0])

#windings of three parts of another coil at x/y = 3/3
coil2a = [Circular(curr=1,dim=3,pos=[3,3,z]) for z in linspace(-3,-1,20)]
coil2b = [Circular(curr=1,dim=3,pos=[3,3,z]) for z in linspace( -1,1,20)]
coil2c = [Circular(curr=1,dim=3,pos=[3,3,z]) for z in linspace( 1,3,20)]

#create individual sub-collections
c2a = Collection(coil2a)
c2b = Collection(coil2b)
c2c = Collection(coil2c)

#combine sub-collections to one big collection
c2 = Collection(c2a,c2b,c2c)

#still manipulate each individual sub-collection
예제 #3
0
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import magpylib as magpy
from magpylib.source.current import Circular

mpl.rcParams['text.usetex'] = True

N_less = 20
N_more = 200

cir = Circular(curr=1, dim=5, pos=[0, 0, 0])

x_less = np.linspace(-10, 10, N_less)
y_less = np.linspace(-10, 10, N_less)
z_less = np.linspace(-10, 10, N_less)
x_more = np.linspace(-10, 10, N_more)
y_more = np.linspace(-10, 10, N_more)
z_more = np.linspace(-10, 10, N_more)

fig = plt.figure("2D Electric Circuit Magnet", figsize=(10, 10))

B_2dplot = fig.add_subplot(1, 1, 1)
for z_item in z_less:
    for x_item in x_less:
        B_item = cir.getB([x_item, 0, z_item])
        B_x = B_item[0]
        B_z = B_item[2]
        B_2dplot.quiver(x_item,
                        z_item,
                        B_x,
예제 #4
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)

예제 #5
0
import magpylib as magpy
from magpylib.source.current import Circular
import numpy as np
from matplotlib import pyplot as plt
from skimage import measure

# windings of three parts of a coil
coil1a = [
    Circular(curr=1, dim=3, pos=[0, 0, z]) for z in np.linspace(-3, 3, 15)
]

# create collection and manipulate step by step
c1 = magpy.Collection(coil1a)

# magpy.displaySystem(c1, figsize=(6,6))

# 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 = [c1.getB(pos) for pos in posis]
Bs = np.array(B).reshape([100, 100, 3])  #reshape
Bamp = np.linalg.norm(Bs, axis=2)
print(Bamp.shape)
print(Bamp[50, 50])  # field in center

fig = plt.figure(figsize=[5, 5])
ax = fig.add_axes([.1, .1, .8, .8])