import matplotlib.pyplot as plt
import numpy as np
import matplotlib
#matplotlib.use('Qt5Agg')
from src import coil_class as BC

scale = 1000
lim = 15
nr_points = (2 * lim) * scale + 1
x = np.linspace(-lim,lim,nr_points)
z = np.linspace(-lim,lim,nr_points)

def mu_it(x_pos):
    it = nr_points//2 + x_pos
    return it


Wire_1 = [0.5, 0.568]

#I_current = 0.94
HH_Coil = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = 16, windings = 16, wire_height = Wire_1[0],
                   wire_width = Wire_1[0], insulation_thickness=(Wire_1[1] - Wire_1[0]) / 2, is_round = True,
                   winding_scheme= 2)


print(f"HH N = {HH_Coil.get_N()}")
I_current = 2

# set radius plus distance
HH_Coil.set_R_inner(34.83)
HH_Coil.set_d_min(177.2)

#x_lim = 50
#z_lim = 50
#nr_points = 200
#x = np.linspace(-x_lim, x_lim, nr_points)
#z = np.linspace(-z_lim, z_lim, nr_points)

Bz, B_x = HH_Coil.B_tot_along_axis(I_current, x, z, raster = 3)
Bz_curv = BC.BCoil.curv(Bz,z)

plt.figure(11)
plt.plot(z, Bz, linestyle="solid", label=r"$B_{tot}$ along x-axis")
plt.plot(x, B_x, label=r"$B_{tot}$ along y/z-axis")
plt.title("B-field, Coil along x - axis")
plt.ylabel(r"B-field [G]")
plt.xlabel("x-axis / z-axis [mm]")
plt.legend()
plt.show()

print(f"B_z(0) = {Bz[15000]} G")
print(f"B_z_curvature(0) = {Bz_curv[15000]:.10f} G/cm^2")


print(f"B_z(1 μm) = {Bz[15001]}")
print(f"B_z(1 mm) = {Bz[16000]}")

print(f"Diff B 1 μm: {Bz[15001] - Bz[15000]}, relative: {(Bz[15001] - Bz[15000])/Bz[15000]}")

print(f"Diff B 0.5 mm: {Bz[15500] - Bz[15000]}, relative: {(Bz[15500] - Bz[15000])/Bz[15000]}")

print(f"Diff B 1 mm: {Bz[16000] - Bz[15000]}, relative: {(Bz[16000] - Bz[15000])/Bz[15000]}")


print(f"Diff B 15 mm: {Bz[30000] - Bz[15000]}, relative: {(Bz[30000] - Bz[15000])/Bz[15000]}")


HH_Coil.cooling(I_current,25)
HH_Coil.print_info()
#HH_Coil.B_curv_quick_plot(I_current)
#HH_Coil.plot_raster()

