This commit is contained in:
@@ -50,15 +50,18 @@ namespace MembranePoreTester.Helpers
|
||||
double[] wetFlows = sorted.Select(p => p.WetFlow).ToArray();
|
||||
double[] dryFlows = sorted.Select(p => p.DryFlow).ToArray();
|
||||
|
||||
// 寻找湿膜流量曲线与干膜流量曲线的所有交点(直接相交),记录交点压力及对应的插值干膜流量
|
||||
var intersections = new List<(double Pressure, double DryFlowAtP)>();
|
||||
const double eps = 1e-12;
|
||||
|
||||
// 按压力升序查找第一个直接交点(wet == dry),找到即返回
|
||||
// 为避免噪声或无效(0 流量)点导致的错误交点,要求两侧点在湿膜/干膜上均有有效流量
|
||||
for (int i = 0; i < pressures.Length - 1; i++)
|
||||
{
|
||||
if (wetFlows[i] <= 0 || dryFlows[i] <= 0 || wetFlows[i + 1] <= 0 || dryFlows[i + 1] <= 0)
|
||||
continue;
|
||||
|
||||
double diff1 = wetFlows[i] - dryFlows[i];
|
||||
double diff2 = wetFlows[i + 1] - dryFlows[i + 1];
|
||||
// 检查差值是否异号或为零(表示相交)
|
||||
if (diff1 * diff2 <= 0 && diff1 != diff2)
|
||||
if (diff1 * diff2 <= 0 && Math.Abs(diff2 - diff1) > eps)
|
||||
{
|
||||
double p;
|
||||
if (Math.Abs(diff1) < eps)
|
||||
@@ -73,51 +76,16 @@ namespace MembranePoreTester.Helpers
|
||||
{
|
||||
double p0 = pressures[i];
|
||||
double p1 = pressures[i + 1];
|
||||
if (Math.Abs(diff2 - diff1) < eps)
|
||||
continue;
|
||||
p = p0 + (p1 - p0) * (0 - diff1) / (diff2 - diff1);
|
||||
}
|
||||
|
||||
if (p <= 0) continue;
|
||||
|
||||
// 线性插值计算交点处的干膜流量
|
||||
double dryAtP;
|
||||
{
|
||||
double d0 = dryFlows[i];
|
||||
double d1 = dryFlows[i + 1];
|
||||
double p0 = pressures[i];
|
||||
double p1 = pressures[i + 1];
|
||||
if (Math.Abs(p1 - p0) < eps)
|
||||
dryAtP = d0;
|
||||
else
|
||||
dryAtP = d0 + (d1 - d0) * (p - p0) / (p1 - p0);
|
||||
}
|
||||
|
||||
intersections.Add((p, dryAtP));
|
||||
if (p > 0)
|
||||
return PoreCalculator.PressureToPore(p, unit, liquid);
|
||||
}
|
||||
}
|
||||
|
||||
if (intersections.Count == 0)
|
||||
return 0;
|
||||
|
||||
// 如果存在多个交点,默认选择压力最小(靠近低压区的第一个交点)
|
||||
var chosen = intersections.OrderBy(x => x.Pressure).First();
|
||||
|
||||
// 将调试信息写入日志文件,便于在非 VS 环境下查看计算过程
|
||||
try
|
||||
{
|
||||
Log($"PoreDistributionAnalysis: unit={unit}, liquid.C_Pa={liquid?.C_Pa}");
|
||||
foreach (var it in intersections)
|
||||
Log($"intersection: P={it.Pressure}, dryAtP={it.DryFlowAtP}");
|
||||
Log($"chosen intersection: P={chosen.Pressure}");
|
||||
double pore = PoreCalculator.PressureToPore(chosen.Pressure, unit, liquid);
|
||||
Log($"calculated pore={pore}");
|
||||
return pore;
|
||||
}
|
||||
catch
|
||||
{
|
||||
try { return PoreCalculator.PressureToPore(chosen.Pressure, unit, liquid); } catch { return 0; }
|
||||
}
|
||||
// 已移除干膜半流量回退算法:如果未找到湿膜与干膜的直接交点,则不进行半流量插值,直接返回 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
|
||||
@@ -315,6 +315,15 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
private void OpenPressureCalibration()
|
||||
{
|
||||
// 弹出确认对话框
|
||||
var result = MessageBox.Show(
|
||||
"确定要进行压力校准吗?此操作将向PLC写入校准信号。",
|
||||
"确认校准",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
ushort address = new ushort();
|
||||
switch (StationId)
|
||||
{
|
||||
@@ -338,12 +347,18 @@ namespace MembranePoreTester.ViewModels
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(address, true);
|
||||
MessageBox.Show("校准成功!");
|
||||
//MessageBox.Show("校准成功!");
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenPressureCalibration2()
|
||||
{
|
||||
// 弹出确认对话框
|
||||
var result = MessageBox.Show(
|
||||
"确定要进行压力校准吗?此操作将向PLC写入校准信号。",
|
||||
"确认校准",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
ushort address = new ushort();
|
||||
switch (StationId)
|
||||
{
|
||||
@@ -367,7 +382,7 @@ namespace MembranePoreTester.ViewModels
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(address, true);
|
||||
MessageBox.Show("校准成功!");
|
||||
// MessageBox.Show("校准成功!");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -209,6 +209,11 @@ namespace MembranePoreTester.ViewModels
|
||||
MessageBox.Show("低压模式,加压上限不能超过200!");
|
||||
return;
|
||||
}
|
||||
if (!_suppressPressureValidation && HighLowPressure.Contains("高压") && value > 800)
|
||||
{
|
||||
MessageBox.Show("高压模式,加压上限不能超过500!");
|
||||
return;
|
||||
}
|
||||
|
||||
bool changed = SetProperty(ref _pressureUpperLimit, value);
|
||||
// 仅在非抑制模式下将改变写回PLC,避免把PLC读回的值再次写入造成循环
|
||||
|
||||
@@ -820,6 +820,12 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
private void OpenFlowCalibration()
|
||||
{
|
||||
// 弹出确认对话框
|
||||
var result = MessageBox.Show(
|
||||
"确定要进行流量校准吗?此操作将向PLC写入校准信号。",
|
||||
"确认校准",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
ushort address = new ushort();
|
||||
switch (StationId)
|
||||
{
|
||||
@@ -843,12 +849,18 @@ namespace MembranePoreTester.ViewModels
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(address, true);
|
||||
MessageBox.Show("校准成功!");
|
||||
//MessageBox.Show("校准成功!");
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenFlowCalibration2()
|
||||
{
|
||||
// 弹出确认对话框
|
||||
var result = MessageBox.Show(
|
||||
"确定要进行流量校准吗?此操作将向PLC写入校准信号。",
|
||||
"确认校准",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
ushort address = new ushort();
|
||||
switch (StationId)
|
||||
{
|
||||
@@ -872,7 +884,7 @@ namespace MembranePoreTester.ViewModels
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(address, true);
|
||||
MessageBox.Show("校准成功!");
|
||||
//MessageBox.Show("校准成功!");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user