Python en Ingeniería Civil

3. Cálculo de Viga Isostática.

Este código fue hecho por el Sr. Mario Semañuk y busca realizar el rograma de Cálculo de Reacciones de vigas isostaticas simple


# -*- coding: utf-8 -*-
"""
Created on Mon Jan 13 16:10:29 2020

@author: Mario Semañuk
"""
from matplotlib import pyplot as plt

print('\n',"--- Programa de Calculo de Reacciones de vigas isostaticas simples ---",'\n')

long=float(input("Ingrese la longitud de la barra en metros: "))

while long<=0:      #BUCLE DE REINGRESO
    print("Error, Reingrese:")
    long=float(input())

print("\nIngrese el tipo de carga a utilizar:","\n1- Carga Puntual","\n2- Carga Uniformemente Distribuida")
tipo_carga=int(input())

while tipo_carga!=1 and tipo_carga!=2:      #BUCLE DE REINGRESO
    tipo_carga=int(input("Error, reingrese: "))

if tipo_carga==1:
    q1=float(input("Ingrese el valor de la carga en kN: "))
    while q1<=0:      #BUCLE DE REINGRESO
        q1=float(input("Error, valor incorrecto, reingrese: "))
        
    da=float(input("Ingrese la posición de la carga en la barra en metros: "))
    while da>long:      #BUCLE DE REINGRESO
        da=float(input("Error, la carga debe estar sobre la barra, reingrese: "))
    
    rb=(q1*da/long)
    ra=q1-rb
    print("La reaccion del vinculo izquierdo es: ",str(ra))
    print("La reaccion del vinculo derechoo es: ",str(rb))

if tipo_carga==2:
    q1=float(input("Ingrese el valor de la carga en kN/m: "))
    while q1<=0:      #BUCLE DE REINGRESO
        q1=float(input("Error, valor incorrecto, reingrese: "))
        
    da=float(input("Ingrese la posición del inicio de la carga en la barra, en metros: "))
    while da>long:      #BUCLE DE REINGRESO
        da=float(input("Error, la carga debe estar sobre la barra, reingrese:"))
        
    l=float(input("Ingrese la longitud de la carga: "))
    while l<=0 or l+da>long:      #BUCLE DE REINGRESO
        l=float(input("Error, la carga excede la barra, reingrese: "))
    
    rb=(q1*l)*(da+(l/2))/long
    ra=(q1*l)-rb
    print("La reacción del vínculo izquierdo es: ",str(ra))
    print("La reacción del vínculo derechoo es: ",str(rb))

""" Calculo de valores de corte y momento
Tomo 1000 puntos dentro de la barra
"""

valoresx=[]         #LISTA DONDE SE GUARDARAN LAS ABSCISAS DE LOS GRAFICOS, ES DECIR, LAS N PARTICIONES DE LA LONGITUD DE LA BARRA
cortes=[]           #LISTA DONDE SE GUARDARAN LOS VALORES DE CORTE DE LA BARRA
momentos=[]         #LISTA DONDE SE GUARDARAN LOS VALORES DE MOMENTOS DE LA BARRA
ejey=[]             #LA FORMA MAS RAPIDA QUE ENCONTRE DE GRAFICAR UN CERO PARA EL GRAFICO (LINEA HORIZONAL DE REFERENCIA)
etiquetasx=[]       #LISTA DONDE SE GUARDARAN LAS 10 PARTES DE LA LONGITUD DE LA BARRA, SE UTILIZA PARA LAS ETIQUETAS DE LOS GRAFICOS
n=int(1000)
if tipo_carga==1:
    for i in range(n):
        valoresx.append(long*(i)/n)     #VALORES DE DISTANCIA RELATIVOS AL ORIGEN DE LA BARRA, SE UTILIZAN PARA LOS CALCULOS DE CORTE Y MOMENTO
        ejey.append(0)                  #AÑADE CEROS A LA LISTA PARA PODER GRAFICAR UNA LINEA HORIZONTAL
        if i==0:
            cortes.append(0)            #AÑADE CERO COMO PRIMER VALOR
            momentos.append(0)          #AÑADE CERO COMO PRIMER VALOR
        else:
            if valoresx[i]<da:          #CONDICION DONDE ESTOY ENTRE EL ORIGEN DE LA BARRA Y LA CARGA
                cortes.append(ra)       
                momentos.append(-ra*valoresx[i])
            if valoresx[i]>=da:         #CONDICION DONDE ESTOY DESPUES DE LA CARGA
                cortes.append(ra-q1)
                momentos.append(-ra*valoresx[i]+q1*(valoresx[i]-da))
    
    for i in range (11):                #CREACION DE LAS ETIQUETAS PARA EL EJE X
        etiquetasx.append(long*i/10)
        
    cortes.append(0)            #AÑADE CERO COMO ULTIMO VALOR
    momentos.append(0)          #AÑADE CERO COMO ULTIMO VALOR          
    valoresx.append(long)       #AÑADE LA LONGITUD DE LA BARRA COMO ULTIMO VALOR
    ejey.append(0)              #AÑADE UN VALOR MAS A LA LINEA HORIZONTAL
    fig, (ax1,ax2) =plt.subplots(2,1)   #CREO DOS GRAFICOS, UNO POR ENCIMA DE OTRO (2 ROWS, 1 COLS)

    ax1.plot(valoresx,cortes)           #GRAFICA DE CORTE
    ax1.plot(valoresx,ejey)             #GRAFICA HORIZONTAL
    ax1.set_xlabel ("Abscisas[m]")      #TITULO DE EJE
    ax1.set_ylabel ("Cortes[kN]")       #TITULO DE EJE
    ax1.set_xticks(etiquetasx)          #ETIQUETAS DEL EJE X

    ax2.plot(valoresx,momentos)         #GRAFICA DE MOMENTO
    ax2.plot(valoresx,ejey)             #GRAFICA HORIZONTAL
    ax2.set_xlabel ("Abscisas[m]")      #TITULO DE EJE
    ax2.set_ylabel ("Momentos[kNm]")    #TITULO DE EJE
    ax2.set_xticks(etiquetasx)          #ETIQUETAS DEL EJE X

#DE ACA EN MAS, EL PROXIMO IF REALIZA LO MISMO QUE EL IF DE ARRIBA, PERO PARA CARGA DISTRIBUIDA
 
if tipo_carga==2:                  
    for i in range(n):
        valoresx.append(long*(i)/n)
        ejey.append(0)
        if i==0:
            cortes.append(0)
            momentos.append(0)
        else:
            if valoresx[i]<da:                                  #DESDE EL ORIGEN DE LA BARRA HASTA DONDE COMIENZA LA CARGA
                cortes.append(ra)
                momentos.append(-ra*valoresx[i])
            if valoresx[i]>=da and valoresx[i]<(da+l):          #DESDE EL COMIENZO DE LA CARGA HASTA EL FINAL DE LA MISMA
                cortes.append(ra-q1*valoresx[i])
                momentos.append(-ra*valoresx[i]+q1*(valoresx[i]-da)*((valoresx[i]-da)/2))
            if valoresx[i]>=(da+l):                             #DESDE EL FINAL DE LA CARGA HASTA EL FINAL DE LA BARRA
                cortes.append(ra-q1*l)
                momentos.append(-ra*valoresx[i]+q1*l*((valoresx[i]-da-(l/2))))
                
    for i in range (11):
        etiquetasx.append(long*i/10)
        
    cortes.append(0)
    momentos.append(0)
    valoresx.append(long)
    ejey.append(0)    
    fig, (ax1,ax2) =plt.subplots(2,1)

    ax1.plot(valoresx,cortes)
    ax1.plot(valoresx,ejey)
    ax1.set_xlabel ("Abscisas[m]")
    ax1.set_ylabel ("Cortes[kN]")
    ax1.set_xticks(etiquetasx)

    ax2.plot(valoresx,momentos)
    ax2.plot(valoresx,ejey)
    ax2.set_xlabel ("Abscisas[m]")
    ax2.set_ylabel ("Momentos[kNm]")
    ax2.set_xticks(etiquetasx)