# -*- 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, include_transport=False): """计算二氧化碳物性""" 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, properties['rho'] = result.D * self.mw properties['cp_mass'] = result.Cp / self.mw * 1000.0 properties['cv_mass'] = result.Cv / self.mw * 1000.0 if include_transport: self._add_transport_properties(properties, result) return properties def _add_transport_properties(self, properties, result): """Add CO2 transport properties needed by PCHE correlations.""" transport = self.rp.TRNPRPdll(properties['T'], result.D, self.z) if getattr(transport, 'ierr', 0) > 0: raise ValueError(f"REFPROP transport calculation error:{transport.ierr}") viscosity_micro_pa_s = getattr(transport, 'eta', None) thermal_conductivity = getattr(transport, 'tcx', None) if viscosity_micro_pa_s is None: viscosity_micro_pa_s = getattr(transport, 'visc', None) if thermal_conductivity is None: thermal_conductivity = getattr(transport, 'tcond', None) if viscosity_micro_pa_s is None or thermal_conductivity is None: raise ValueError("REFPROP transport result missing viscosity or conductivity") viscosity_pa_s = viscosity_micro_pa_s * 1.0e-6 properties['mu'] = viscosity_pa_s properties['viscosity'] = viscosity_pa_s properties['lambda'] = thermal_conductivity properties['thermal_conductivity'] = thermal_conductivity