Texto y código sujeto bajo Creative Commons Attribution license, CC-BY-SA. (c) Original por Lorena A. Barba y Gilbert Forsyth en 2013, traducido por F.J. Navarro-Brull para CAChemE.org from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import matplotlib.pyplot as plt import numpy as np ### Declaración de variables nx = 41 ny = 41 nt = 120 c = 1 dx = 2.0/(nx-1) dy = 2.0/(ny-1) sigma = .0009 nu = 0.01 dt = sigma*dx*dy/nu x = np.linspace(0,2,nx) y = np.linspace(0,2,ny) u = np.ones((ny,nx)) ## crea un vector 1xn de unos v = np.ones((ny,nx)) un = np.ones((ny,nx)) ## vn = np.ones((ny,nx)) comb = np.ones((ny,nx)) ### Asignar variables inciales ## establece función de sobrero como C.I. : # u(.5<=x<=1 && .5<=y<=1) es 2 u[.5/dy:1/dy+1,.5/dx:1/dx+1]=2 v[.5/dy:1/dy+1,.5/dx:1/dx+1]=2 ### Representar condiciones iniciales. fig = plt.figure(figsize=(11,7), dpi=100) ax = fig.gca(projection='3d') X,Y = np.meshgrid(x,y) wire1 = ax.plot_wireframe(X,Y,u[:], cmap=cm.coolwarm) wire2 = ax.plot_wireframe(X,Y,v[:], cmap=cm.coolwarm) #ax.set_xlim(1,2) #ax.set_ylim(1,2) #ax.set_zlim(1,5) plt.show() for n in range(nt+1): ## Bucle a través del numéro de intervalos de t un[:] = u[:] vn[:] = v[:] u[1:-1,1:-1] = un[1:-1,1:-1] - dt/dx*un[1:-1,1:-1]*(un[1:-1,1:-1]-un[0:-2,1:-1])-dt/dy*vn[1:-1,1:-1]* \ (un[1:-1,1:-1]-un[1:-1,0:-2])+nu*dt/dx**2*(un[2:,1:-1]-2*un[1:-1,1:-1]+un[0:-2,1:-1])+ \ nu*dt/dy**2*(un[1:-1,2:]-2*un[1:-1,1:-1]+un[1:-1,0:-2]) v[1:-1,1:-1] = vn[1:-1,1:-1] - dt/dx*un[1:-1,1:-1]*(vn[1:-1,1:-1]-vn[0:-2,1:-1])-dt/dy*vn[1:-1,1:-1]* \ (vn[1:-1,1:-1]-vn[1:-1,0:-2])+nu*dt/dx**2*(vn[2:,1:-1]-2*vn[1:-1,1:-1]+vn[0:-2,1:-1])+ \ nu*dt/dy**2*(vn[1:-1,2:]-2*vn[1:-1,1:-1]+vn[1:-1,0:-2]) u[0,:] = 1 u[-1,:] = 1 u[:,0] = 1 u[:,-1] = 1 v[0,:] = 1 v[-1,:] = 1 v[:,0] = 1 v[:,-1] = 1 fig = plt.figure(figsize=(11,7), dpi=100) ax = fig.gca(projection='3d') X,Y = np.meshgrid(x,y) wire1 = ax.plot_wireframe(X,Y,u[:]) wire2 = ax.plot_wireframe(X,Y,v[:]) #ax.set_xlim(1,2) #ax.set_ylim(1,2) #ax.set_zlim(1,5) plt.show() from IPython.display import YouTubeVideo YouTubeVideo('tUg_dE3NXoY') from IPython.core.display import HTML def css_styling(): styles = open("../styles/custom.css", "r").read() return HTML(styles) css_styling()