75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""REFPROP-backed CO2 property helpers."""
|
|
|
|
import ctREFPROP.ctREFPROP as ct
|
|
|
|
|
|
class CO2PropertyCalculator():
|
|
"""二氧化碳物性计算"""
|
|
def __init__(self, refprop_path = None):
|
|
"""初始化库"""
|
|
self.rp = ct.REFPROPFunctionLibrary(refprop_path)
|
|
# 设置流体文件
|
|
self.rp.SETUPdll(1, 'CO2.FLD', 'HMX.BNC', 'DEF')
|
|
# 设置单位
|
|
self.rp.SETUPdll(2, 'SI', 'SI', 'DEF')
|
|
self.z = [1.0]
|
|
self.mw = self.rp.WMOLdll(self.z)
|
|
def calculate_properties(self, T=None, P=None, h=None, s=None):
|
|
"""计算二氧化碳物性"""
|
|
if T is not None and P is not None:
|
|
# 已知Tp
|
|
result = self.rp.TPFLSHdll(T, P, self.z)
|
|
properties = {
|
|
'T': T,
|
|
'P': P,
|
|
'h': result.h,
|
|
's': result.s,
|
|
}
|
|
elif P is not None and h is not None:
|
|
# 已知Ph
|
|
result = self.rp.PHFLSHdll(P, h, self.z)
|
|
properties = {
|
|
'T': result.T,
|
|
'P': P,
|
|
'h': h,
|
|
's': result.s,
|
|
}
|
|
elif T is not None and h is not None:
|
|
# 已知Th
|
|
result = self.rp.THFLSHdll(T, h, self.z)
|
|
properties = {
|
|
'T': T,
|
|
'P': result.P,
|
|
'h': h,
|
|
's': result.s,
|
|
}
|
|
elif P is not None and s is not None:
|
|
# 已知Ps
|
|
result = self.rp.PSFLSHdll(P, s, self.z)
|
|
properties = {
|
|
'T': result.T,
|
|
'P': P,
|
|
'h': result.h,
|
|
's': s,
|
|
}
|
|
else:
|
|
raise ValueError("提供的参数不足")
|
|
if result.ierr > 0:
|
|
raise ValueError(f"REFPROP计算错误:{result.ierr}")
|
|
|
|
# 补充提取的物性,这里由于后续还要使用,不进行参数变换
|
|
properties['D'] = result.D
|
|
properties['density_kg_m3'] = result.D * self.mw
|
|
properties['cp'] = result.Cp
|
|
properties['cp_j_kg_k'] = result.Cp / self.mw * 1000
|
|
properties['cv'] = result.Cv
|
|
properties['cv_j_kg_k'] = result.Cv / self.mw * 1000
|
|
|
|
transport = self.rp.TRNPRPdll(result.T, result.D, self.z)
|
|
if transport.ierr > 0:
|
|
raise ValueError(f"REFPROP transport calculation error:{transport.ierr}")
|
|
properties['viscosity_pa_s'] = transport.eta * 1e-6
|
|
properties['thermal_conductivity_w_m_k'] = transport.tcx
|
|
return properties
|