物性更改2

一些已知的更改
This commit is contained in:
2026-05-07 22:11:27 +08:00
parent bdc90d4473
commit 47834ea4dc
14 changed files with 2050 additions and 732 deletions

View File

@@ -461,29 +461,21 @@ namespace CapMachine.Wpf.Services
/// <param name="error">失败原因。</param>
/// <returns>是否计算成功。</returns>
/// <remarks>
/// 当前流程:
/// 1. BarA -> MPa
/// 2. 用气相 TPRHO 求摩尔密度 D
/// 3. 用 THERM 求焓
/// 当前流程(与 HASCO_KR26001_Fr25002 保持一致)
/// 1. 使用 TPFLSH 一次计算得到 h
/// </remarks>
private bool TryGetVaporPointEnthalpy_ByTP_BarA_C(double pressureBarA, double temperatureC, out double h_kJkg, out string error)
{
h_kJkg = double.NaN;
error = string.Empty;
// 物性 helper 的压力输入单位是 MPa因此先换算。
double pMPa = pressureBarA * 0.1;
// 先求气相摩尔密度 D。
if (!_support.TryTPRHO_VaporDensity_ByTP_MPa_C(pMPa, temperatureC, out var d_molL, out var dErr))
if (!_support.TryTPFLSH_ByTP_BarA_C(pressureBarA, temperatureC, out _, out var h_Jmol, out _, out _, out var flashErr))
{
error = dErr;
error = flashErr;
return false;
}
// THERM helper 的温度输入为 K因此把 ℃ 转成 K 后再求焓。
double tK = temperatureC + 273.15;
if (!_support.TryTHERM_Enthalpy_kJkg_ByT_K_D(tK, d_molL, out h_kJkg, out var hErr))
if (!_support.TryConvertH_Jmol_To_kJkg(h_Jmol, out h_kJkg, out var hErr))
{
error = hErr;
return false;
@@ -535,6 +527,10 @@ namespace CapMachine.Wpf.Services
/// <param name="v_m3kg">输出比容,单位 m³/kg。</param>
/// <param name="error">失败原因。</param>
/// <returns>是否计算成功。</returns>
/// <remarks>
/// 当前流程(与 HASCO_KR26001_Fr25002 保持一致):
/// 1. 使用 TPFLSH 一次计算得到 d, h, s
/// </remarks>
private bool TryGetVaporPointState_ByTP_BarA_C(double pressureBarA, double temperatureC, out double h_kJkg, out double s_kJkgK, out double v_m3kg, out string error)
{
h_kJkg = double.NaN;
@@ -542,32 +538,25 @@ namespace CapMachine.Wpf.Services
v_m3kg = double.NaN;
error = string.Empty;
// 第一步BarA -> MPa。
double pMPa = pressureBarA * 0.1;
// 第二步:由气相 TPRHO 求摩尔密度 D。
if (!_support.TryTPRHO_VaporDensity_ByTP_MPa_C(pMPa, temperatureC, out var d_molL, out var dErr))
if (!_support.TryTPFLSH_ByTP_BarA_C(pressureBarA, temperatureC, out var d_molL, out var h_Jmol, out var s_JmolK, out _, out var flashErr))
{
error = dErr;
error = flashErr;
return false;
}
// 第三步:用 THERM 求吸气点比焓 h1。
double tK = temperatureC + 273.15;
if (!_support.TryTHERM_Enthalpy_kJkg_ByT_K_D(tK, d_molL, out h_kJkg, out var hErr))
if (!_support.TryConvertH_Jmol_To_kJkg(h_Jmol, out h_kJkg, out var hErr))
{
error = hErr;
return false;
}
// 第四步:用 THERM 求吸气点比熵 s1。
if (!_support.TryTHERM_VaporEntropy_ByTD(temperatureC, d_molL, out s_kJkgK, out var sErr))
s_kJkgK = s_JmolK / _support.GetMolarMass() * 0.001;
if (double.IsNaN(s_kJkgK) || double.IsInfinity(s_kJkgK))
{
error = sErr;
error = "无效吸气熵 s1";
return false;
}
// 第五步:由摩尔密度换算为质量比容 v1。
if (!_support.TryConvertMolarDensityToSpecificVolume(d_molL, out v_m3kg, out var vErr))
{
error = vErr;
@@ -1089,6 +1078,7 @@ namespace CapMachine.Wpf.Services
{
private readonly object _refpropLock;
private static volatile bool _rpInitialized;
private static double _molarMassKgPerMol = double.NaN;
public LocalCalculationSupport(object refpropLock)
{
@@ -1100,6 +1090,39 @@ namespace CapMachine.Wpf.Services
error = string.Empty;
if (_rpInitialized)
{
if (!double.IsNaN(_molarMassKgPerMol) && !double.IsInfinity(_molarMassKgPerMol) && _molarMassKgPerMol > 0)
{
return true;
}
lock (_refpropLock)
{
if (!double.IsNaN(_molarMassKgPerMol) && !double.IsInfinity(_molarMassKgPerMol) && _molarMassKgPerMol > 0)
{
return true;
}
double wmm = 0;
double Trp = 0;
double Tnbpt = 0;
double Tc = 0;
double Pc = 0;
double Dc = 0;
double Zc = 0;
double acf = 0;
double dip = 0;
double Rgas = 0;
long componentId = 1;
IRefProp64.INFOdll(ref componentId, ref wmm, ref Trp, ref Tnbpt, ref Tc, ref Pc, ref Dc, ref Zc, ref acf, ref dip, ref Rgas);
_molarMassKgPerMol = wmm * 0.001;
if (double.IsNaN(_molarMassKgPerMol) || double.IsInfinity(_molarMassKgPerMol) || _molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
return false;
}
}
return true;
}
@@ -1155,6 +1178,30 @@ namespace CapMachine.Wpf.Services
return false;
}
if (double.IsNaN(_molarMassKgPerMol) || double.IsInfinity(_molarMassKgPerMol) || _molarMassKgPerMol <= 0)
{
double wmm = 0;
double Trp = 0;
double Tnbpt = 0;
double Tc = 0;
double Pc = 0;
double Dc = 0;
double Zc = 0;
double acf = 0;
double dip = 0;
double Rgas = 0;
long componentId = 1;
IRefProp64.INFOdll(ref componentId, ref wmm, ref Trp, ref Tnbpt, ref Tc, ref Pc, ref Dc, ref Zc, ref acf, ref dip, ref Rgas);
_molarMassKgPerMol = wmm * 0.001;
if (double.IsNaN(_molarMassKgPerMol) || double.IsInfinity(_molarMassKgPerMol) || _molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
_rpInitialized = false;
return false;
}
}
_rpInitialized = true;
return true;
}
@@ -1262,7 +1309,7 @@ namespace CapMachine.Wpf.Services
double w = 0;
double hjt = 0;
double molarMassKgPerMol = GetMolarMass();
double molarMassKgPerMol = _molarMassKgPerMol;
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
@@ -1331,7 +1378,7 @@ namespace CapMachine.Wpf.Services
double w = 0;
double hjt = 0;
double molarMassKgPerMol = GetMolarMass();
double molarMassKgPerMol = _molarMassKgPerMol;
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
@@ -1367,7 +1414,7 @@ namespace CapMachine.Wpf.Services
double w = 0;
double hjt = 0;
double molarMassKgPerMol = GetMolarMass();
double molarMassKgPerMol = _molarMassKgPerMol;
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
@@ -1394,7 +1441,7 @@ namespace CapMachine.Wpf.Services
return false;
}
double molarMassKgPerMol = GetMolarMass();
double molarMassKgPerMol = _molarMassKgPerMol;
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
@@ -1412,6 +1459,105 @@ namespace CapMachine.Wpf.Services
return true;
}
public bool TryTPFLSH_ByTP_BarA_C(
double pressureBarA,
double temperatureC,
out double d_molL,
out double h_Jmol,
out double s_JmolK,
out double t_K,
out string error)
{
d_molL = double.NaN;
h_Jmol = double.NaN;
s_JmolK = double.NaN;
t_K = double.NaN;
error = string.Empty;
if (!EnsureRefpropInitialized(out var initErr))
{
error = initErr;
return false;
}
double t = temperatureC + 273.15;
double pKPa = pressureBarA * 100.0;
if (pKPa <= 0)
{
error = $"无效压力: {pressureBarA} BarA";
return false;
}
double[] x = new double[20];
x[0] = 1.0;
double d = 0.0;
double Dl = 0.0;
double Dv = 0.0;
double[] xliq = new double[20];
double[] xvap = new double[20];
double q = 0.0;
double ee = 0.0;
double h = 0.0;
double ss = 0.0;
double Cv = 0.0;
double Cp = 0.0;
double w = 0.0;
long ierr = 0;
long herrLen = 255;
string herr = new string(' ', 255);
lock (_refpropLock)
{
IRefProp64.TPFLSHdll(ref t, ref pKPa, x, ref d, ref Dl, ref Dv, xliq, xvap, ref q, ref ee, ref h, ref ss, ref Cv, ref Cp, ref w, ref ierr, ref herr, ref herrLen);
}
if (ierr != 0)
{
error = $"TPFLSH 错误: {herr.Trim()} (ierr={ierr})";
return false;
}
d_molL = d;
h_Jmol = h;
s_JmolK = ss;
t_K = t;
return true;
}
public bool TryConvertH_Jmol_To_kJkg(double h_Jmol, out double h_kJkg, out string error)
{
h_kJkg = double.NaN;
error = string.Empty;
double molarMassKgPerMol = _molarMassKgPerMol;
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
return false;
}
h_kJkg = (h_Jmol / molarMassKgPerMol) * 0.001;
return true;
}
public double GetMolarMass()
{
if (double.IsNaN(_molarMassKgPerMol) || double.IsInfinity(_molarMassKgPerMol) || _molarMassKgPerMol <= 0)
{
double wmm = 0, Trp = 0, Tnbpt = 0, Tc = 0, Pc = 0, Dc = 0, Zc = 0, acf = 0, dip = 0, Rgas = 0;
long componentId = 1;
lock (_refpropLock)
{
IRefProp64.INFOdll(ref componentId, ref wmm, ref Trp, ref Tnbpt, ref Tc, ref Pc, ref Dc, ref Zc, ref acf, ref dip, ref Rgas);
}
_molarMassKgPerMol = wmm * 0.001;
}
return _molarMassKgPerMol;
}
public bool TryGetIsentropicOutletEnthalpy_h2s_ByP2AndS1_BarA(double dischargePressureBarA, double suctionEntropy_kJkgK, out double h2s_kJkg, out string error)
{
h2s_kJkg = double.NaN;
@@ -1469,46 +1615,12 @@ namespace CapMachine.Wpf.Services
return TryConvertH_Jmol_To_kJkg(h, out h2s_kJkg, out error);
}
private static double GetMolarMass()
{
double wmm = 0;
double Trp = 0;
double Tnbpt = 0;
double Tc = 0;
double Pc = 0;
double Dc = 0;
double Zc = 0;
double acf = 0;
double dip = 0;
double Rgas = 0;
long componentId = 1;
IRefProp64.INFOdll(ref componentId, ref wmm, ref Trp, ref Tnbpt, ref Tc, ref Pc, ref Dc, ref Zc, ref acf, ref dip, ref Rgas);
return wmm * 0.001;
}
private static bool TryConvertH_Jmol_To_kJkg(double h_Jmol, out double h_kJkg, out string error)
{
h_kJkg = double.NaN;
error = string.Empty;
double molarMassKgPerMol = GetMolarMass();
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";
return false;
}
h_kJkg = (h_Jmol / molarMassKgPerMol) * 0.001;
return true;
}
private static bool TryConvertS_kJkgK_To_JmolK(double s_kJkgK, out double s_JmolK, out string error)
{
s_JmolK = double.NaN;
error = string.Empty;
double molarMassKgPerMol = GetMolarMass();
double molarMassKgPerMol = _molarMassKgPerMol;
if (molarMassKgPerMol <= 0)
{
error = "无效的摩尔质量";