secciones.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import math
  4. import pandas as pd
  5. import openpyxl
  6. print("")
  7. print("")
  8. print("DISEÑO DE SECCIONES")
  9. print("")
  10. print("")
  11. #-------------------------------------MATERIALES------------------------------------------------
  12. dens=7850 #kg/m3
  13. fy=355 #MPA
  14. gammas=1.05 #Factor seguridad acero
  15. Eyoung=210000 #MPa
  16. nu=0.3 #Coef Poisson
  17. #---
  18. fyd=fy*10**6/gammas # Pa (resistencia diseño)
  19. Eyoung=Eyoung*10**6 # Pa (rigidez)
  20. G=Eyoung/(2*(1+nu)) # Pa, Módulo Cizalladura
  21. #----------------------------------------------------CARGAR DATOS DESDE EXCEL (debe estar en la misma carpeta que el archivo python)
  22. archivo_excel = 'C:/Users/Daniel.p/Documents/Automatizaciones/Propiedades seccion/datos_generales.xlsx'
  23. #base_datos=openpyxl.load_workbook('/datos_generales.xlsx')
  24. base_datos=openpyxl.load_workbook(archivo_excel)
  25. #obtener los nombres de las secciones.
  26. hojas =base_datos.sheetnames
  27. print("Secciones Disponibles")
  28. nsec=np.size(hojas)
  29. #Enumera todas las hojas menos la primera con el nombre de la sección
  30. for i in range(nsec-1):
  31. k=str(i+1)
  32. print(" - "+k+". "+hojas[i+1])
  33. print("")
  34. print("")
  35. sec=input("Elige una sección: ")
  36. sec=int(sec)
  37. nombreseccion=hojas[sec]
  38. #Obtener el nº de filas de la sección
  39. filas=base_datos[hojas[sec]].max_row
  40. #print("filas = "+filas)
  41. npuntos=filas-1
  42. #importamos los valores de los puntos
  43. puntos=np.zeros([npuntos,2])
  44. for i in range(npuntos):
  45. for j in range(2):
  46. puntos[i,j]=base_datos[hojas[sec]].cell(row=i+2,column=j+1).value
  47. px=np.zeros([npuntos,1])
  48. py=np.zeros([npuntos,1])
  49. for i in range(npuntos):
  50. px[i]=puntos[i,0]
  51. py[i]=puntos[i,1]
  52. #--------------------------CÁLCULO DEL ANCHO y CANTO MÁXIMO (segun ejes de referencia)--------------------------------
  53. bmax=np.amax(px)-np.amin(px)
  54. hmax=np.amax(py)-np.amin(py)
  55. #------------------------CALCULO DEL PERÍMETRO----------------------------- ## ERROR DE PERIMETRO EN PIEZAS COMPUESTAS
  56. long_i=np.zeros([npuntos-1,1])
  57. for i in range(npuntos-1):
  58. long_i[i]=((puntos[i+1,0]-puntos[i,0])**2+(puntos[i+1,1]-puntos[i,1])**2)**(1/2)
  59. p=abs(sum(long_i))
  60. perimetro=p[0]
  61. #--------------------------------CÁLCULO DEL ÁREA-------------------------------------------------------
  62. area_i=np.zeros([npuntos-1,1])
  63. for i in range(npuntos-1):
  64. area_i[i]=(puntos[i+1,0]-puntos[i,0])*(puntos[i+1,1]+puntos[i,1])/2
  65. a=(sum(area_i))
  66. area=abs(a[0])
  67. #--------------------------PESO POR METRO DE SECCIÓN-----------------------------------------------
  68. peso=area*dens
  69. #-----------------------------------------CÁLCULO DEL CENTRO DE GRAVEDAD ----------------------------------------------------------
  70. cdg_i=np.zeros([npuntos,2])
  71. for i in range(npuntos-1):
  72. h1=puntos[i,1]
  73. h2=puntos[i+1,1]
  74. b=puntos[i+1,0]-puntos[i,0]
  75. d=puntos[i,0]
  76. #Centro de gravedad y_i
  77. if h1+h2==0:
  78. cdg_i[i,1]=0
  79. else:
  80. cdg_i[i,1]=1/3*(h1*h1+h1*h2+h2*h2)/(h1+h2)
  81. #centro de gravedad x_i
  82. if h1+h2==0:
  83. cdg_i[i,0]=d+b/2
  84. else:
  85. cdg_i[i,0]=d+b/3*(h1+2*h2)/(h1+h2)
  86. #Cálculo del momento estático
  87. statico_i=np.zeros([npuntos,2])
  88. for i in range(npuntos-1):
  89. #momento_estático respecto eje x (para cdg,y)
  90. statico_i[i,1]=area_i[i,0]*cdg_i[i,1]
  91. #momento_estático respecto eje y (para cdg,x)
  92. statico_i[i,0]=area_i[i,0]*cdg_i[i,0]
  93. #cdg=sum(statico_i)/sum(area_i)
  94. cdg=sum(statico_i)/a
  95. xg=(cdg[0])
  96. yg=(cdg[1])
  97. #Cálculo de las fibras más alejadas desde el CDG:
  98. v1y=np.amax(py)-yg
  99. v2y=np.amin(py)-yg
  100. v1x=np.amax(px)-xg
  101. v2x=np.amin(px)-xg
  102. # ----------------- CÁLCULO MOMENTOS DE INERCIA ----------------------------------
  103. inercia_i=np.zeros([npuntos,3])
  104. for i in range(npuntos-1):
  105. h1=puntos[i,1]
  106. h2=puntos[i+1,1]
  107. b=puntos[i+1,0]-puntos[i,0]
  108. d=puntos[i,0]
  109. xgi=cdg_i[i,0]
  110. ygi=cdg_i[i,1]
  111. ai=area_i[i,0]
  112. #momento de inercia Ixg
  113. if h2>=h1 :
  114. ixcuad_G_local=1/12*b*(h1*h1*h1)+b*h1*(h1/2-ygi)*(h1/2-ygi)
  115. ixtriang_G_loc=1/36*b*(h2-h1)*(h2-h1)*(h2-h1)+1/2*b*(h2-h1)*((2*h1+h2)/3-ygi)*((2*h1+h2)/3-ygi)
  116. else:
  117. ixcuad_G_local=1/12*b*(h2*h2*h2)+b*h2*(h2/2-ygi)*(h2/2-ygi)
  118. ixtriang_G_loc=1/36*b*(h1-h2)*(h1-h2)*(h1-h2)+1/2*b*(h1-h2)*((2*h2+h1)/3-ygi)*((2*h2+h1)/3-ygi)
  119. inercia_i[i,0]=ixcuad_G_local+ixtriang_G_loc+ai*(yg-ygi)*(yg-ygi)
  120. #momento de inercia Iyg
  121. if h2>=h1:
  122. iycuad=1/12*h1*b*b*b+h1*b*(b/2+d-xgi)*(b/2+d-xgi)
  123. iytrian=1/36*(h2-h1)*b*b*b+1/2*b*(h2-h1)*(2/3*b+d-xgi)*(2/3*b+d-xgi)
  124. else:
  125. iycuad=1/12*h2*b*b*b+h2*b*(b/2+d-xgi)*(b/2+d-xgi)
  126. iytrian=1/36*(h1-h2)*b*b*b+1/2*b*(h1-h2)*(1/3*b+d-xgi)*(1/3*b+d-xgi)
  127. inercia_i[i,1]=iycuad+iytrian+ai*(xg-xgi)*(xg-xgi)
  128. #producto de inercia pxyg
  129. if h2>=h1:
  130. pxygcuadrado=b*h1*(-h1/2+ygi)*(-d-b/2+xgi)
  131. pxytriangulo=b*b*(h2-h1)*(h2-h1)/72+b*(h2-h1)/2*(-(h2-h1)/3-h1+ygi)*(-d-2/3*b+xgi)
  132. else:
  133. pxygcuadrado=b*h2*(-h2/2+ygi)*(-d-b/2+xgi)
  134. pxytriangulo=-b*b*(h1-h2)*(h1-h2)/72+b*(h1-h2)/2*(-(h1-h2)/3-h2+ygi)*(-d-1/3*b+xgi)
  135. inercia_i[i,2]=pxygcuadrado+pxytriangulo+ai*(-xg+xgi)*(-yg+ygi)
  136. ig=sum(inercia_i)
  137. ixg=abs(ig[0])
  138. iyg=abs(ig[1])
  139. pxyg=ig[2]
  140. if a>=0:
  141. pxyg=pxyg
  142. else:
  143. pxyg=-pxyg
  144. #Radios de Giro
  145. rx=(ixg/area)**0.5
  146. ry=(iyg/area)**0.5
  147. #EJES PRINCIPALES DE INERCIA
  148. ic= (ixg+iyg)/2
  149. ir= (((ixg-iyg)/2)**2+pxyg**2)**0.5
  150. imax=ic+ir
  151. imin=ic-ir
  152. rmax=(imax/area)**0.5
  153. rmin=(imin/area)**0.5
  154. #obtención de la orientación de los ejes principales de inercia
  155. rest=ixg-iyg
  156. if abs(rest)<10**-12:
  157. tetha=45
  158. else:
  159. tetha=0.5*math.atan((pxyg*2)/(ixg-iyg))
  160. tetha=abs(tetha)*180/math.pi
  161. #Criterio de signos producto de inercia
  162. if pxyg>0:
  163. if ixg>iyg:
  164. tetha=-tetha
  165. else:
  166. tetha=tetha
  167. else:
  168. if ixg>iyg:
  169. tetha=tetha
  170. else:
  171. tetha=-tetha
  172. #--------------------------------CALCULO DE LOS PUNTOS ROTADOS RESPECTO DE LOS EJES PRINCIPALES---------------
  173. pxrot=np.zeros([npuntos,1])
  174. pyrot=np.zeros([npuntos,1])
  175. for i in range(npuntos):
  176. pxrot[i]=puntos[i,0]
  177. pyrot[i]=puntos[i,1]
  178. #-----------------------------CÁLCULO DEL MÓDULO RESISTENTE ELÁSTICO---------------------------
  179. ##SOLAMENTE ESTÁ EN EJES PRINCIPALES
  180. wel1x=abs(ixg/v1y)
  181. wel2x=abs(ixg/v2y)
  182. wel1y=abs(iyg/v1x)
  183. wel2y=abs(iyg/v2x)
  184. #-----------------AXIL ELÁSTICO
  185. nel=area*fyd
  186. #--------------------MOMENTO ELÁSTICO--------------------
  187. melx=min(wel1x,wel2x)*fyd
  188. mely=min(wel1y,wel2y)*fyd
  189. #--------------------------------------DIBUJO DE LA SECCIÓN (colocar antes de imprimir resultados para no modificar las unidades)-------------------
  190. fig, ax=plt.subplots()
  191. #Nombre de la sección y notación de ejes
  192. plt.title(nombreseccion +" (m)",color="SteelBlue",fontsize=16,fontweight="bold")
  193. plt.xlabel('X',fontsize=14,fontweight="bold")
  194. plt.ylabel('Y',fontsize=14,fontweight="bold")
  195. ax.set_aspect("equal")
  196. #Dibujamos los puntos
  197. ax.plot(px,py)
  198. ax.fill(px,py,facecolor="lightblue")
  199. #Dibujamos el centro de gravedad
  200. ax.plot(xg, yg, 'ro',markersize=4, fillstyle='full', markerfacecolor='red')
  201. #Dibujamos los ejes X,Y
  202. tt=min(bmax,hmax)
  203. ax.arrow(xg,yg,tt/3,0,head_width=tt/30, head_length=tt/30, fc='green', ec='green')
  204. ax.arrow(xg,yg,0,tt/3,head_width=tt/30, head_length=tt/30, fc='green', ec='green')
  205. tet=tetha*(math.pi)/180
  206. #Dibujamos los ejes principales
  207. ax.arrow(xg,yg,tt/3*math.cos(tet),tt/3*math.sin(tet),head_width=tt/30, head_length=tt/30, fc='red', ec='red')
  208. ax.arrow(xg,yg,-tt/3*math.sin(tet),tt/3*math.cos(tet),head_width=tt/30, head_length=tt/30, fc='red', ec='red')
  209. #--------------------------------------------------------------------------IMPRIMIR RESULTADOS (siempre al final)---------------------------------------------------
  210. # UNIDADES REDONDEO
  211. redondeo=2
  212. # ------------------------------------------------CAMBIO DE UNIDADES ------------
  213. # Pasar a cm
  214. pot=2
  215. bmax=bmax*10**pot
  216. hmax=hmax*10**pot
  217. perimetro = perimetro*10**pot
  218. xg=xg*10**pot
  219. yg=yg*10**pot
  220. v1y=v1y*10**pot
  221. v2y=v2y*10**pot
  222. v1x=v1x*10**pot
  223. v2x=v2x*10**pot
  224. rx=rx*10**pot
  225. ry=ry*10**pot
  226. rmax=rmax*10**pot
  227. rmin=rmin*10**pot
  228. area=area*10**(pot*2)
  229. wel1x=wel1x*10**(pot*3)
  230. wel2x=wel2x*10**(pot*3)
  231. wel1y=wel1y*10**(pot*3)
  232. wel2y=wel2y*10**(pot*3)
  233. ixg=ixg*10**(pot*4)
  234. iyg=iyg*10**(pot*4)
  235. pxyg=pxyg*10**(pot*4)
  236. imax=imax*10**(pot*4)
  237. imin=imin*10**(pot*4)
  238. # pasar a KN
  239. nel=nel/1000
  240. melx=melx/1000
  241. mely=mely/1000
  242. Eyoung=Eyoung/(10**6)
  243. G=G/(10**6)
  244. print("")
  245. print("")
  246. print(" ___________________________________________________________________________________________________________")
  247. print("")
  248. print(" MATERIAL DE LA SECCIÓN")
  249. print(" - Densidad = "+str(dens)+ " kg/m3")
  250. print(" - σy = "+str(fy)+ " MPa")
  251. print(" - γm = "+str(gammas)+ " [ ]")
  252. print(" - E = "+str(Eyoung)+ " MPa")
  253. print(" - υ = "+str(nu)+ " [ ]")
  254. print(" - G = "+str(round(G,0))+ " MPa")
  255. print(" ___________________________________________________________________________________________________________")
  256. print(" DATOS GEOMÉTRICOS")
  257. print(" - Área = " + str(round(area,redondeo))+ " cm2")
  258. print(" - Perímetro = " + str(round(perimetro,redondeo))+ " cm")
  259. print("")
  260. print(" DIMENSIONES MÁXIMAS")
  261. print(" - b_max = "+str(round(bmax,redondeo))+" cm")
  262. print(" - h_max = "+str(round(hmax,redondeo))+" cm")
  263. print("")
  264. print(" POSICIÓN DEL CDG (respecto ejes de referencia)")
  265. print(" - CDG = [ "+ str(round(xg,redondeo))+ " ; "+str(round(yg,redondeo))+" ] cm")
  266. print("")
  267. print(" FIBRAS MÁS ALEJADAS DESDE G")
  268. print(" - v1y = "+str(round(v1y,redondeo))+" cm")
  269. print(" - v2y = "+str(round(v2y,redondeo))+" cm")
  270. print(" - v1x = "+str(round(v1x,redondeo))+" cm")
  271. print(" - v2x = "+str(round(v2x,redondeo))+" cm")
  272. print("")
  273. print(" TENSOR DE INERCIA EN G RESPECTO DE LOS EJES Xg E Yg")
  274. print(" - IxG = "+str(round(ixg,redondeo))+" cm4")
  275. print(" - IyG = "+str(round(iyg,redondeo))+" cm4")
  276. print(" - PxyG = "+str(round(pxyg,redondeo))+" cm4")
  277. print(" - rx = "+str(round(rx,redondeo))+" cm")
  278. print(" - ry = "+str(round(ry,redondeo))+" cm")
  279. print("")
  280. print(" TENSOR PRINCIPAL DE INERCIA EN G")
  281. print(" - Imax = "+str(round(imax,redondeo))+" cm4")
  282. print(" - Imin = "+str(round(imin,redondeo))+" cm4")
  283. print(" - ϴ (orientación ejes princiaples respecto Xg e Yg) = "+str(round(tetha,redondeo))+" º")
  284. print(" - rmax = "+str(round(rmax,redondeo))+" cm")
  285. print(" - rmin = "+str(round(rmin,redondeo))+" cm")
  286. print("")
  287. print(" MÓDULO RESISTENTE ELÁSTICO")
  288. print(" - wel1x = "+str(round(wel1x,redondeo))+" cm3")
  289. print(" - wel2x = "+str(round(wel2x,redondeo))+" cm3")
  290. print(" - wel1y = "+str(round(wel1y,redondeo))+" cm3")
  291. print(" - wel2y = "+str(round(wel2y,redondeo))+" cm3")
  292. print("")
  293. print(" ___________________________________________________________________________________________________________")
  294. print(" PROPIEDADES MECÁNICAS")
  295. print(" - Peso_unitario = "+str(round(peso,redondeo))+" kg/m")
  296. print(" - Nel = "+str(round(nel,redondeo))+" kN")
  297. print(" - Melx = "+str(round(melx,redondeo))+" kN·m")
  298. print(" - Mely = "+str(round(mely,redondeo))+" kN·m")
  299. print("")
  300. plt.show()