物性更改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

@@ -11,7 +11,9 @@ using Prism.Mvvm;
using Prism.Services.Dialogs;
using SixLabors.ImageSharp.ColorSpaces;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
namespace CapMachine.Wpf.Services
{
@@ -37,6 +39,11 @@ namespace CapMachine.Wpf.Services
private readonly PPCThermodynamicSixResultsCalculator _thermodynamicSixResultsCalculator;
private readonly EnthalpyDrynessCalculator _enthalpyDrynessCalculator;
private DateTime _lastSuperheatSubcoolErrorLogAt = DateTime.MinValue;
private string _lastSuperheatSubcoolErrorText = string.Empty;
private int _hvZeroStreak;
/// <summary>
/// 标签中心
/// </summary>
@@ -120,7 +127,7 @@ namespace CapMachine.Wpf.Services
SuperHeatCoolConfig.FluidsPath = ConfigHelper.GetValue("FluidsPath");
SuperHeatCoolConfig.Cryogen = ConfigHelper.GetValue("Cryogen");
_superheatSubcoolCalculator = new PPCSuperheatSubcoolCalculator();
_superheatSubcoolCalculator = new PPCSuperheatSubcoolCalculator(_refpropLock);
_thermodynamicSixResultsCalculator = new PPCThermodynamicSixResultsCalculator(_refpropLock);
_enthalpyDrynessCalculator = new EnthalpyDrynessCalculator(_refpropLock);
ReloadTherdyH3TempOffset();
@@ -337,14 +344,19 @@ namespace CapMachine.Wpf.Services
{
while (RtCalcEnable)
{
await Task.Delay(100);
await Task.Delay(300);
try
{
if (!TryUpdateSuperheatAndSubcool(out var superheatSubcoolErr))
_ = TryUpdateSuperheatAndSubcool(out var superheatSubcoolErr);
if (!string.IsNullOrWhiteSpace(superheatSubcoolErr))
{
if (!string.IsNullOrWhiteSpace(superheatSubcoolErr))
var now = DateTime.UtcNow;
if (!string.Equals(superheatSubcoolErr, _lastSuperheatSubcoolErrorText, StringComparison.Ordinal)
|| (now - _lastSuperheatSubcoolErrorLogAt) >= TimeSpan.FromSeconds(5))
{
Logger?.Error($"过热度/过冷度计算失败: {superheatSubcoolErr}");
_lastSuperheatSubcoolErrorLogAt = now;
_lastSuperheatSubcoolErrorText = superheatSubcoolErr;
}
}
@@ -363,7 +375,6 @@ namespace CapMachine.Wpf.Services
// }
//}
if (TryUpdateThermodynamicSixResults(out var thermoErr))
{
if (!string.IsNullOrWhiteSpace(thermoErr))
@@ -400,7 +411,7 @@ namespace CapMachine.Wpf.Services
}
else if (_superheatSubcoolCalculator.TryCalculateSuperheatK(InhPressTag.EngPvValue, InhTempTag.EngPvValue, out var superheatValue, out var superheatErr))
{
Superheat.EngPvValue = superheatValue;
Superheat.EngPvValue = Math.Abs(superheatValue);
updated = true;
}
else
@@ -414,7 +425,7 @@ namespace CapMachine.Wpf.Services
}
else if (_superheatSubcoolCalculator.TryCalculateSubcoolK(TxvFrPressTag.EngPvValue, TxvFrTempTag.EngPvValue, out var subcoolValue, out var subcoolErr))
{
Subcool.EngPvValue = subcoolValue;
Subcool.EngPvValue = Math.Abs(subcoolValue);
updated = true;
}
else
@@ -521,6 +532,52 @@ namespace CapMachine.Wpf.Services
{
error = string.Empty;
double w_W = HVPwTag?.EngPvValue ?? double.NaN;
if (!double.IsNaN(w_W) && !double.IsInfinity(w_W) && w_W == 0)
{
_hvZeroStreak = Math.Min(_hvZeroStreak + 1, 1000);
if (_hvZeroStreak < 3)
{
return false;
}
HeatingCapacityQh_kW = 0;
CoolingCapacityQc_kW = 0;
COPHeating = 0;
COPCooling = 0;
IsentropicEfficiencyPct = 0;
VolumetricEfficiencyPct = 0;
if (HeatingCapacity != null)
{
HeatingCapacity.EngPvValue = 0;
}
if (COPHeat != null)
{
COPHeat.EngPvValue = 0;
}
if (IsentrpEff != null)
{
IsentrpEff.EngPvValue = 0;
}
if (CoolCapacity != null)
{
CoolCapacity.EngPvValue = 0;
}
if (COPCool != null)
{
COPCool.EngPvValue = 0;
}
if (VoltricEff != null)
{
VoltricEff.EngPvValue = 0;
}
return true;
}
_hvZeroStreak = 0;
// 先把本周期所需的标签值组装为输入模型。
// PPCService 在这里负责完成“标签 -> 领域输入对象”的映射,
// 从而把计算类和 UI/标签层解耦。
@@ -672,29 +729,50 @@ namespace CapMachine.Wpf.Services
displacement_cc = double.NaN;
error = string.Empty;
displacement_cc = 35;
return true;
const double defaultDisplacementCc = 35d;
const string key = "CompressorDisplacementCc";
//if (!ConfigHelper.IsExist(key))
//{
// error = $"未配置压缩机排量,请在 App.config/appSettings 增加 {key}(单位 cc";
// return false;
//}
string v = ConfigHelper.GetValue(key);
if (!double.TryParse(v, out displacement_cc))
static bool TryParseDisplacementCc(string? text, out double displacementCc)
{
error = $"压缩机排量配置无法解析: {v}";
return false;
displacementCc = double.NaN;
if (string.IsNullOrWhiteSpace(text))
{
return false;
}
var normalized = text.Trim().ToLowerInvariant();
normalized = normalized.Replace(',', '.');
var match = Regex.Match(normalized, @"[-+]?\d+(\.\d+)?");
if (!match.Success)
{
return false;
}
if (!double.TryParse(match.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var v))
{
return false;
}
displacementCc = v;
return true;
}
if (displacement_cc <= 0)
try
{
error = $"压缩机排量<=0: {displacement_cc}";
return false;
string raw = ConfigHelper.GetValue(key);
if (TryParseDisplacementCc(raw, out var cfgCc) && cfgCc > 0)
{
displacement_cc = cfgCc;
return true;
}
}
catch
{
// 忽略配置读取异常,走默认回退值
}
displacement_cc = defaultDisplacementCc;
return true;
}
}