import numpy as np import pandas as pd import random, os def valores_objetivo(archivo, material): carga = pd.read_excel(archivo, sheet_name='carga', engine='openpyxl').dropna() E = np.mean(carga.loc[carga['material'] == material, ['V1', 'V2']].values, axis=1) I = np.mean(carga.loc[carga['material'] == material, ['I1', 'I2']].values, axis=1) f = np.array(carga['f'][carga['material'] == material]) return E, I, f def generar_curva(offset, ruta): muVacio = 4 * np.pi * 1e-7 h = np.arange(0,30000,1000) b = muVacio * h + offset with open(ruta, "w") as f: f.write('[PLACOND]\n') f.write('Type=Fixed_Solid\n') f.write('Solid Type=Steel\n') f.write('Thermal Conductivity=28\n') f.write('Specific Heat=460\n') f.write('Density=7800\n') f.write('Notes=\n') f.write('ElectricalResistivity=5.2E-7\n') f.write('TempCoefElectricalResistivity=0\n') f.write('PoissonsRatio=0\n') f.write('YoungsCoefficient=0\n') f.write('YieldStress=0\n') for i in np.arange(len(h)): f.write(f'BValue[{i}]={b[i]}\n') f.write(f'HValue[{i}]={h[i]}\n') def logica_offset(offset, error, errorObjetivo): ''' Coge el offset, error actual y lo analiza. devuelve flag y offset nuevo si se cumple la condicion devuelve un True y None para offset ''' limSup = 1 + errorObjetivo limInf = 1 - errorObjetivo delta = random.random()/100 if error <= limSup and error >= limInf: return True, None if error > 1: offset = offset - delta elif error < 1: offset = offset + delta return False, offset if __name__ == '__main__': directorio = '' nombre = "curva.mdb" ruta = f'{directorio}{nombre}' generar_curva(1,ruta)