commit 384d6d5cfbb6d54c02b351c4ca2d518b73b705cc
Author: Pedro Romero <promerogomb@unav.es>
Date:   Wed Mar 26 10:26:29 2025 +0100

    first commit

diff --git a/Ensayos.xlsx b/Ensayos.xlsx
new file mode 100644
index 0000000..800261b
Binary files /dev/null and b/Ensayos.xlsx differ
diff --git a/automation.py b/automation.py
new file mode 100644
index 0000000..565143d
--- /dev/null
+++ b/automation.py
@@ -0,0 +1,11 @@
+import numpy as np
+import pandas as pd
+import json
+import h5py
+
+pyenv("Version", "3.9", "ExecutionMode","OutOfProcess")
+pymotorcad = py.importlib.import_module('ansys.motorcad.core')
+
+pymotorcad.set_motorcad_exe('D:\Ansys_Motor-CAD\2024_2_2_1\Motor-CAD_2024_2_2_1.exe')
+
+mcApp=pymotorcad.MotorCAD()
\ No newline at end of file
diff --git a/ensayos_motor.py b/ensayos_motor.py
new file mode 100644
index 0000000..e7391a3
--- /dev/null
+++ b/ensayos_motor.py
@@ -0,0 +1,173 @@
+import numpy as np
+import pandas as pd
+import matplotlib.pyplot as plt
+import json
+
+def ensayo_vacio(V,f):
+
+    '''
+    Entrada:
+        V = {
+        'a': [datos]
+        'b': [datos]
+        'c': [datos]
+        }
+
+        f = [datos]
+    
+    Salida:
+        ke media por fase
+        ke por fase
+    '''
+
+    keA = []
+    keB = []
+    keC = []
+
+    for i in range(len(f)):
+
+        keA.append(V['a'][i]/f[i])
+        keB.append(V['b'][i]/f[i])
+        keC.append(V['c'][i]/f[i])
+    
+    keMedia = { 
+        'a': np.mean(keA),
+        'b' : np.mean(keB),
+        'c' : np.mean(keC)
+    }
+    ke = { 
+        'a': keA,
+        'b' : keB,
+        'c' : keC
+    }
+
+    return keMedia, ke
+
+def ensayo_corto(I, f, ke, R):
+    '''
+    Entrada:
+        I = {
+        'a': [datos]
+        'b': [datos]
+        'c': [datos]
+        }
+
+        f = [datos]
+
+        R = cte
+
+    Salida:
+        media induccion [mH]
+        todas las inducciones
+        coeficiente de variacion
+    '''
+    L = []
+    for i in range(len(f)):
+        xa = np.sqrt((ke['a']*f[i]/I['a'][i])**2 - R**2 )
+        xb = np.sqrt((ke['b']*f[i]/I['b'][i])**2 - R**2 )
+        xc = np.sqrt((ke['c']*f[i]/I['c'][i])**2 - R**2 )
+        
+        L.append(np.mean([xa,xb,xc]) / (2 * np.pi * f[i]) * 1e3)
+
+    return np.mean(L), np.array(L), np.std(L)/np.mean(L)*100
+
+
+def ensayo_carga(V, I, f, R, L):
+    '''
+    Entrada:
+        V = {
+        'a': [datos]
+        'b': [datos]
+        }
+
+        I = {
+        'a': [datos]
+        'b': [datos]
+        }
+
+        f = [datos]
+
+    '''
+    E = []
+    Ireal = []
+    for i in range(len(f)):
+        Vtemp = np.mean([V['a'][i], V['b'][i]])
+        Itemp = np.mean([I['a'][i], I['b'][i]])
+
+        Ireal.append(Itemp)
+        E.append(np.sqrt((R + Vtemp/Itemp) ** 2 + (2*np.pi*f[i]*L*1e-3) ** 2) * Itemp)
+
+        
+    return np.array(E), np.array(Ireal)
+
+if __name__ == '__main__':
+    archivo = 'Ensayos.xlsx'
+
+    vacio = pd.read_excel(archivo, sheet_name='vacio', engine='openpyxl').dropna()
+    corto = pd.read_excel(archivo, sheet_name='corto', engine='openpyxl').dropna()
+    carga = pd.read_excel(archivo, sheet_name='carga', engine='openpyxl').dropna()
+
+
+    resistencia = 4.5
+    materiales = np.unique(vacio['material'])
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111, projection='3d')
+
+    for material in materiales:
+        tensionVacio = {
+            'a' : np.array(vacio['V1'][vacio['material'] == material]),
+            'b' : np.array(vacio['V2'][vacio['material'] == material]),
+            'c' : np.array(vacio['V3'][vacio['material'] == material])
+        }
+        fVacio = np.array(vacio['f'][vacio['material'] == material])
+
+        keMedia, ke= ensayo_vacio(tensionVacio, fVacio)
+
+
+        corrienteCorto ={
+            'a' : np.array(corto['I1'][corto['material'] == material]),
+            'b' : np.array(corto['I2'][corto['material'] == material]),
+            'c' : np.array(corto['I3'][corto['material'] == material])
+        }
+        fCorto = np.array(corto['f'][corto['material'] == material])
+
+        lMedia, l, lCV = ensayo_corto(corrienteCorto, fCorto, keMedia, resistencia)
+
+
+        tensionCarga = {
+            'a' : np.array(carga['V1'][carga['material'] == material]),
+            'b' : np.array(carga['V2'][carga['material'] == material])
+        }
+        corrienteCarga = {
+            'a' : np.array(carga['I1'][carga['material'] == material]),
+            'b' : np.array(carga['I2'][carga['material'] == material])
+        }
+        fCarga = np.array(carga['f'][carga['material'] == material])
+
+        E, I = ensayo_carga(tensionCarga, corrienteCarga, fCarga, resistencia, lMedia)
+
+        ax.plot3D(I, fCarga, E, label = material)
+
+        if material == 'PLACOND':
+            datos = {
+                'E' : E.tolist(),
+                'I' : I.tolist(),
+                'f' : fCarga.tolist()
+            }
+            with open('resultados_ensayos.json', 'w') as f: json.dump(datos, f, indent=4)
+
+    ax.set_xlabel('Corriente [A]')
+    ax.set_ylabel('Frecuencia [Hz]')
+    ax.set_zlabel('Tension [V]')
+
+    Imax = np.max(I)
+    Emax = np.max(E)
+    fmax = np.max(fCarga)
+
+    ax.set_xlim(0, Imax * 1.1)
+    ax.set_ylim(0, fmax * 1.1)
+    ax.set_zlim(0, Emax * 1.1)
+
+    ax.legend()
+    plt.show()
\ No newline at end of file
diff --git a/genCurvas.py b/genCurvas.py
new file mode 100644
index 0000000..7455d0e
--- /dev/null
+++ b/genCurvas.py
@@ -0,0 +1,62 @@
+import numpy as np
+import pandas as pd
+import json
+
+def generar_curva(offset):
+    muVacio = 4 * np.pi * 1e-7
+
+    hPos = np.arange(1,5001,1)
+    hNeg = np.arange(-5000,0,1)
+    
+    bPos = muVacio*hPos + offset
+    bNeg = muVacio*hNeg - offset
+
+    h = np.concatenate((hNeg, hPos))
+    b = np.concatenate((bNeg, bPos))
+
+    return h, b
+
+if __name__ == '__main__':
+
+    with open('resultados_ensayos.json', 'r') as f: datos = json.load(f)
+
+    Eobjetivo = np.array(datos['E'])
+    Iobjetivo = np.array(datos['I'])
+    fObjetivo = np.array(datos['f'])
+
+    errorObjetivo = 0.01 # +- cuanto % puede haber de diferencia
+    limSup = 1 + errorObjetivo
+    limInf = errorObjetivo
+
+    offset = 0
+
+    flag = False
+
+    while flag:
+        h,b = generar_curva(offset)
+
+        datos = np.column_stack((h,b))
+
+        np.savetxt('curva.csv', datos, delimiter=',')
+        
+        ############################
+        '''
+        Logica de motorCAD-Pyhton, se sacaran unos vectores con 
+        corrientes, frecuencias y tensiones de operacion en 
+        distintos puntos con una curva dada. Esto se hara estableciendo
+        como fijo la frecuencia y la corriente, si se puede solo 
+        con frecuencia mejor. Se compara la tension (y corriente si no se fija)
+        con los valores objetivos.
+
+        '''
+        Ecalc = [1, 1, 1, 1, 1]
+
+        ############################
+
+        error = Ecalc / Eobjetivo
+
+
+
+
+
+
diff --git a/requirements.py b/requirements.py
new file mode 100644
index 0000000..115055f
--- /dev/null
+++ b/requirements.py
@@ -0,0 +1,5 @@
+numpy
+pandas
+json
+openpyxl
+h5py==3.9
\ No newline at end of file
diff --git a/resultados_ensayos.json b/resultados_ensayos.json
new file mode 100644
index 0000000..743bd45
--- /dev/null
+++ b/resultados_ensayos.json
@@ -0,0 +1,23 @@
+{
+    "E": [
+        175.66197827609287,
+        160.81787128674983,
+        145.4009250653107,
+        104.3877062608225,
+        95.01237852797996
+    ],
+    "I": [
+        2.085,
+        1.87,
+        1.635,
+        0.965,
+        0.79
+    ],
+    "f": [
+        138.9,
+        139.6,
+        140.6,
+        144.3,
+        145.3
+    ]
+}
\ No newline at end of file