From b3c97e00499cb890f5ded305fc9e944f1471d6ad Mon Sep 17 00:00:00 2001 From: schoener Date: Wed, 27 Oct 2021 12:17:16 +0200 Subject: [PATCH] Added alternating number of windings per layer --- Coil_geometry/12_Final_Plotting.py | 2 +- .../13_new_HH_coil_comp_different_wires.py | 8 +- Coil_geometry/14_new_HH_coil_wire_decision.py | 10 +-- .../00_Try_slightly_shifted_coil.py | 75 +++++++++++++++++++ src/coil_class.py | 63 ++++++++++------ untitled0.py | 18 ++++- 6 files changed, 141 insertions(+), 35 deletions(-) diff --git a/Coil_geometry/12_Final_Plotting.py b/Coil_geometry/12_Final_Plotting.py index 5d220c2..8ff0030 100644 --- a/Coil_geometry/12_Final_Plotting.py +++ b/Coil_geometry/12_Final_Plotting.py @@ -29,7 +29,7 @@ HH_Coil = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 4, windings = 2 HH_Coil.set_R_inner(44.5) HH_Coil.set_d_min(48.8) -HH_Coil = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 8, windings = 8, wire_height = 0.4, wire_width = 0.4,insulation_thickness= 0.1,is_round = False, winding_offset= False) +HH_Coil = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.4, wire_width = 0.4, insulation_thickness= 0.1, is_round = False, winding_scheme= False) HH_Coil.set_R_outer(49.3) HH_Coil.set_d_min(49.8) diff --git a/Coil_geometry/13_new_HH_coil_comp_different_wires.py b/Coil_geometry/13_new_HH_coil_comp_different_wires.py index a487ab7..bff0ae2 100644 --- a/Coil_geometry/13_new_HH_coil_comp_different_wires.py +++ b/Coil_geometry/13_new_HH_coil_comp_different_wires.py @@ -15,7 +15,7 @@ from IPython import get_ipython I = 1.25 -Wire_1 = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 8, windings = 8, wire_height = 0.425, wire_width = 0.425,insulation_thickness= 0.09,is_round = True, winding_offset= False) +Wire_1 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.425, wire_width = 0.425, insulation_thickness= 0.09, is_round = True, winding_scheme= False) Wire_1.set_R_outer(49.3) Wire_1.set_d_min(49.8) Wire_1.print_info() @@ -25,7 +25,7 @@ Wire_1.cooling(I,22.5) Wire_1.plot_raster(30) -Wire_2 = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 8, windings = 8, wire_height = 0.425, wire_width = 0.425,insulation_thickness= 0.09,is_round = False, winding_offset= False) +Wire_2 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.425, wire_width = 0.425, insulation_thickness= 0.09, is_round = False, winding_scheme= False) Wire_2.set_R_outer(49.3) Wire_2.set_d_min(49.8) Wire_2.print_info() @@ -35,7 +35,7 @@ Wire_2.cooling(I,22.5) Wire_2.plot_raster(30) -Wire_2 = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 8, windings = 8, wire_height = 0.55, wire_width = 0.55,insulation_thickness= 0.09,is_round = True, winding_offset= True) +Wire_2 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.55, wire_width = 0.55, insulation_thickness= 0.09, is_round = True, winding_scheme= True) Wire_2.set_R_outer(49.3) Wire_2.set_d_min(49.8) Wire_2.print_info() @@ -45,7 +45,7 @@ Wire_2.cooling(I,22.5) Wire_2.plot_raster(30) I = 64/42 * 1.25 -Wire_2 = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 6, windings = 7, wire_height = 0.55, wire_width = 0.55,insulation_thickness= 0.09,is_round = True, winding_offset= True) +Wire_2 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 6, windings = 7, wire_height = 0.55, wire_width = 0.55, insulation_thickness= 0.09, is_round = True, winding_scheme= True) Wire_2.set_R_outer(49.3) Wire_2.set_d_min(49.8) Wire_2.print_info() diff --git a/Coil_geometry/14_new_HH_coil_wire_decision.py b/Coil_geometry/14_new_HH_coil_wire_decision.py index 81718c7..8bac1bb 100644 --- a/Coil_geometry/14_new_HH_coil_wire_decision.py +++ b/Coil_geometry/14_new_HH_coil_wire_decision.py @@ -8,16 +8,15 @@ Created on Tue Sep 7 13:18:18 2021 import matplotlib.pyplot as plt import numpy as np import matplotlib -matplotlib.use('Qt5Agg') +#matplotlib.use('Qt5Agg') from src import coil_class as BC -from IPython import get_ipython -#get_ipython().run_line_magic('matplotlib', 'qt') + I = 10/8 print(I) -Wire_1 = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 8, windings = 8, wire_height = 0.5, wire_width = 0.5,insulation_thickness= 0.06,is_round = True, winding_offset= True) +Wire_1 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.5, wire_width = 0.5, insulation_thickness= 0.06, is_round = True, winding_scheme= 2) Wire_1.set_R_outer(49.8) Wire_1.set_d_min(49.8) Wire_1.print_info() @@ -25,11 +24,12 @@ print(Wire_1.get_coil_width() * 1e3 * Wire_1.get_coil_height() * 1e3) print(f"H = {Wire_1.get_coil_height() * 1e3}, W = {Wire_1.get_coil_width()*1e3}") + Wire_1.cooling(I,22.5) Wire_1.plot_raster(30) Wire_1.B_quick_plot(I) -Wire_1.B_curv_quick_plot(I) +Wire_1.B_curv_quick_plot(I,nr_points= 1000) diff --git a/Winding_inhomogenities/00_Try_slightly_shifted_coil.py b/Winding_inhomogenities/00_Try_slightly_shifted_coil.py index e69de29..f329c4b 100644 --- a/Winding_inhomogenities/00_Try_slightly_shifted_coil.py +++ b/Winding_inhomogenities/00_Try_slightly_shifted_coil.py @@ -0,0 +1,75 @@ +import numpy as np +import matplotlib.pyplot as plt +import src.coil_class as BC + + +I_current = 1.25 + +# scale = 1000 --> μm +scale = 1000 +lim = 5 +nr_points = (2 * lim) * scale + 1 +x = np.linspace(-lim,lim,nr_points) +z = np.linspace(-lim,lim,nr_points) +print(x) + +def mu_it(x_pos): + it = nr_points//2 + x_pos + return it + +print(x[mu_it(-60)]) + +#standard +C1 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.5, wire_width = 0.5, insulation_thickness= 0.06, is_round = True, winding_scheme= True) +C1.set_R_outer(49.8) +C1.set_d_min(49.8) +C1.print_info() + +Bz, Bx = C1.B_tot_along_axis(I_current, x, z,raster = 2) + +# plt.figure(5) +# plt.plot(z,Bz) +# plt.plot(x,Bx, label = "B_tot along x-axis") +# plt.show() +#plt.close(5) + + +#coil is ~ 500 μm thicker +shift_radius = 1#0.125 +C_shift = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_height = 0.5, wire_width = 0.5, insulation_thickness= 0.06, is_round = True, winding_scheme= True) +C_shift.set_R_outer(49.8 + shift_radius) +C_shift.set_d_min(49.8) + +#shift_radius = 0.125 + +Bz2, By = C_shift.B_tot_along_axis(I_current+0.00082, x, z,raster = 2) + +shift_int = int(shift_radius * scale - 1) +print(shift_int) +By_shift = By[shift_int:] +y_shift = x[:-shift_int] +print(By_shift) +print(y_shift) +B_sum = (By_shift + Bx[:-shift_int])/2 +# shift By shift with shift radius + +plt.figure(6) +#plt.plot(z,Bz) +plt.plot(x,Bx, label = "B_tot along x-axis") +plt.plot(y_shift,By_shift, label = "Shiftet tot B") +plt.plot(y_shift,B_sum, label = "B_sum") +plt.legend() +plt.show() +#plt.close(5) + +it = mu_it(int(-shift_radius * 1e3 // 2)) +#it = μm_it(-60) +print(it) +zero = mu_it(0) +print(y_shift[it]) +print(y_shift[zero]) + +tot_diff = B_sum[it]-B_sum[zero] + +print(f"diff {y_shift[it]} μm --> 0: {tot_diff} G, relative = {tot_diff/B_sum[it]}") + diff --git a/src/coil_class.py b/src/coil_class.py index 234156d..6f88b7b 100644 --- a/src/coil_class.py +++ b/src/coil_class.py @@ -10,19 +10,23 @@ import logging as log from scipy import special as sp import matplotlib -matplotlib.use('Qt5Agg') - +#matplotlib.use('Qt5Agg') +#matplotlib.use('Agg') +#get_ipython().run_line_magic('matplotlib', 'qt') +# get_ipython().run_line_magic('matplotlib', 'inline') import time from src import physical_constants as cs - +#logger = log.getLogger('example') +#log.setLevel(log.info) +log.basicConfig(level = log.ERROR, format = '%(message)s') # TODO: Docstrings for every function # TODO: Implement conventions class BCoil: def __init__(self, HH, distance, radius, layers, windings, wire_width, wire_height, insulation_thickness=0. - , is_round=False, winding_offset=False): + , is_round=False, winding_scheme=False): """ Creates object that represents a configuration of two coils, with symmetry axis = z :param HH: HH = 1 --> current in same direction, homogeneous field, HH = -1 --> current in opposite direction, quadrupole field @@ -34,10 +38,10 @@ class BCoil: :param wire_height: height of conductive wire core :param insulation_thickness: thickness of wire insulation :param is_round: True --> Round wire, False --> rectangular wire - :param winding_offset: layer offset by half winding (especially for round wires) + :param winding_scheme: 0: standard, layer on layer, 1: with offset (for round wires primarily), 2: like 1, but alternatingly 8 --> 7 windings per layer """ if not is_round: - if winding_offset: + if winding_scheme == 1 or winding_scheme == 2: log.warning('Is there a reason you want to wind a not round wire like that?') if is_round: if wire_width != wire_height: @@ -52,7 +56,7 @@ class BCoil: self.wire_height = wire_height * 1e-3 self.insulation_thickness = insulation_thickness * 1e-3 self.is_round = is_round - self.winding_offset = winding_offset + self.winding_scheme = winding_scheme def get_wire_area(self): """ @@ -67,7 +71,11 @@ class BCoil: """ Calculates number of windings """ - return self.layers * self.windings + N = self.layers * self.windings + + if self.winding_scheme == 2: + N -= self.windings//2 + return N def get_wire_length(self): """ @@ -84,15 +92,15 @@ class BCoil: return self.wire_width + 2 * self.insulation_thickness def get_coil_height(self): - if self.winding_offset: + if self.winding_scheme == 1: return self.get_tot_wire_height() * (self.windings + 0.5) return self.get_tot_wire_height() * self.windings def get_coil_width(self): - if self.winding_offset: + if self.winding_scheme == 1 or self.winding_scheme == 2: 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)") + log.info("Coil width: 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 @@ -141,17 +149,19 @@ class BCoil: for xx in range(0, self.layers): for zz in range(0, self.windings): + if self.winding_scheme == 2 and xx % 2 == 1 and zz == self.windings-1: + continue # leave out every last winding in every second layer 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 - if self.winding_offset: + if self.winding_scheme == 1 or self.winding_scheme == 2: if xx % 2 == 1: 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) - outer_raster[it] = [z_pos, R_pos] + #print(outer_raster[it]) it += 1 return outer_raster @@ -166,14 +176,14 @@ class BCoil: # TODO: Less important, but rastering for round wires could be improved if raster_value == 0: raster_value = 1 - log.warning("raster value is 0 increased to 1") + log.info("raster value is 0 increased to 1") if raster_value == 1: return [0,0] if self.is_round & (raster_value % 2 == 0): raster_value += 1 - log.warning(f"for round wire rastering works better with uneven rastering value --> rastering value set to: {raster_value}") + log.info(f"for round wire rastering works better with uneven rastering value --> rastering value set to: {raster_value}") inner_raster = np.zeros((raster_value ** 2, 2)) it = 0 @@ -206,6 +216,7 @@ 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)) @@ -226,6 +237,7 @@ class BCoil: plt.scatter(full_structure[:, :, 1], full_structure[:, :, 0], linewidths=0.001) plt.xlabel("radius [mm]") plt.ylabel("z position [mm]") + plt.axvline(x=self.get_R_inner()*1e3-0.1, lw = 5,color = "red") 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) @@ -627,15 +639,20 @@ class BCoil: def main(): - HH_Coil = BCoil(HH=-1, distance=50, radius=40, layers=8, windings=8, wire_height=0.5, wire_width=0.4, - insulation_thickness=0.2, is_round = True, winding_offset=True) + HH_Coil = BCoil(HH=-1, distance=50, radius=40, layers=7, windings=7, wire_height=0.5, wire_width=0.5, + insulation_thickness=0.1, is_round = True, winding_scheme=2) + #HH_Coil.get_coil_width() #ras = HH_Coil.full_raster(raster_value = 3) # print(HH_Coil.is_round) - HH_Coil.plot_raster(10) + #print(HH_Coil.winding_raster()) - HH_Coil.B_quick_plot(1.25, abs = False) - HH_Coil.B_grad_quick_plot(1.25) - HH_Coil.B_curv_quick_plot(1.25) + + HH_Coil.plot_raster(30) + print(HH_Coil.get_N()) + # + # HH_Coil.B_quick_plot(1.25, abs = False) + # HH_Coil.B_grad_quick_plot(1.25) + # HH_Coil.B_curv_quick_plot(1.25) # if True & 1 == 1: # print("test") #print(ras) @@ -656,5 +673,5 @@ def main(): #main() if __name__ == "__main__": - print("g") + log.info("Run main Coil class") main() diff --git a/untitled0.py b/untitled0.py index 87ed634..fa5a5c1 100644 --- a/untitled0.py +++ b/untitled0.py @@ -6,6 +6,20 @@ Created on Fri Oct 1 10:42:13 2021 """ import numpy as np -print(np.sqrt(0.2)) +a = np.ones(50) -print(0.56*8+ 0.1*4.48) \ No newline at end of file +for i in range(0,len(a)): + a[i] *= i + +print(a) + +print(a[:5]) +print(a[5:]) +print(a[:-5]) + +print(10e-3/13.7) + +a = 7 + +if (a == (7 or 3)): + print("true") \ No newline at end of file