This commit is contained in:
xyy
2026-06-16 21:18:46 +08:00
parent 8c0af19f02
commit 4489514b5d
7 changed files with 163 additions and 47 deletions

View File

@@ -140,6 +140,7 @@ namespace AciTester.ViewModels
};
}
public IAsyncRelayCommand StopTestCommand { get; }
public IAsyncRelayCommand ConnectCommand { get; }
public IRelayCommand DisconnectCommand { get; }
@@ -403,7 +404,8 @@ namespace AciTester.ViewModels
IsTesting = true;
_testCts = new CancellationTokenSource();
//StopTestCommand.NotifyCanExecuteChanged();
StopTestCommand.NotifyCanExecuteChanged();
try
{
await _plcService.WriteCoilAsync(_config.PumpCoil, true);
@@ -448,17 +450,68 @@ namespace AciTester.ViewModels
return;
}
// 1. 计算各级占比和累积分布
// 注意Stages[0] ~ Stages[7] 对应 Stage0~Stage7Stages[8] 是 Filter
// 截止直径数组(与 Stages 的顺序一致)
double[] diamArray = new double[9];
for (int i = 0; i < 9; i++)
diamArray[i] = Stages[i].CutoffDiameter;
// 占比和累积分布
double[] percentages = new double[9];
double[] cumulatives = new double[9];
double sum = 0;
for (int i = 0; i < 9; i++)
{
percentages[i] = Stages[i].NetWeight / totalMass * 100;
sum += percentages[i];
cumulatives[i] = sum;
}
// 2. 插值函数:给定累积百分比,返回对应的粒径(对数线性插值)
double Interpolate(double targetCum)
{
if (targetCum <= cumulatives[0]) return diamArray[0];
if (targetCum >= cumulatives[8]) return diamArray[8];
for (int i = 0; i < 8; i++)
{
if (cumulatives[i] <= targetCum && cumulatives[i + 1] >= targetCum)
{
double d1 = diamArray[i];
double d2 = diamArray[i + 1];
double c1 = cumulatives[i];
double c2 = cumulatives[i + 1];
double logD1 = Math.Log(d1);
double logD2 = Math.Log(d2);
double logD = logD1 + (targetCum - c1) * (logD2 - logD1) / (c2 - c1);
return Math.Exp(logD);
}
}
return diamArray[8];
}
double d10 = Interpolate(10);
double d50 = Interpolate(50);
double d90 = Interpolate(90);
// 3. 计算 GSD几何标准偏差GSD = D84 / D16如果可用
double d16 = Interpolate(16);
double d84 = Interpolate(84);
double gsd = (d16 > 0 && d84 > 0) ? d84 / d16 : 0;
// 4. 计算微细粒子剂量和分数(原有逻辑)
double fineMass = 0;
foreach (var stage in Stages)
{
if (stage.CutoffDiameter <= 5.0 && stage.CutoffDiameter > 0)
fineMass += stage.NetWeight;
}
fineMass += Stages[8].NetWeight;
fineMass += Stages[8].NetWeight; // Filter
double fpd = fineMass * 1000;
double fpd = fineMass * 1000; // mg
double fpf = (fineMass / totalMass) * 100;
// 5. 赋值给 CurrentResult
CurrentResult = new TestResult
{
TestTime = DateTime.Now,
@@ -468,10 +521,15 @@ namespace AciTester.ViewModels
Stages = Stages.ToList(),
FlowRate = CurrentFlow,
Temperature = RealTime.Temperature,
DifferentialPressure = RealTime.DifferentialPressure
DifferentialPressure = RealTime.DifferentialPressure,
// 新增粒径参数
D10 = d10,
D50 = d50,
D90 = d90,
GSD = gsd
};
MessageBox.Show($"计算完成\n总质量: {totalMass:F4} g\n微细粒子剂量: {fpd:F2} mg\n微细粒子分数: {fpf:F2}%",
MessageBox.Show($"计算完成\n总质量: {totalMass:F4} g\n微细粒子剂量: {fpd:F2} mg\n微细粒子分数: {fpf:F2}%\nD50: {d50:F2} μm",
"计算结果", MessageBoxButton.OK, MessageBoxImage.Information);
}