Exemplo n.º 1
0
mu = 1
T = 0.1
Ny = 50
F = 0
dy = L/(Ny-1)
dt = 0.0001
Nt = round(T / dt + 1)

t = np.zeros(Nt)
y = np.zeros(Ny)
u = np.zeros([Nt,Ny])
u_sol = np.zeros(Ny)

for i in range(Ny):
  y[i] = -L/2 + i*dy
  u[0,i] = 0
  u_sol[i] = 2*U*y[i]/L

i = 1
while t[i-1]+dt <= T:
  t[i] = t[i-1] + dt
  u[i,:] = pde.euler_diffusion(u[i-1,:],mu,dt,dy,F)
  u[i,0] = -U
  u[i,Ny-1] = U
  i = i+1

plt.plot(y,u_sol,'o',y,u[0,:],y,u[np.floor(Nt/8),:],y,u[np.floor(Nt/4),:],y,u[np.floor(Nt/2),:],y,u[Nt-2,:])
plt.legend(["Exact solution","0","T/8","T/4","T/2","T"],loc = "upper left")
plt.show()

Exemplo n.º 2
0
mu = 1
T = 0.1
Ny = 50
F = 0
dy = L / (Ny - 1)
dt = 0.0001
Nt = round(T / dt + 1)

t = np.zeros(Nt)
y = np.zeros(Ny)
u = np.zeros([Nt, Ny])
u_sol = np.zeros(Ny)

for i in range(Ny):
    y[i] = -L / 2 + i * dy
    u[0, i] = 0
    u_sol[i] = 2 * U * y[i] / L

i = 1
while t[i - 1] + dt <= T:
    t[i] = t[i - 1] + dt
    u[i, :] = pde.euler_diffusion(u[i - 1, :], mu, dt, dy, F)
    u[i, 0] = -U
    u[i, Ny - 1] = U
    i = i + 1

plt.plot(y, u_sol, 'o', y, u[0, :], y, u[np.floor(Nt / 8), :], y,
         u[np.floor(Nt / 4), :], y, u[np.floor(Nt / 2), :], y, u[Nt - 2, :])
plt.legend(["Exact solution", "0", "T/8", "T/4", "T/2", "T"], loc="upper left")
plt.show()
Exemplo n.º 3
0
F = -1
dx = L/(Nx-1)
dt = 0.90*0.5*dx*dx/D
Nt = round(T / dt + 1)

t = np.zeros(Nt)
x = np.zeros(Nx)
u = np.zeros([Nt,Nx])
U = np.zeros(Nx)

for i in range(Nx):
  x[i] = i*dx
  u[0,i] = 0
  U[i] = 0.5*F/D*(x[i]*x[i] - x[i]*L)
  # temperature diffusion initial condition
#  if x[i] >= L/3 and x[i] <= 2*L/3:
#    u[0,i] = 1

i = 1
while t[i-1]+dt <= T:
  t[i] = t[i-1] + dt
  u[i,:] = pde.euler_diffusion(u[i-1,:],D,dt,dx,F)
  # specify boundary condition
  u[i,0] = 0
  u[i,Nx-1] = 0
  i = i + 1

#plt.plot(x,u[0,:],x,u[np.floor(Nt/80),:],x,u[np.floor(5*Nt/40),:],x,u[np.floor(Nt-1),:])
plt.plot(U,x,'o',u[np.floor(Nt/20),:],x,u[np.floor(Nt/10),:],x,u[np.floor(Nt/5),:],x,u[Nt-2,:],x)
plt.show()