0% found this document useful (0 votes)
20 views12 pages

PROBLEMA 3 .Ipynb - Colab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views12 pages

PROBLEMA 3 .Ipynb - Colab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.

ipynb - Colab

keyboard_arrow_down Universidad Nacional de San Cristobal de Huamanga


Maestría en Ciencias con mención en Hidrologia e Hidraulica

Flujo en Superficie Libre

Alumno: Ricardo Hinostroza Tello

Problema 3

Fecha: Octubre 2024

# Importar librerías
import numpy as np
import math
import matplotlib.pyplot as plt

# Datos generales
Imax = 100
tol = 1e-5

# Datos del problema


nx = 25 # Número de divisiones en la dirección x
ny = 25 # Número de divisiones en la dirección y
lx = 1 # Longitud del dominio en x
ly = 1 # Longitud del dominio en y
cd = 0.25 # Coeficiente de difusión ajustado para un código par

#Cálculos previos
dx=lx/nx
dy=ly/ny
rows,cols=(nx+2,ny+2)

# Asignación de matrices
x = np.zeros((rows,cols))
y = np.zeros((rows,cols))
AP = np.zeros((rows,cols))
SP = np.zeros((rows,cols))
SU = np.zeros((rows,cols))
phi = np.zeros((rows,cols))
AE = np.ones((rows,cols))
AW = np.ones((rows,cols))
AN = np.ones((rows,cols))
AS = np.ones((rows,cols))

phi

array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 1/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])

# Condiciones de borde
# Condición de borde: Oeste (x=0), �(0, y) = y
AW[1, :] = 0.
SP[1, :] = -2.
for j in range(1, ny + 1):
SU[1, j] = dy * (j - 1) # Asigna el valor de `y` en cada posición
# Condición de borde: Este (x=1), �(1, y) = 1 - y^2
AE[nx, :] = 0.
SP[nx, :] = -2.
for j in range(1, ny + 1):
SU[nx, j] = 1 - (dy * (j - 1))**2
# Condición de borde: Sur (y=0), �(x, 0) = x
AS[:, 1] = 0.
SP[:, 1] = -2.
for i in range(1, nx + 1):
SU[i, 1] = dx * (i - 1)
# Condición de borde: Norte (y=1), �(x, 1) = x^2
AN[:, ny] = 0.
SP[:, ny] = -2.
for i in range(1, nx + 1):
SU[i, ny] = (dx * (i - 1))**2

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 2/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
# Sobre escribir Condiciones de borde en las celdas de esquinas
# Esquina Sur-Oeste
AS[1, 1] = 0.
AW[1, 1] = 0.
SU[1, 1] = 0.
SP[1, 1] = -4.

# Esquina Nor-Oeste
AN[1, ny] = 0.
AW[1, ny] = 0.
SU[1, ny] = 2. * (dx / 2.)
SP[1, ny] = -4.

# Esquina Sur-Este
AS[nx, 1] = 0.
AE[nx, 1] = 0.
SU[nx, 1] = 2. * (dy / 2.)
SP[nx, 1] = -4.

# Esquina Nor-Este
AN[nx, ny] = 0.
AE[nx, ny] = 0.
SU[nx, ny] = 2. * ((dx / 2.) + dx * float(nx - 1)) + 2. * ((dy / 2.) + dy *float(ny - 1))
SP[nx, ny] = -4.

AE

array([[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 3/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]])

# Condiciones de borde
# Condición de borde: Oeste (x=0), �(0, y) = y
AW[1, :] = 0.
SP[1, :] = -2.
for j in range(1, ny + 1):
SU[1, j] = dy * (j - 1) # Asigna el valor de `y` en cada posición
# Condición de borde: Este (x=1), �(1, y) = 1 - y^2
AE[nx, :] = 0.
SP[nx, :] = -2.
for j in range(1, ny + 1):
SU[nx, j] = 1 - (dy * (j - 1))**2
# Condición de borde: Sur (y=0), �(x, 0) = x
AS[:, 1] = 0.
SP[:, 1] = -2.
for i in range(1, nx + 1):
SU[i, 1] = dx * (i - 1)
# Condición de borde: Norte (y=1), �(x, 1) = x^2
AN[:, ny] = 0.
SP[:, ny] = -2.
for i in range(1, nx + 1):
SU[i, ny] = (dx * (i - 1))**2

# Compilando todas las matrices AP


AP[:, :] = AE[:,:]+AW[:,:]+AN[:,:] + AS[:,:]-SP[:,:]

AP

array([[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[5., 4., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 5., 5., 5., 5., 5., 5., 5., 4., 5.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 4/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.],
[5., 4., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 5., 5., 5., 5., 5., 5., 5., 4., 5.],
[4., 5., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4.,
4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 4.]])

# Modo iterativo
omega = 1.7 # Factor de relajación

for iterations in range(1,Imax+1):


print('--------- Iteración = :',iterations)
for i in range(1,nx+1):
for j in range(1,ny+1):
phi[i,j] = phi[i,j]+omega/AP[i,j]*(AE[i,j]*phi[i+1,j]+AW[i,j]*phi[i-1,j]+AN[i,j]*phi[i,j+1]+A

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 5/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
--------- Iteración = : 70
--------- Iteración = : 71
--------- Iteración = : 72
--------- Iteración = : 73
--------- Iteración = : 74
--------- Iteración = : 75
--------- Iteración = : 76
--------- Iteración = : 77
--------- Iteración = : 78
--------- Iteración = : 79
--------- Iteración = : 80
--------- Iteración = : 81
--------- Iteración = : 82
--------- Iteración = : 83
--------- Iteración = : 84
--------- Iteración = : 85
--------- Iteración = : 86
--------- Iteración = : 87
--------- Iteración = : 88
--------- Iteración = : 89
--------- Iteración = : 90
--------- Iteración = : 91
--------- Iteración = : 92
--------- Iteración = : 93
--------- Iteración = : 94
--------- Iteración = : 95
--------- Iteración = : 96
--------- Iteración = : 97
--------- Iteración = : 98
--------- Iteración = : 99
--------- Iteración = : 100

phi

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 6/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
0.38714836, 0.37536533, 0.36250236, 0.34864679, 0.33392428,
0.31851519, 0.30268012, 0.2868007 , 0.27144683, 0.25748996,
0.24629602, 0.24004711, 0.24222834, 0.25813241, 0.29438607,
0.35390297, 0. ],
[0. , 0.45889217, 0.45970409, 0.45855405, 0.45543122,
0.45064203, 0.444355 , 0.4366454 , 0.42754829, 0.41708553,
0.40527862, 0.39215563, 0.37775657, 0.36213923, 0.34538717,
0.32762181, 0.30902201, 0.28985718, 0.27054646, 0.25177051,
0.23469519, 0.22144419, 0.21613006, 0.2270402 , 0.27029527,
0.36818739, 0. ],
[0. , 0.47555819, 0.48334058, 0.4830406 , 0.47970836,
0.47446991, 0.46759912, 0.45917063, 0.44920856, 0.43772381,
0.42472488, 0.41022191, 0.39422897, 0.37676631, 0.35786327,
0.3375628 , 0.31592887, 0.29305947, 0.26911127, 0.24435036,
0.21926998, 0.19490434, 0.17380749, 0.16360302, 0.1915674 ,
0.3703387 , 0. ],
[0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. ]])

# Ploteo
x[1, :] = 0.5 * dx
y[:, 1] = 0.5 * dy
for i in range(2, nx + 1):
for j in range(2, ny + 1):
x[i, j] = x[i - 1, j] + dx
y[i, j] = y[i, j - 1] + dy
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_aspect(aspect=1.0)
CS = plt.contour(x[1:nx + 1, 1:ny + 1], y[1:nx + 1, 1:ny + 1], phi[1:nx + 1, 1:ny + 1], levels=10)
plt.clabel(CS, fontsize=12, inline=1, fmt='%3.2f')
plt.show()

# Crear una matriz para la solucion analitica


phi_analitica = np.zeros((rows, cols))

#calcular la solucion analitica en cada punto de la malla


for i in range(1, nx + 1):
for j in range(1, ny + 1):
https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 7/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
x_val = dx*(i - 1)
y_val = dy*(j - 1)
phi_analitica[i,j] = x_val**2*y_val

phi_analitica

1.47456e-01, 1.63840e-01, 1.80224e-01, 1.96608e-01, 2.12992e-01,


2.29376e-01, 2.45760e-01, 2.62144e-01, 2.78528e-01, 2.94912e-01,
3.11296e-01, 3.27680e-01, 3.44064e-01, 3.60448e-01, 3.76832e-01,
3.93216e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 1.84960e-02, 3.69920e-02, 5.54880e-02,
7.39840e-02, 9.24800e-02, 1.10976e-01, 1.29472e-01, 1.47968e-01,
1.66464e-01, 1.84960e-01, 2.03456e-01, 2.21952e-01, 2.40448e-01,
2.58944e-01, 2.77440e-01, 2.95936e-01, 3.14432e-01, 3.32928e-01,
3.51424e-01, 3.69920e-01, 3.88416e-01, 4.06912e-01, 4.25408e-01,
4.43904e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 2.07360e-02, 4.14720e-02, 6.22080e-02,
8.29440e-02, 1.03680e-01, 1.24416e-01, 1.45152e-01, 1.65888e-01,
1.86624e-01, 2.07360e-01, 2.28096e-01, 2.48832e-01, 2.69568e-01,
2.90304e-01, 3.11040e-01, 3.31776e-01, 3.52512e-01, 3.73248e-01,
3.93984e-01, 4.14720e-01, 4.35456e-01, 4.56192e-01, 4.76928e-01,
4.97664e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 2.31040e-02, 4.62080e-02, 6.93120e-02,
9.24160e-02, 1.15520e-01, 1.38624e-01, 1.61728e-01, 1.84832e-01,
2.07936e-01, 2.31040e-01, 2.54144e-01, 2.77248e-01, 3.00352e-01,
3.23456e-01, 3.46560e-01, 3.69664e-01, 3.92768e-01, 4.15872e-01,
4.38976e-01, 4.62080e-01, 4.85184e-01, 5.08288e-01, 5.31392e-01,
5.54496e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 2.56000e-02, 5.12000e-02, 7.68000e-02,
1.02400e-01, 1.28000e-01, 1.53600e-01, 1.79200e-01, 2.04800e-01,
2.30400e-01, 2.56000e-01, 2.81600e-01, 3.07200e-01, 3.32800e-01,
3.58400e-01, 3.84000e-01, 4.09600e-01, 4.35200e-01, 4.60800e-01,
4.86400e-01, 5.12000e-01, 5.37600e-01, 5.63200e-01, 5.88800e-01,
6.14400e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 2.82240e-02, 5.64480e-02, 8.46720e-02,
1.12896e-01, 1.41120e-01, 1.69344e-01, 1.97568e-01, 2.25792e-01,
2.54016e-01, 2.82240e-01, 3.10464e-01, 3.38688e-01, 3.66912e-01,
3.95136e-01, 4.23360e-01, 4.51584e-01, 4.79808e-01, 5.08032e-01,
5.36256e-01, 5.64480e-01, 5.92704e-01, 6.20928e-01, 6.49152e-01,
6.77376e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 3.09760e-02, 6.19520e-02, 9.29280e-02,
1.23904e-01, 1.54880e-01, 1.85856e-01, 2.16832e-01, 2.47808e-01,
2.78784e-01, 3.09760e-01, 3.40736e-01, 3.71712e-01, 4.02688e-01,
4.33664e-01, 4.64640e-01, 4.95616e-01, 5.26592e-01, 5.57568e-01,
5.88544e-01, 6.19520e-01, 6.50496e-01, 6.81472e-01, 7.12448e-01,
7.43424e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 3.38560e-02, 6.77120e-02, 1.01568e-01,
1.35424e-01, 1.69280e-01, 2.03136e-01, 2.36992e-01, 2.70848e-01,
3.04704e-01, 3.38560e-01, 3.72416e-01, 4.06272e-01, 4.40128e-01,
4.73984e-01, 5.07840e-01, 5.41696e-01, 5.75552e-01, 6.09408e-01,
6.43264e-01, 6.77120e-01, 7.10976e-01, 7.44832e-01, 7.78688e-01,
8.12544e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 3.68640e-02, 7.37280e-02, 1.10592e-01,
1.47456e-01, 1.84320e-01, 2.21184e-01, 2.58048e-01, 2.94912e-01,
3.31776e-01, 3.68640e-01, 4.05504e-01, 4.42368e-01, 4.79232e-01,
5.16096e-01, 5.52960e-01, 5.89824e-01, 6.26688e-01, 6.63552e-01,
7.00416e-01, 7.37280e-01, 7.74144e-01, 8.11008e-01, 8.47872e-01,
8.84736e-01, 0.00000e+00],
[0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00,
0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00,
0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00,
0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00,
0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00, 0.00000e+00,
0.00000e+00, 0.00000e+00]])

# calcular el error absoluto entre la solucion numerica y la solucion analitica


error_absoluto = np.abs(phi - phi_analitica)

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 8/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab

error_absoluto

1.11032756e-01, 1.33696716e-01, 1.54888638e-01, 1.74687819e-01,


1.93506255e-01, 2.12148737e-01, 0.00000000e+00],
[0.00000000e+00, 3.59115690e-01, 3.36527640e-01, 3.13691203e-01,
2.90458175e-01, 2.66707940e-01, 2.42350103e-01, 2.17322448e-01,
1.91588006e-01, 1.65133190e-01, 1.37967631e-01, 1.10125771e-01,
8.16701453e-02, 5.26962896e-02, 2.33392441e-02, 6.21852113e-03,
3.57382513e-02, 6.49163893e-02, 9.33791450e-02, 1.20685515e-01,
1.46348225e-01, 1.69887341e-01, 1.90935060e-01, 2.09404606e-01,
2.25705483e-01, 2.40916786e-01, 0.00000000e+00],
[0.00000000e+00, 3.78999771e-01, 3.53796462e-01, 3.28287310e-01,
3.02290949e-01, 2.75670843e-01, 2.48333927e-01, 2.20222319e-01,
1.91306146e-01, 1.61579688e-01, 1.31060689e-01, 9.97922475e-02,
6.78469712e-02, 3.53333612e-02, 2.40465308e-03, 3.07295580e-02,
6.37886654e-02, 9.64036507e-02, 1.28098642e-01, 1.58276393e-01,
1.86219298e-01, 2.11129385e-01, 2.32247692e-01, 2.49106110e-01,
2.61938338e-01, 2.72137753e-01, 0.00000000e+00],
[0.00000000e+00, 3.98982864e-01, 3.71243331e-01, 3.43114831e-01,
3.14363671e-01, 2.84838751e-01, 2.54452630e-01, 2.23158932e-01,
1.90938731e-01, 1.57794874e-01, 1.23751319e-01, 8.88556721e-02,
5.31842268e-02, 1.68496100e-02, 1.99883726e-02, 5.71076526e-02,
9.42031707e-02, 1.30858890e-01, 1.66511375e-01, 2.00406126e-01,
2.31555210e-01, 2.58723237e-01, 2.80508248e-01, 2.95649846e-01,
3.03748054e-01, 3.06409678e-01, 0.00000000e+00],
[0.00000000e+00, 4.19071340e-01, 3.88951322e-01, 3.58309161e-01,
3.26826294e-01, 2.94355992e-01, 2.60839032e-01, 2.26254156e-01,
1.90599069e-01, 1.53885841e-01, 1.16142114e-01, 7.74149529e-02,
3.77766994e-02, 2.66674200e-03, 4.37640793e-02, 8.53014982e-02,
1.26977474e-01, 1.68365373e-01, 2.08857858e-01, 2.47585548e-01,
2.83304209e-01, 3.14260138e-01, 3.38100255e-01, 3.52053013e-01,
3.53938394e-01, 3.44834615e-01, 0.00000000e+00],
[0.00000000e+00, 4.39198602e-01, 4.07053560e-01, 3.74088291e-01,
3.39892436e-01, 3.04407963e-01, 2.67653409e-01, 2.29651641e-01,
1.90421587e-01, 1.49983336e-01, 1.08364359e-01, 6.56053341e-02,
2.17663591e-02, 2.30652069e-02, 6.87637198e-02, 1.15148809e-01,
1.61959879e-01, 2.08815299e-01, 2.55145171e-01, 3.00078035e-01,
3.42247975e-01, 3.79472887e-01, 4.08267659e-01, 4.23339593e-01,
4.18061929e-01, 3.89521027e-01, 0.00000000e+00],
[0.00000000e+00, 4.58892169e-01, 4.25848085e-01, 3.90842051e-01,
3.53863224e-01, 3.15218034e-01, 2.75075003e-01, 2.33509404e-01,
1.90556286e-01, 1.46237530e-01, 1.00574619e-01, 5.35956277e-02,
5.34056699e-03, 4.41327711e-02, 9.47408327e-02, 1.46362187e-01,
1.98817987e-01, 2.51838821e-01, 3.05005539e-01, 3.57637493e-01,
4.08568812e-01, 4.55675815e-01, 4.94845938e-01, 5.17791803e-01,
5.08392730e-01, 4.44356609e-01, 0.00000000e+00],
[0.00000000e+00, 4.75558186e-01, 4.46476577e-01, 4.09312602e-01,
3.69116355e-01, 3.27013912e-01, 2.83279121e-01, 2.37986630e-01,
1.91160559e-01, 1.42811809e-01, 9.29488833e-02, 4.15819120e-02,
1.12750274e-02, 6.56016911e-02, 1.21368730e-01, 1.78533196e-01,
2.37031130e-01, 2.96764525e-01, 3.57576731e-01, 4.19201639e-01,
4.81146016e-01, 5.42375662e-01, 6.00336511e-01, 6.47404979e-01,
6.56304600e-01, 5.14397301e-01, 0.00000000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00]])

print("Error absoluto promedio:", np.mean(error_absoluto))

Error absoluto promedio: 0.15120111964577948

# Mostrar la solucion analitica y error


print("Solución nalitica:")
https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 9/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
print(phi_analitica)

print("Eroor absoluto")
print(error_absoluto)

1.11032756e-01 1.33696716e-01 1.54888638e-01 1.74687819e-01


1.93506255e-01 2.12148737e-01 0.00000000e+00]
[0.00000000e+00 3.59115690e-01 3.36527640e-01 3.13691203e-01
2.90458175e-01 2.66707940e-01 2.42350103e-01 2.17322448e-01
1.91588006e-01 1.65133190e-01 1.37967631e-01 1.10125771e-01
8.16701453e-02 5.26962896e-02 2.33392441e-02 6.21852113e-03
3.57382513e-02 6.49163893e-02 9.33791450e-02 1.20685515e-01
1.46348225e-01 1.69887341e-01 1.90935060e-01 2.09404606e-01
2.25705483e-01 2.40916786e-01 0.00000000e+00]
[0.00000000e+00 3.78999771e-01 3.53796462e-01 3.28287310e-01
3.02290949e-01 2.75670843e-01 2.48333927e-01 2.20222319e-01
1.91306146e-01 1.61579688e-01 1.31060689e-01 9.97922475e-02
6.78469712e-02 3.53333612e-02 2.40465308e-03 3.07295580e-02
6.37886654e-02 9.64036507e-02 1.28098642e-01 1.58276393e-01
1.86219298e-01 2.11129385e-01 2.32247692e-01 2.49106110e-01
2.61938338e-01 2.72137753e-01 0.00000000e+00]
[0.00000000e+00 3.98982864e-01 3.71243331e-01 3.43114831e-01
3.14363671e-01 2.84838751e-01 2.54452630e-01 2.23158932e-01
1.90938731e-01 1.57794874e-01 1.23751319e-01 8.88556721e-02
5.31842268e-02 1.68496100e-02 1.99883726e-02 5.71076526e-02
9.42031707e-02 1.30858890e-01 1.66511375e-01 2.00406126e-01
2.31555210e-01 2.58723237e-01 2.80508248e-01 2.95649846e-01
3.03748054e-01 3.06409678e-01 0.00000000e+00]
[0.00000000e+00 4.19071340e-01 3.88951322e-01 3.58309161e-01
3.26826294e-01 2.94355992e-01 2.60839032e-01 2.26254156e-01
1.90599069e-01 1.53885841e-01 1.16142114e-01 7.74149529e-02
3.77766994e-02 2.66674200e-03 4.37640793e-02 8.53014982e-02
1.26977474e-01 1.68365373e-01 2.08857858e-01 2.47585548e-01
2.83304209e-01 3.14260138e-01 3.38100255e-01 3.52053013e-01
3.53938394e-01 3.44834615e-01 0.00000000e+00]
[0.00000000e+00 4.39198602e-01 4.07053560e-01 3.74088291e-01
3.39892436e-01 3.04407963e-01 2.67653409e-01 2.29651641e-01
1.90421587e-01 1.49983336e-01 1.08364359e-01 6.56053341e-02
2.17663591e-02 2.30652069e-02 6.87637198e-02 1.15148809e-01
1.61959879e-01 2.08815299e-01 2.55145171e-01 3.00078035e-01
3.42247975e-01 3.79472887e-01 4.08267659e-01 4.23339593e-01
4.18061929e-01 3.89521027e-01 0.00000000e+00]
[0.00000000e+00 4.58892169e-01 4.25848085e-01 3.90842051e-01
3.53863224e-01 3.15218034e-01 2.75075003e-01 2.33509404e-01
1.90556286e-01 1.46237530e-01 1.00574619e-01 5.35956277e-02
5.34056699e-03 4.41327711e-02 9.47408327e-02 1.46362187e-01
1.98817987e-01 2.51838821e-01 3.05005539e-01 3.57637493e-01
4.08568812e-01 4.55675815e-01 4.94845938e-01 5.17791803e-01
5.08392730e-01 4.44356609e-01 0.00000000e+00]
[0.00000000e+00 4.75558186e-01 4.46476577e-01 4.09312602e-01
3.69116355e-01 3.27013912e-01 2.83279121e-01 2.37986630e-01
1.91160559e-01 1.42811809e-01 9.29488833e-02 4.15819120e-02
1.12750274e-02 6.56016911e-02 1.21368730e-01 1.78533196e-01
2.37031130e-01 2.96764525e-01 3.57576731e-01 4.19201639e-01
4.81146016e-01 5.42375662e-01 6.00336511e-01 6.47404979e-01
6.56304600e-01 5.14397301e-01 0.00000000e+00]
[0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00]]

#Grafico de la solucion analitica


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_aspect(aspect=1.0)
CS = plt.contour(x[1:nx+1, 1:ny+1], y[1:nx+1, 1:ny+1], phi_analitica[1:nx + 1, 1:ny+1], levels=10)
https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 10/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab
plt.clabel(CS, fontsize=12, inline=1, fmt='%3.2f')
plt.title("solucion muneran")
plt.show()

#Grafico de la solucion numerica


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_aspect(aspect=1.0)
CS = plt.contour(x[1:nx+1, 1:ny+1], y[1:nx+1, 1:ny+1], phi[1:nx + 1, 1:ny+1], levels=10)
plt.clabel(CS, fontsize=12, inline=1, fmt='%3.2f')
plt.title("solucion Numerica")
plt.show()

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 11/12
6/11/24, 19:47 Copia de PROBLEMA 1 DE DIFUSIÓN.ipynb - Colab

https://colab.research.google.com/drive/1UwBZz2_TiCLTfIhZTeGyOQqs6hNKe549?authuser=1#scrollTo=QFzGHmgLtEaZ 12/12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy