This commit is contained in:
xyy
2026-05-26 20:58:48 +08:00
parent e8a8c7bebf
commit 5bbbddf509
2 changed files with 134 additions and 35 deletions

View File

@@ -194,7 +194,7 @@ public partial class D7896ViewModel : ObservableObject
await _th1963Ustd.ConnectAsync("192.168.1.12", 45454); // 改为实际IP
await _th1963Ustd.ConfigureForHighSpeedDcvAsync();
await _th1953Ustd.ConnectAsync("192.168.1.13", 45454); // 改为实际IP
await _th1953Ustd.ConnectAsync("192.168.1.12", 45454); // 改为实际IP
await _th1953Ustd.ConfigureForHighSpeedDcvAsync();
}
catch (Exception ex)
@@ -355,8 +355,94 @@ public partial class D7896ViewModel : ObservableObject
}
}
///// <summary>
///// 根据采集到的电压序列计算热导率 λ、热扩散率 α、温升数组以及冷却曲线数据点
///// </summary>
//private (double lambda, double alpha, double[] deltaT, List<DataPoint> coolingPoints) ComputeThermalProperties(
// double[] upt, double[] ustd, double[] time, double initialResistance, double bathTemp)
//{
// int n = Math.Min(upt.Length, ustd.Length);
// double[] current = new double[n];
// double[] ptResistance = new double[n];
// double[] deltaT = new double[n];
// // 1. 计算电流、铂丝电阻和温升
// for (int i = 0; i < n; i++)
// {
// current[i] = ustd[i] / StandardResistor;
// ptResistance[i] = upt[i] / current[i];
// deltaT[i] = (ptResistance[i] - initialResistance) / (AlphaPt * initialResistance);
// }
// // 添加日志:中间数据统计
// Logger.Log($"电流平均值: {current.Average():F6} A, 最大值: {current.Max():F6} A");
// Logger.Log($"铂丝电阻平均值: {ptResistance.Average():F6} Ω, 初始电阻: {initialResistance:F6} Ω");
// Logger.Log($"温升最大值: {deltaT.Max():F4} ℃, 平均值: {deltaT.Average():F4} ℃");
// // 2. ========== 加热段拟合 → 热导率 λ ==========
// double tStart = 0.1;
// double tEndHeating = 0.8;
// int startIdx = FindIndex(time, tStart);
// int endIdxHeating = FindIndex(time, tEndHeating);
// if (startIdx < 0) startIdx = 0;
// if (endIdxHeating >= n) endIdxHeating = n - 1;
// var heatingPoints = new List<DataPoint>();
// for (int i = startIdx; i <= endIdxHeating; i++)
// {
// heatingPoints.Add(new DataPoint(Math.Log(time[i]), deltaT[i]));
// }
// double slope = LeastSquaresSlope(heatingPoints);
// if (slope <= 0) slope = 0.0001;
// Logger.Log($"加热段拟合斜率 B = {slope:F6} (ΔT vs ln(t))");
// double avgCurrentSq = current.Average(c => c * c);
// double avgResistance = ptResistance.Average();
// double powerPerLength = (avgCurrentSq * avgResistance) / _config.TestParameters.PlatinumWireLength;
// double lambda = powerPerLength / (4 * Math.PI * slope);
// Logger.Log($"单位长度加热功率 Q = {powerPerLength:F6} W/m");
// Logger.Log($"热导率 λ = {lambda:F6} W/(m·K)");
// // 3. ========== 冷却段拟合 → 热扩散率 α ==========
// double coolingStart = heatingDuration; // 0.8 秒
// double coolingEnd = totalDuration; // 1.6 秒
// int coolingStartIdx = FindIndex(time, coolingStart);
// int coolingEndIdx = FindIndex(time, coolingEnd);
// if (coolingStartIdx < 0) coolingStartIdx = n / 2;
// if (coolingEndIdx >= n) coolingEndIdx = n - 1;
// var coolingPointsForFit = new List<DataPoint>();
// for (int i = coolingStartIdx; i <= coolingEndIdx; i++)
// {
// if (deltaT[i] > 0.001)
// coolingPointsForFit.Add(new DataPoint(time[i], Math.Log(deltaT[i])));
// }
// double coolingSlope = LeastSquaresSlopeOnTime(coolingPointsForFit);
// double tau = -1.0 / coolingSlope;
// double wireRadius = 0.00003; // 半径 = 直径0.06mm /2
// double alpha = (wireRadius * wireRadius) / (4.0 * tau);
// if (alpha <= 0 || double.IsNaN(alpha) || double.IsInfinity(alpha))
// alpha = 0.12e-6; // 默认值
// Logger.Log($"冷却段拟合斜率 D = {coolingSlope:F6} (lnΔT vs t)");
// Logger.Log($"时间常数 τ = {tau:F6} s");
// Logger.Log($"热扩散率 α = {alpha:E6} m²/s");
// // 准备冷却曲线数据点(用于绘图)
// var coolingPoints = new List<DataPoint>();
// for (int i = coolingStartIdx; i <= coolingEndIdx; i++)
// {
// if (deltaT[i] > 0.001)
// coolingPoints.Add(new DataPoint(time[i], deltaT[i]));
// }
// return (lambda, alpha, deltaT, coolingPoints);
//}
/// <summary>
/// 根据采集到的电压序列计算热导率 λ热扩散率 α、温升数组以及冷却曲线数据点
/// 根据采集到的电压序列计算热导率 λ热扩散率 α(标准截距法)
/// </summary>
private (double lambda, double alpha, double[] deltaT, List<DataPoint> coolingPoints) ComputeThermalProperties(
double[] upt, double[] ustd, double[] time, double initialResistance, double bathTemp)
@@ -373,12 +459,11 @@ public partial class D7896ViewModel : ObservableObject
ptResistance[i] = upt[i] / current[i];
deltaT[i] = (ptResistance[i] - initialResistance) / (AlphaPt * initialResistance);
}
// 添加日志:中间数据统计
Logger.Log($"电流平均值: {current.Average():F6} A, 最大值: {current.Max():F6} A");
Logger.Log($"铂丝电阻平均值: {ptResistance.Average():F6} Ω, 初始电阻: {initialResistance:F6} Ω");
Logger.Log($"温升最大值: {deltaT.Max():F4} ℃, 平均值: {deltaT.Average():F4} ℃");
// 2. ========== 加热段拟合 → 热导率 λ ==========
// 2. 加热段拟合:选取有效时间窗口 (0.1s ~ 0.8s)
double tStart = 0.1;
double tEndHeating = 0.8;
int startIdx = FindIndex(time, tStart);
@@ -386,51 +471,43 @@ public partial class D7896ViewModel : ObservableObject
if (startIdx < 0) startIdx = 0;
if (endIdxHeating >= n) endIdxHeating = n - 1;
var heatingPoints = new List<DataPoint>();
var points = new List<DataPoint>();
for (int i = startIdx; i <= endIdxHeating; i++)
{
heatingPoints.Add(new DataPoint(Math.Log(time[i]), deltaT[i]));
points.Add(new DataPoint(Math.Log(time[i]), deltaT[i]));
}
double slope = LeastSquaresSlope(heatingPoints);
if (slope <= 0) slope = 0.0001;
// 最小二乘法拟合直线 ΔT = slope * ln(t) + intercept
(double slope, double intercept) = LinearRegression(points);
if (slope <= 0) slope = 1e-6;
Logger.Log($"加热段拟合斜率 B = {slope:F6} (ΔT vs ln(t))");
Logger.Log($"加热段拟合斜率 S = {slope:F6}, 截距 B = {intercept:F6}");
// 3. 计算单位长度加热功率 q (W/m)
double avgCurrentSq = current.Average(c => c * c);
double avgResistance = ptResistance.Average();
double powerPerLength = (avgCurrentSq * avgResistance) / _config.TestParameters.PlatinumWireLength;
// 4. 热导率 λ = q / (4π * slope)
double lambda = powerPerLength / (4 * Math.PI * slope);
Logger.Log($"单位长度加热功率 Q = {powerPerLength:F6} W/m");
Logger.Log($"热导率 λ = {lambda:F6} W/(m·K)");
// 3. ========== 冷却段拟合 → 热扩散率 α ==========
double coolingStart = heatingDuration; // 0.8 秒
double coolingEnd = totalDuration; // 1.6 秒
// 5. 热扩散率 α(截距法)
double wireRadius = 0.00003; // 铂丝半径 0.03 mm
double eulerGamma = 0.5772156649;
double alpha = (wireRadius * wireRadius / 4.0) * Math.Exp(intercept / slope + eulerGamma);
if (alpha <= 0 || double.IsNaN(alpha) || double.IsInfinity(alpha))
alpha = 1e-7; // 合理默认值
Logger.Log($"热扩散率 α = {alpha:E6} m²/s");
// 冷却曲线数据点(仅用于绘图,不参与 α 计算)
var coolingPoints = new List<DataPoint>();
double coolingStart = heatingDuration;
double coolingEnd = totalDuration;
int coolingStartIdx = FindIndex(time, coolingStart);
int coolingEndIdx = FindIndex(time, coolingEnd);
if (coolingStartIdx < 0) coolingStartIdx = n / 2;
if (coolingEndIdx >= n) coolingEndIdx = n - 1;
var coolingPointsForFit = new List<DataPoint>();
for (int i = coolingStartIdx; i <= coolingEndIdx; i++)
{
if (deltaT[i] > 0.001)
coolingPointsForFit.Add(new DataPoint(time[i], Math.Log(deltaT[i])));
}
double coolingSlope = LeastSquaresSlopeOnTime(coolingPointsForFit);
double tau = -1.0 / coolingSlope;
double wireRadius = 0.00003; // 半径 = 直径0.06mm /2
double alpha = (wireRadius * wireRadius) / (4.0 * tau);
if (alpha <= 0 || double.IsNaN(alpha) || double.IsInfinity(alpha))
alpha = 0.12e-6; // 默认值
Logger.Log($"冷却段拟合斜率 D = {coolingSlope:F6} (lnΔT vs t)");
Logger.Log($"时间常数 τ = {tau:F6} s");
Logger.Log($"热扩散率 α = {alpha:E6} m²/s");
// 准备冷却曲线数据点(用于绘图)
var coolingPoints = new List<DataPoint>();
for (int i = coolingStartIdx; i <= coolingEndIdx; i++)
{
if (deltaT[i] > 0.001)
@@ -440,6 +517,28 @@ public partial class D7896ViewModel : ObservableObject
return (lambda, alpha, deltaT, coolingPoints);
}
/// <summary>
/// 最小二乘法线性回归,返回 (斜率, 截距)
/// </summary>
private (double slope, double intercept) LinearRegression(List<DataPoint> points)
{
if (points.Count < 2) return (0.001, 0);
double sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
foreach (var p in points)
{
sumX += p.X;
sumY += p.Y;
sumXY += p.X * p.Y;
sumX2 += p.X * p.X;
}
double n = points.Count;
double denominator = n * sumX2 - sumX * sumX;
if (Math.Abs(denominator) < 1e-10) return (0.001, 0);
double slope = (n * sumXY - sumX * sumY) / denominator;
double intercept = (sumY - slope * sumX) / n;
return (slope, intercept);
}
/// <summary>
/// 查找时间数组中与目标时间最接近的索引
/// </summary>

View File

@@ -25,7 +25,7 @@
"TestParameters": {
"MeasurementCount": 10,
"IntervalSeconds": 30,
"PlatinumWireLength": 0.07, //铂丝长度(单位:米)
"PlatinumWireLength": 0.06, //铂丝长度(单位:米)
"PlatinumWireDiameter": 0.00006,
"ReportOutputPath": "Reports\\",
"DefaultSampleVolume": 40.0,