You are on page 1of 3

from cmath import pi

import numpy as np
import time

np.set_printoptions(threshold=np.inf)
# 105223
t1 = time.time()
Padron = 105223 # Padrón de un integrante del grupo
Thot = Padron / 100 + 300 # °C
Tamb = 20 # temperatura ambiente en °C
ni = 180 # nodos coordenada angular
nj = 50 # nodos coordenada radial
n = ni * nj # nodos totales
rext = 0.250 # radio externo del tubo en metros
wt = 0.015 # espesor de la pared del tubo en metros
rint = rext - wt # radio interno del tubo en metros
dr = wt / (nj - 1) # delta r de la malla en metros
ncc = round(0.04 * (ni - 1) / (2 * pi * rint)) # variable entera auxiliar

T = np.zeros((ni, nj))
b = np.zeros((n, 1))
A = np.zeros((n, n))

for i in range(0, ni):


# Aplico condiciones de contorno
# j=1 - nodos internos
kx = 1 + nj * (i - 1)
A[kx, kx - 1] = 1
if i <= ncc or i > ni - ncc + 1:
b[kx - 1] = Thot * 0.931
else:
b[kx - 1] = Tamb

for j in range(1, nj - 1):


# Índices de los coeficientes de las ecuaciones
kx = j + nj * (i - 1)
kn = j + 1 + nj * (i - 1)
ks = j - 1 + nj * (i - 1)
ke = j + nj * i
kw = j + nj * (i - 2)
if ke > n:
ke = ke - n
if kw < 0:
kw = kw + n

# Coeficientes de las ecuaciones


rj = rint + dr * (j - 1)
df = 2 * pi * rj / (ni - 1)
cn = 1 / dr ** 2 + 1 / (2 * dr * rj)

ce = 1 / (rj ** 2 * df ** 2)
cs = 1 / dr ** 2 - 1 / (2 * dr * rj)
cw = 1 / (rj ** 2 * df ** 2)
cx = -2 / dr ** 2 - 2 / (rj ** 2 * df ** 2)
ci = 0
# Matriz del sistema
if ke < kx:
A[kx, ke - 1] = ce
if kw < kx:
A[kx, kw - 1] = cw

A[kx, ks - 1] = cs
A[kx, kx - 1] = cx
A[kx, kn - 1] = cn

if ke > kx:
A[kx, ke - 1] = ce

if kw > kx:
A[kx, kw - 1] = cw

# Vector terminos independientes


b[kx - 1] = ci

# Aplico condiciones de contorno


# j=nj - nodos externos
kx = nj + nj * (i - 1)
A[kx, kx - 1] = 1
if i <= ncc or i > ni - ncc + 1:
b[kx - 1] = Thot
else:
b[kx - 1] = Tamb

def solver_SOR(A, B, w, tol):


n = np.shape(A)[0]
X0 = np.zeros(n)
X1 = np.zeros(n)
iteracion = 0
error = 2 * tol
while error > tol and iteracion < 100:

for i in range(0, n):


X1[i] = B[i]

for j in range(0, i):


X1[i] -= A[i, j] * X1[j]

for j in range(i + 1, n):


X1[i] -= A[i, j] * X0[j]
if A[i, i] != 0:
X1[i] /= A[i, i]

X1[i] = (1 - w) * X0[i] + w * X1[i]

error = np.linalg.norm((X1 - X0), np.inf) / np.linalg.norm(X1, np.inf)

X0 = X1.copy()
iteracion += 1
print(iteracion, "error =", error)
return X1

# Resuelvo el SEL A*x=b por el método SOR

x = solver_SOR(A, b, 1.0, 0.01)


# Recupero la solución del sistema
for i in range(0, ni):
for j in range(0, nj):
kx = j + nj * (i - 1) # fila-columna
T[i, j] = x[kx]
print("posicion", i, "solucion", T[i, j])

t2 = time.time()
t_total = t2 - t1
print("tiempo", t_total)

#Con esto imprimis la x


# for y in range (0,n):
# print("posicion", y, "solucion", x[y])

#Con esto imprimis la T


#for a in range(0, ni):
# for b in range(0, nj):
# print("posicion", a, "solucion", T[a, b])

# print("matriz A", A)
# print("matriz b", b)
# print("matriz T", T)

# x = solver_SOR(A, b, 1.0, 0.01) 3 iter


# x = solver_SOR(A, b, 1.1, 0.01) 5 iter
# x = solver_SOR(A, b, 1.2, 0.01) 7 iter
# x = solver_SOR(A, b, 1.3, 0.01) 8 iter
# x = solver_SOR(A, b, 1.4, 0.01) 11 iter
# x = solver_SOR(A, b, 1.5, 0.01) 14 iter

# x = solver_SOR(A, b, 1.0, 0.1) 3 iter


# x = solver_SOR(A, b, 1.1, 0.1) 4 iter
# x = solver_SOR(A, b, 1.2, 0.1) 5 iter
# x = solver_SOR(A, b, 1.3, 0.1) 6 iter

You might also like