def add_coil(pos, N, normal=[0,0,1], width=5.3e-3, r_o=30.25e-3 - 1e-3, r_i=5e-3, current=1): # pos is coil midpoint A = width * (r_o - r_i) A_loop = A/N d_loop = np.sqrt(A_loop) N_d = int(round(width/d_loop)) N_r = int(round((r_o-r_i)/d_loop)) N_prod = N_d * N_r print("building coil with %d x %d = %d loops, error = %d ( %.2g percent)" % (N_d, N_r, N_prod, N_prod - N, 100 * np.abs((N_prod - N) / N))) radiuses = np.linspace(r_i, r_o, N_r) mid_points = pos + np.outer(np.linspace(-width/2, width/2, N_d), normal) for radius in (radiuses): for mid_point in (mid_points): field.addLoop(loopfield.Loop(mid_point, normal, radius, current))
# Maxwell coil plot example # import math import loopfield as lf import loopfield.plot as lfp # field object field = lf.Field(length_units=lf.cm, current_units=lf.A, field_units=lf.uT) # Maxwell coil model with single current loops R = 10 # center winding c1 = lf.Loop([0, 0, 0], [1, 0, 0], R, 64) # outer windings c2 = lf.Loop([-R * math.sqrt(3. / 7.), 0, 0], [1, 0, 0], R * math.sqrt(4. / 7.), 49) c3 = lf.Loop([+R * math.sqrt(3. / 7.), 0, 0], [1, 0, 0], R * math.sqrt(4. / 7.), 49) # add windings to field field.addLoop(c1) field.addLoop(c2) field.addLoop(c3) # evaluate field at center of coil Bc = field.evaluate([0., 0., 0.]) print('Bc = ', Bc)
# # Helmholtz coil plot example # import math import loopfield as lf import loopfield.plot as lfp # field object field = lf.Field(length_units=lf.cm, current_units=lf.A, field_units=lf.uT) # Helmholtz coil model with single current loops R = 10. # 2 windings c1 = lf.Loop([-R / 2., 0, 0], [1, 0, 0], R, 1) c2 = lf.Loop([+R / 2., 0, 0], [1, 0, 0], R, 1) # add windings to field field.addLoop(c1) field.addLoop(c2) # evaluate field at center of coil Bc = field.evaluate([0., 0., 0.]) print('Bc = ', Bc) print('Calculating plot...') # function returns ratio of x-component to that at coil center def x_ratio(B):
#!/usr/bin/env python3 import loopfield as lf # create empty field with specified units field = lf.Field(length_units=lf.cm, current_units=lf.A, field_units=lf.uT) # single-turn 10 cm x-oriented coil at origin position = [0., 0., 0.] normal = [1., 0., 0.] radius = 10. current = 1. c = lf.Loop(position, normal, radius, current) # add loop to field field.addLoop(c) # evaluate vector field at origin B = field.evaluate([0., 0., 0.]) print('B = ', B) # evaluate vector field 100 cm along axis B = field.evaluate([100., 0., 0.]) print('B = ', B) # evaluate vector field on loop (infinite result) B = field.evaluate([0., radius, 0.]) print('B = ', B)