Files
VacuumPressureMembranePoreS…/Helpers/PoreDistributionAnalysis.cs
2026-02-27 16:03:49 +08:00

69 lines
2.7 KiB
C#

using MembranePoreTester.Models;
using System.Collections.Generic;
using System.Linq;
namespace MembranePoreTester.Helpers
{
public static class PoreDistributionAnalysis
{
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[] dryFlows = sorted.Select(p => p.DryFlow).ToArray();
double[] wetFlows = sorted.Select(p => p.WetFlow).ToArray();
double halfDryFlow = dryFlows.Max() / 2.0;
// 找到湿膜流量等于 halfDryFlow 的压力(交点)
for (int i = 0; i < wetFlows.Length - 1; i++)
{
if ((wetFlows[i] <= halfDryFlow && wetFlows[i + 1] >= halfDryFlow) ||
(wetFlows[i] >= halfDryFlow && wetFlows[i + 1] <= halfDryFlow))
{
double p = Interpolation.Linear(
new[] { wetFlows[i], wetFlows[i + 1] },
new[] { pressures[i], pressures[i + 1] },
halfDryFlow);
return PoreCalculator.PressureToPore(p, unit, liquid);
}
}
return 0;
}
public static double CalculatePoreRangePercentage(
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();
// 大孔径对应低压,小孔径对应高压
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);
double ratioLow = qWetLower / qDryLower;
double ratioHigh = qWetUpper / qDryUpper;
return (ratioHigh - ratioLow) * 100;
}
}
}