This commit is contained in:
@@ -37,6 +37,71 @@ namespace MembranePoreTester.Helpers
|
||||
// }
|
||||
// return 0;
|
||||
//}
|
||||
//public static double CalculateAveragePore(
|
||||
// IEnumerable<DataPoint> points,
|
||||
// string unit,
|
||||
// TestLiquid liquid)
|
||||
//{
|
||||
// var sorted = points.OrderBy(p => p.Pressure).ToList();
|
||||
// if (sorted.Count < 2) return 0;
|
||||
|
||||
// double[] pressures = sorted.Select(p => p.Pressure).ToArray();
|
||||
// double[] wetFlows = sorted.Select(p => p.WetFlow).ToArray();
|
||||
// double[] dryFlows = sorted.Select(p => p.DryFlow).ToArray();
|
||||
|
||||
// // 日志文件路径(位于程序运行目录)
|
||||
// string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PoreCalcLog.txt");
|
||||
// void Log(string msg)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// File.AppendAllText(logPath, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} - {msg}{Environment.NewLine}");
|
||||
// }
|
||||
// catch { /* 忽略日志写入错误,不影响主流程 */ }
|
||||
// }
|
||||
|
||||
// Log($"开始计算平均孔径,数据点数={sorted.Count},单位={unit},液体={liquid.Name},表面张力={liquid.SurfaceTension}");
|
||||
|
||||
// for (int i = 0; i < pressures.Length - 1; i++)
|
||||
// {
|
||||
// double diff1 = wetFlows[i] - dryFlows[i];
|
||||
// double diff2 = wetFlows[i + 1] - dryFlows[i + 1];
|
||||
|
||||
// Log($"区间{i}: 压力=[{pressures[i]}, {pressures[i + 1]}], 湿膜=[{wetFlows[i]}, {wetFlows[i + 1]}], 干膜=[{dryFlows[i]}, {dryFlows[i + 1]}], diff1={diff1}, diff2={diff2}");
|
||||
|
||||
// // 检查是否异号或其中之一为零
|
||||
// if (diff1 * diff2 < 0 || Math.Abs(diff1) < 1e-8 || Math.Abs(diff2) < 1e-8)
|
||||
// {
|
||||
// double p;
|
||||
// if (Math.Abs(diff1) < 1e-8)
|
||||
// {
|
||||
// p = pressures[i];
|
||||
// Log($"直接命中点i,压力={p}");
|
||||
// }
|
||||
// else if (Math.Abs(diff2) < 1e-8)
|
||||
// {
|
||||
// p = pressures[i + 1];
|
||||
// Log($"直接命中点i+1,压力={p}");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// double t = -diff1 / (diff2 - diff1); // t 在 0~1 之间
|
||||
// p = pressures[i] + t * (pressures[i + 1] - pressures[i]);
|
||||
// Log($"线性插值: t={t}, 交点压力={p}");
|
||||
// }
|
||||
|
||||
// if (p > 0)
|
||||
// {
|
||||
// double pore = PoreCalculator.PressureToPore(p, unit, liquid);
|
||||
// Log($"平均孔径计算结果: 交点压力={p} {unit}, 孔径={pore} μm");
|
||||
// return pore;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Log("未找到湿膜与干膜曲线的交点");
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
public static double CalculateAveragePore(
|
||||
IEnumerable<DataPoint> points,
|
||||
@@ -50,44 +115,49 @@ namespace MembranePoreTester.Helpers
|
||||
double[] wetFlows = sorted.Select(p => p.WetFlow).ToArray();
|
||||
double[] dryFlows = sorted.Select(p => p.DryFlow).ToArray();
|
||||
|
||||
const double eps = 1e-12;
|
||||
// 日志记录
|
||||
string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PoreCalcLog.txt");
|
||||
void Log(string msg)
|
||||
{
|
||||
try { File.AppendAllText(logPath, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} - {msg}{Environment.NewLine}"); }
|
||||
catch { }
|
||||
}
|
||||
|
||||
Log($"开始计算平均孔径,数据点数={sorted.Count}");
|
||||
|
||||
// 按压力升序查找第一个直接交点(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)
|
||||
// 跳过干膜流量为0的点(避免虚假交点)
|
||||
if (dryFlows[i] == 0 || dryFlows[i + 1] == 0)
|
||||
continue;
|
||||
|
||||
double diff1 = wetFlows[i] - dryFlows[i];
|
||||
double diff2 = wetFlows[i + 1] - dryFlows[i + 1];
|
||||
if (diff1 * diff2 <= 0 && Math.Abs(diff2 - diff1) > eps)
|
||||
|
||||
Log($"区间{i}: P=[{pressures[i]}, {pressures[i + 1]}], diff1={diff1}, diff2={diff2}");
|
||||
|
||||
if (diff1 * diff2 < 0 || Math.Abs(diff1) < 1e-8 || Math.Abs(diff2) < 1e-8)
|
||||
{
|
||||
double p;
|
||||
if (Math.Abs(diff1) < eps)
|
||||
{
|
||||
if (Math.Abs(diff1) < 1e-8)
|
||||
p = pressures[i];
|
||||
}
|
||||
else if (Math.Abs(diff2) < eps)
|
||||
{
|
||||
else if (Math.Abs(diff2) < 1e-8)
|
||||
p = pressures[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
double p0 = pressures[i];
|
||||
double p1 = pressures[i + 1];
|
||||
p = p0 + (p1 - p0) * (0 - diff1) / (diff2 - diff1);
|
||||
double t = -diff1 / (diff2 - diff1);
|
||||
p = pressures[i] + t * (pressures[i + 1] - pressures[i]);
|
||||
}
|
||||
|
||||
if (p > 0)
|
||||
return PoreCalculator.PressureToPore(p, unit, liquid);
|
||||
Log($"找到交点: 压力={p} Pa");
|
||||
double pore = PoreCalculator.PressureToPore(p, unit, liquid);
|
||||
Log($"平均孔径={pore} μm");
|
||||
return pore;
|
||||
}
|
||||
}
|
||||
|
||||
// 已移除干膜半流量回退算法:如果未找到湿膜与干膜的直接交点,则不进行半流量插值,直接返回 0
|
||||
Log("未找到有效交点");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace MembranePoreTester.ViewModels
|
||||
}
|
||||
if (!_suppressPressureValidation && HighLowPressure.Contains("高压") && value > 800)
|
||||
{
|
||||
MessageBox.Show("高压模式,加压上限不能超过500!");
|
||||
MessageBox.Show("高压模式,加压上限不能超过800!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user