This commit is contained in:
xyy
2026-04-11 20:47:41 +08:00
parent 9da91d4ca5
commit ea8e76bff4
2 changed files with 164 additions and 21 deletions

View File

@@ -36,34 +36,71 @@ namespace MembranePoreTester.Helpers
return 0;
}
public static double CalculatePoreRangePercentage(
IEnumerable<DataPoint> points,
string unit,
TestLiquid liquid,
double lowerPore,
double upperPore)
IEnumerable<DataPoint> points,
string unit,
TestLiquid liquid,
double lowerPore,
double upperPore)
{
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();
// 提取有效点(流量 > 0
var wetValid = sorted.Where(p => p.WetFlow > 0).Select(p => (Pressure: p.Pressure, Flow: p.WetFlow)).ToList();
var dryValid = sorted.Where(p => p.DryFlow > 0).Select(p => (Pressure: p.Pressure, Flow: p.DryFlow)).ToList();
// 大孔径对应低压,小孔径对应高压
if (wetValid.Count < 2 || dryValid.Count < 2) return 0;
// 有效压力重叠区间
double minPressure = Math.Max(wetValid.First().Pressure, dryValid.First().Pressure);
double maxPressure = Math.Min(wetValid.Last().Pressure, dryValid.Last().Pressure);
if (minPressure >= maxPressure) return 0;
// 孔径转压力
double pLower = PoreCalculator.PoreToPressure(upperPore, unit, liquid);
double pUpper = PoreCalculator.PoreToPressure(lowerPore, unit, liquid);
// 插值
double qWetLower = Interpolation.Linear(pressures, wetFlows, pLower);
double qDryLower = Interpolation.Linear(pressures, dryFlows, pLower);
double qWetUpper = Interpolation.Linear(pressures, wetFlows, pUpper);
double qDryUpper = Interpolation.Linear(pressures, dryFlows, pUpper);
pLower = Math.Max(pLower, minPressure);
pUpper = Math.Min(pUpper, maxPressure);
if (pUpper <= pLower) return 0;
// 在有效点集上插值
double qWetLower = InterpolateOnValid(wetValid, pLower);
double qDryLower = InterpolateOnValid(dryValid, pLower);
double qWetUpper = InterpolateOnValid(wetValid, pUpper);
double qDryUpper = InterpolateOnValid(dryValid, pUpper);
if (qDryLower <= 0 || qDryUpper <= 0) return 0;
double ratioLow = qWetLower / qDryLower;
double ratioHigh = qWetUpper / qDryUpper;
double result = (ratioHigh - ratioLow) * 100;
return result < 0 ? 0 : result;
}
return (ratioHigh - ratioLow) * 100;
// 辅助插值函数:基于有效点列表(已按压力升序)
private static double InterpolateOnValid(List<(double Pressure, double Flow)> validPoints, double pressure)
{
if (validPoints.Count == 0) return 0;
if (pressure <= validPoints[0].Pressure) return validPoints[0].Flow;
if (pressure >= validPoints[^1].Pressure) return validPoints[^1].Flow;
for (int i = 0; i < validPoints.Count - 1; i++)
{
if (pressure >= validPoints[i].Pressure && pressure <= validPoints[i + 1].Pressure)
{
double p1 = validPoints[i].Pressure;
double f1 = validPoints[i].Flow;
double p2 = validPoints[i + 1].Pressure;
double f2 = validPoints[i + 1].Flow;
return f1 + (f2 - f1) * (pressure - p1) / (p2 - p1);
}
}
return 0;
}
}
}