增加干度计算的数据

This commit is contained in:
2025-03-26 19:52:04 +08:00
parent df07efe5b6
commit 9273f6db42
6 changed files with 264 additions and 30 deletions

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.PPCalculation
{
/// <summary>
/// 干度的REFPROP 封装
/// </summary>
public static class DrynessREFPROP
{
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CharSet = CharSet.Ansi)]
public static extern void SETPATHdll(string hpth, long hpth_length);
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern void SETUPdll(int ncomp, string hFiles, string hFmix, string hrf, out long ierr, out string herr, long hFiles_length, long hFmix_length, long hrf_length, long herr_length);
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern void SATPdll(double P, double x, string inputType, string outputType, out double Tsat, out double Dl, out double Dv, out double hl, out double hv, out double sl, out double sv, out int ierr, StringBuilder herr, int inputTypeLength, int outputTypeLength);
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
//[DllImport(@".\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern void TPFLSHdll(double T, double P, string inputType1, string inputType2, out double D, out double Dl, out double Dv, out double h, out double s, out double u, out double cv, out int ierr, StringBuilder herr, int inputType1Length, int inputType2Length);
/// <summary>
/// 根据温度和压力计算干度
/// </summary>
/// <param name="temperature">温度(K)</param>
/// <param name="pressure">压力(kPa)</param>
/// <returns>干度值(0~1)</returns>
public static double GetDryness(double temperature, double pressure)
{
// 设置REFPROP路径
SETPATHdll(@".\PPCalculation\REFPROP", 256);
// 设置制冷剂以R134a为例
long ierr = 0;
string herr = new string(' ', 255);
SETUPdll(1, "R134A", "DEF", "DEF", out ierr, out herr, 255, 3, 3, 255);
if (ierr != 0)
throw new Exception($"REFPROP初始化失败: {herr}");
// 获取饱和状态参数
double Tsat, Dl, Dv, hl, hv, sl, sv;
StringBuilder errMsg = new StringBuilder(255);
SATPdll(pressure, 0, "P", "T", out Tsat, out Dl, out Dv, out hl, out hv, out sl, out sv,
out int satIerr, errMsg, 1, 1);
if (satIerr != 0)
throw new Exception($"饱和状态计算失败: {errMsg}");
// 获取当前状态参数
double D, curDl, curDv, h, s, u, cv;
StringBuilder curErrMsg = new StringBuilder(255);
TPFLSHdll(temperature, pressure, "T", "P", out D, out curDl, out curDv, out h, out s,
out u, out cv, out int tpIerr, curErrMsg, 1, 1);
if (tpIerr != 0)
throw new Exception($"当前状态计算失败: {curErrMsg}");
// 计算干度
double dryness;
if (temperature <= Tsat) // 饱和液或湿蒸气
{
dryness = (h - hl) / (hv - hl);
dryness = Math.Max(0, Math.Min(1, dryness)); // 确保干度在0-1之间
}
else // 过热蒸气
{
dryness = 1;
}
return dryness;
}
}
}