106 lines
2.3 KiB
Python
106 lines
2.3 KiB
Python
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() * 1e-6
|
|
|
|
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__':
|
|
'''
|
|
Esto solo se activa si se lanza este script en concreto
|
|
no si se invocan las funciones.
|
|
|
|
Contiene ejemplos de como funciona el codigo
|
|
|
|
'''
|
|
directorio = ''
|
|
nombre = "curva.mdb"
|
|
|
|
ruta = f'{directorio}{nombre}'
|
|
|
|
generar_curva(1,ruta)
|
|
|
|
offset = 0
|
|
|
|
B = 1e-2
|
|
BObjetivo = 2e-2
|
|
|
|
errorObjetivo = 0.01
|
|
|
|
flag = False
|
|
|
|
while flag == False:
|
|
os.system('cls')
|
|
|
|
B = B + offset
|
|
|
|
error = B/BObjetivo
|
|
|
|
print(B)
|
|
print(error)
|
|
|
|
flag, offset = logica_offset(offset, error, errorObjetivo)
|
|
|
|
|
|
|