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

@author: Joschka
"""

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

scale = 1000
lim = 1
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):
    step =
    it = nr_points//2 + x_pos
    return it


#Wire_1 = [0.45, 0.514]
#Wire_1 = [0.475, 0.543]
#Wire_1 = [0.5, 0.568]

Wires = [[0.45, 0.514],[0.475, 0.543],[0.5, 0.568]]

for i in range(0,2):
    Wire_1 = Wires[i]
    print(f"Wire core = {Wire_1[0]} mm:")
    print(" ")
    for ll in [8,10]:
        for ww in [8,9]:
            print(f"layers = {ll}, windings = {ww}")
            Coil_1 = BC.BCoil(HH = 1, distance = 54, radius = 48, layers = ll, windings = ww, 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)

            #set radius plus distance
            Coil_1.set_R_outer(50.5-Coil_1.get_tot_wire_width()*1e3)

            Coil_1.set_d_min(47.15)
            #Coil_1.print_info()


            print(f"    Coil crossection area = {Coil_1.get_coil_width() * 1e3 * Coil_1.get_coil_height() * 1e3} mm2")
            print(f"    H = {Coil_1.get_coil_height() * 1e3}, W = {Coil_1.get_coil_width() * 1e3}")

            I = 64 / Coil_1.get_N() * 1.25
            #I = 1
            print(f"    Current needed for 13.8 G: I = {I} A")
            Coil_1.cooling(I, 22.5)

            Bz, Bx = Coil_1.B_field(I, x, z, raster = 7)
            Bz_curv = BC.BCoil.curv(Bz,z)
            zero = mu_it(0)

            print(f"    Curvature = {Bz_curv[zero]:.4f} G/mm^2, B(0) = {Bz[zero]:.4f}")
            print(f"ratio Power/Curvature: {Coil_1.power(I,22.5) *  Bz_curv[zero]}")
            print(" ")



