# -*- coding: utf-8 -*-
"""
Created on Tue Sep  7 13:18:18 2021

@author: Joschka
"""

import matplotlib.pyplot as plt
import numpy as np

from src import coil_class as BC

from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'qt')

I = 10

HH_Coil = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 4, windings = 2, wire_height = 2, wire_width = 1,windings_spacing=0.25, layers_spacing = 0.25)
HH_Coil.set_R_outer(49.3)
HH_Coil.set_d_min(49.8)
HH_Coil.print_info()
HH_Coil.cooling(I,20)
print(f"length = {HH_Coil.get_wire_length()}")


Fast_Coil = BC.BCoil(HH = 1, distance = 54 ,radius = 48 , layers = 8, windings = 8, wire_height =0.5, wire_width = 0.5,windings_spacing=0, layers_spacing = 0)
Fast_Coil.set_R_outer(49.3)
Fast_Coil.set_d_min(49.8)

Ilz_Coil = BC.BCoil(HH = 1, distance = 70 ,radius = 40.5 , layers = 6, windings = 1, wire_height = 2.7, wire_width = 1,windings_spacing=0.25, layers_spacing = 0.25)
Ilz_Coil.set_R_inner(40.5)
Ilz_Coil.print_info()

L = HH_Coil.inductivity()

R = HH_Coil.resistance(20)

HH_Coil.cooling(I,22)

#AHH_Coil = BC.BCoil(-1, 82 , 47.3 , 4, 6, wire_width= 1, wire_height= 1.5 ,layers_spacing = 0.25, windings_spacing= 0.25)

def I_current(Coil, I_0, t):
    L = Coil.induct_perry()
    
    #L = Coil.inductivity()
    R = Coil.resistance(22.5)
    print(f"L={L}")
    print(f" R= {R}")
    tau = L/R
    print(f" τ = {tau}")
    I = I_0 * (1-np.exp(-R/L * t))
    return I

def I_current_exp(I_0,R,L,t):
    print("")
    print(L/R)
    I = I_0* (1-np.exp(-R/L * t))
    return I

t = np.linspace(0,0.005,1000)
plt.title("time response")
plt.plot(t*1e3,I_current(HH_Coil,I,t),label = "I_max = 10 A, 2 x 4")
plt.plot(t*1e3,8*I_current(Fast_Coil,10/8,t),label =  "I_max = 10/8 A, 8 x 8")
#plt.plot(t*1e3,I_current(Ilz_Coil,I,t),label =  "Ilz theo")
#plt.plot(t*1e3,I_current_exp(I,42e-3,14e-6,t),label =  "Ilz exp")
#plt.plot(t*1e3,I_current_exp(I,0.85,3.75e-3,t),label =  "Paper: Fast switching")

plt.xlabel("time [ms]")
plt.ylabel("current I [A]")
plt.legend()
plt.show()

print(Fast_Coil.power(10/8,22))

print(Fast_Coil.resistance(22))