Refactor B_multiple --> B_field

Update B_field function with raster function
This commit is contained in:
schoener 2021-10-20 16:49:17 +02:00
parent 66892a0ad2
commit dc1e81ee2f
27 changed files with 127 additions and 109 deletions

View File

@ -38,7 +38,7 @@ wire_width = 1
wire_height = 2.6
B_z, B_x = bf.B_multiple(I,HH,R_inner,d_coils,layers,windings,wire_width, wire_height, x_m,z_m)
B_z, B_x = bf.B_field(I, HH, R_inner, d_coils, layers, windings, wire_width, wire_height, x_m, z_m)
#B_test = B_field_ideal_AHH(layers*windings,I,R_inner*1e-3,d_coils*1e-3,z_m)
#B_x = np.concatenate((-np.flip(B_r),B_r[1:len(B_r)]))

View File

@ -25,10 +25,10 @@ percentage = 0.05
absolut = 5
diff = percentage*0.01*5+ absolut *1e-3
print(diff)
Bz1, Bx = HH_Coil.B_multiple(5, x, z)
Bz1, Bx = HH_Coil.B_field(5, x, z)
Bz2, Bx = HH_Coil.B_multiple(5+ diff, x, z)
Bz2, Bx = HH_Coil.B_field(5 + diff, x, z)
print(Bz2[1500]-Bz1[1500])
print(" ")
@ -38,7 +38,7 @@ diff = percentage*0.01*5+ absolut *1e-3
print(diff)
Bz2, Bx = HH_Coil.B_multiple(5+ diff, x, z)
Bz2, Bx = HH_Coil.B_field(5 + diff, x, z)
print(Bz2[1500]-Bz1[1500])
print((Bz2[1500]-Bz1[1500])/Bz2[1500])

View File

@ -40,7 +40,7 @@ HH_Coil_44 = BC.BCoil(HH, 44 ,44, 6, 2, wire_width = 1.7, wire_height= 2.6)
#Coil from first sketch
HH_Coil_y = BC.BCoil(HH, 55.2 ,44, 6, 2, wire_width = 1.7, wire_height= 2.6)
B_z_y, B_x_y = HH_Coil_y.B_multiple(6.5,x,z)
B_z_y, B_x_y = HH_Coil_y.B_field(6.5, x, z)
B_z_y_curv = BC.BCoil.curv(B_z_y, z)
d_coils_2 = 55.2
@ -58,10 +58,10 @@ HH_Coil_78 = BC.BCoil(1,54,37,4, 4, 1,1)
#HH_Coil_44.Bz_plot_HH_comp(HH_Coil_54,I,x,z)
B_z, B_x = HH_Coil_44.B_multiple(I,x,z)
B_z_2, B_x_2 = HH_Coil_54.B_multiple(I,x,z)
B_z, B_x = HH_Coil_44.B_field(I, x, z)
B_z_2, B_x_2 = HH_Coil_54.B_field(I, x, z)
B_z_3,B_x_3 = HH_Coil_78.B_multiple(-0.72,x,z)
B_z_3,B_x_3 = HH_Coil_78.B_field(-0.72, x, z)

View File

@ -26,7 +26,7 @@ HH_Coil_78 = BC.BCoil(-1,54,37,4, 4, 1,1)
B_z,B_x = HH_Coil_78.B_multiple(1,x,z)
B_z,B_x = HH_Coil_78.B_field(1, x, z)
#B_x = np.concatenate((-np.flip(B_x),B_x))
#x = np.concatenate((-np.flip(r),r))

View File

@ -25,7 +25,7 @@ HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 50)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 50)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current,30)
print(f"B_z(0) = {Bz[1]:.2f} G")
@ -42,7 +42,7 @@ for width in array_width:
HH_Coil.set_d_min(49.8)
#HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 30)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 30)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current,30)
B.append(Bz[5])

View File

@ -27,7 +27,7 @@ HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 10)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current)
@ -43,7 +43,7 @@ print(x[500])
# HH_Coil.set_d_min(49.8)
# HH_Coil.print_info()
# Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 50)
# Bz, Bx = HH_Coil.B_field(I_current,x,z,raster = 50)
# Bz_curv = BC.BCoil.curv(Bz, z)
# HH_Coil.cooling(I_current)
@ -65,8 +65,8 @@ I_HH = 5
I_comp = -1.4
#calculate field
B_z, B_x = HH_Coil.B_multiple(I_HH,x,z)
B_z_comp,B_x_comp = HH_Coil_comp.B_multiple(I_comp,x,z)
B_z, B_x = HH_Coil.B_field(I_HH, x, z)
B_z_comp,B_x_comp = HH_Coil_comp.B_field(I_comp, x, z)
#Calculate curvature
B_z_curv = BC.BCoil.curv(B_z, z)

View File

@ -28,7 +28,7 @@ AHH_Coil.set_R_outer(49.3)
#AHH_Coil.print_info()
#B_z,B_x = AHH_Coil.B_multiple(1,x,z)
#B_z,B_x = AHH_Coil.B_field(1,x,z)
#B_z_grad = BC.BCoil.Bgrad(B_z, z)
#B_x_grad = BC.BCoil.Bgrad(B_x,x)
@ -49,7 +49,7 @@ AHH_Coil.print_info()
#B = AHH_Coil.B_multiple_3d(10, x,z,raster=2)
AHH_Coil.cooling(10)
B_z,B_x = AHH_Coil.B_multiple(10,x,z)
B_z,B_x = AHH_Coil.B_field(10, x, z)
#B_z = B[:,150,1]
#B_x = B[150,:,0]

View File

@ -30,7 +30,7 @@ HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
#Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
#Bz, Bx = HH_Coil.B_field(I_current,x,z,raster = 10)
B_tot_z, B_tot_x = HH_Coil.B_tot_along_axis(I_current, x, z,raster = 8)
Bz_curv = BC.BCoil.curv(B_tot_z, z)

View File

@ -27,7 +27,7 @@ HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 10)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current)
@ -35,7 +35,7 @@ HH_Coil.cooling(I_current)
I_HH = 5
#calculate field
B_z, B_x = HH_Coil.B_multiple(I_HH,x,z)
B_z, B_x = HH_Coil.B_field(I_HH, x, z)
#Calculate curvature
B_z_curv = BC.BCoil.curv(B_z, z)

View File

@ -28,7 +28,7 @@ HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 4)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 4)
Bz_curv = BC.BCoil.curv(Bz, z)
B = HH_Coil.B_multiple_3d(I_current, x, z,raster = 2)
@ -54,7 +54,7 @@ print(f"Diff B 1 mm: {Bz[16000] - Bz[15000]}, relative: {(Bz[16000] - Bz[15000])
I_HH = 5
#calculate field
B_z, B_x = HH_Coil.B_multiple(I_HH,x,z)
B_z, B_x = HH_Coil.B_field(I_HH, x, z)
#Calculate curvature
B_z_curv = BC.BCoil.curv(B_z, z)

View File

@ -28,7 +28,7 @@ HH_Coil.set_R_inner(40.5)
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 10)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current)
@ -51,7 +51,7 @@ print(f"Diff B 0.5 mm: {Bz[15500] - Bz[15000]}, relative: {(Bz[15500] - Bz[15000
I_HH = 5
#calculate field
B_z, B_x = HH_Coil.B_multiple(I_HH,x,z)
B_z, B_x = HH_Coil.B_field(I_HH, x, z)
#Calculate curvature
B_z_curv = BC.BCoil.curv(B_z, z)

View File

@ -29,9 +29,9 @@ HH_Coil.set_d_min(48.8)
print(f"height = {HH_Coil.get_coil_height()}")
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 10)
B_tot_z, B_tot_x = HH_Coil.B_multiple(I_current, x, z,raster = 10)
B_tot_z, B_tot_x = HH_Coil.B_field(I_current, x, z, raster = 10)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current,28)

View File

@ -37,7 +37,7 @@ print(HH_Coil.resistance(22))
print(HH_Coil.induct_perry())
HH_Coil.print_info()
#Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
#Bz, Bx = HH_Coil.B_field(I_current,x,z,raster = 10)
B_tot_z, B_tot_x = HH_Coil.B_tot_along_axis(I_current, x, z,raster = 8)
Bz_curv = BC.BCoil.curv(B_tot_z, z)

View File

@ -25,10 +25,10 @@ percentage = 0.05
absolut = 5
diff = percentage*0.01*5+ absolut *1e-3
print(diff)
Bz1, Bx = HH_Coil.B_multiple(5, x, z)
Bz1, Bx = HH_Coil.B_field(5, x, z)
Bz2, Bx = HH_Coil.B_multiple(5+ diff, x, z)
Bz2, Bx = HH_Coil.B_field(5 + diff, x, z)
print(Bz2[1500]-Bz1[1500])
print(" ")
@ -38,7 +38,7 @@ diff = percentage*0.01*5+ absolut *1e-3
print(diff)
Bz2, Bx = HH_Coil.B_multiple(5+ diff, x, z)
Bz2, Bx = HH_Coil.B_field(5 + diff, x, z)
print(Bz2[1500]-Bz1[1500])
print((Bz2[1500]-Bz1[1500])/Bz2[1500])

View File

@ -35,7 +35,7 @@ print(f"R = {R} ")
#B = AHH_Coil.B_multiple_3d(10, x,z,raster=2)
AHH_Coil.cooling(I,30)
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
#B_z = B[:,150,1]
#B_x = B[150,:,0]

View File

@ -38,7 +38,7 @@ print(f"R = {R} ")
#B = AHH_Coil.B_multiple_3d(10, x,z,raster=2)
AHH_Coil.cooling(I,30)
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
#B_z = B[:,150,1]
#B_x = B[150,:,0]
@ -57,7 +57,7 @@ distance = np.arange(80,95,2)
for d in distance:
print(d)
AHH_Coil = BC.BCoil(HH = -1, distance = d ,radius = 46.875 ,layers = 4, windings = 4 , wire_width= 1, wire_height= 2 ,layers_spacing = 0.25, windings_spacing= 0.25)
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
B_z_grad = BC.BCoil.Bgrad(B_z, z)
B_x_grad = BC.BCoil.Bgrad(B_x,x)

View File

@ -36,7 +36,7 @@ AHH_Coil.print_info()
AHH_Coil.cooling(I, 30)
print(f"R (30 degree C)= {AHH_Coil.resistance(30)}")
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
B_z_grad = BC.BCoil.Bgrad(B_z, z)
B_x_grad = BC.BCoil.Bgrad(B_x,x)

View File

@ -48,7 +48,7 @@ print(f"R = {R} ")
#B = AHH_Coil.B_multiple_3d(10, x,z,raster=2)
AHH_Coil.cooling(I,30)
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
#B_z = B[:,150,1]
#B_x = B[150,:,0]

View File

@ -45,8 +45,8 @@ print("Not cutting optical axis:")
AHH_comp.print_info()
Bz_opt, Bx_opt = AHH_opt.B_multiple(I,x,z)
Bz_comp, Bx_comp = AHH_comp.B_multiple(I, x, z)
Bz_opt, Bx_opt = AHH_opt.B_field(I, x, z)
Bz_comp, Bx_comp = AHH_comp.B_field(I, x, z)
#B_z = B[:,150,1]

View File

@ -48,7 +48,7 @@ print(f"R = {R} ")
#B = AHH_Coil.B_multiple_3d(10, x,z,raster=2)
AHH_Coil.cooling(I,30)
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
#B_z = B[:,150,1]
#B_x = B[150,:,0]

View File

@ -48,7 +48,7 @@ print(f"R = {R} ")
#B = AHH_Coil.B_multiple_3d(10, x,z,raster=2)
AHH_Coil.cooling(I,30)
B_z,B_x = AHH_Coil.B_multiple(I,x,z)
B_z,B_x = AHH_Coil.B_field(I, x, z)
#B_z = B[:,150,1]
#B_x = B[150,:,0]

View File

@ -29,9 +29,9 @@ HH_Coil = BC.BCoil(HH = -1, distance = d ,radius = 46.875 ,layers = 4, windings
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 10)
B_tot_z, B_tot_x = HH_Coil.B_multiple(I_current, x, z,raster = 10)
B_tot_z, B_tot_x = HH_Coil.B_field(I_current, x, z, raster = 10)
Bz = BC.BCoil.Bgrad(Bz, z)
HH_Coil.cooling(I_current,28)

View File

@ -29,7 +29,7 @@ print(diff)
Bz2, Bx = HH_Coil.B_multiple(I+ diff, x, z)
Bz2, Bx = HH_Coil.B_field(I+ diff, x, z)
print(Bz2[1500]-Bz1[1500])
print(" ")
"""
@ -38,8 +38,8 @@ absolut = 0.125
diff = percentage*0.01*5+ absolut *1e-3
print(diff)
Bz1, Bx = HH_Coil.B_multiple(I, x, z)
Bz2, Bx = HH_Coil.B_multiple(I+ diff, x, z)
Bz1, Bx = HH_Coil.B_field(I, x, z)
Bz2, Bx = HH_Coil.B_field(I + diff, x, z)
print(Bz2[1500]-Bz1[1500])
print((Bz2[1500]-Bz1[1500])/Bz2[1500])
#print(100e-6/10)

View File

@ -28,7 +28,7 @@ HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
Bz, Bx = HH_Coil.B_multiple(I_current,x,z,raster = 10)
Bz, Bx = HH_Coil.B_field(I_current, x, z, raster = 10)
Bz_curv = BC.BCoil.curv(Bz, z)
HH_Coil.cooling(I_current)
@ -48,7 +48,7 @@ print(f"Diff B 0.5 mm: {Bz[15500] - Bz[15000]}, relative: {(Bz[15500] - Bz[15000
I_HH = I_current
#calculate field
B_z, B_x = HH_Coil.B_multiple(I_HH,x,z)
B_z, B_x = HH_Coil.B_field(I_HH, x, z)
#Calculate curvature
B_z_curv = BC.BCoil.curv(B_z, z)

View File

@ -39,7 +39,7 @@ wire_height = 2.6
HH_Coil1 = BC.BCoil(HH, d_coils ,R_mid, layers, windings, wire_width, wire_height)
#HH_Coil1.print_info()
#B_z_sim, B_x_sim = HH_Coil1.B_multiple(5, x, z)
#B_z_sim, B_x_sim = HH_Coil1.B_field(5, x, z)
#B_z, B_x = bf.B_multiple_raster(I,HH,R_inner,d_coils,layers,windings,wire_width, wire_height, x_m,z_m)

View File

@ -43,8 +43,8 @@ HH_Coil_54 = BC.BCoil(HH, d_coils_2 ,R_mid, layers, windings, wire_width, wire_h
#HH_Coil_44.Bz_plot_HH_comp(HH_Coil_54,I,x,z)
B_z, B_x = HH_Coil_44.B_multiple(I,x,z)
B_z_2, B_x_2 = HH_Coil_54.B_multiple(I,x,z)
B_z, B_x = HH_Coil_44.B_field(I, x, z)
B_z_2, B_x_2 = HH_Coil_54.B_field(I, x, z)
B_z_curvature = np.gradient(np.gradient(B_z,z),z)*1e2
B_z_curvature_2 = np.gradient(np.gradient(B_z_2,z),z)*1e2

View File

@ -88,8 +88,10 @@ class BCoil:
def get_coil_width(self):
if self.winding_offset:
if self.is_round:
log.info("Be aware of the fact that this is an idealized situation of coil winding (slope of windings changes each layer)")
return self.layers * self.get_tot_wire_width() - (self.layers-1) * (2 - np.sqrt(3)) *self.get_tot_wire_width()/2 #width is reduced due to winding offset
log.info(
"Be aware of the fact that this is an idealized situation of coil winding (slope of windings changes each layer)")
return self.layers * self.get_tot_wire_width() - (self.layers - 1) * (
2 - np.sqrt(3)) * self.get_tot_wire_width() / 2 # width is reduced due to winding offset
return self.get_tot_wire_width() * self.layers
def get_zmin(self):
@ -129,22 +131,22 @@ class BCoil:
:param raster_value: wire height/raster_value is distance between rastered points in one wire
:return: 2 dim array [[z1,R1], [z2,R2], ...]
"""
outer_raster = np.zeros((self.get_N(),2))
outer_raster = np.zeros((self.get_N(), 2))
it = 0
z_start = self.get_zmin() + self.get_tot_wire_height()/2 # (distance_coils/2 - windings * wire_height/2 + wire_height/2)*1e-3
R_start = self.get_R_inner() + self.get_tot_wire_width()/2 # (R_inner + wire_width/2 )
z_start = self.get_zmin() + self.get_tot_wire_height() / 2 # (distance_coils/2 - windings * wire_height/2 + wire_height/2)*1e-3
R_start = self.get_R_inner() + self.get_tot_wire_width() / 2 # (R_inner + wire_width/2 )
for xx in range(0, self.layers):
for zz in range(0, self.windings):
z_pos = z_start + zz * self.get_tot_wire_height()
R_pos = R_start + xx * self.get_tot_wire_width()
#correct for different winding techniques and round wire
# correct for different winding techniques and round wire
if self.winding_offset:
if xx % 2 == 1:
z_pos += self.get_tot_wire_height()/2
z_pos += self.get_tot_wire_height() / 2
if self.is_round:
R_pos -= xx * ((2-np.sqrt(3)) * self.get_tot_wire_width()/2)
R_pos -= xx * ((2 - np.sqrt(3)) * self.get_tot_wire_width() / 2)
outer_raster[it] = [z_pos, R_pos]
it += 1
@ -159,24 +161,24 @@ class BCoil:
Returns: array containing raster around 0,0 [[z_pos_in_1,r_pos_in_1],...]
"""
inner_raster = np.zeros((raster_value**2,2))
inner_raster = np.zeros((raster_value ** 2, 2))
it = 0
for xx_in in range(0, raster_value):
for zz_in in range(0, raster_value):
z_pos_in = - self.wire_height/2 + zz_in * self.wire_height/(raster_value-1)
r_pos_in = - self.wire_width/2 + xx_in * self.wire_width/(raster_value-1)
z_pos_in = - self.wire_height / 2 + zz_in * self.wire_height / (raster_value - 1)
r_pos_in = - self.wire_width / 2 + xx_in * self.wire_width / (raster_value - 1)
inner_raster[it] = [z_pos_in, r_pos_in]
it += 1
#delete points out of round geometry
# delete points out of round geometry
if self.is_round:
delete_list = []
for i in range(0, len(inner_raster)):
abs = np.sqrt(inner_raster[i, 0]**2 + inner_raster[i, 1]**2)
if abs > self.wire_width/2:
abs = np.sqrt(inner_raster[i, 0] ** 2 + inner_raster[i, 1] ** 2)
if abs > self.wire_width / 2:
delete_list.append(i)
inner_raster = np.delete(inner_raster, delete_list,axis = 0)
inner_raster = np.delete(inner_raster, delete_list, axis=0)
return inner_raster
@ -191,9 +193,9 @@ class BCoil:
"""
outer_ras = self.winding_raster()
inner_ras = self.inner_raster(raster_value)
full_ras = np.zeros((len(outer_ras),len(inner_ras),2))
full_ras = np.zeros((len(outer_ras), len(inner_ras), 2))
for i in range(0,len(full_ras)):
for i in range(0, len(full_ras)):
full_ras[i] = outer_ras[i] + inner_ras
return full_ras
@ -205,12 +207,12 @@ class BCoil:
else:
extension = self.get_coil_height()
extension *= 1e3
plt.figure(77,figsize=(5,5))
plt.scatter(full_structure[:,:,1],full_structure[:,:,0], linewidths= 0.01)
plt.figure(77, figsize=(5, 5))
plt.scatter(full_structure[:, :, 1], full_structure[:, :, 0], linewidths=0.01)
plt.xlabel("radius [mm]")
plt.ylabel("z position [mm]")
plt.xlim(1e3*self.get_R_inner()-0.5, 1e3*self.get_R_inner() + extension + 0.5)
plt.ylim(1e3*self.get_zmin()- 0.5,1e3*self.get_zmin() + extension + 0.5)
plt.xlim(1e3 * self.get_R_inner() - 0.5, 1e3 * self.get_R_inner() + extension + 0.5)
plt.ylim(1e3 * self.get_zmin() - 0.5, 1e3 * self.get_zmin() + extension + 0.5)
plt.show()
plt.close(77)
@ -223,6 +225,9 @@ class BCoil:
f"HH = {self.HH}, Distance = {self.distance * 1e3} mm, z_min = {self.get_zmin() * 1e3} mm, z_max = {self.get_zmax() * 1e3} mm")
print(
f"Radius = {self.radius * 1e3} mm, Radius_inner = {self.get_R_inner() * 1e3} mm, Radius_outer = {self.get_R_outer() * 1e3:.2f} mm")
print(
f"Coil width = {self.get_coil_width() * 1e3} mm, Coil height = {self.get_coil_height() * 1e3} mm"
)
print(
f"layers = {self.layers}, windings = {self.windings}, wire_width = {self.wire_width * 1e3}, wire_height = {self.wire_height * 1e3} mm, round wire = {self.is_round} ")
print(" ")
@ -269,14 +274,15 @@ class BCoil:
B_r *= 1e4 # conversion to gauss
return B_r
def B_multiple(self, I_current, x, z, raster=10):
def B_field(self, I_current, x, z, raster=10):
pass
"""
Returns B_z along z-axis and B_x along x-axis,
HH = +1 --> Helmholtz configuration, HH = -1 --> Anti Helmholtz configuration
"""
z_start = self.get_zmin() + self.wire_height / 2 # (distance_coils/2 - windings * wire_height/2 + wire_height/2)*1e-3
R_start = self.get_R_inner() + self.wire_width / 2 # (R_inner + wire_width/2 )*1e-3
# z_start = self.get_zmin() + self.wire_height / 2 # (distance_coils/2 - windings * wire_height/2 + wire_height/2)*1e-3
# R_start = self.get_R_inner() + self.wire_width / 2 # (R_inner + wire_width/2 )*1e-3
# Convert axis to SI units
x_SI = x * 1e-3
@ -290,34 +296,34 @@ class BCoil:
B_z = np.zeros(len(z))
B_x_pos = np.zeros(len(x_pos))
B_x_neg = np.zeros(len(x_neg))
B_x_zero = x_zero # If there is a zero in the x-array it is assured that the x component of the field at this point is zero
B_x_zero = x_zero # 0 in x-array --> field is zero at this position
# dividing each wire into 10 x 10 raster
calc_raster = self.full_raster(raster)
I_current /= raster ** 2
if self.get_N() != len(calc_raster):
log.error("N is not equal length of raster")
for xx in range(0, self.layers):
for zz in range(0, self.windings):
for xx_in in range(0, raster):
for zz_in in range(0, raster):
z_pos = z_start + zz * (
self.wire_height + self.windings_spacing) - self.wire_height / 2 + zz_in * self.wire_height / (
raster - 1)
R_pos = R_start + xx * (
self.wire_width + self.layers_spacing) - self.wire_width / 2 + xx_in * self.wire_width / (
raster - 1)
# TODO: fix z_pos, R_pos, either by raster or by spacing
rastering_value = len(calc_raster[0])
B_z += BCoil.B_z_loop(I_current, R_pos, z_pos, 0, z_SI) + BCoil.B_z_loop(self.HH * I_current,
R_pos, -z_pos, 0, z_SI)
B_x_pos += BCoil.B_r_loop(I_current, R_pos, z_pos, x_pos, 0) + BCoil.B_r_loop(
self.HH * I_current, R_pos, -z_pos, x_pos, 0)
B_x_neg += BCoil.B_r_loop(I_current, R_pos, z_pos, x_neg, 0) + BCoil.B_r_loop(
self.HH * I_current, R_pos, -z_pos, x_neg, 0)
I_current /= rastering_value # divide current into smaller currents for mapping the whole wire
start = time.time()
for wire in range(0, self.get_N()):
for ii in range(0, rastering_value):
# extract position information out of raster
z_pos = calc_raster[wire, ii, 0]
r_pos = calc_raster[wire, ii, 1]
B_z += BCoil.B_z_loop(I_current, r_pos, z_pos, 0, z_SI) + BCoil.B_z_loop(self.HH * I_current,
r_pos, -z_pos, 0, z_SI)
B_x_pos += BCoil.B_r_loop(I_current, r_pos, z_pos, x_pos, 0) + BCoil.B_r_loop(
self.HH * I_current, r_pos, -z_pos, x_pos, 0)
B_x_neg += BCoil.B_r_loop(I_current, r_pos, z_pos, x_neg, 0) + BCoil.B_r_loop(
self.HH * I_current, r_pos, -z_pos, x_neg, 0)
B_x_neg *= -1 # B_x_neg is pointing in opposite x_direction
B_x = np.concatenate((B_x_neg, B_x_zero, B_x_pos))
end = time.time()
print(f"time = {end - start} s")
return B_z, B_x
def B_tot_along_axis(self, I_current, x, z, raster=10):
@ -354,10 +360,10 @@ class BCoil:
for xx_in in range(0, raster):
for zz_in in range(0, raster):
z_pos = z_start + zz * (
self.wire_height + self.windings_spacing) - self.wire_height / 2 + zz_in * self.wire_height / (
self.wire_height + self.insulation_thickness * 2) - self.wire_height / 2 + zz_in * self.wire_height / (
raster - 1)
R_pos = R_start + xx * (
self.wire_width + self.layers_spacing) - self.wire_width / 2 + xx_in * self.wire_width / (
self.wire_width + self.insulation_thickness * 2) - self.wire_width / 2 + xx_in * self.wire_width / (
raster - 1)
# TODO: fix z_pos, R_pos, either by raster or by spacing
@ -377,11 +383,12 @@ class BCoil:
B_x_neg *= -1 # B_x_neg is pointing in opposite x_direction
B_x_x = np.zeros(len(x_SI))
B_x_x = np.concatenate((B_x_neg, B_x_zero, B_x_pos))
# B_x_x = np.zeros(len(x_SI))
B_tot_x = np.sqrt(B_x_x ** 2 + B_z_x ** 2)
B_x_x = np.concatenate((B_x_neg, B_x_zero, B_x_pos))
return B_tot_z, B_tot_x
def B_multiple_3d(self, I_current, x, z, raster=4):
@ -458,7 +465,7 @@ class BCoil:
return np.gradient(B_field, z) * 1e1
def Bz_plot_HH(self, I_current, x, z):
B_z, B_x = self.B_multiple(I_current, x, z)
B_z, B_x = self.B_field(I_current, x, z)
B_z_curvature = np.gradient(np.gradient(B_z, z), z)
@ -491,8 +498,8 @@ class BCoil:
plt.show()
def Bz_plot_HH_comp(self, Coil2, I_current, x, z):
B_z, B_x = self.B_multiple(I_current, x, z)
B_z_2, B_x_2 = Coil2.B_multiple(I_current, x, z)
B_z, B_x = self.B_field(I_current, x, z)
B_z_2, B_x_2 = Coil2.B_field(I_current, x, z)
B_z_curvature = np.gradient(np.gradient(B_z, z), z) * 1e2
B_z_curvature_2 = np.gradient(np.gradient(B_z_2, z), z) * 1e2
@ -590,14 +597,25 @@ class BCoil:
return BCoil.resistivity_copper(T) * self.get_wire_length() / self.get_wire_area()
#HH_Coil = BCoil(HH=1, distance=50, radius=40, layers=4, windings=4, wire_height=0.4, wire_width=0.4,insulation_thickness=0.1, is_round=False, winding_offset=False)
#HH_Coil.set_R_outer(70)
#HH_Coil.print_info()
#raster = HH_Coil.plot_raster(10)
#print(raster[:,:,0])
def main():
HH_Coil = BCoil(HH=-1, distance=50, radius=40, layers=4, windings=8, wire_height=0.4, wire_width=0.4,
insulation_thickness=0.1, is_round=True, winding_offset=False)
x = np.linspace(-50, 50, 200)
z = np.linspace(-50, 50, 200)
# Bz, Bx = HH_Coil.B_tot_along_axis(1.25, x, z)
Bz, Bx = HH_Coil.B_field(1.25, x, z)
print(Bx)
print(Bz)
plt.plot(x,Bx,label = "Bx")
plt.plot(z,Bz, label = "Bz")
plt.legend()
plt.show()
HH_Coil.plot_raster(3)
ras = HH_Coil.full_raster(10)
main()
# if __name__ == "__main__":
# print("g")
# main()