本文主要是介绍准一维喷管亚声超声流动 有限差分求解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
写一个准一维喷管流动的有限差分数值解,经典算例,计算流体力学入门第七章
该运动等熵,气体在喉部达到声速,后超声速流动,本例采用非守恒方程,显式MacCormark方法求解。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.ticker import FixedLocator
定义格子宽度Δx = 0.1 写出无量纲长度
delta_x = 0.1 x = np.arange(0.0,3.1,0.1,dtype = float)print("无量纲距离",x)
无量纲距离 [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. 1.1 1.2 1.3 1.4 1.5 1.6 1.71.8 1.9 2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3. ]
定义喷管形状A=A(x)
A = 1+2.2*(x-1.5)**2 #可以看出,在x=1.5处,喉部面积为1,故A1即为无量纲面积plt.figure(figsize=(10,5))
plt.plot(x,A,linewidth=4)
plt.xlabel('Distance',labelpad=30, size=40, weight='bold')
plt.xticks( size=30, weight='bold')
plt.yticks( size=30, weight='bold')print("各点截面积",A)
各点截面积 [5.95 5.312 4.718 4.168 3.662 3.2 2.782 2.408 2.078 1.792 1.55 1.3521.198 1.088 1.022 1. 1.022 1.088 1.198 1.352 1.55 1.792 2.078 2.4082.782 3.2 3.662 4.168 4.718 5.312 5.95 ]
定义t=0时各点状态
density =1 - 0.3146*x
T = 1 - 0.2314*x
V = (0.1+1.09*x)*T**(1/2)plt.figure(figsize=(10,5))
plt.plot(x,density,linewidth=4,c='gold')
plt.plot(x,T,linewidth=4,c='tan')
plt.plot(x,V,linewidth=4,c='orange')
plt.legend(['density','T','V'],frameon=False,loc="upper left",fontsize=20)
plt.xlabel('Distance',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("各点密度",density)
print("各点温度",T)
print("各点速度",V)
各点密度 [1. 0.96854 0.93708 0.90562 0.87416 0.8427 0.81124 0.77978 0.748320.71686 0.6854 0.65394 0.62248 0.59102 0.55956 0.5281 0.49664 0.465180.43372 0.40226 0.3708 0.33934 0.30788 0.27642 0.24496 0.2135 0.182040.15058 0.11912 0.08766 0.0562 ]
各点温度 [1. 0.97686 0.95372 0.93058 0.90744 0.8843 0.86116 0.83802 0.814880.79174 0.7686 0.74546 0.72232 0.69918 0.67604 0.6529 0.62976 0.606620.58348 0.56034 0.5372 0.51406 0.49092 0.46778 0.44464 0.4215 0.398360.37522 0.35208 0.32894 0.3058 ]
各点速度 [0.1 0.20656772 0.31055431 0.41191227 0.5105917 0.606540110.69970225 0.79001982 0.87743124 0.96187135 1.04327104 1.121556931.19665091 1.26846965 1.33692406 1.40191865 1.46335081 1.521109941.57507649 1.62512075 1.67110158 1.71286469 1.75024077 1.783043161.81106497 1.83407564 1.85181659 1.86399585 1.87028111 1.870290821.86358258]
计算时间步长
C = 0.5 #定义克朗数为0.5delta_t1=[]
for i in range(1,31): delta_t_i = C*(delta_x/(T[i]**(1/2)+V[i]))delta_t1.append(delta_t_i)delta_t = min(delta_t1) #取最小时间步长
print("最小时间步长为",delta_t)
最小时间步长为 0.020134450213606162
定义速度,温度,密度,压力比,马赫数,无量纲质量流量 集合
V1=[list(V)]
density1 = [list(density)]
T1 = [list(T)]
A1=list(A)
ma=[]
for i in range(0,len(V1[0])):ma.append(V1[0][i]/T1[0][i]**(1/2))
Ma=[ma]p=[]
for i in range(0,len(V1[0])):p.append(density1[0][i]*T1[0][i])
P1=[p]mm=[]
for i in range(0,len(V1[0])):mm.append(density1[0][i]*V1[0][i]*A1[i])
M=[mm]
MacCormark 显式方法
推进1400个时间步
gamma = 1.4for j in range(0,1401):ma=[]p=[]mm=[]d_den_d_t=[]d_V_d_t=[]d_T_d_t=[]_den=[]_V=[]_T=[]_d_den_d_t=[0]_d_V_d_t=[0]_d_T_d_t=[0]av_d_den_d_t=[0]av_d_V_d_t=[0]av_d_T_d_t=[0]den_next_t=[0]V_next_t=[0]T_next_t=[0]#预测步for i in range(0,30):#用向前差分计算对时间的微分d_den_d_t.append(-density1[j][i]*(V1[j][i+1]-V1[j][i])/delta_x - density1[j][i]*V1[j][i]*(np.log(A1[i+1])-np.log(A1[i]))/delta_x - V1[j][i]*(density1[j][i+1]-density1[j][i])/delta_x)d_V_d_t.append(-V1[j][i]*(V1[j][i+1]-V1[j][i])/delta_x - 1/gamma*((T1[j][i+1]-T1[j][i])/delta_x+T1[j][i]/density1[j][i]*(density1[j][i+1]-density1[j][i])/delta_x))d_T_d_t.append(-V1[j][i]*(T1[j][i+1]-T1[j][i])/delta_x - (gamma-1)*T1[j][i]*((V1[j][i+1]-V1[j][i])/delta_x+V1[j][i]*(np.log(A1[i+1])-np.log(A1[i]))/delta_x))#得到各个预测量_den.append(density1[j][i]+d_den_d_t[i]*delta_t)_V.append(V1[j][i]+d_V_d_t[i]*delta_t)_T.append(T1[j][i]+d_T_d_t[i]*delta_t)#修正步 for i in range(1,30):#使用带横线量进行向后差分_d_den_d_t.append(-_den[i]*(_V[i]-_V[i-1])/delta_x - _den[i]*_V[i]*(np.log(A1[i])-np.log(A1[i-1]))/delta_x - _V[i]*(_den[i]-_den[i-1])/delta_x)_d_V_d_t.append(-_V[i]*(_V[i]-_V[i-1])/delta_x - 1/gamma*((_T[i]-_T[i-1])/delta_x+_T[i]/_den[i]*(_den[i]-_den[i-1])/delta_x))_d_T_d_t.append(-_V[i]*(_T[i]-_T[i-1])/delta_x - (gamma-1)*_T[i]*((_V[i]-_V[i-1])/delta_x+_V[i]*(np.log(A1[i])-np.log(A1[i-1]))/delta_x))#计算各值时间导数的平均值-averageav_d_den_d_t.append(0.5*(d_den_d_t[i]+_d_den_d_t[i]))av_d_V_d_t.append(0.5*(d_V_d_t[i]+_d_V_d_t[i]))av_d_T_d_t.append(0.5*(d_T_d_t[i]+_d_T_d_t[i]))#得到下一时刻流动参数的修正值den_next_t.append(density1[j][i]+av_d_den_d_t[i]*delta_t)V_next_t.append(V1[j][i]+av_d_V_d_t[i]*delta_t)T_next_t.append(T1[j][i]+av_d_T_d_t[i]*delta_t)#计算下一时刻第一个点的速度,密度,温度den_next_t[0]=1V_next_t[0]=2*V_next_t[1]-V_next_t[2]T_next_t[0]=1#计算下一时刻最后一个点的速度,密度,温度den_next_t.append(2*den_next_t[29]-den_next_t[28])V_next_t.append(2*V_next_t[29]-V_next_t[28])T_next_t.append(2*T_next_t[29]-T_next_t[28])for i in range(len(V1[0])):ma.append(V1[j][i]/T1[j][i]**(1/2))for i in range(0,len(V1[0])):p.append(density1[j][i]*T1[j][i])for i in range(0,len(V1[0])):mm.append(density1[j][i]*V1[j][i]*A1[i])#将下一时刻各流动参量加入流动参量大集合中V1.append(V_next_t)T1.append(T_next_t)density1.append(den_next_t)Ma.append(ma)P1.append(p)M.append(mm)
t=list(range(0,1401))
D=[]
for i in range(0,1401):D.append(density1[i][15])plt.figure(figsize=(10,5))
plt.plot(t,D,linewidth=4)
plt.xlabel('TIME(Δt)',labelpad=30, size=40, weight='bold')
plt.ylabel('$\mathregular{ρ/ρ_0}$',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("喷管喉部密度随时间步变化")
喷管喉部密度随时间步变化
t=list(range(0,1401))
TTT=[]
for i in range(0,1401):TTT.append(T1[i][15])plt.figure(figsize=(10,5))
plt.plot(t,TTT,linewidth=4)
plt.xlabel('TIME(Δt)',labelpad=30, size=40, weight='bold')
plt.ylabel('$\mathregular{T/T_0}$',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("喷管喉部温度随时间步变化")
喷管喉部温度随时间步变化
t=list(range(0,1401))
MMA=[]
for i in range(0,1401):MMA.append(Ma[i][15])plt.figure(figsize=(10,5))
plt.plot(t,MMA,linewidth=4)
plt.xlabel('TIME(Δt)',labelpad=30, size=40, weight='bold')
plt.ylabel('Ma',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("喷管喉部马赫数随时间步变化")
喷管喉部马赫数随时间步变化
t=list(range(0,1401))
PPP=[]
for i in range(0,1401):PPP.append(P1[i][15])plt.figure(figsize=(10,5))
plt.plot(t,PPP,linewidth=4)
plt.xlabel('TIME(Δt)',labelpad=30, size=40, weight='bold')
plt.ylabel('$\mathregular{P/P_0}$',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("喷管喉部压力比马赫数随时间步变化")
喷管喉部压力比马赫数随时间步变化
plt.figure(figsize=(10,10))
plt.plot(x,Ma[1400],linewidth=4)
plt.scatter(x,Ma[1400],marker = "^",linewidths=6)
plt.xlabel('DISTANCE (x)',labelpad=30, size=40, weight='bold')
plt.ylabel('Ma',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("数值解:喷管内马赫数随随无量纲距离x的变化")
数值解:喷管内马赫数随随无量纲距离x的变化
plt.figure(figsize=(10,10))
plt.plot(x,density1[1400],linewidth=4)
plt.scatter(x,density1[1400],marker = "^",linewidths=6)
plt.xlabel('DISTANCE (x)',labelpad=30, size=40, weight='bold')
plt.ylabel('$\mathregular{ρ/ρ_0}$',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("数值解:喷管内无量纲密度随无量纲距离x的变化")
数值解:喷管内无量纲密度随无量纲距离x的变化
plt.figure(figsize=(8,10))
plt.plot(x,M[0],linewidth=4,c='#D9CBDF')
plt.plot(x,M[50],linewidth=4,c='#C19CC4')
plt.plot(x,M[100],linewidth=4,c='#FAE9BD')
plt.plot(x,M[150],linewidth=4,c='#F4D6CE')
plt.plot(x,M[200],linewidth=4,c='#E3E2E1')
plt.plot(x,M[700],linewidth=4,c='#C1BDBC')
#plt.scatter(x,density1[1400],marker = "^",linewidths=6)
plt.legend(['0Δt','50Δt','100Δt','150Δt','200Δt','700Δt'],frameon=False,loc="upper right",fontsize=20)
plt.xlabel('DISTANCE (x)',labelpad=30, size=40, weight='bold')
plt.ylabel('$\mathregular{ρVA/{ρ_0}{a_0}{A^*}}$',labelpad=30, size=40, weight='bold')
plt.xticks( size=25, weight='bold')
plt.yticks( size=25, weight='bold')print("数值解:喷管内无量纲密度随无量纲距离x的变化")
数值解:喷管内无量纲密度随无量纲距离x的变化
给出1400步以后的流场参数
data_1400 = {'x':x, 'A':A, 'ρ':density1[1400], 'V':V1[1400], 'T':T1[1400], 'P':P1[1400], 'Ma':Ma[1400],'m':M[1400]}df_1400 = pd.DataFrame(data_1400)
df_1400
x | A | ρ | V | T | P | Ma | m | |
---|---|---|---|---|---|---|---|---|
0 | 0.0 | 5.950 | 1.000000 | 0.098614 | 1.000000 | 1.000000 | 0.098614 | 0.586751 |
1 | 0.1 | 5.312 | 0.997535 | 0.111935 | 0.999010 | 0.996547 | 0.111991 | 0.593135 |
2 | 0.2 | 4.718 | 0.996673 | 0.125257 | 0.998668 | 0.995345 | 0.125341 | 0.588998 |
3 | 0.3 | 4.168 | 0.993975 | 0.142578 | 0.997583 | 0.991573 | 0.142750 | 0.590683 |
4 | 0.4 | 3.662 | 0.991314 | 0.162266 | 0.996517 | 0.987860 | 0.162549 | 0.589057 |
5 | 0.5 | 3.200 | 0.987027 | 0.186533 | 0.994790 | 0.981885 | 0.187021 | 0.589163 |
6 | 0.6 | 2.782 | 0.981490 | 0.215433 | 0.992557 | 0.974185 | 0.216239 | 0.588241 |
7 | 0.7 | 2.408 | 0.973470 | 0.250749 | 0.989307 | 0.963060 | 0.252101 | 0.587785 |
8 | 0.8 | 2.078 | 0.962304 | 0.293556 | 0.984759 | 0.947638 | 0.295819 | 0.587014 |
9 | 0.9 | 1.792 | 0.946355 | 0.345760 | 0.978209 | 0.925733 | 0.349590 | 0.586364 |
10 | 1.0 | 1.550 | 0.923824 | 0.408998 | 0.968850 | 0.895047 | 0.415521 | 0.585655 |
11 | 1.1 | 1.352 | 0.892197 | 0.485004 | 0.955488 | 0.852484 | 0.496172 | 0.585036 |
12 | 1.2 | 1.198 | 0.848889 | 0.574738 | 0.936740 | 0.795188 | 0.593827 | 0.584490 |
13 | 1.3 | 1.088 | 0.791798 | 0.677972 | 0.911147 | 0.721444 | 0.710260 | 0.584056 |
14 | 1.4 | 1.022 | 0.720719 | 0.792484 | 0.877688 | 0.632567 | 0.845903 | 0.583724 |
15 | 1.5 | 1.000 | 0.638459 | 0.913958 | 0.836343 | 0.533971 | 0.999388 | 0.583525 |
16 | 1.6 | 1.022 | 0.550822 | 1.036592 | 0.788494 | 0.434320 | 1.167371 | 0.583540 |
17 | 1.7 | 1.088 | 0.464806 | 1.154537 | 0.736700 | 0.342423 | 1.345125 | 0.583860 |
18 | 1.8 | 1.198 | 0.386202 | 1.263325 | 0.683926 | 0.264134 | 1.527603 | 0.584503 |
19 | 1.9 | 1.352 | 0.318254 | 1.360495 | 0.632744 | 0.201373 | 1.710342 | 0.585393 |
20 | 2.0 | 1.550 | 0.261733 | 1.445483 | 0.584867 | 0.153079 | 1.890099 | 0.586412 |
21 | 2.1 | 1.792 | 0.215835 | 1.518860 | 0.541191 | 0.116808 | 2.064631 | 0.587458 |
22 | 2.2 | 2.078 | 0.179004 | 1.581969 | 0.501922 | 0.089846 | 2.232956 | 0.588445 |
23 | 2.3 | 2.408 | 0.149598 | 1.636070 | 0.466957 | 0.069856 | 2.394216 | 0.589363 |
24 | 2.4 | 2.782 | 0.126051 | 1.682840 | 0.435862 | 0.054941 | 2.548992 | 0.590130 |
25 | 2.5 | 3.200 | 0.107172 | 1.722989 | 0.408345 | 0.043763 | 2.696303 | 0.590901 |
26 | 2.6 | 3.662 | 0.091829 | 1.758455 | 0.383748 | 0.035239 | 2.838628 | 0.591327 |
27 | 2.7 | 4.168 | 0.079450 | 1.788559 | 0.362060 | 0.028766 | 2.972438 | 0.592280 |
28 | 2.8 | 4.718 | 0.069020 | 1.816603 | 0.342233 | 0.023621 | 3.105266 | 0.591549 |
29 | 2.9 | 5.312 | 0.060935 | 1.839138 | 0.325239 | 0.019818 | 3.224877 | 0.595301 |
30 | 3.0 | 5.950 | 0.052850 | 1.861674 | 0.308245 | 0.016291 | 3.353173 | 0.585412 |
参考资料:
[1] 计算流体力学基础及其应用. [美]John D.Anderson. 著;吴颂平, 刘赵淼译. 北京:机械工业出版社,2007. 6
这篇关于准一维喷管亚声超声流动 有限差分求解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!