Subido por ingcivilcarreno

codigo vb6

Anuncio
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
import ipywidgets as ipw
from google.colab import widgets, files
from ipywidgets import Layout
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning
import sys
sys.path.insert(0, "/content/drive/MyDrive/Tesis_python")
from libdibujo import DibujaCota, Poligono
class Empuje_muros():
def __init__(self, nf, sc, sigmams1, Hs1, c1, beta, B, W, q, µ, NSQW,
NSQL, H, dt, nver, p,.sigma2, Hs2, p, c2, Ao, aod, enf):
# Para la presión activa
self.nf = nf
self.sc = sc # Magnitud de la sobrecarga
self.sigmams1 = sigmams1# Peso específico del material
self.Hs1 = Hs1 # Espesor del estrato.
self.fi1=fi1 # Ángulo de fricción interna del material
self.c1 = c1 # Cohesión del material
#Para la(s) sobrecargas(s)
self.B = B
self.W = W
self.q = q
self.μ = μ
self.NSQW = NSQW
self.NSQL = NSQL
self.H = H
self.dt = dt
self.nvert = nvert
self.p = p # Magnitud de la sobrecarga puntual
self.a_o_d = aod # Para la de variación lineal si es ascendente o descendente
# Para el sismo
self.Ao = Ao
.# Para la presión pasiva
self.sigma2 = sigma2
self.Hs2 = Hs2
self.fi2 = fi2
self.c2 = c2
def presion_activa_rankine(self):
""" calcula la presión activa total y su resultante por el método de rankine.
Puede tomar en cuenta: - Rellenos con cohesión. - Sobrecargas sobre el
muro. - Relleno con una inclinación por encima del muro """
sigmaw = 9.81 #kN/m3
Profs = np.cumsum(self.Hs)
sigmae = self.sigmams1.copy() # Array para almacenar los gammas
efectivos
Profsw = np.zeros_like(self.Hs1) # Array de ceros donde se va a indicar el nf
Proftotal = sum(self.Hs1) # Variable con la profundidad total
beta = np.radians(self.beta) # Ángulo de inclinación del relleno por encima del muro
fi1 = np.radians(self.fi1) # Transforma a radianes para poder utilizar las funciones
trigonométricas
ka = np.array([ ] )
for i in range(len(fi1)):
if beta >= fi1[i]:
a = (1 - np.sin(fi1[i])) / (1 + np.sin(fi1[i]))
ka = np.append(ka, a)
elif β < fi1[i]:
nume = (np.cos(beta) - ((np.cos(beta)) ** 2 - (np.cos(fi1[i])) ** 2) ** (1/2))
deno = (np.cos(beta) + ((np.cos(beta)) ** 2 - (np.cos(fi1[i])) ** 2) ** (1/2))
a = np.cos(beta) * (nume / deno)
ka = np.append(ka, a)
if self.enf == 1:
pass
elif self.enf == 2:
Profsw = np.where(Profs > self.nf, Profs - self.nf, Profsw)
sigmae = np.where(Profs > self.nf, self.sigmams1 - self.sigmaw, sigmae)
u = self.sigmaw * Profsw
sigmae = np.insert(sigmae, 0, self.sc)
Hs1 = np.insert(self.Hs1, 0, 1)
u = np.insert(u, 0, 0)
Profs = np.insert(Profs, 0, 0)
esfa = np.cumsum(Hs1 * sigmae)
###### repite las arrays para hacer el cambio de estrato con los ka de los
dos materiales #######
esfa = np.repeat(esfa, 2)
esfa = np.delete(esfa, 0)
esfa = np.delete(esfa, len(esfa) - 1)
u = np.repeat(u, 2)
u = np.delete(u, 0)
u = np.delete(u, len(u) - 1)
Profs = np.repeat(Profs, 2)
Profs = np.delete(Profs, 0)
Profs = np.delete(Profs, len(Profs) - 1)
ka = np.repeat(ka, 2)
c = np.repeat(self.c, 2)
if self.enf == 1:
efee = (ka * σa)
elif self.enf == 2:
efee = (ka * σa) + u # Vector con las presiones efectivas
###### cohesión (2 * c * √ka) #######
raizka = ka ** (1/2)
tension = 2 * c * raizka
Presionactiva = sigmae - tension # Empuje activo total
Presionactiva = np.insert(Presionactiva, 0, 0) # Agrega el punto 0 en Y
Profs = np.insert(Profs, 0, 0) # Agrega el punto 0 en X
i = np.stack((Presionactiva, Profs), axis=1) # Junta la matriz de profundidad con la
de presión efectiva
point = np.array([[0, Prof_total]]) # Agrega el punto necesario para cerrar el polígono
b = np.vstack((i, point)) # Tuple con las coordenadas para el polígono
a = Polygon(b) # Polígono representa la presión lateral
self.Empujeactivo = round(a.area,2)
self.ResultanteEA = round((Proftotal - a.centroid.y),2) # Para graficar
self.XPA = Presion_activa
self.YPA = Profs self.PoliPA =
aself.TextPA = "debido a presión activa"
self.empujeRankine = b # Almacena la variable donde está la gráfica para poder usarla
en otros métodos.
return self.Empujeactivo, self.ResultanteEA
def presion_pasiva_rankine(self):
"""calcula la presión pasiva total y su resultante por el método de rankine. """
Profs = np.cumsum(self.Hs2) # Array con las profundidades acumuladas
sigmae = self.sigmam2.copy() # Array para almacenar los gammas efectiva
Proftotal = sum(self.Hs2) # Variable con la profundidad total
kp = (np.tan(np.radians(45 + self.fi2 / 2))) ** 2 # Vector con los coeficientes de
presión activa de Rankine
esfa = np.cumsum(self.Hs2 * sigmae) # Vector con en el empuje acumulado en la
profundidad
###### repite las arrays para hacer el cambio de estrato con los kp de los
dos materiales #######
efea = np.repeat(efea, 2)
Profs = np.repeat(Profs, 2)
kp = np.repeat(kp, 2)
efee = (kp * efea) #+ u # vector con las presiones
###### COHESIÓN (2 * c * √kp) #######
raizkp = kp ** (1/2)
self.c2 = np.repeat(self.c2, 2)
tension = 2 *self.c2 * raizkp
Empujepasivo = σe - tension # Empuje activo total
Empujepasivo = np.insert(Empujepasivo, 0, 0) # Agrega el punto 0 en Y
Profs = np.insert(Profs, 0, 0) # Agrega el punto 0 en X
a = np.stack((Empujepasivo, Profs), axis=1) # Junta la matriz de profundidac con la
de presión efectivos
point = np.array([[0, Proftotal]]) # Agrega el punto necesario para cerrar el polígono
b = np.vstack((a, point)) # Tuple con las coordenadas para el polígono
prepasfig = Polygon(b) # Polígono representa la presión lateral # Para graficar
self.XPP = Empujepasivo
self.YPP = Profs self
PoliPP = prepasfig
self.TextPP = "debido a presión pasiva"
Presionpasiva = round(prepasfig.area,2)
ResultanteEP = round((Proftotal - prepasfig.centroid.y),2)
return Presionpasiva, ResultanteEP
def presion_activa_okabe(self):
""" calcula el incremento de la presión activa debido a sismo por el método
de mononobe-okabe. """
Profs = np.cumsum(self.Hs1)
sigmae = self.sigmams1.copy() # Array para almacenar los gammas efectiva
Proftotal = sum(self.Hs1) # Variable con la profundidad total
beta = np.radians(self.beta) # Ángulo de inclinación del relleno por encima del muro
fi1 = np.radians(self.fi1) # Transforma a radianes
Kh = 2/3 * self.A0 # Coeficiente sísmico horizontal
Kv = 2/3 * Kh # Coeficiente sísmico vertical
fi1 = 0 # Ángulo de la cara interna del muro respecto a la vertical (Es 0 si el muro no se
encuentra inclinado)
delta = np.radians(np.degrees(fi1) / 2) # Ángulo de fricción entre el material de
relleno y la estructura de contención
ro = np.arctan(Kh / (1 - Kv))
numerador = (np.cos(fi1 - teta - ro)) ** 2
deno1 = np.cos(ro) * ((np.cos(teta)) ** 2) * np.cos(delta + teta + ro)
deno2 = (1 + ((np.sin(fi1 + delta) * np.sin(fi1 - beta - ro)) / (np.cos(delta + teta
+ ro) * np.cos(beta - teta))) ** (1/2)) ** 2
kae = numerador / (deno1 * deno2)
sigmae = np.insert(sigmae, 0, self.sc)
Hs1 = np.insert(self.Hs1, 0, 1)
Profs = np.insert(Profs, 0, 0)
efea = np.cumsum(Hs1 * sigmae)
###### repite las arrays para hacer el cambio de estrato con los kae de los
dos materiales #######
delta = np.repeat(delta, 2)
efea = np.repeat(efea, 2)
efea = np.delete(efea, 0)
efea = np.delete(efea, len(efea) - 1)
Profs = np.repeat(Profs, 2)
Profs = np.delete(Profs, 0)
Profs = np.delete(Profs, len(Profs) - 1)
kae = np.repeat(kae, 2)
efee = (kae * efea)
###### COHESIÓN (2 * c * √kae) #######
raizkae = kae ** (1/2)
c1 = np.repeat(self.c1, 2)
tension = 2 * c1 * raizkae
Presionsismo = sigmae - tension # empuje activo total
Presionsismo = (Presionsismo) * (1 - Kv)
Presionsismo = np.insert(Presionsismo, 0, 0)
Profs = np.insert(Profs, 0, 0)
a = np.stack((Presionsismo, Profs), axis=1)
point = np.array([[0, Proftotal]])
b = np.vstack((a, point))
self.empujeSismo = a
presismo = Polygon(b)
Pae = round(presismo.area,2)
resultantesismo = round(0.6 * max(Profs), 2)
dEa = round(Pae - self.Empujeactivo, 2)
Resultanteambas = (self.Empujeactivo * self.ResultanteEA + dEa *
resultantesismo) / Pae
if self.Ao == 0:
dEa = 0
resultantesismo =0
self.XSismo = Presionsismo - self.XPA
self.YSismo = Profs
self.PoliSismo = presismo
self.TextSismo = "debido a sismo"
return dEa, resultantesismo
def prelat_sobrecarga_areacargada1(self):
""" calcula el empuje debido a una sobrecarga con la forma de un área
cargada con magnitud constante. """
DDY = self.H / (self.nvert - 1)
DOP = self.W / 2
B1 = self.B / self.NSQW
W1 = self.W / self.NSQL
P = self.q * (B1 * W1)
y = np.arange(B1 / 2, self.B, B1)
x = np.arange(W1 / 2, self.W, W1)
z = np.arange(0, self.H + DDY, DDY)
z = np.where(z == 0, 0.000000001, z)
z=5
xx, yy = np.meshgrid(x, y)
r = ((abs(DOP - xx) ** 2) + (self.dt + yy) ** 2) ** (1/2)
sigmarpolygon = np.array([])
for l in range(len(z)):
R = (r ** 2 + z[l] ** 2) ** (1/2)
R = np.ravel(R)
r = np.ravel(r)
teta = np.arccos(z[l] / R)
term1 = 3 * np.sin(teta) ** 2 * np.cos(teta) ** 3
term2 = (1 - 2 * self.miu) * np.cos(teta) ** 2 / (1 + np.cos(teta))
efer = (P / (2 * np.pi * z[l] ** 2)) * (term1 - term2)
efertotal = np.sum(efer)
eferpolygon = np.append(eferpolygon, efertotal)
eferpolygon = np.where(eferpolygon < 0, 0, eferpolygon)
t = np.stack((eferpolygon, z), axis=1)
t = np.vstack((t, [0, self.H]))
a = Polygon(t)
self.XSA = sigmarpolygon
self.YSA = z
self.PoliSA = a
self.TextSA = "por sobrecarga tipo área cargada"
self.empujesobrearea = t
EmpujeSAC = round(a.area, 2)
ResultanteSAC = round(self.H - a.centroid.y, 2)
return EmpujeSAC, ResultanteSAC
def prelat_sobrecarga_linearload(self):
""" calcula el empuje debido a una sobrecarga con la forma de un área
cargada con variación lineal. la variación de la carga puede ser: - ascendente
en dirección del muro. - descendete en dirección del muro. """
DDY = self.H / (self.nvert - 1)
DOP = self.W / 2
B1 = self.B / self.NSQW # Dimensiones del área eje x
W1 = self.W / self.NSQL # Dimensiones del área eje y
P = (self.q * (self.B * self.W)) / 2 # Carga de todas las strips juntas
y = np.arange(B1 / 2, self.B, B1)
x = np.arange(W1 / 2, self.W, W1)
z = np.arange(0, self.H + DDY, DDY)
z = np.where(z == 0, 0.000000001, z
xx, yy = np.meshgrid(x, y)
nq = yy[:, 0] * 10 # Calcula las nqs
qunit = P / (sum(nq) * B1 * W1 * 10) # Carga unitaria
stripintensities = np.array([]) # Array vacía para almacenar las strip intensities
stripintensities = nq * B1 * W1 * qunit
if self.aod == 4:
stripintensities = np.flip(stripintensities)
stripintensities = np.repeat(stripintensities, 10)
r = ((abs(DOP - xx) ** 2) + (self.dt + yy) ** 2) ** (1/2)
sigmarpolygon = np.array([])
for l in range(len(z)): # Calcular para cada profundidad
R = (r ** 2 + z[l] ** 2) ** (1/2)
R = np.ravel(R) # Transforma la array (10,10) a (100, )
r = np.ravel(r) # Transforma la array (10,10) a (100, )
teta = np.arccos(z[l] / R)
term1 = 3 * np.sin(tteta) ** 2 * np.cos(teta) ** 3
term2 = (1 - 2 * self.miu) * np.cos(teta) ** 2 / (1 + np.cos(teta))
efer = (stripintensities / (2 * np.pi * z[l] ** 2)) * (term1 - term2)
efertotal = np.sum(efer)
eferpolygon = np.append(eferpolygon, efertotal)
eferpolygon = np.where(eferpolygon < 0, 0,
t = np.stack((eferpolygon, z), axis=1)
t = np.vstack((t, [0, self.H]))
a = Polygon(t)
self.XSL = eferpolygon
self.YSL = z
self.PoliSL = a
self.TextSL = "por sobrecarga tipo variación lineal"
self.empuje_sobre_linear = t
EmpujeSLL = round(a.area, 2)
ResultanteSLL = round(self.H - a.centroid.y, 2)
return EmpujeSLL, ResultanteSLL
def prelat_sobrecarga_cargapuntual(self):
""" calcula la presión lateral debido a una sobrecarga con la forma de una
carga puntual. """
DDY = self.H / (self.nvert - 1) # Incremento de la distancia vertical
z = np.arange(0, self.H + DDY, DDY)
z = np.where(z == 0, 0.0000001, z)
r = (0 ** 2 + self.dt ** 2) ** (1 / 2)
sigmarpolygon = np.array([])
for i in range(int(self.nvert)):
R = (r ** 2 + z[i] ** 2) ** (1/2)
teta = np.arccos(z[i] / R)
term1 = 3 * np.sin(teta) ** 2 * np.cos(teta) ** 3
term2 = (1 - 2 * self.miu) * np.cos(teta) ** 2 / (1 + np.cos(teta))
efer = (self.P / (2 * np.pi * z[i] ** 2)) * (term1 - term2)
eferpolygon = np.append(eferpolygon, efer)
eferpolygon = np.where(eferpolygon < 0, 0, eferpolygon)
t = np.stack((eferpolygon, z), axis=1)
t = np.vstack((t, [0, self.H]))
a = Polygon(t) # Crea el polígono # Para graficar
self.XSP = eferpolygon
self.YSP = z
self.PoliSP = a
self.TextSP = "por sobrecarga tipo puntual"
self.empujesobrepuntual = t
EmpujeSP = round(a.area, 2)
ResultanteSP = round(self.H- a.centroid.y, 2)
return EmpujeSP, ResultanteSP
def suma(self):
""" calcula la suma de todos los empujes laterales por medio de una
inteporlación entre los diagramas de distribución de presiones. """
xtotal = 0
newy = np.linspace(0, self.H, num=1000)
self.cualessobrecargas = np.array([])
##### revisa cuales son las funciones de presión lateral que fueron llamadas #####
try:
newx1 = np.interp(newy, self.empujeRankine[:,1], self.empujeRankine[:,0])
newx1 = newx1 * np.cos(np.radians(self.beta))
xtotal = xtotal + newx1
except AttributeError:
self.empuje_Rankine = None
try:
newx2
=
np.interp(newy,
self.empujesobre_area[:,1],
self.empujesobrearea[:,0])
xtotal = xtotal + newx2
self.cualessobrecargas = np.append(self.cualessobrecargas, "area cargada")
except AttributeError:
self.empujesobrearea = None
try:
newx3
=
np.interp(newy,
self.empujesobrelinear[:,1],
self.empujesobrelinear[:,0])
xtotal = xtotal + newx3
self.cualessobrecargas = np.append(self.cualessobrecargas, "variación
lineal")
except AttributeError:
self.empujesobre_linear = None
try:
newx4
=
np.interp(newy,
self.empujesobre_puntual[:,1],
self.empujesobre_puntual[:,0])
xtotal = xtotal + newx4
self.cualessobrecargas
=
np.append(self.cualessobrecargas,
"carga
puntual")
except AttributeError:
self.empujesobrepuntual = None
if self.Ao > 0:
newx5 = np.interp(newy, self.empujeSismo[:,1], self.empujeSismo[:,0]self.XPA)
xtotal = xtotal + newx5
xtotal[0] = 0
xtotal[len(xtotal) - 1] = 0
poly = np.stack((xtotal, newy), axis=1)
a = Polygon(poly)
self.XSuma = xtotal
self.YSuma = newy
self.PoliSuma = a
self.TextSuma = "debido a la presión total"
Empujetotal = round(a.area, 2)
brazopalanca = round(self.H - a.centroid.y, 2)
return Empujetotal, brazopalanca
def graficar(self):
""" grafica cada uno de los diagramas de distribución de presiones laterales. """
fig = plt.figure(figsize=(12,10))
gs = plt.GridSpec(nrows=3, ncols=2)
ax0 = fig.add_subplot(gs[0, 0])
ax0.plot(self.XPA, self.YPA, color="blue", linewidth=3)
plt.ylim(np.max(self.YPA), 0)
ax0.plot(0, self.PoliPA.centroid.y, marker="<", ms=10, c="blue")
plt.ylabel("Profundidad (m)")
plt.xlabel("Presión (kN/m2)")
ax0.set_title(f"Distribución de presiones {self.TextPA}", fontsize=12)
plt.grid()
plt.ylim(np.max(self.YPP), 0)
ax1.set_title(f"Distribución de presiones {self.TextPP}", fontsize=12)
plt.grid()
if self.Ao > 0:
ax2 = fig.add_subplot(gs[1, 0])
ax2.plot(self.XSismo, self.YSismo, color="green", linewidth=3)
plt.ylim(np.max(self.Y_Sismo), 0)
ax2.set_title(f"Distribución de presiones {self.Text_Sismo}", fontsize=12)
plt.grid()
if "area cargada" in self.cualessobrecargas:
ax3 = fig.addsubplot(gs[1, 1])
ax3.plot(self.XSA, self.YSA, color="red", linewidth=3)
plt.ylim(np.max(self.YSA), 0)
self.PoliSA.centroid.y, - np.max(self.XSA)/5, 0, headwidth=0.2, shape="full",
color="red")
ax3.plot(0, self.PoliSA.centroid.y, marker="<", ms=10, c="red")
plt.ylabel("Profundidad
(m)")
plt.xlabel("Presión
(kN/m2)")
ax3.set_title(f"Distribución de presiones {self.Text_SA}", fontsize=12)
plt.grid() # Para la sobrecarga tipo área con carga variación lineal if "variación
lineal" in self.cuales_sobrecargas: ax3 = fig.add_subplot(gs[1, 1])
ax3.plot(self.X_SL,
self.Y_SL,
color="red",
linewidth=3)
plt.ylim(np.max(self.Y_SL),
0)
#
ax.arrow(np.max(self.X_SL),
self.Poli_SL.centroid.y, - np.max(self.X_SL)/5, 0, head_width=0.15,
shape="full", color="red") ax3.plot(0, self.Poli_SL.centroid.y, marker="<",
ms=10, c="red") plt.ylabel("Profundidad (m)") plt.xlabel("Presión (kN/m2)")
ax3.set_title(f"Distribución de presiones {self.Text_SL}", fontsize=12) plt.grid()
# Para sobrecarga tipo carga puntual if "carga puntual" in
self.cuales_sobrecargas: ax3 = fig.add_subplot(gs[1, 1]) ax3.plot(self.X_SP,
self.Y_SP, color="red", linewidth=3)plt.ylim(np.max(self.Y_SP), 0) #
ax.arrow(np.max(self.X_SP), self.Poli_SP.centroid.y, - np.max(self.X_SP)/5,
0,
head_width=0.2,
shape="full",
color="red")
ax3.plot(0,
self.Poli_SP.centroid.y, marker="<", ms=10, c="red") plt.ylabel("Profundidad
(m)") plt.xlabel("Presión (kN/m2)") ax3.set_title(f"Distribución de presiones
{self.Text_SP}", fontsize=12) plt.grid() # Para la sobrecarga total de la función
suma ax4 = fig.add_subplot(gs[2, 0]) ax4.plot(self.X_Suma, self.Y_Suma,
color="purple",
linewidth=3)
plt.ylim(np.max(self.Y_Suma),
0)
#
ax.arrow(np.max(self.X_Suma),
self.Poli_Suma.centroid.y,
np.max(self.X_Suma)/5, 0, head_width=0.25, shape="full", color="red")
ax4.plot(0, self.Poli_Suma.centroid.y, marker="<", ms=10, c="purple")
plt.ylabel("Profundidad
(m)")
plt.xlabel("Presión
(kN/m2)")
ax4.set_title(f"Distribución de presiones {self.Text_Suma}", fontsize=12)
plt.grid()
plt.tight_layout()
plt.savefig("/content/drive/MyDrive/Tesis_python/Reporte_descargar/Diagram
as_pr esiones", dpi=250) plt.show()
Descargar