Files
Brayton-Cycle-Optimization/brayton_cycle/properties.py
T
2026-06-20 14:12:51 +08:00

66 lines
2.2 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['cp'] = result.Cp
properties['cv'] = result.Cv,
return properties