You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
"""Термодинамика метана по уравнению состояния Пенга–Робинсона (1976) — для метода прямого интегрирования
ГОСТ 12.2.085-2017, прил. Е.1 (изоэнтропа реального газа) и для дросселирования (прил. Ж, ф-ла (Ж.5): h = const).
Константы метана: Tc = 190.56 K, Pc = 4.599 МПа, ω = 0.011, M = 16.043 кг/кмоль (справочные; ГОСТ 12.2.085
табл. И.1 даёт Pкр = 46,41 бар, Tкр = 190,65 К, M = 16,03 — расхождение < 1 %).
Теплоёмкость идеального газа: cp/R = a0 + a1·T + … + a4·T^4 (Poling, Prausnitz, O'Connell, «The Properties of
Gases and Liquids», 5th ed., табл. A — CH4: 4,568; −8,975e−3; 3,631e−5; −3,407e−8; 1,091e−11; 50–1000 К).
Единицы СИ: P — Па, T — К, ρ — кг/м³, h — Дж/кг, s — Дж/(кг·К).
"""
import math
from scipy.optimize import brentq
R_U = 8.314462618
M = 16.043e-3
R = R_U / M
TC, PC, OMEGA = 190.56, 4.599e6, 0.011
CP_A = (4.568, -8.975e-3, 3.631e-5, -3.407e-8, 1.091e-11)
T_REF, P_REF = 298.15, 101325.0
_KAPPA = 0.37464 + 1.54226 * OMEGA - 0.26992 * OMEGA ** 2
_A0 = 0.45724 * R_U ** 2 * TC ** 2 / PC
_B = 0.07780 * R_U * TC / PC
_S2 = math.sqrt(2.0)
def _a(T):
al = (1.0 + _KAPPA * (1.0 - math.sqrt(T / TC))) ** 2
dadT = -_A0 * _KAPPA * math.sqrt(al) / math.sqrt(T * TC)
return _A0 * al, dadT
def Z(P, T):
"""Коэффициент сжимаемости (газовый корень — наибольший действительный)."""
a, _ = _a(T)
A = a * P / (R_U * T) ** 2
B = _B * P / (R_U * T)
c2, c1, c0 = -(1.0 - B), (A - 3 * B ** 2 - 2 * B), -(A * B - B ** 2 - B ** 3)
import numpy as np
roots = np.roots([1.0, c2, c1, c0])
real = [r.real for r in roots if abs(r.imag) < 1e-9 and r.real > B]
return max(real)
def rho(P, T):
return P / (Z(P, T) * R * T)
def _cp_int(T):
"""∫cp dT от T_REF до T и ∫cp/T dT (на 1 моль, Дж/моль и Дж/(моль·К)) для идеального газа."""
a = CP_A
H = lambda t: R_U * (a[0] * t + a[1] * t ** 2 / 2 + a[2] * t ** 3 / 3 + a[3] * t ** 4 / 4 + a[4] * t ** 5 / 5)
S = lambda t: R_U * (a[0] * math.log(t) + a[1] * t + a[2] * t ** 2 / 2 + a[3] * t ** 3 / 3 + a[4] * t ** 4 / 4)
return H(T) - H(T_REF), S(T) - S(T_REF)
def hs(P, T):
"""Удельные энтальпия и энтропия (Дж/кг, Дж/(кг·К)) относительно идеального газа при T_REF, P_REF."""
a, dadT = _a(T)
z = Z(P, T)
B = _B * P / (R_U * T)
lg = math.log((z + (1 + _S2) * B) / (z + (1 - _S2) * B))
h_dep = R_U * T * (z - 1.0) + (T * dadT - a) / (2 * _S2 * _B) * lg
s_dep = R_U * math.log(z - B) + dadT / (2 * _S2 * _B) * lg
hig, sig = _cp_int(T)
sig -= R_U * math.log(P / P_REF)
return (hig + h_dep) / M, (sig + s_dep) / M
def T_at_ps(P, s, T_guess=250.0):
return brentq(lambda T: hs(P, T)[1] - s, 80.0, 600.0, xtol=1e-6)
def T_at_ph(P, h):
return brentq(lambda T: hs(P, T)[0] - h, 80.0, 600.0, xtol=1e-6)
def isentropic_mass_flux(P1, T1, P_out, n=400):
"""Метод прямого интегрирования (ГОСТ 12.2.085, Е.1): G*ideal(P0) = ρ0·sqrt(2·(h1 − h0)) вдоль s = s1
(−∫dP/ρ = h1 − h0 на изоэнтропе). Возвращает dict: G*ideal, режим, P*, T*, ρ*, v* для P0 ∈ [P_out, P1]."""
h1, s1 = hs(P1, T1)
best = None
prev = None
P_lo = max(P_out, 0.02 * P1)
for i in range(1, n + 1):
P0 = P1 - (P1 - P_lo) * i / n
T0 = T_at_ps(P0, s1)
h0, _ = hs(P0, T0)
r0 = rho(P0, T0)
G = r0 * math.sqrt(max(2.0 * (h1 - h0), 0.0))
rec = dict(P=P0, T=T0, rho=r0, G=G, v=G / r0)
if prev is not None and G < prev["G"]: # первый максимум — критическое сечение
best = prev
break
prev = rec
if best is None: # монотонный рост до P_out — докритический режим
return dict(regime="докритический", **prev)
# уточнение максимума золотым сечением
def negG(P0):
T0 = T_at_ps(P0, s1)
return -rho(P0, T0) * math.sqrt(max(2.0 * (h1 - hs(P0, T0)[0]), 0.0))
from scipy.optimize import minimize_scalar
d = (P1 - P_lo) / n
r = minimize_scalar(negG, bounds=(best["P"] - d, best["P"] + d), method="bounded",
options=dict(xatol=P1 * 1e-7))
P0 = r.x
T0 = T_at_ps(P0, s1)
r0 = rho(P0, T0)
G = -r.fun
return dict(regime="критический", P=P0, T=T0, rho=r0, G=G, v=G / r0, beta_cr=P0 / P1)

Powered by TurnKey Linux.