From 21bba550911e9144d5c6cce4fba04fc4cc3d6e8f Mon Sep 17 00:00:00 2001 From: schoener Date: Fri, 22 Oct 2021 18:53:04 +0200 Subject: [PATCH] Checked class until line 552 Added plot functions --- Coil_geometry/01_geometry_HH.py | 2 +- ...y_AHH_Try_inside_of_HH_for_compensation.py | 4 +- Coil_geometry/05_try_diff_geometry_HH1.py | 2 +- Coil_geometry/06_only_geometry_AHH.py | 8 +- Coil_geometry/Untitled.ipynb | 2 +- Coil_geometry_AHH/01_geometry_fixed_AHH.py | 4 +- ...02_geometry_fixed_search_distance_plots.py | 18 ++-- ...iteratively_find_exact_d_3rd_derivative.py | 12 +-- Coil_geometry_AHH/04_final_AHH_coil.py | 4 +- ...rison_opt_AHH_vs_not_cutting_optical_ax.py | 10 +-- .../06_surface_calculation_AHH.py | 4 +- .../07_final_AHH_lowered height.py | 4 +- Coil_geometry_AHH/11_Final_HH.py | 2 +- Coil_geometry_AHH/Untitled.ipynb | 2 +- Test_class.py | 2 +- Test_class1.py | 2 +- src/coil_class.py | 84 ++++++++++++------- 17 files changed, 93 insertions(+), 73 deletions(-) diff --git a/Coil_geometry/01_geometry_HH.py b/Coil_geometry/01_geometry_HH.py index 60f91b2..3a58186 100644 --- a/Coil_geometry/01_geometry_HH.py +++ b/Coil_geometry/01_geometry_HH.py @@ -53,7 +53,7 @@ HH_Coil_54.cooling(5) #Compensation Coil HH_Coil_78 = BC.BCoil(1,54,37,4, 4, 1,1) -#HH_Coil_44.Bz_plot_HH(I,x,z) +#HH_Coil_44.B_quick_plot(I,x,z) #HH_Coil_44.Bz_plot_HH_comp(HH_Coil_54,I,x,z) diff --git a/Coil_geometry/02_geometry_AHH_Try_inside_of_HH_for_compensation.py b/Coil_geometry/02_geometry_AHH_Try_inside_of_HH_for_compensation.py index c1ce6a8..301cbb9 100644 --- a/Coil_geometry/02_geometry_AHH_Try_inside_of_HH_for_compensation.py +++ b/Coil_geometry/02_geometry_AHH_Try_inside_of_HH_for_compensation.py @@ -32,8 +32,8 @@ B_z,B_x = HH_Coil_78.B_field(1, x, z) #x = np.concatenate((-np.flip(r),r)) -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) #plt.rcParams.update({'font.size': 15}) plt.suptitle("Anti Helmholtz coil field, I = 1 A, d = 54 mm, R = 37 mm ", fontsize = 30) diff --git a/Coil_geometry/05_try_diff_geometry_HH1.py b/Coil_geometry/05_try_diff_geometry_HH1.py index 5614c00..77143d1 100644 --- a/Coil_geometry/05_try_diff_geometry_HH1.py +++ b/Coil_geometry/05_try_diff_geometry_HH1.py @@ -57,7 +57,7 @@ HH_Coil_comp = BC.BCoil(HH = 1, distance = 54 ,radius = 37, layers = 4, windings -#HH_Coil_44.Bz_plot_HH(I,x,z) +#HH_Coil_44.B_quick_plot(I,x,z) #HH_Coil_44.Bz_plot_HH_comp(HH_Coil_54,I,x,z) diff --git a/Coil_geometry/06_only_geometry_AHH.py b/Coil_geometry/06_only_geometry_AHH.py index 2e410bd..ebf81a0 100644 --- a/Coil_geometry/06_only_geometry_AHH.py +++ b/Coil_geometry/06_only_geometry_AHH.py @@ -30,8 +30,8 @@ AHH_Coil.set_R_outer(49.3) #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) +#B_z_grad = BC.BCoil.grad(B_z, z) +#B_x_grad = BC.BCoil.grad(B_x,x) plt.figure(1,figsize=(10,13)) #plt.rcParams.update({'font.size': 15}) @@ -53,8 +53,8 @@ B_z,B_x = AHH_Coil.B_field(10, x, z) #B_z = B[:,150,1] #B_x = B[150,:,0] -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) plt.subplot(2,1,1) diff --git a/Coil_geometry/Untitled.ipynb b/Coil_geometry/Untitled.ipynb index a97bb14..1d87220 100644 --- a/Coil_geometry/Untitled.ipynb +++ b/Coil_geometry/Untitled.ipynb @@ -45,7 +45,7 @@ "\n", "\n", "\n", - "#HH_Coil_44.Bz_plot_HH(I,x,z)\n" + "#HH_Coil_44.B_quick_plot(I,x,z)\n" ] }, { diff --git a/Coil_geometry_AHH/01_geometry_fixed_AHH.py b/Coil_geometry_AHH/01_geometry_fixed_AHH.py index 80ef3fd..aa5155f 100644 --- a/Coil_geometry_AHH/01_geometry_fixed_AHH.py +++ b/Coil_geometry_AHH/01_geometry_fixed_AHH.py @@ -41,8 +41,8 @@ B_z,B_x = AHH_Coil.B_field(I, x, z) B_tot_z, B_tot_x = AHH_Coil.B_tot_along_axis(I, x, z) -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) lim = 7000 B_0 = B_z_grad[5000] diff --git a/Coil_geometry_AHH/02_geometry_fixed_search_distance_plots.py b/Coil_geometry_AHH/02_geometry_fixed_search_distance_plots.py index 0b79aa8..078d9fc 100644 --- a/Coil_geometry_AHH/02_geometry_fixed_search_distance_plots.py +++ b/Coil_geometry_AHH/02_geometry_fixed_search_distance_plots.py @@ -44,8 +44,8 @@ B_z,B_x = AHH_Coil.B_field(I, x, z) B_tot_z, B_tot_x = AHH_Coil.B_tot_along_axis(I, x, z) -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) # lim = 7000 # B_0 = B_z_grad[5000] @@ -58,14 +58,14 @@ 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_field(I, x, z) - B_z_grad = BC.BCoil.Bgrad(B_z, z) - B_x_grad = BC.BCoil.Bgrad(B_x,x) + B_z_grad = BC.BCoil.grad(B_z, z) + B_x_grad = BC.BCoil.grad(B_x, x) - B_z_curv = BC.BCoil.Bgrad(B_z_grad, z) - B_x_curv = BC.BCoil.Bgrad(B_z_grad, z) + B_z_curv = BC.BCoil.grad(B_z_grad, z) + B_x_curv = BC.BCoil.grad(B_z_grad, z) - B_z_3rd = BC.BCoil.Bgrad(B_z_curv, z) - B_x_3rd = BC.BCoil.Bgrad(B_z_curv, z) + B_z_3rd = BC.BCoil.grad(B_z_curv, z) + B_x_3rd = BC.BCoil.grad(B_z_curv, z) plt.subplot(2,2,1) @@ -89,7 +89,7 @@ for d in distance: plt.subplot(2,2,3) plt.title("Curvature") plt.plot(z,B_z_curv,linestyle = "solid", label = f"$ d = {d} mm") - #plt.plot(x,B_x_curv, label = f"Curv. $B_x$, d = {d} mm") + #plt.plot(x,B_x_curv, label = f"curv. $B_x$, d = {d} mm") plt.title("B-field" ) plt.ylabel(r"$B$ [G/cm^2]") diff --git a/Coil_geometry_AHH/03_iteratively_find_exact_d_3rd_derivative.py b/Coil_geometry_AHH/03_iteratively_find_exact_d_3rd_derivative.py index 87ea825..fec6443 100644 --- a/Coil_geometry_AHH/03_iteratively_find_exact_d_3rd_derivative.py +++ b/Coil_geometry_AHH/03_iteratively_find_exact_d_3rd_derivative.py @@ -38,14 +38,14 @@ print(f"R (30 degree C)= {AHH_Coil.resistance(30)}") 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) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) -B_z_curv = BC.BCoil.Bgrad(B_z_grad, z) -B_x_curv = BC.BCoil.Bgrad(B_z_grad, z) +B_z_curv = BC.BCoil.grad(B_z_grad, z) +B_x_curv = BC.BCoil.grad(B_z_grad, z) -B_z_3rd = BC.BCoil.Bgrad(B_z_curv, z) -B_x_3rd = BC.BCoil.Bgrad(B_z_curv, z) +B_z_3rd = BC.BCoil.grad(B_z_curv, z) +B_x_3rd = BC.BCoil.grad(B_z_curv, z) diff --git a/Coil_geometry_AHH/04_final_AHH_coil.py b/Coil_geometry_AHH/04_final_AHH_coil.py index 4a39347..b8c23df 100644 --- a/Coil_geometry_AHH/04_final_AHH_coil.py +++ b/Coil_geometry_AHH/04_final_AHH_coil.py @@ -54,8 +54,8 @@ B_z,B_x = AHH_Coil.B_field(I, x, z) B_tot_z, B_tot_x = AHH_Coil.B_tot_along_axis(I, x, z) -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) lim = 7000 B_0 = B_z_grad[5000] diff --git a/Coil_geometry_AHH/05_comparison_opt_AHH_vs_not_cutting_optical_ax.py b/Coil_geometry_AHH/05_comparison_opt_AHH_vs_not_cutting_optical_ax.py index e63ddc5..2171105 100644 --- a/Coil_geometry_AHH/05_comparison_opt_AHH_vs_not_cutting_optical_ax.py +++ b/Coil_geometry_AHH/05_comparison_opt_AHH_vs_not_cutting_optical_ax.py @@ -53,11 +53,11 @@ Bz_comp, Bx_comp = AHH_comp.B_field(I, x, z) #B_x = B[150,:,0] #B_tot_z, B_tot_x = AHH_Coil.B_tot_along_axis(I, x, z) -Bz_grad_opt = BC.BCoil.Bgrad(Bz_opt, z) -Bx_grad_opt = BC.BCoil.Bgrad(Bx_opt,x) +Bz_grad_opt = BC.BCoil.grad(Bz_opt, z) +Bx_grad_opt = BC.BCoil.grad(Bx_opt, x) -Bz_grad_comp = BC.BCoil.Bgrad(Bz_comp, z) -Bx_grad_comp = BC.BCoil.Bgrad(Bx_comp,x) +Bz_grad_comp = BC.BCoil.grad(Bz_comp, z) +Bx_grad_comp = BC.BCoil.grad(Bx_comp, x) Bz_rel_opt = (Bz_grad_opt[zr]- Bz_grad_opt)/Bz_grad_opt[zr]*100 Bx_rel_opt = (Bx_grad_opt[zr]- Bx_grad_opt)/Bx_grad_opt[zr]*100 @@ -103,7 +103,7 @@ plt.plot(z,Bz_rel_comp,linestyle = "solid",color = "blue", label = f"$B_z$, d = plt.plot(x,Bx_rel_opt,linestyle = "dashed",color = "orange", label = f"$B_x$, d = {d_opt} mm") plt.plot(x,Bx_rel_comp, linestyle = "dashed",color = "blue", label = f"$B_x$, d = {d_comp} mm") -plt.ylabel(r"rel. Deviation from Grad to center [%]$") +plt.ylabel(r"rel. Deviation from grad to center [%]$") plt.xlabel("z-axis /x-axis [mm]")#plt.xlim(-10,10) #plt.title(r"$\nabla_i B_i") #plt.ylim(-0.05,0.05) diff --git a/Coil_geometry_AHH/06_surface_calculation_AHH.py b/Coil_geometry_AHH/06_surface_calculation_AHH.py index 8df7a6d..0baa2da 100644 --- a/Coil_geometry_AHH/06_surface_calculation_AHH.py +++ b/Coil_geometry_AHH/06_surface_calculation_AHH.py @@ -54,8 +54,8 @@ B_z,B_x = AHH_Coil.B_field(I, x, z) B_tot_z, B_tot_x = AHH_Coil.B_tot_along_axis(I, x, z) -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) lim = 7000 B_0 = B_z_grad[5000] diff --git a/Coil_geometry_AHH/07_final_AHH_lowered height.py b/Coil_geometry_AHH/07_final_AHH_lowered height.py index 3450e09..d927ed4 100644 --- a/Coil_geometry_AHH/07_final_AHH_lowered height.py +++ b/Coil_geometry_AHH/07_final_AHH_lowered height.py @@ -54,8 +54,8 @@ B_z,B_x = AHH_Coil.B_field(I, x, z) B_tot_z, B_tot_x = AHH_Coil.B_tot_along_axis(I, x, z) -B_z_grad = BC.BCoil.Bgrad(B_z, z) -B_x_grad = BC.BCoil.Bgrad(B_x,x) +B_z_grad = BC.BCoil.grad(B_z, z) +B_x_grad = BC.BCoil.grad(B_x, x) lim = 7000 B_0 = B_z_grad[5000] diff --git a/Coil_geometry_AHH/11_Final_HH.py b/Coil_geometry_AHH/11_Final_HH.py index a0a8217..57e3611 100644 --- a/Coil_geometry_AHH/11_Final_HH.py +++ b/Coil_geometry_AHH/11_Final_HH.py @@ -33,7 +33,7 @@ Bz, Bx = HH_Coil.B_field(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) +Bz = BC.BCoil.grad(Bz, z) HH_Coil.cooling(I_current,28) print(f"B_z(0) = {Bz[15000]} G") diff --git a/Coil_geometry_AHH/Untitled.ipynb b/Coil_geometry_AHH/Untitled.ipynb index a97bb14..1d87220 100644 --- a/Coil_geometry_AHH/Untitled.ipynb +++ b/Coil_geometry_AHH/Untitled.ipynb @@ -45,7 +45,7 @@ "\n", "\n", "\n", - "#HH_Coil_44.Bz_plot_HH(I,x,z)\n" + "#HH_Coil_44.B_quick_plot(I,x,z)\n" ] }, { diff --git a/Test_class.py b/Test_class.py index f077595..f181124 100644 --- a/Test_class.py +++ b/Test_class.py @@ -48,7 +48,7 @@ HH_Coil1 = BC.BCoil(HH, d_coils ,R_mid, layers, windings, wire_width, wire_heigh #B_x = np.concatenate((-np.flip(B_r),B_r[1:len(B_r)])) -HH_Coil1.Bz_plot_HH(I,x,z) +HH_Coil1.B_quick_plot(I, x, z) diff --git a/Test_class1.py b/Test_class1.py index 5c5b647..b621a41 100644 --- a/Test_class1.py +++ b/Test_class1.py @@ -38,7 +38,7 @@ HH_Coil_44 = BC.BCoil(HH, d_coils ,R_mid, layers, windings, wire_width, wire_hei d_coils_2 = 55.2 HH_Coil_54 = BC.BCoil(HH, d_coils_2 ,R_mid, layers, windings, wire_width, wire_height) -#HH_Coil_44.Bz_plot_HH(I,x,z) +#HH_Coil_44.B_quick_plot(I,x,z) #HH_Coil_44.Bz_plot_HH_comp(HH_Coil_54,I,x,z) diff --git a/src/coil_class.py b/src/coil_class.py index c5578de..b14a980 100644 --- a/src/coil_class.py +++ b/src/coil_class.py @@ -461,43 +461,59 @@ class BCoil: plt.ylabel("z-axis [mm]") plt.show() - def curv(B_field, z): - return np.gradient(np.gradient(B_field, z), z) * 1e2 + def curv(B_f, z): + return np.gradient(np.gradient(B_f, z), z) * 1e2 - def Bgrad(B_field, z): - return np.gradient(B_field, z) * 1e1 + def grad(B_f, z): + return np.gradient(B_f, z) * 1e1 - def Bz_plot_HH(self, I_current, x, z): - B_z, B_x = self.B_field(I_current, x, z) + def B_quick_plot(self, I_current, abs = True, x_lim = 50, z_lim = 50, nr_points = 500): + x = np.linspace(-x_lim, x_lim, nr_points) + z = np.linspace(-z_lim, z_lim, nr_points) + if abs: + B_z, B_x = self.B_tot_along_axis(I_current, x, z) + else: + B_z, B_x = self.B_field(I_current, x, z) - B_z_curvature = np.gradient(np.gradient(B_z, z), z) - - plt.figure(100, figsize=(13, 10)) - - # plt.rcParams.update({'font.size': 15}) - plt.suptitle("Helmholtz coil field B_z along z-axis") - - # Field plot - ########################## - plt.subplot(2, 1, 1) - plt.plot(z, B_z, linestyle="solid", label=r"$B_z$: Result via elliptic integrals") - - # plt.xlim(-0.01,0.01) + plt.plot(z, B_z, linestyle="solid", label=r"$B_{tot}$ along z-axis") + plt.plot(x, B_x, label = r"$B_{tot}$ along x-axis") plt.title("B-field") - - plt.ylabel(r"$B_z$ [G]") - plt.xlabel("z-axis [mm]") + plt.ylabel(r"B-field [G]") + plt.xlabel("x-axis / z-axis [mm]") plt.legend() + plt.show() - plt.subplot(2, 1, 2) - plt.plot(z, B_z_curvature, linestyle="solid", label=r"$\nabla_z^2 B_z$: Result via elliptic integrals") + def B_grad_quick_plot(self, I_current, x_lim = 50, z_lim = 50, nr_points = 500): + x = np.linspace(-x_lim, x_lim, nr_points) + z = np.linspace(-z_lim, z_lim, nr_points) - plt.ylabel(r"$\nabla_z^2 B_z [G/cm^2]$") - plt.xlabel("z-axis [mm]") - plt.xlim(-10, 10) - plt.title("Curvature of B-field") - plt.legend(loc='lower right') + B_z, B_x = self.B_field(I_current, x, z) + # TODO: Think about Gradient calculation of tot B_field + B_z = BCoil.grad(B_z, z) + B_x = BCoil.grad(B_x, x) + plt.plot(z, B_z, linestyle="solid", label=r"$B_{tot}$ along z-axis") + plt.plot(x, B_x, label=r"$B_{tot}$ along x-axis") + plt.title("Gradient of B-field") + plt.ylabel(r"B-field [G]") + plt.xlabel("x-axis / z-axis [mm]") + plt.legend() + plt.show() + + def B_curv_quick_plot(self, I_current, x_lim=50, z_lim=50, nr_points=500): + x = np.linspace(-x_lim, x_lim, nr_points) + z = np.linspace(-z_lim, z_lim, nr_points) + + B_z, B_x = self.B_field(I_current, x, z) + B_z = BCoil.curv(B_z, z) + B_x = BCoil.curv(B_x, x) + + plt.plot(z, B_z, linestyle="solid", label=r"$B_{tot}$ along z-axis") + plt.plot(x, B_x, label=r"$B_{tot}$ along x-axis") + plt.title("B-field") + plt.ylabel(r"B-field [G]") + plt.xlabel("x-axis / z-axis [mm]") + plt.legend() plt.show() def Bz_plot_HH_comp(self, Coil2, I_current, x, z): @@ -601,11 +617,15 @@ class BCoil: def main(): - HH_Coil = BCoil(HH=1, distance=50, radius=40, layers=8, windings=3, wire_height=0.4, wire_width=0.4, + HH_Coil = BCoil(HH=-1, distance=50, radius=40, layers=8, windings=8, wire_height=0.4, wire_width=0.4, insulation_thickness=0.2, is_round = True, winding_offset=True) #ras = HH_Coil.full_raster(raster_value = 3) # print(HH_Coil.is_round) - HH_Coil.plot_raster(4) + #HH_Coil.plot_raster(4) + + HH_Coil.B_quick_plot(1.25, abs = True) + HH_Coil.B_grad_quick_plot(1.25) + #HH_Coil.B_curv_quick_plot(1.25) # if True & 1 == 1: # print("test") #print(ras) @@ -622,7 +642,7 @@ def main(): # # HH_Coil.plot_raster(3) # ras = HH_Coil.full_raster(10) - HH_Coil.plot_3d(1.25,50,50) + #HH_Coil.plot_3d(1.25,50,50) main() # if __name__ == "__main__":