def __init__(self, left, right): self.left = left self.right = right import math u1 = left[0] u2 = right[0] # r1 = left[1]; # r2 = right[1] T1 = left[1] T2 = right[1] p1 = left[2] p2 = right[2] # T1 = p1 / r1 / Rg(); # T2 = p2 / r2 / Rg() r1 = p1 / Rg() / T1 r2 = p2 / Rg() / T2 k1 = k_Justi(T1) k2 = k_Justi(T2) a1 = math.sqrt(k1 * p1 / r1) a2 = math.sqrt(k2 * p2 / r2) print("-" * 100) print("{0:^50}|{1:^50}".format("ul=%.5gm/s" % u1, "ur=%.5gm/s" % u2)) print("{0:^50}|{1:^50}".format("rhol=%.5gkg/m^3" % r1, "rhor=%.5gkg/m^3" % r2)) print("{0:^50}|{1:^50}".format("pl=%sPa" % p1, "pr=%sPa" % p2)) print("{0:^50}|{1:^50}".format("Tl=%sK" % T1, "Tr=%sK" % T2)) print("-" * 100)
def compress(self, pim=1.e5, Tim=300, Tr=800, xr=0.0, kc=1.3, phic=1): self.kc=kc from GasProperty import DieselMixture, Rg ivc = self.ValveTiming.IVC self.pim = pivc = pim Tim = 313. + 5. / 6. * (Tim - 273.15) # 新鲜充量温度 self.Tim = Tivc = Tim * (1 - xr) + xr * Tr # 新鲜充量质量 mivc = phic * pivc * self.CylGeo.V(180) / Rg() / Tivc self.mix = DieselMixture() self.mix.init_With_Mc_r(mivc, xr, mivc / 14.3 / 1.1) print("Intake air mass {} mg".format(mivc * 1.e6)) print("Tivc=", Tivc) Vivc = self.CylGeo.V(ivc) for i in range(ivc, ivc + 720): V = self.CylGeo.V(i) T = Tivc * pow(Vivc / V, kc - 1) p = pivc * pow(Vivc / V, kc) m = p * V / self.mix.Rg_gas(0) / T self.CompressData.append([i, V, p, T, m]) from Valve import mod for i in range(self.CompressData.row): self.CompressData.table[0].data[i] = mod(self.CompressData.table[0].data[i]) self.CompressData.doQuickSort(0)
def openEnd(p, p0=1.e5, T0=300, R=None, k=None): from GasProperty import k_Justi, Rg from math import sqrt if R is None: R = Rg() if k is None: k = k_Justi(T0) return sqrt(2 * k * R * T0 / (k - 1) * (1 - pow(p / p0, (k - 1) / k)))
def openEnd2(u, p0=1.e5, T0=300, R=None, k=None): from GasProperty import k_Justi, Rg from math import sqrt if R is None: R = Rg() if k is None: k = k_Justi(T0) temp = 2 * k * R * T0 / (k - 1) temp2 = 1 - u ** 2 / temp return p0 * pow(temp2, k / (k - 1))
def airFlowExample(self, p1, T1, p2=None, T2=None, K2=None): from GasProperty import Rg, k_Justi R1 = Rg(T1) R2 = Rg(T2) k1 = k_Justi(T1) k2 = k_Justi(T2) step = 1.e-3 * p1 import numpy as np for i in np.arange(0, p1, step): self.data.append([i / p1, self.__massFlowRate(p1, T1, R1, k1, i)]) if p2 is not None and T2 is not None: step2 = 0.01 * p2 for i in np.arange(0.5 * p2, p2, step): self.data.append([ p2 / i, self.__massFlowRate(i, T1, R1, k1, p2, T2, R2, K2) ]) return self.data
def eqnozzle(p, u, p0=1.e5, T0=300, phi=1, R=None, k=None): from GasProperty import k_Justi, Rg from math import sqrt if R is None: R = Rg() if k is None: k = k_Justi(T0) temp = 2 * k * R * T0 / (k - 1) temp2 = pow(p / p0, (k - 1) / k) - 1 temp3 = 1 / pow(phi, 2) * pow(p / p0, 2. / k) - 1 # return u ** 2 * temp3 - temp * temp2 return u ** 2 - temp * temp2*temp3
def nozzle(p, p0=1.e5, T0=300, phi=0.5, R=None, k=None): from GasProperty import k_Justi, Rg from math import sqrt if R is None: R = Rg() if k is None: k = k_Justi(T0) temp = 2 * k * R * T0 / (k - 1) temp2 = pow(p / p0, (k - 1) / k) - 1 temp3 = 1 / pow(phi, 2) * pow(p / p0, 2. / k) - 1 return sqrt(temp * temp2 / temp3)
def solve(self, U=None, A=1, AFAK=1.e8): from GasProperty import Rg from GasProperty import k_Justi if U is None: U = self.U else: self.U = U self.rho = U[0] / A self.u = U[1] / U[0] self.e = U[2] / U[0] - 1. / 2. * pow(U[1] / U[0], 2) T = self.e * (1.4 - 1.) / Rg(AFAK) # def kite(T): # return self.e - Rg(AFAK) * T / (k_Justi(T, AFAK) - 1) # # h = 1. # while abs(kite(T)) > 1.e-5: # T -= kite(T) / ((kite(T + h) - kite(T - h)) / 2. / h) self.T = T self.k = k_Justi(T, AFAK) self.p = Rg(AFAK) * T * self.rho
def Uinit(self, u, p, T, AFAK=1.e8, A=1): from GasProperty import Rg from GasProperty import k_Justi self.p = p self.T = T self.rho = p / (Rg(AFAK) * T) self.u = u self.k = 1.4 # k_Justi(self.T, AFAK) self.e = self.p / self.rho / (self.k - 1.) self.e0 = self.e + self.u**2 / 2. self.h0 = self.e0 + self.p / self.rho self.a = pow(self.k * self.p / self.rho, 1. / 2.) from numpy import array self.U = array([ self.rho * A, self.rho * self.u * A, (self.p / (self.k - 1) + 1. / 2. * self.rho * self.u**2) * A ]).transpose()
def TurbochargePressure(pme=10e5, T_im=300, eta_et=0.36, phi_a=1.1, VE=0.86, L0=14.3, Hu=42700e3): """ 计算增压压力 :param pme: 平均有效压力(Pa) :param T_im: 进气管温度(K) :param eta_et: 有效热效率 :param phi_a: 过量空气系数 :param VE: 充量系数,自然吸气式发动机最大为90% :param L0: 燃空当量比 :param Hu: 燃料低热值 :return: 增压压力(Pa) """ from GasProperty import Rg return pme * T_im / eta_et * phi_a / VE * Rg() * L0 / Hu
def nozzle2(u, p0=1.e5, T0=300, phi=0.9, R=None, k=None): from GasProperty import k_Justi, Rg if R is None: R = Rg() if k is None: k = k_Justi(T0) pinit = 1.1 * p0 def fun(p): # return nozzle(p,p0,T0,phi,R,k)-u return eqnozzle(p, u, p0, T0, phi, R, k) h = p0 / 1.e4 # print(fun(pinit)) while abs(fun(pinit)) > 1.e-5: # print(fun(pinit)) # print(fun(pinit+h)-fun(pinit-h)) pinit -= fun(pinit) / ((fun(pinit + h) - fun(pinit - h)) / 2. / h) return pinit
def AnalyticalSolution(t, left=[], right=[], xlim=None): import math u1 = left[0] u2 = right[0] # r1 = left[1]; # r2 = right[1] T1 = left[1] T2 = right[1] p1 = left[2] p2 = right[2] # T1 = p1 / r1 / Rg(); # T2 = p2 / r2 / Rg() r1 = p1 / Rg() / T1 r2 = p2 / Rg() / T2 k1 = k_Justi(T1) k2 = k_Justi(T2) a1 = math.sqrt(k1 * p1 / r1) a2 = math.sqrt(k2 * p2 / r2) # print("-" * 100) # print("{0:^50}|{1:^50}".format("ul=%.5gm/s" % u1, "ur=%.5gm/s" % u2)) # print("{0:^50}|{1:^50}".format("rhol=%.5gkg/m^3" % r1, "rhor=%.5gkg/m^3" % r2)) # print("{0:^50}|{1:^50}".format("pl=%sPa" % p1, "pr=%sPa" % p2)) # print("{0:^50}|{1:^50}".format("Tl=%sK" % T1, "Tr=%sK" % T2)) # print("-" * 100) def function(pbar, pj, rhoj, gamma=1.4): if pbar == pj: return 0 elif pbar > pj: import math aj = math.sqrt(gamma * pj / rhoj) return (pbar - pj) / rhoj / aj / math.sqrt( (gamma + 1) / 2. / gamma * pbar / pj + (gamma - 1) / 2. / gamma) elif pbar < pj: import math aj = math.sqrt(gamma * pj / rhoj) return 2. * aj / (gamma - 1.) * (pow(pbar / pj, (gamma - 1) / 2. / gamma) - 1) def F(p): return function(p, p1, r1, k1) + function(p, p2, r2, k2) pbar = (p1 + p2) / 2 h = 10. while abs(u1 - u2 - F(pbar)) > 1.e-5: pbar -= (u1 - u2 - F(pbar)) / ((-F(pbar + h) + F(pbar - h)) / 2. / h) # print(pbar) ubar = (u1 + u2 - function(pbar, p1, r1, k1) + function(pbar, p2, r2, k2)) / 2. # print(ubar) A1 = r1 * a1 * math.sqrt((k1 + 1.) / (2. * k1) * pbar / p1 + (k1 - 1) / 2. / k1) A2 = r2 * a2 * math.sqrt((k2 + 1.) / (2. * k2) * pbar / p2 + (k2 - 1) / 2. / k2) if pbar >= p1: Z1 = u1 - A1 / r1 else: Z1 = u1 - a1 if pbar >= p2: Z2 = u2 + A2 / r2 else: Z2 = u2 + a2 if pbar >= p1: Z1star = Z1 elif pbar > 0: a1star = a1 + (k1 - 1) / 2. * (u1 - ubar) Z1star = ubar - a1star else: Z1star = u1 - 2. * a1 / (k1 - 1) if pbar >= p2: Z2star = Z2 elif pbar > 0: a2star = a2 - (k2 - 1) / 2. * (u2 - ubar) Z2star = ubar + a2star else: Z2star = u2 + 2 * a2 / (k2 - 1) r1bar = r1 * A1 / (A1 - r1 * (u1 - ubar)) r2bar = r2 * A2 / (A2 + r2 * (u2 - ubar)) # print("Z1=", Z1) # print("Z1star=", Z1star) # print("ubar=", ubar) # print("Z2star=", Z2star) # print("Z2=", Z2) if xlim is None: Zlaggest = abs(Z1) if abs(Z1) > abs(Z2) else abs(Z2) xlim = [-1.5 * t * Zlaggest, 1.5 * t * Zlaggest] # print("Will draw air state between [{},{}]".format(xlim[0],xlim[1])) def fun(t, x): if x / t > Z2: return u2, r2, p2 elif x / t < Z1: return u1, r1, p1 elif Z1star < x / t < ubar: return ubar, r1bar, pbar elif ubar < x / t < Z2star: return ubar, r2bar, pbar elif Z1 < x / t < Z1star: a = (k1 - 1) / (k1 + 1) * (u1 - x / t) + 2 * a1 / (k1 + 1) u = x / t + a p = p1 * pow(a / a1, 2 * k1 / (k1 - 1)) r = k1 * p / a / a return u, r, p elif Z2star < x / t < Z2: a = (k2 - 1) / (k2 + 1) * (x / t - u2) + 2 * a2 / (k2 - 1) u = x / t - a p = p2 * pow(a / a2, 2 * k2 / (k2 - 1)) r = k2 * p / a / a return u, r, p result = ArrayTable(5, 0) result.setTableHeader( ["x", "Velocity", "Density", "Pressure", "Temperature"]) result.setTableUnit(["m", "m/s", "kg/m^3", "Pa", "K"]) import numpy as np step = (xlim[1] - xlim[0]) / 1000. xx = np.arange(xlim[0], xlim[1], step) for each in xx: u, r, p = fun(t, each) result.append([each, u, r, p, p / r / Rg()]) return result
def fun(pt): Rge=Rg(setting["过量空气系数"]) k=k_Justi(Tt,setting["过量空气系数"]) temp=setting["涡轮当量流通面积,m^2"]*flowUnitArea(pt,Tt,Rge,k,Pt0) print("涡前压力{},流量{}".format(pt,temp)) return (temp-ma)/ma