From f204cdd5bce24a7ab71069ca6ee02a7cef9cfa74 Mon Sep 17 00:00:00 2001 From: Oscar Suescun Elizalde Date: Wed, 26 Mar 2025 12:19:53 +0100 Subject: [PATCH] Logica de ajuste --- genCurvas.py | 53 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/genCurvas.py b/genCurvas.py index 01494e9..0dde8b0 100644 --- a/genCurvas.py +++ b/genCurvas.py @@ -1,6 +1,6 @@ import numpy as np import pandas as pd -import json +import random, os def valores_objetivo(archivo, material): carga = pd.read_excel(archivo, sheet_name='carga', engine='openpyxl').dropna() @@ -11,6 +11,7 @@ def valores_objetivo(archivo, material): return E, I, f + def generar_curva(offset): muVacio = 4 * np.pi * 1e-7 @@ -23,51 +24,33 @@ def generar_curva(offset): h = np.concatenate((hNeg, hPos)) b = np.concatenate((bNeg, bPos)) - datos = np.column_stack((h,b)) np.savetxt('curva.csv', datos, delimiter=',') -if __name__ == '__main__': - archivo = 'Ensayos.xlsx' - material = 'PLACOND' +def logica_offset(offset, error, errorObjetivo): + ''' + Coge el offset, error actual y lo analiza. - Eobjetivo, Iobjetivo, fObjetivo = valores_objetivo(archivo, material) + devuelve flag y offset nuevo - errorObjetivo = 0.01 # +- cuanto % puede haber de diferencia - errorCVobjetivo = 1 + si se cumple la condicion devuelve + un True y None para offset + + ''' limSup = 1 + errorObjetivo - limInf = errorObjetivo + limInf = 1 - errorObjetivo - offset = 0 + delta = random.random()/100 - flag = True + if error <= limSup and error >= limInf: return True, None + + if error > 1: offset = offset - delta + elif error < 1: offset = offset + delta + + return False, offset - errorAnterior = 10000 - - while flag: - generar_curva(offset) - ############################ - ''' - 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 - error = np.mean(Ecalc / Eobjetivo) - - if error <= limSup and error >= limInf: flag = False - - flag = False