From 7dc0bf1c78c6799d61bffa8c437382eb41acd399 Mon Sep 17 00:00:00 2001 From: schoener Date: Fri, 3 Dec 2021 12:09:23 +0100 Subject: [PATCH] new calculations --- Coil_geometry/01_FINAL_coil_max_current.py | 7 ++- .../Export_field/01_Export_quarter_radial.py | 45 ++++++++------- .../Export_field/02_plotting_data.py | 9 +-- .../Export_field/03_B_quarter_to_field.py | 30 ++-------- .../Export_field/04_B_cart_to_B_field.py | 56 +++++++++++++++++++ Coil_geometry/Export_field/04_Write_to_txt.py | 22 -------- Coil_geometry/Export_field/05_Write_to_txt.py | 30 ++++++++++ untitled0.py | 5 +- 8 files changed, 128 insertions(+), 76 deletions(-) create mode 100644 Coil_geometry/Export_field/04_B_cart_to_B_field.py delete mode 100644 Coil_geometry/Export_field/04_Write_to_txt.py create mode 100644 Coil_geometry/Export_field/05_Write_to_txt.py diff --git a/Coil_geometry/01_FINAL_coil_max_current.py b/Coil_geometry/01_FINAL_coil_max_current.py index bd7b5d3..ae616bf 100644 --- a/Coil_geometry/01_FINAL_coil_max_current.py +++ b/Coil_geometry/01_FINAL_coil_max_current.py @@ -24,6 +24,9 @@ HH_Coil = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 8, windings = 8, wire_width = Wire_1[0], insulation_thickness=(Wire_1[1] - Wire_1[0]) / 2, is_round = True, winding_scheme= 2) -R = HH_Coil.resistance(150) +R = HH_Coil.resistance(25) -print(2400/R) \ No newline at end of file +I = 2 +print(f"U ={I*R*2}") + +print(f"resistance {R}") \ No newline at end of file diff --git a/Coil_geometry/Export_field/01_Export_quarter_radial.py b/Coil_geometry/Export_field/01_Export_quarter_radial.py index d42080e..cdac23e 100644 --- a/Coil_geometry/Export_field/01_Export_quarter_radial.py +++ b/Coil_geometry/Export_field/01_Export_quarter_radial.py @@ -8,6 +8,7 @@ import matplotlib.pyplot as plt from src import coil_class as BC from src import physical_constants as cs import logging as log +import time log.basicConfig(level=log.DEBUG, format='%(message)s') @@ -18,7 +19,7 @@ def main(): x, z = BC.BCoil.make_axis(50, 5) - I_current = 5 + I_current = 0.3804 # print(BC.BCoil._BCoil__B_z_loop(I_current = I, r_loop = 1, z_loop = 1, r_pos = 0, z_pos = 0.1) @@ -27,7 +28,7 @@ def main(): # - BC.BCoil._BCoil__B_z_loop(I_current=I, r_loop=1, z_loop=-1, r_pos=0, z_pos=-0.1)) - step = 5 + step = 0.05 xlim_mm = 30 xlim = int(xlim_mm/step) + 1 ylim_mm = 30 @@ -35,37 +36,39 @@ def main(): zlim_mm = 20 zlim = int(zlim_mm/step) + 1 - B_quarter = np.zeros((xlim, ylim, zlim, 2)) + B_quarter = np.zeros((xlim, ylim, zlim, 2),dtype= np.float32) + print(np.shape(B_quarter)) #print(B_quarter) x = np.linspace(0,xlim_mm,xlim) * 1e-3 y = np.linspace(0,ylim_mm,ylim) * 1e-3 z = np.linspace(0,zlim_mm,zlim) * 1e-3 calc_raster = AHH_Coil.full_raster(1) - rastering_value = len(calc_raster[0]) - I_current /= rastering_value + start = time.time() for wire in range(0,AHH_Coil.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] - for xx in range(0,xlim): - for yy in range(0,ylim): + print(f"time = {(time.time()-start)/60} min") + print(f"wire = {wire} of {AHH_Coil.get_N()}") - r = np.sqrt(x[xx]**2 + y[yy]**2) + # extract position information out of raster + z_pos = calc_raster[wire, 0, 0] + r_pos = calc_raster[wire, 0, 1] + for xx in range(0, xlim): + for yy in range(0, ylim): - # calculate z-component at x,y - B_quarter[xx, yy, :, 1] += BC.BCoil._BCoil__B_z_loop(I_current, r_pos, z_pos, r, z) \ - + BC.BCoil._BCoil__B_z_loop(AHH_Coil.HH * I_current, r_pos, -z_pos, r, z) + r = np.sqrt(x[xx]**2 + y[yy]**2) - if r == 0: - continue - # calculate r-component at x, y - B_quarter[xx, yy, :, 0] += BC.BCoil._BCoil__B_r_loop(I_current, r_pos, z_pos, r, z) \ - + BC.BCoil._BCoil__B_r_loop(AHH_Coil.HH * I_current, r_pos, -z_pos, r, z) + # calculate z-component at x,y + B_quarter[xx, yy, :, 1] += BC.BCoil._BCoil__B_z_loop(I_current, r_pos, z_pos, r, z) \ + + BC.BCoil._BCoil__B_z_loop(AHH_Coil.HH * I_current, r_pos, -z_pos, r, z) - np.save('output/B_quarter_step_5.npy', B_quarter) + if r == 0: + continue + # calculate r-component at x, y + B_quarter[xx, yy, :, 0] += BC.BCoil._BCoil__B_r_loop(I_current, r_pos, z_pos, r, z) \ + + BC.BCoil._BCoil__B_r_loop(AHH_Coil.HH * I_current, r_pos, -z_pos, r, z) + + np.save('output/final/B_quarter_1Gcm.npy', B_quarter) #B_tot = np.zeros(((2 * xlim) - 1, (2 * ylim) - 1, (2 * zlim)-1, 2)) diff --git a/Coil_geometry/Export_field/02_plotting_data.py b/Coil_geometry/Export_field/02_plotting_data.py index 601cb55..ee3d7ba 100644 --- a/Coil_geometry/Export_field/02_plotting_data.py +++ b/Coil_geometry/Export_field/02_plotting_data.py @@ -11,7 +11,7 @@ def main(): wire_height=0.5, wire_width=0.5, insulation_thickness=0.068 / 2, is_round=True, winding_scheme=2) - step = 5 + step = 0.03 xlim_mm = 30 xlim = int(xlim_mm/step) + 1 ylim_mm = 30 @@ -29,9 +29,10 @@ def main(): z = np.linspace(-zlim_mm, zlim_mm, 2 *zlim - 1) * 1e-3 - # b_plot = np.load('output/B_quarter.npy') - b_raw = np.load('output/b_cart_1_step_5.npy') - b_raw = np.load('output/b_full_test.npy') + + b_plot = np.load('output/B_quarter.npy') + #b_raw = np.load('output/b_cart_1_step_5.npy') + #b_raw = np.load('output/b_full_test.npy') b_plot = np.swapaxes(b_raw,0,1) # Meshgrid uses different order of axis (y,x,z) # x_m, z_m = np.meshgrid(x, z) diff --git a/Coil_geometry/Export_field/03_B_quarter_to_field.py b/Coil_geometry/Export_field/03_B_quarter_to_field.py index 719560f..b68ca77 100644 --- a/Coil_geometry/Export_field/03_B_quarter_to_field.py +++ b/Coil_geometry/Export_field/03_B_quarter_to_field.py @@ -13,7 +13,7 @@ import logging as log def main(): - step = 5 + step = 0.05 xlim_mm = 30 xlim = int(xlim_mm / step) + 1 print(xlim) @@ -26,7 +26,7 @@ def main(): y = np.linspace(0, ylim_mm, ylim) * 1e-3 z = np.linspace(0, zlim_mm, zlim) * 1e-3 - b_qu_polar = np.load('output/B_quarter_step_5.npy') + b_qu_polar = np.load('output/final/B_quarter_1Gcm.npy') @@ -34,7 +34,7 @@ def main(): shape = np.shape(b_qu_polar) print(shape) new_shape = (shape[0], shape[1], shape[2], shape[3] + 1) - b_cart_1 = np.zeros(new_shape) + b_cart_1 = np.zeros(new_shape,dtype = np.float32) # add z-component b_cart_1[:, :, :, 2] = b_qu_polar[:, :, :, 1] @@ -48,28 +48,10 @@ def main(): b_cart_1[xx, yy, :, 0] = b_qu_polar[xx, yy, :, 0] * np.cos(phi) b_cart_1[xx, yy, :, 1] = b_qu_polar[xx, yy, :, 0] * np.sin(phi) - np.save('output/b_cart_1_step_5.npy', b_cart_1) + np.save('output/final/b_cart_1Gcm.npy', b_cart_1) + del b_qu_polar + del b_cart_1 - full_shape = (new_shape[0]*2 - 1, new_shape[1] * 2 - 1, new_shape[2] * 2 - 1, new_shape[3]) - b_full = np.zeros(full_shape) - - # fill first quarter - b_full[xlim-1:, ylim-1:, zlim-1:, :] = b_cart_1 - print(xlim-1) - - # mirror along y - z plane - b_full[:xlim-1, ylim-1:, zlim-1:, :] = b_cart_1[:0:-1, :, :, :] - b_full[:xlim-1, :, :, 0] *= - 1 - - # mirror along x - z plane - b_full[:, :ylim-1, zlim - 1:, :] = b_full[:, :ylim-1:-1 , zlim-1:, :] - b_full[:, :ylim-1, :, 1] *= -1 - - # mirror along x - y plane - b_full[:, :, :zlim-1, :] = b_full[:, :, :zlim-1 : -1, :] - b_full[:, :, :zlim-1, 2] *= -1 - - np.save('output/b_full_test.npy', b_full) if __name__ == '__main__': main() diff --git a/Coil_geometry/Export_field/04_B_cart_to_B_field.py b/Coil_geometry/Export_field/04_B_cart_to_B_field.py new file mode 100644 index 0000000..f2e0267 --- /dev/null +++ b/Coil_geometry/Export_field/04_B_cart_to_B_field.py @@ -0,0 +1,56 @@ +""" +Created on 11.11.21 + +@author: Joschka +""" +import numpy as np +import matplotlib.pyplot as plt +from src import coil_class as BC +from src import physical_constants as cs +import logging as log + + + + +def main(): + step = 0.05 + xlim_mm = 30 + xlim = int(xlim_mm / step) + 1 + print(xlim) + ylim_mm = 30 + ylim = int(ylim_mm / step) + 1 + zlim_mm = 20 + zlim = int(zlim_mm / step) + 1 + + x = np.linspace(0, xlim_mm, xlim) * 1e-3 + y = np.linspace(0, ylim_mm, ylim) * 1e-3 + z = np.linspace(0, zlim_mm, zlim) * 1e-3 + + + b_cart_1 = np.load('output/final/b_cart_1Gcm.npy') + + new_shape = np.shape(b_cart_1) + full_shape = (new_shape[0]*2 - 1, new_shape[1] * 2 - 1, new_shape[2] * 2 - 1, new_shape[3]) + + b_full = np.zeros(full_shape, dtype= np.float32) + + # fill first quarter + b_full[xlim-1:, ylim-1:, zlim-1:, :] = b_cart_1 + print(xlim-1) + + # mirror along y - z plane + b_full[:xlim-1, ylim-1:, zlim-1:, :] = b_cart_1[:0:-1, :, :, :] + b_full[:xlim-1, :, :, 0] *= - 1 + + # mirror along x - z plane + b_full[:, :ylim-1, zlim - 1:, :] = b_full[:, :ylim-1:-1 , zlim-1:, :] + b_full[:, :ylim-1, :, 1] *= -1 + + # mirror along x - y plane + b_full[:, :, :zlim-1, :] = b_full[:, :, :zlim-1 : -1, :] + b_full[:, :, :zlim-1, 2] *= -1 + + np.save('output/final/b_full.npy', b_full) + +if __name__ == '__main__': + main() diff --git a/Coil_geometry/Export_field/04_Write_to_txt.py b/Coil_geometry/Export_field/04_Write_to_txt.py deleted file mode 100644 index ebcfd74..0000000 --- a/Coil_geometry/Export_field/04_Write_to_txt.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -Created on 15.11.21 - -@author: Joschka -""" -import numpy as np - -def main(): - b_full = np.load('output/b_full_test.npy') - - bx_txt = open("output/Bx.txt", "w+") - xx = 0 - yy = 0 - str = np.array2string(b_full[xx, yy, :, 0]) - bx_txt.write(str) - - - - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/Coil_geometry/Export_field/05_Write_to_txt.py b/Coil_geometry/Export_field/05_Write_to_txt.py new file mode 100644 index 0000000..811e9d1 --- /dev/null +++ b/Coil_geometry/Export_field/05_Write_to_txt.py @@ -0,0 +1,30 @@ +""" +Created on 15.11.21 + +@author: Joschka +""" +import numpy as np +from scipy.io import savemat + +def main(): + # b_full = np.load('output/b_full_test.npy') + # + # bx_txt = open("output/Bx.txt", "w+") + # xx = 0 + # yy = 0 + # str = np.array2string(b_full[xx, yy, :, 0]) + # bx_txt.write(str) + b_full = np.load('output/final/b_full.npy') + # mdic = {"B": b_full} + # del b_full + + # savemat("b_full_matlab.mat",b_full) + + np.savetxt("b_x.csv", b_full[:,:,0,0]) + + + + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/untitled0.py b/untitled0.py index 4e6232e..2841415 100644 --- a/untitled0.py +++ b/untitled0.py @@ -9,9 +9,8 @@ import matplotlib.pyplot as plt def main(): - x = np.linspace(-10, 10, 21) - print(x) - print(x[:0:-1]) + print(2e8/4.9e-3) + #print(zlim*35921/(1024)**2)