🎯达朗贝尔一维波动通解,二维变速模拟 | 🎯达朗贝尔算子解双曲波形微分方程 | 🎯耗散系统粘性伯格斯方程快速傅里叶变换算法 | 🎯二维线性和非线性对流扩散解和湍流隐式建模
Copy import numpy as np
import sympy as sp
import pylab as pl
pl . ion ()
x , nu , t = sp . symbols ( 'x nu t' )
phi = sp . exp ( - (x - 4 * t) ** 2 / ( 4 * nu * (t + 1 ))) + sp . exp ( - (x - 4 * t - 2 * np.pi) ** 2 / ( 4 * nu * (t + 1 )))
phiprime = phi . diff (x)
u = - 2 * nu * (phiprime / phi) + 4
from sympy . utilities . lambdify import lambdify
ufunc = lambdify ((t, x, nu), u)
nx = 101
nt = 100
dx = 2 * np . pi / (nx - 1 )
nu = 0.07
dt = dx * nu
T = nt * dt
grid = np . linspace ( 0 , 2 * np.pi, nx)
un = np . empty (nx)
t = 0
u = np . asarray ([ ufunc (t, x, nu) for x in grid])
pl . figure (figsize = ( 11 , 7 ), dpi = 100 )
pl . plot (grid,u, marker = 'o' , lw = 2 )
pl . xlim ([ 0 , 2 * np.pi])
pl . ylim ([ 0 , 10 ])
pl . xlabel ( 'X' )
pl . ylabel ( 'Velocity' )
pl . title ( '1D Burgers Equation - Initial condition' )
for n in range (nt):
un = u . copy ()
for i in range (nx - 1 ):
u [ i ] = un [ i ] - un [ i ] * dt / dx * (un [ i ] - un [ i - 1 ] ) + \
nu * dt / (dx ** 2 ) * (un [ i + 1 ] - 2 * un [ i ] + un [ i - 1 ] )
u [ - 1 ] = un [ - 1 ] - un [ - 1 ] * dt / dx * (un [ - 1 ] - un [ - 2 ] ) + \
nu * dt / (dx ** 2 ) * (un [ 0 ] - 2 * un [ - 1 ] + un [ - 2 ] )
u_analytical = np . asarray ([ ufunc (T, xi, nu) for xi in grid])
pl . figure (figsize = ( 11 , 7 ), dpi = 100 )
pl . plot (grid, u, marker = 'o' , lw = 2 , label = 'Computational' )
pl . plot (grid, u_analytical, label = 'Analytical' )
pl . xlim ([ 0 , 2 * np.pi])
pl . ylim ([ 0 , 10 ])
pl . legend ()
pl . xlabel ( 'X' )
pl . ylabel ( 'Velocity' )
pl . title ( '1D Burgers Equation - Solutions' )