流量积算仪检定系统

This commit is contained in:
ldeyun 2024-09-13 16:48:21 +08:00
commit 75ec21431b
306 changed files with 45862 additions and 0 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
.vs/NGToolsPC/v15/.suo Normal file

Binary file not shown.

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
.vs/NGToolsPC/v16/.suo Normal file

Binary file not shown.

1250
AGA8_10/Detail.cs Normal file

File diff suppressed because it is too large Load Diff

1826
AGA8_10/FlowCal.cs Normal file

File diff suppressed because it is too large Load Diff

179
AGA8_10/GB11062.cs Normal file
View File

@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NG_Tools
{
public class GB11062
{
int iNCC;// number of components
int[] aiCID = new int[21];// component IDs
double[] dXi = new double[21];// mole fraction of component i
Detail ptDetail;
public GB11062()
{
ptDetail = new Detail();
for (int i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) dXi[i] = 0;
}// Detail()
public void Run(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
int i;
// Check for gas composition change
ptAGA10.bForceUpdate = (ptAGA10.bForceUpdate || ptDetail.compositionchange(ref ptAGA10));
// assign component IDs and values
if (ptAGA10.bForceUpdate)
{
iNCC = -1;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] > 0.0)
{
iNCC = iNCC + 1;
aiCID[iNCC] = i;
dXi[iNCC] = ptAGA10.adMixture[i];
}
}
iNCC = iNCC + 1;
//calculate composition dependent quantities; ported from original
//FORTRAN functions paramdl() and chardl()
GasPropsCal(ref ptAGA10);
}
}
void GasPropsCal(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double[] adTableMri = new double[NG_Cal.NUMBEROFCOMPONENTS] { 16.0430, 28.0135, 44.0100, 30.0700, 44.0970, 18.0153, 34.0820, 2.0159, 28.0100, 31.9988, 58.1230, 58.1230, 72.1500, 72.1500, 86.1770, 100.2040, 114.2310, 128.2580, 142.2850, 4.0026, 39.9480 };
double[] adTablePc = new double[NG_Cal.NUMBEROFCOMPONENTS] { 4.604, 3.399, 7.382, 4.88, 4.249, 22.118, 9.005, 1.297, 3.499, 5.081, 3.648, 3.797, 3.381, 3.369, 3.012, 2.736, 2.486, 0, 0, 0.2275, 4.876 };
double[] adTableTc = new double[NG_Cal.NUMBEROFCOMPONENTS] { 190.55, 126.1, 304.19, 305.43, 369.82, 647.3, 373.5, 33.2, 132.92, 154.7, 408.13, 425.16, 460.39, 469.6, 507.4, 540.2, 568.76, 0, 0, 5.2, 150.82 };
double[] adTableBzsx = new double[NG_Cal.NUMBEROFCOMPONENTS] { 15, 0, 0, 13, 9.5, 0, 45.5, 74.2, 74.2, 0, 8.4, 8.4, 8.3, 8.3, 7.7, 7.0, 0, 0, 0, 0, 0 };
double[] adTableBzxx = new double[NG_Cal.NUMBEROFCOMPONENTS] { 5.0, 0, 0, 2.9, 2.1, 0, 4.3, 4.0, 12.5, 0, 1.8, 1.8, 1.4, 1.4, 1.2, 1.0, 0.96, 0, 0, 0, 0 };
double[,] adTableZn = new double[3, NG_Cal.NUMBEROFCOMPONENTS]
{{0.9976,0.9995,0.9933,0.99,0.9789,0.93,0.99,1.0006,0.9993,0.999,0.958,0.9572,0.9377,0.918,0.892,0.83,0.742,0.613,0.434,1.0005,0.999},
{0.998,0.9997,0.9944,0.9915,0.9821,0.945,0.99,1.0006,0.9995,0.9992,0.968,0.965,0.948,0.937,0.913,0.866,0.802,0.71,0.584,1.0005,0.9992},
{0.9981,0.9997,0.9944,0.992,0.9834,0.952,0.99,1.0006,0.9996,0.9993,0.971,0.9682,0.953,0.945,0.919,0.876,0.817,0.735,0.623,1.0005,0.9993}};
double[,] adTableSqrtbj = new double[3, NG_Cal.NUMBEROFCOMPONENTS]
{{0.049,0.0224,0.0819,0.1,0.1453,0.2646,0.1,-0.004,0.0265,0.0316,0.2049,0.2069,0.251,0.2864,0.3286,0.4123,0.5079,0.6221,0.7523,0.0006,0.0316},
{0.0447,0.0173,0.0748,0.0922,0.1338,0.2345,0.1,-0.0048,0.0224,0.0283,0.1789,0.1871,0.228,0.251,0.295,0.3661,0.445,0.5385,0.645,0.0002,0.0283},
{0.0436,0.0173,0.0728,0.0894,0.1288,0.2191,0.1,-0.0051,0.02,0.0265,0.1703,0.1783,0.2168,0.2345,0.2846,0.3521,0.4278,0.5148,0.614,0,0.0265}};
double[,] adTableHhvMol = new double[4, NG_Cal.NUMBEROFCOMPONENTS]
{{892.97,0,0,1564.34,2224.01,45.074,562.94,286.63,282.8,0,2874.2,2883.82,3535.98,3542.89,4203.23,4862.87,5522.4,6182.91,6842.69,0,0},
{891.56,0,0,1562.14,2221.1,44.433,562.38,286.15,282.91,0,2870.58,2879.76,3531.68,3538.6,4198.24,4857.18,5516.01,6175.82,6834.9,0,0},
{891.09,0,0,1561.41,2220.13,44.224,562.19,285.99,282.95,0,2869.38,2878.57,3530.24,3537.17,4196.58,4855.29,5513.88,6173.46,6832.31,0,0},
{890.63,0,0,1560.69,2219.17,44.016,562.01,285.83,282.98,0,2868.2,2877.4,3528.83,3535.77,4194.95,4853.43,5511.8,6171.15,6829.77,0,0}};
double[,] adTableLhvMol = new double[4, NG_Cal.NUMBEROFCOMPONENTS]
{{802.82,0,0,1429.12,2043.71,0,517.87,241.56,282.8,0,2648.83,2658.45,3265.54,3272.45,3887.71,4502.28,5116.73,5732.17,6346.88,0,0},
{802.69,0,0,1428.84,2043.37,0,517.95,241.72,282.91,0,2648.42,2657.6,3265.08,3272,3887.21,4501.72,5116.11,5731.49,6346.14,0,0},
{802.65,0,0,1428.74,2043.23,0,517.97,241.76,282.95,0,2648.26,2657.45,3264.89,3271.83,3887.01,4501.49,5115.87,5731.22,6345.85,0,0},
{802.6,0,0,1428.64,2043.11,0,517.99,241.81,282.98,0,2648.12,2657.32,3264.73,3271.67,3886.84,4501.3,5115.66,5730.99,6345.59,0,0}};
int i;
double dMair = 28.9626;
double dZair = 0;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] != 0)
{
ptAGA10.Pc += adTablePc[i] * ptAGA10.adMixture[i];
ptAGA10.TC += adTableTc[i] * ptAGA10.adMixture[i];
if (adTableBzsx[i] != 0)
{
ptAGA10.Bzsx += ptAGA10.adMixture[i] / adTableBzsx[i];
ptAGA10.Bzxx += ptAGA10.adMixture[i] / adTableBzxx[i];
}
if (i >= 10 & i <= 18)
{
ptAGA10.C4j += ptAGA10.adMixture[i] * adTableMri[i];
}
if (i >= 12 & i <= 18)
{
ptAGA10.C5j += ptAGA10.adMixture[i] * adTableMri[i];
}
if (i >= 14 & i <= 18)
{
ptAGA10.C6j += ptAGA10.adMixture[i] * adTableMri[i];
}
if (i == 3)
{
ptAGA10.C2 += ptAGA10.adMixture[i] * adTableMri[i];
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dZb11062 += adTableSqrtbj[0, i] * ptAGA10.adMixture[i];
dZair = 0.99941;
break;
case 1:
ptAGA10.dZb11062 += adTableSqrtbj[1, i] * ptAGA10.adMixture[i];
dZair = 0.99958;
break;
case 0:
ptAGA10.dZb11062 += adTableSqrtbj[2, i] * ptAGA10.adMixture[i];
dZair = 0.99963;
break;
}
switch (ptAGA10.dCbtj_E)
{
case 0:
ptAGA10.dHhvMol += adTableHhvMol[0, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[0, i] * ptAGA10.adMixture[i];
break;
case 1:
ptAGA10.dHhvMol += adTableHhvMol[1, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[1, i] * ptAGA10.adMixture[i];
break;
case 2:
ptAGA10.dHhvMol += adTableHhvMol[2, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[2, i] * ptAGA10.adMixture[i];
break;
case 3:
ptAGA10.dHhvMol += adTableHhvMol[3, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[3, i] * ptAGA10.adMixture[i];
break;
}
}
}
ptAGA10.Bzsx = ptAGA10.Bzsx == 0 ? 0 : 1 / ptAGA10.Bzsx;
ptAGA10.Bzxx = ptAGA10.Bzxx == 0 ? 0 : 1 / ptAGA10.Bzxx;
ptAGA10.dZb11062 = 1 - ptAGA10.dZb11062 * ptAGA10.dZb11062;
ptAGA10.dHhvm = ptAGA10.dHhvMol / ptAGA10.dMrx;
ptAGA10.dLhvm = ptAGA10.dLhvMol / ptAGA10.dMrx;
ptAGA10.dHhvv = ptAGA10.dHhvMol * ptAGA10.dPb / ptAGA10.dTb / 8314.510 / ptAGA10.dZb11062;
ptAGA10.dLhvv = ptAGA10.dLhvMol * ptAGA10.dPb / ptAGA10.dTb / 8314.510 / ptAGA10.dZb11062;
ptAGA10.dRD_Ideal11062 = ptAGA10.dMrx / dMair;
ptAGA10.dRD_Real11062 = ptAGA10.dRD_Ideal11062 * dZair / ptAGA10.dZb11062;
ptAGA10.dRhob11062 = ptAGA10.dMrx * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.dRhof11062 = ptAGA10.dMrx * ptAGA10.dPf / 8314.51 / ptAGA10.dTf / ptAGA10.dZf;
ptAGA10.dWobbeIndex = ptAGA10.dHhvv / Math.Sqrt(ptAGA10.dRD_Real11062);
ptAGA10.C3j = ptAGA10.C4j + ptAGA10.adMixture[4] * adTableMri[4];
ptAGA10.C2j = ptAGA10.C3j + ptAGA10.adMixture[3] * adTableMri[3];
ptAGA10.C3C4 = ptAGA10.adMixture[4] * adTableMri[4] + ptAGA10.adMixture[10] * adTableMri[10] + ptAGA10.adMixture[11] * adTableMri[11];
ptAGA10.TotalC = ptAGA10.C2j + ptAGA10.adMixture[0] * adTableMri[0];
ptAGA10.TotalC = ptAGA10.TotalC * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C2 = ptAGA10.C2 * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C3C4 = ptAGA10.C3C4 * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C2j = ptAGA10.C2j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C3j = ptAGA10.C3j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C4j = ptAGA10.C4j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C5j = ptAGA10.C5j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C6j = ptAGA10.C6j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
}
}
}

530
AGA8_10/NG_Cal.cs Normal file
View File

@ -0,0 +1,530 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace NG_Tools
{
public class NG_Cal
{
public const int NORMAL = 9000;
public const int NG_Cal_INITIALIZED = 9001;
public const int MEMORY_ALLOCATION_ERROR = 9002;
public const int GENERAL_CALCULATION_FAILURE = 9003;
public const int MAX_NUM_OF_ITERATIONS_EXCEEDED = 9004;
public const int NEGATIVE_DENSITY_DERIVATIVE = 9005;
public const int MAX_DENSITY_IN_BRAKET_EXCEEDED = 9006;
/* number of components */
public const int NUMBEROFCOMPONENTS = 21;
/* maximum number of tries within search routines */
public const int MAX_NUM_OF_ITERATIONS = 100;
/* default tolerance limits */
public const double P_CHG_TOL = 0.001; /* 0.001 Pa */
public const double T_CHG_TOL = 0.001; /* 0.001 of a Kelvin */
/* maximum allowable P & T */
public const double P_MAX = 1.379e8; // maximum pressure (Pa) ~= 20,000 psi
public const double P_MIN = 0.0; // maximum pressure = 0
public const double T_MAX = 473.15; // maximum temperature (K) ~= 392 F
public const double T_MIN = 143.0; // maximum temperature (K) ~= -200 F
/* universal gas constant, in two configurations */
public const double RGASKJ = 8.314510e-3; /* in kJ mol^-1 K^-1 */
public const double RGAS = 8.314510; /* in J mol^-1 K^-1 */
/* the main data structure used by this library */
public struct GasPropsSTRUCT
{ /* corresponds to the control group in meter classes */
public int lStatus; /* calculation status 计算状态 */
public bool bForceUpdate; /*执行全部计算的标志 signal to perform full calculation */
public double[] adMixture; /*气体摩尔组成 Composition in mole fraction */
public double[] adMixtureV; /*气体体积组成 Composition in mole fraction */
public double[] adMixtureD; /*气体质量组成 Composition in mole fraction */
public int dCbtj; //参比条件 101325 0,15,20
public int dCbtj_E; //燃烧参比条件 101325 0,15,20
public double dPb; /*参比压力 Contract base Pressure (Pa) */
public double dTb; /* 参比温度Contract base temperature (K) */
public double dPf; /*绝对压力 Absolute Pressure (Pa) */
public double dTf; /*工况温度 Flowing temperature (K) */
// basic output from AGA 8 Detail method
public double dMrx; /*分子量 mixture molar mass */
public double dZb; /* 标况压缩因子compressibility at contract base condition */
public double dZf; /* 工况压缩因子compressibility at flowing condition */
public double dFpv; /*超压缩系数 supercompressibility */
public double dDb; /* 标况摩尔密度molar density at contract base conditions (moles/dm3) */
public double dDf; /*工况摩尔密度 molar density at flowing conditions (moles/dm3) */
public double dRhob; /* 标况质量密度mass density at contract base conditions (kg/m3) */
public double dRhof; /*工况质量密度 mass density at flowing conditions (kg/m3) */
public double dRD_Ideal; /* 理想气体的相对密度ideal gas relative density */
public double dRD_Real; /* 真实气体的相对密度real gas relative density */
// additional output
public double dHo; /*理想气体的比焓 ideal gas specific enthalpy */
public double dH; /*真实气体的焓 real gas specific enthalpy (J/kg) */
public double dS; /* 真实气体的熵real gas specific entropy (J/kg-mol.K)*/
public double dCpi; /*理想气体定压热容 ideal gas constant pressure heat capacity (J/kg-mol.K)*/
public double dCp; /* 定压热容real gas constant pressure heat capacity (J/kg-mol.K)*/
public double dCv; /*定容积热容 real gas constant volume heat capacity (J/kg-mol.K)*/
public double dk; /* 比热比ratio of specific heats */
public double dKappa; /*等熵指数 isentropic exponent, denoted with Greek letter kappa */
public double dSOS; /* 声速speed of sound (m/s) */
public double dCstar; /*临界流函数 critical flow factor C* */
// 11062 输出
public double dHhvMol; //摩尔高位发热量
public double dLhvMol; //摩尔低位发热量
public double dHhvv; //体积高位发热量
public double dLhvv; //体积低位发热量
public double dHhvm; //质量高位发热量
public double dLhvm; //质量地位发热量
public double dZb11062; //标况压缩因子
public double dRhob11062; /* 标况质量密度mass density at contract base conditions (kg/m3) */
public double dRhof11062; /*工况质量密度 mass density at flowing conditions (kg/m3) */
public double dRD_Ideal11062; /* 理想气体的相对密度ideal gas relative density */
public double dRD_Real11062; /* 真实气体的相对密度real gas relative density */
public double dWobbeIndex; /* 真实气体的沃泊指数 */
public double Pc; // '临界压力
public double TC; /// '临界温度
public double Bzsx; // '爆炸上限
public double Bzxx; // '爆炸下限
public double TotalC; // '总炭含量 (kg/m3)
public double C2; // 'C2组分含量 (kg/m3)
public double C2j; // 'C2以上组分含量 (kg/m3)
public double C3j; // 'C3以上组分含量 (kg/m3)
public double C4j; // 'C4以上组分含量 (kg/m3)
public double C5j; // 'C5以上组分含量 (kg/m3)
public double C6j; // 'C6以上组分含量 (kg/m3)
public double C3C4; // 'C3C4组分含量 (kg/m3)
}
public struct FlowParStruct //流量相关参数
{
//流量计算输入参数信息
public int dFlowCalbz; //流量计算标准
public int dZcalbz; //压缩因子计算标准
public int dCbtj; //计量参比条件压力
public double dPb_M; //计量参比条件压力
public double dTb_M; //计量参比条件温度
public double dPb_E; //燃烧参比条件压力
public double dTb_E; //燃烧参比条件温度
public double dPatm;//当地大气压
public int dPatmUnit;//当地大气压单位
public double[] dNG_Compents;//天然气组分
public int dMeterType;// 流量计类别
public int dCoreType;//节流装置类型
public int dPtmode; //取压方式
public int dPipeType; // 管道类型
public double dPipeD; //管道内径
public int dLenUnit; //长度单位
public double dPipeDtemp; //管道内径参考温度
public int dPileDtempUint; //温度单位
public int dPipeMaterial; //管道材料
public double dOrificeD; //孔板孔径
public int dOrificeUnit; //长度单位
public double dOrificeDtemp; //孔板内径参考温度
public int dOrificeDtempUnit; //温度单位
public int dOrificeMaterial; //孔板材料
public int dOrificeSharpness; //锐利度系数计算方法
public double dOrificeRk; //孔板入口圆弧半径
public int dOrificeRkLenUint;//长度单位
public double dPf;//输入压力
public int dPfUnit;//压力单位
public int dPfType; //压力类型
public double dTf; //输入温度
public int dTfUnit;//温度单位
public double dDp; //输入差压
public int dDpUnit; //压力单位
public int dVFlowUnit; //体积流量单位
public int dMFlowUnit; //'NG_Par(33) = ComboBox15.SelectedIndex '质量流量单位
public int dEFlowUnit; //'NG_Par(34) = ComboBox16.SelectedIndex '能量流量单位
public double dCd;//流出系数
public double dCdCalMethod;//流出系数计算方法 0 检定证书 0回归公式
public double dMeterFactor;//仪表系数
public double dPulseNum;//脉冲数
public double dVFlowMax; //'NG_par(39)=’最大体积流量
public double dVFlowMin; //'NG_par(40)=’最小体积流量
public double dVFlowCon;//'NG_par(41)=’常用流量
public double dPfRangeMin; //'NG_par(42)=’压力量程
public double dPfRangeMax; //'NG_par(42)=’压力量程
public double dDpRangeMin; //'NG_par(43)=’差压量程
public double dDpRangeMax; //'NG_par(43)=’差压量程
public double dTfRangeMin; //'NG_par(44)=’温度计量程
public double dTfRangeMax; //'NG_par(44)=’温度计量程
//流量计算输出参数
public double dE; //'求渐近速度系数 E
public double dFG; //'求相对密度系数 FG
public double dFT; //'求流动温度系数 'FT
public double dDViscosity; //'求动力粘度 dlnd
public double dDExpCoefficient; //'求可膨胀系数
public double dRnPipe; //'管道雷诺数
public double dBk; //'孔板锐利度系数Bk
public double dRoughNessPipe; //'管道粗糙度系数 Gme
public double dCdCorrect; //'修正后的流出系数
public double dCdNozell; //'喷嘴的流出系数
public double dVFlowb;//'标况体积流量 m³、s
public double dVFlowf; //'工况体积流量
public double dMFlowb;//'标况质量流量
public double dEFlowb;//'标况能量流量
public double dVelocityFlow;//'管道内天然气流速
public double dPressLost;//'压力损失
public double dBeta;//'直径比
public double dKappa;//'等熵指数
}
//public struct SqgyParStruct //输气工艺相关参数
//{
// public int dCalName; //计算项目
// public int dPipleD; //管道内径mm
// public int dPipleDw; //管道内径外径mm
// public int dPipleBh; //管道壁厚 mm
// public double dPipleTotalLength; //管道总长度 km
// public double dPiplePointLength; //管道任意点长度 km
// public double dPstart; //起点压力终点压力MPa
// public double dPend; //终点压力MPa
// public double dFlow; //输气能力
// public double dRd;//相对密度
// public double dZf;//压缩因子
// public double[] dNG_Compents;//天然气组分
// public double dPavg;//管道平均压力
// public double dPavgPoint;//管道任意点的平均压力
//}
/* enumerations for tracking gas components */
enum gascomp
{
XiC1 = 0, XiN2, XiCO2, XiC2, XiC3,
XiH2O, XiH2S, XiH2, XiCO, XiO2, XiIC4, XiNC4,
XiIC5, XiNC5, XiNC6, XiNC7, XiNC8, XiNC9, XiNC10, XiHe, XiAr
};
/* FUNCTION PROTOTYPES */
/* prototypes for initialization */
// int NG_Cal_Init(void) ; /* initialize library */
// int NG_Cal_UnInit(void) ; /* un-initialize library */
///* function prototype for basic VOS calculation */
// double SOS(ref AGA10.GasPropsSTRUCT ) ;
///* function prototype for a C* calculation */
// double Crit(ref AGA10.GasPropsSTRUCT , double) ;
public Therm ptTherm;
public Detail ptDetail;
/**************************************************************************
* Function : NG_Cal_Init()
* Arguments : void
* Returns : int
* Purpose : Initializes library; creates required objects
* Revisions :
**************************************************************************/
public int NG_Cal_Init()
{
//create object for calculating density
if (null == (ptDetail = new Detail()))
{
return MEMORY_ALLOCATION_ERROR;
}
//create object for calculating thermodynamic properties
if (null == (ptTherm = new Therm()))
{
return MEMORY_ALLOCATION_ERROR;
}
return NG_Cal_INITIALIZED;
}// NG_Cal_Init
/**************************************************************************
* Function : NG_Cal_UnInit()
* Arguments : void
* Returns : int
* Purpose : Un-initializes library; deletes objects
* Revisions :
**************************************************************************/
public int NG_Cal_UnInit()
{
// delete the objects (if they exist)
ptDetail = null;
ptTherm = null;
return 0;
}// NG_Cal_UnInit
/**************************************************************************
* Function : SOS()
* Arguments : Pointers to external AGA10 data struct
* Returns : double
* Purpose : calculates speed of sound and other parameters
* Revisions :
**************************************************************************/
public double SOS(ref GasPropsSTRUCT ptAGA10)
{
// check if library is ready; initialize if necessary
if (null == ptDetail || null == ptTherm)
{
NG_Cal_UnInit();
NG_Cal_Init();
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 273.15;
break;
case 1:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 288.15;
break;
case 0:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 293.15;
break;
}
//Call function to calculate densities and thermodynamic properties
ptTherm.Run(ref ptAGA10, ref ptDetail);
//the basic sound speed calculation doesn't calculate C*; initialize to zero
ptAGA10.dCstar = 0.0;
//return the speed of sound to caller
return ptAGA10.dSOS;
}// VOS()
/**************************************************************************
* Function : Crit()
* Arguments : Pointers to external AGA10 data struct, Detail and Therm
* objects and a double precision float (gas velocity in plenum)
* Returns : double
* Purpose : calculates C*
* Revisions :
**************************************************************************/
public double Crit(ref NG_Cal.GasPropsSTRUCT ptAGA10, double dPlenumVelocity)
{
//variables local to function
double DH, DDH, S, H;
double tolerance = 1.0;
double R, P, T, Z;
int i;
//check objects for readiness; try to initialize if not
if (null == ptDetail || null == ptTherm)
{
NG_Cal_UnInit();
if (NG_Cal_INITIALIZED != NG_Cal_Init())
{
ptAGA10.lStatus = MEMORY_ALLOCATION_ERROR; return 0.0;
}
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 273.15;
break;
case 1:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 288.15;
break;
case 0:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 293.15;
break;
}
//begin by calculating densities and thermodynamic properties
ptTherm.Run(ref ptAGA10, ref ptDetail);
//DH is enthalpy change from plenum to throat; this is our initial guess
DH = (ptAGA10.dSOS * ptAGA10.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0;
//trap plenum conditions before we alter the data stucture's contents
S = ptAGA10.dS;
H = ptAGA10.dH;
R = ptAGA10.dRhof;
P = ptAGA10.dPf;
Z = ptAGA10.dZf;
T = ptAGA10.dTf;
//initialize delta of DH to an arbitrary value outside of
//convergence tolerance
DDH = 10.0;
//Via simple repetition, search for a pressure, temperature and sound speed
//at a nozzle throat which provide constant enthalpy, given the entropy known
//at the plenum. Abort if loop executes more than 100 times without convergence.
for (i = 1; i < MAX_NUM_OF_ITERATIONS; i++)
{
// calculate P and T to satisfy H and S
ptTherm.HS_Mode(ref ptAGA10, ref ptDetail, H - DH, S, true);
//calculate new thermo, including SOS
ptTherm.Run(ref ptAGA10, ref ptDetail);
//hold DH for tolerance check
DDH = DH;
// recalculate DH
DH = (ptAGA10.dSOS * ptAGA10.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0;
// end loop if tolerance reached
if (Math.Abs(DDH - DH) < tolerance) break;
}
//C* is the real gas critical flow constant (not to be confused with Cperf or CRi)
ptAGA10.dCstar = (ptAGA10.dRhof * ptAGA10.dSOS) / Math.Sqrt(R * P * Z);
//put the original plenum pressure and temperature back
ptAGA10.dPf = P;
ptAGA10.dTf = T;
//restore fluid props to plenum conditions
ptTherm.Run(ref ptAGA10, ref ptDetail);
GB11062 ptGB11062 = new GB11062();
ptGB11062.Run(ref ptAGA10);
//return the critical flow function to caller
return ptAGA10.dCstar;
}// Crit()
/**************************************************************************
* Function : Crit()
* Arguments : Pointers to external AGA10 data struct, Detail and Therm
* objects and a double precision float (gas velocity in plenum)
* Returns : double
* Purpose : calculates C*
* Revisions :
**************************************************************************/
public double Zcal(ref NG_Cal.GasPropsSTRUCT ptAGA10, double dPlenumVelocity)
{
//variables local to function
//check objects for readiness; try to initialize if not
if (null == ptDetail || null == ptTherm)
{
NG_Cal_UnInit();
if (NG_Cal_INITIALIZED != NG_Cal_Init())
{
ptAGA10.lStatus = MEMORY_ALLOCATION_ERROR; return 0.0;
}
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 273.15;
break;
case 1:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 288.15;
break;
case 0:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 293.15;
break;
}
//begin by calculating densities and thermodynamic properties
ptTherm.Run(ref ptAGA10, ref ptDetail);
GB11062 ptGB11062 = new GB11062();
ptGB11062.Run(ref ptAGA10);
//return the critical flow function to caller
return ptAGA10.dZf;
}// Z()
/**************************************************************************
* Function : Cperf()
* Arguments : pointer to external AGA10 data struct
* Returns : double
* Purpose : calculates isentropic perfect gas critical flow function
* Revisions :
**************************************************************************/
double Cperf(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double k, root, exponent;
k = ptAGA10.dKappa; root = 2.0 / (k + 1.0);
exponent = (k + 1.0) / (k - 1.0);
// isentropic perfect gas critical flow function C*i
return (Math.Sqrt(k * Math.Pow(root, exponent)));
}// Cperf
/**************************************************************************
* Function : CRi()
* Arguments : pointer to external AGA10 data struct
* Returns : double
* Purpose : calculates isentropic real gas critical flow function CRi
* Revisions :
**************************************************************************/
double CRi(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
return (Cperf(ref ptAGA10) / Math.Sqrt(ptAGA10.dZf));
}// CRi()
}
}

60
AGA8_10/NG_Cal.csproj Normal file
View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{186107A4-D8E6-46C1-A6CE-65E5C4F14C1B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NG_Cal</RootNamespace>
<AssemblyName>NG_Cal</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FlowCal.cs" />
<Compile Include="NG_Cal.cs" />
<Compile Include="Detail.cs" />
<Compile Include="GB11062.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Therm.cs" />
<Compile Include="UnitConvert.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

BIN
AGA8_10/NG_TOOLS.snk Normal file

Binary file not shown.

65
AGA8_10/NG_Tools.csproj Normal file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{186107A4-D8E6-46C1-A6CE-65E5C4F14C1B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NG_Tools</RootNamespace>
<AssemblyName>NG_Tools</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\NGToolsPC\bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FlowCal.cs" />
<Compile Include="NG_Cal.cs" />
<Compile Include="Detail.cs" />
<Compile Include="GB11062.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Therm.cs" />
<Compile Include="UnitConvert.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("NG_Tools")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NG_Tools")]
[assembly: AssemblyCopyright("Copyright © 2017 廖德云 ldeyun@163.com")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("7f6505ae-7989-41df-9888-b7b7c2e4ed67")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

534
AGA8_10/Therm.cs Normal file
View File

@ -0,0 +1,534 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NG_Tools
{
public class Therm
{
// member data
//double dT;// current temperature, in Kelvins
//double dP;// current pressure, in Pascals
//double dD;// molar density, in moles/dm3
//double dRho;// mass density, in kg/m3
double dPdD;// partial deriv of P wrt D
double dPdT;// partial deriv of P wrt T
double dSi;// ideal gas specific entropy, kJ/kg.K
double dTold;// temperature previously used
double dMrxold;// mixture molar mass previously used
double[] GK_root = new double[5] { 0.14887433898163121088, 0.43339539412924719080, 0.67940956829902440263, 0.86506336668898451073, 0.97390652851717172008 };
double[] GK_weight = new double[5] { 0.29552422471475286217, 0.26926671930999634918, 0.21908636251598204295, 0.14945134915058059038, 0.066671344308688137179 };
//set the number of points for quadrature
int GK_points = 5;
//equation constants for ideal gas heat capacity, enthalpy and entropy
double[,] ThermConstants = new double[21, 11] {{-29776.4, 7.95454, 43.9417, 1037.09, 1.56373, 813.205, -24.9027, 1019.98,-10.1601, 1070.14,-20.0615},
{-3495.34, 6.95587, 0.272892, 662.738,-0.291318,-680.562, 1.78980, 1740.06, 0.0, 100.0, 4.49823},
{ 20.7307, 6.96237, 2.68645, 500.371,-2.56429,-530.443, 3.91921, 500.198, 2.13290, 2197.22, 5.81381},
{-37524.4, 7.98139, 24.3668, 752.320, 3.53990, 272.846, 8.44724, 1020.13,-13.2732, 869.510,-22.4010},
{-56072.1, 8.14319,37.0629,735.402,9.38159,247.190,13.4556, 1454.78,-11.7342, 984.518,-24.0426},
{-13773.1, 7.97183, 6.27078,2572.63,2.05010,1156.72,0.0,100.0,0.0,100.0,-3.24989},
{-10085.4, 7.94680,-0.08380,433.801,2.85539, 843.792,6.31595, 1481.43,-2.88457, 1102.23,-0.51551},
{-5565.60, 6.66789, 2.33458,2584.98,.749019, 559.656,0.0,100.0,0.0,100.0,-7.94821},
{-2753.49, 6.95854, 2.02441,1541.22,.096774, 3674.81,0.0,100.0,0.0,100.0,6.23387},
{-3497.45, 6.96302, 2.40013, 2522.05, 2.21752, 1154.15, 0.0,100.0,0.0,100.0,9.19749},
{-72387.0, 17.8143, 58.2062, 1787.39, 40.7621, 808.645, 0.0,100.0,0.0,100.0,-44.1341},
{-72674.8, 18.6383, 57.4178, 1792.73, 38.6599, 814.151, 0.0,100.0,0.0,100.0,-46.1938},
{-91505.5, 21.3861, 74.3410, 1701.58, 47.0587, 775.899, 0.0,100.0,0.0,100.0,-60.2474},
{-83845.2, 22.5012, 69.5789, 1719.58, 46.2164, 802.174, 0.0,100.0,0.0,100.0,-62.2197},
{-94982.5, 26.6225, 80.3819, 1718.49, 55.6598, 802.069, 0.0,100.0,0.0,100.0,-77.5366},
{-103353.0, 30.4029, 90.6941, 1669.32, 63.2028, 786.001, 0.0,100.0,0.0,100.0,-92.0164},
{-109674.0, 34.0847, 100.253, 1611.55, 69.7675, 768.847, 0.0,100.0,0.0,100.0,-106.149},
{-122599.0, 38.5014, 111.446, 1646.48, 80.5015, 781.588, 0.0,100.0,0.0,100.0,-122.444},
{-133564.0, 42.7143, 122.173, 1654.85, 90.2255, 785.564, 0.0,100.0,0.0,100.0,-138.006},
{0.0,4.9680,0.0,100.0,0.0,100.0,0.0,100.0,0.0,100.0,0.0},
{0.0,4.9680,0.0,100.0,0.0,100.0,0.0,100.0,0.0,100.0,0.0}};
// enumerations for indexing of coefficients
//public enum CoefficientList { coefA = 0, coefB, coefC, coefD, coefE, coefF, coefG, coefH, coefI, coefJ, coefK } ;
public int coefA = 0;
public int coefB = 1;
public int coefC = 2;
public int coefD = 3;
public int coefE = 4;
public int coefF = 5;
public int coefG = 6;
public int coefH = 7;
public int coefI = 8;
public int coefJ = 9;
public int coefK = 10;
// conversion constant for thermochemical calories to Joules: 1 cal(IT) = 4.1840 J
const double CalTH = 4.1840;
public Therm()
{
// initialize 3 history-sensitive variables
dSi = 0.0;
dTold = 0.0;
dMrxold = 0.0;
}//Therm()
/**************************************************************************
*Function:Math.Coth()
*Arguments:double
*Returns:double
*Purpose:calculate hyperbolic cotangent; used in Ho calculations
*Revisions:
*Notes:Not a Therm object class member, just a utility for this
*file. The C++ language has no intrinsic support for
*hyperbolic cotangent
**************************************************************************/
double coth(double x)
{
return Math.Cosh(x) / Math.Sinh(x);
}// Math.Coth()
/**************************************************************************
*Function:Run()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:void
*Purpose:overall execution control; top level math for SOS and k
*Revisions:
**************************************************************************/
public void Run(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
//local variables
double c, x, y, z;
//first run basic set of functions within AGA 8 (1994) Detail Method
ptD.Run(ref ptAGA10);
//find first partial derivative of Z wrt D
ptD.dZdD(ptAGA10.dDf);
//find real gas cv, cp, specific enthalpy and entropy
CprCvrHS(ref ptAGA10, ref ptD);
//ratio of real gas specific heats
ptAGA10.dk = ptAGA10.dCp / ptAGA10.dCv;
//solve c in three steps, for clarity and ease of debugging
x = ptAGA10.dk * NG_Cal.RGAS * 1000.0 * ptAGA10.dTf;
y = ptAGA10.dMrx;
z = ptAGA10.dZf + ptAGA10.dDf * ptD.ddZdD;
//calculate c, which is SOS^2
c = (x / y) * z;
//speed of sound
ptAGA10.dSOS = Math.Sqrt(c);
//calculate the real gas isentropic exponent
//using expression functionally equivalent to Equation 3.2
ptAGA10.dKappa = (c * ptAGA10.dRhof) / ptAGA10.dPf;
return;
}//Run()
/**************************************************************************
*Function:CpiMolar()
*Arguments:ref AGA10.GasPropsSTRUCT
*Returns:double
*Purpose:Calculate constant pressure ideal gas molar heat capacity
*in (J/mol-K), applying eqns from Aly, Lee, McFall
*Notes:For continuity, the original constants and eqn's have been
*retained. Conversion from thermochemical calories(th) to
*Joules is applied after the primary calculations are complete.
*Revisions:
**************************************************************************/
double CpiMolar(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double Cp = 0.0;
double Cpx;
double DT, FT, HT, JT;
double Dx, Fx, Hx, Jx;
double T;
int i;
//to maximize readability of this section, use intermediate variable T
T = ptAGA10.dTf;
//calculate heat capacity for each component
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
//skip species whose concentration is zero
if (ptAGA10.adMixture[i] <= 0.0) continue;
//initialize Cp of species to zero
Cpx = 0.0;
// calculate species intermediate terms
DT = ThermConstants[i, coefD] / T;
FT = ThermConstants[i, coefF] / T;
HT = ThermConstants[i, coefH] / T;
JT = ThermConstants[i, coefJ] / T;
// use intermediate terms to avoid redundant calcs
Dx = DT / Math.Sinh(DT);
Fx = FT / Math.Cosh(FT);
Hx = HT / Math.Sinh(HT);
Jx = JT / Math.Cosh(JT);
Cpx += ThermConstants[i, coefB];
Cpx += ThermConstants[i, coefC] * Dx * Dx;
Cpx += ThermConstants[i, coefE] * Fx * Fx;
Cpx += ThermConstants[i, coefG] * Hx * Hx;
Cpx += ThermConstants[i, coefI] * Jx * Jx;
//use current mole fraction to weight the contribution
Cpx *= ptAGA10.adMixture[i];
//add this contribution to the sum
Cp += Cpx;
}
// convert from cal(th)/mol-K to J/mol-K
Cp *= CalTH;
return Cp;
}//CpiMolar()
/**************************************************************************
*Function:Ho()
*Arguments:ref AGA10.GasPropsSTRUCT
*Returns:double
*Purpose:Calculate ideal gas specific enthalpy (J/kg)
*Notes:For continuity, the original constants and eqn's have been
*retained. Conversion from thermochemical calories(th) to
*Joules is applied after the primary calculations are complete.
*Revisions:
**************************************************************************/
double Ho(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double H = 0.0; double Hx;
double DT, FT, HT, JT;
double cothDT, tanhFT, cothHT, tanhJT; double T;
int i;
// to maximize readability of this section, use intermediate variable T
T = ptAGA10.dTf;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
// skip species whose concentration is zero
if (ptAGA10.adMixture[i] <= 0.0) continue;
Hx = 0.0;
// calculate species intermediate terms
DT = ThermConstants[i, coefD] / T;
FT = ThermConstants[i, coefF] / T; HT = ThermConstants[i, coefH] / T; JT = ThermConstants[i, coefJ] / T;
cothDT = coth(DT); tanhFT = Math.Tanh(FT); cothHT = coth(HT); tanhJT = Math.Tanh(JT);
Hx += ThermConstants[i, coefA];
Hx += ThermConstants[i, coefB] * T;
Hx += ThermConstants[i, coefC] * ThermConstants[i, coefD] * cothDT;
Hx -= ThermConstants[i, coefE] * ThermConstants[i, coefF] * tanhFT;
Hx += ThermConstants[i, coefG] * ThermConstants[i, coefH] * cothHT;
Hx -= ThermConstants[i, coefI] * ThermConstants[i, coefJ] * tanhJT;
//use current mole fraction to weight the contribution
Hx *= ptAGA10.adMixture[i];
//add this contribution to the sum
H += Hx;
}
//convert from cal(th)/g-mol to kJ/kg-mol
H *= CalTH;
//convert from kJ/kg-mol to J/kg
H /= ptAGA10.dMrx;
// return in J/kg
return H * 1.0e3;
}
// Ho()
/**************************************************************************
*Function:So()
*Arguments:ref AGA10.GasPropsSTRUCT
*Returns:double
*Purpose:ideal gas specific entropy (J/kg-K)
*Notes:For continuity, the original constants and eqn's have been
*retained. Conversion from thermochemical calories(th) to
*Joules is applied after the primary calculations are complete.
*Revisions:
**************************************************************************/
double So(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double S = 0.0; double Sx;
double DT, FT, HT, JT;
double cothDT, tanhFT, cothHT, tanhJT; double sinhDT, coshFT, sinhHT, coshJT; double T;
int i;
// to improve readability of this section, use intermediate variable T
T = ptAGA10.dTf;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
// skip species whose concentration is zero
if (ptAGA10.adMixture[i] <= 0.0) continue;
Sx = 0.0;
// calculate species intermediate terms
DT = ThermConstants[i, coefD] / T;
FT = ThermConstants[i, coefF] / T;
HT = ThermConstants[i, coefH] / T;
JT = ThermConstants[i, coefJ] / T;
cothDT = coth(DT); tanhFT = Math.Tanh(FT); cothHT = coth(HT);
tanhJT = Math.Tanh(JT);
sinhDT = Math.Sinh(DT); coshFT = Math.Cosh(FT); sinhHT = Math.Sinh(HT); coshJT = Math.Cosh(JT);
Sx += ThermConstants[i, coefK];
Sx += ThermConstants[i, coefB] * Math.Log(T);
Sx += ThermConstants[i, coefC] * (DT * cothDT - Math.Log(sinhDT));
Sx -= ThermConstants[i, coefE] * (FT * tanhFT - Math.Log(coshFT));
Sx += ThermConstants[i, coefG] * (HT * cothHT - Math.Log(sinhHT));
Sx -= ThermConstants[i, coefI] * (JT * tanhJT - Math.Log(coshJT));
//use current mole fraction to weight the contribution
Sx *= ptAGA10.adMixture[i];
//add this contribution to the sum
S += Sx;
}
//convert cal(th)/mol-K basis to to kJ/kg mol-K
S *= CalTH;
//convert from kJ/kg mol-K to kJ/kg-K
S /= ptAGA10.dMrx;
// return in J/kg-K
return S * 1.0e3;
}//So()
/**************************************************************************
*Function:CprCvrHS()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:void
*Purpose:reasonably efficient group calculation of Cp, Cv, H and S
*Revisions:
**************************************************************************/
void CprCvrHS(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
double Cvinc, Cvr, Cpr;
double Hinc;
double Sinc;
double Smixing;
double Cp, Si;
double a, b, x;
int i;
//initialize integrals to zero
Cvinc = 0.0;
Hinc = 0.0;
Sinc = 0.0;
//initialize entropy of mixing
Smixing = 0.0;
//find ideal gas Cp
Cp = CpiMolar(ref ptAGA10);
//find ideal gas enthalpy
ptAGA10.dHo = Ho(ref ptAGA10);
//find ideal gas entropy
Si = So(ref ptAGA10);
//calculate ideal gas specific heat capacity at constant pressure in J/kgK
ptAGA10.dCpi = (Cp * 1000.0) / ptAGA10.dMrx;
//integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature
for (i = 0; i < GK_points; i++)
{
// set calculation point at + abscissa
x = ptAGA10.dDf * (1.0 + GK_root[i]) / 2.0;
//get Z at D
ptD.zdetail(x);
ptD.dZdT(x);
ptD.d2ZdT2(x);
//gather contributions at + abscissa; applying weighting factor
Hinc += GK_weight[i] * ptD.ddZdT / x;
Cvinc += GK_weight[i] * (2.0 * ptD.ddZdT + ptAGA10.dTf * ptD.dd2ZdT2) / x;
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
//set calculation point at - abscissa
x = ptAGA10.dDf * (1.0 - GK_root[i]) / 2.0;
//get Z at D
ptD.zdetail(x);
//calculate 1st and 2nd partial derivatives of Z wrt T
ptD.dZdT(x);
ptD.d2ZdT2(x);
//gather contributions at - abscissa; applying weighting factor
Hinc += GK_weight[i] * ptD.ddZdT / x;
Cvinc += GK_weight[i] * (2.0 * ptD.ddZdT + ptAGA10.dTf * ptD.dd2ZdT2) / x;
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
}
//return Z and partial derivatives to full molar density
ptD.zdetail(ptAGA10.dDf);
ptD.dZdT(ptAGA10.dDf);
ptD.d2ZdT2(ptAGA10.dDf);
//complete Cv molar
Cvr = Cp - NG_Cal.RGAS * (1.0 + ptAGA10.dTf * Cvinc * 0.5 * ptAGA10.dDf);
//intermediate values for Cp, containing 2 partial derivatives
a = (ptAGA10.dZf + ptAGA10.dTf * ptD.ddZdT);
b = (ptAGA10.dZf + ptAGA10.dDf * ptD.ddZdD);
//calculate dPdT, the partial derivative of P wrt T, at D
dPdT = NG_Cal.RGAS * ptAGA10.dDf * a;
//calculate dPdD, the partial derivative of P wrt D, at T
dPdD = NG_Cal.RGAS * ptAGA10.dTf * b;
//equation completing molar Cp, cancelling appropriate terms
Cpr = Cvr + NG_Cal.RGAS * ((a * a) / b);
//change from molar to mass basis
Cpr /= ptAGA10.dMrx;
Cvr /= ptAGA10.dMrx;
// write to the data stucture
ptAGA10.dCv = Cvr * 1000.0; // convert from joules/kgK to kilojoules/kgK
ptAGA10.dCp = Cpr * 1000.0;
// calculate specific enthalpy
ptAGA10.dH = ptAGA10.dHo + 1000.0 * NG_Cal.RGAS * ptAGA10.dTf * (ptAGA10.dZf - 1.0 - ptAGA10.dTf * Hinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
// calculate entropy of mixing
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] != 0) Smixing += ptAGA10.adMixture[i] * Math.Log(ptAGA10.adMixture[i]);
}
Smixing *= NG_Cal.RGAS;
// calculate specific entropy
ptAGA10.dS = Si - Smixing - 1000.0 * NG_Cal.RGAS * (Math.Log(ptAGA10.dPf / 101325.0) - Math.Log(ptAGA10.dZf) + Sinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
return;
}//CprCvrHS()
/**************************************************************************
*Function:HS_Mode()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *, double, double, bool
*Returns:void
*Purpose:Calculates a pressure & temperature from known enthalpy & entropy,
*with or without prior estimates.This function has a role in the
*calculation of C*.
*Solution based on a doubly-nested trial & error algorithm and Newton's
*method.
*
*For illustrative purpose, two approaches are supported by this example.
*If you are starting without advance knowledge of P & T, set the input parm
*bGuess to false, thus specifying a conservative search approach.
*If, however, you have a basis for guessing P & T (plenum conditions of a
*critical flow nozzle, for example) set P & T via GasPropsSTRUCT and set
*bGuess = true. The initial guess allows the search function to be more
*aggressive and, typically, faster.
*
*Revisions:
**************************************************************************/
public void HS_Mode(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD, double H, double S, bool bGuess)
{
double s0, s1, s2, t0, t1, t2, tmin, tmax; double h0, h1, h2, p0, p1, p2, px, pmin, pmax; double delta1, delta2;
double tolerance = 0.001;// convergence tolerance (used for both H and S searches)
int i, j;
//s0and h0 are our real gas reference points
s0 = S;
h0 = H;
//calling function specifies whether search parameters are supplied thru ptAGA10 or unknown
if (bGuess)
{
t1 = ptAGA10.dTf; px = ptAGA10.dPf; pmax = px * 2.0; pmin = px * 0.1;
tmax = t1 * 1.5; tmin = t1 * 0.67;
}
else// use arbitrary, generic limits
{
t1 = 273.15;
px = 1013250.0; // 10 atmospheres
pmax = NG_Cal.P_MAX;
pmin = 10000.0; // 10 kPa
tmax = NG_Cal.T_MAX;
tmin = NG_Cal.T_MIN;
}
// set the temperature differential
t2 = t1 + 10.0;
///////////////////////////////////////////
//begin double trial-and-error, searching for T & P
//run the calculation with initial guesses
ptD.Run(ref ptAGA10);
//h1 is difference between h given and h@Tf, Pf
h1 = this.H(ref ptAGA10, ref ptD) - h0;
//outer loop: search for a t2 which will satisfy constant enthalpy
for (i = 0; i < NG_Cal.MAX_NUM_OF_ITERATIONS; i++)
{
ptAGA10.dTf = t2;
p1 = px;// reset one bracket
p2 = px * 0.1;// set other bracket to 0.1x the upper bracket
ptAGA10.dPf = p1;
ptD.Run(ref ptAGA10);
s1 = this.S(ref ptAGA10, ref ptD) - s0;
//inside loop: search for a p2 which will satisfy constant entropy
for (j = 0; j < NG_Cal.MAX_NUM_OF_ITERATIONS; j++)
{
ptAGA10.dPf = p2; ptD.Run(ref ptAGA10);
s2 = this.S(ref ptAGA10, ref ptD) - s0;
//calculate our proportional change
delta2 = Math.Abs(s1 - s2) / s0; // close enough?
if (delta2 < tolerance) break;
//revise our estimate to p2
p0 = p2;
p2 = (p1 * s2 - p2 * s1) / (s2 - s1);
//check for negative pressure and clamp to pmin for safety
if (p2 <= pmin)
{
p2 = pmin;
}
//check if we've created an unrealistic pressure
if (p2 >= pmax) p2 = pmax; // swap values
p1 = p0;
s1 = s2;
}
// check for failure to converge
if (j >= NG_Cal.MAX_NUM_OF_ITERATIONS) ptAGA10.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED;
//calc enthalpy at guessed P & current iter T
h2 = this.H(ref ptAGA10, ref ptD) - h0;
//calculate our proportional change
delta1 = Math.Abs(h1 - h2) / h0;
// close enough?
if (delta1 < tolerance && i > 0) break;
//revise our estimate to t2
t0 = t2;
t2 = (t1 * h2 - t2 * h1) / (h2 - h1);
//check if we've created an unrealistic temperature
if (t2 >= tmax) t2 = tmax;
//revise t2, if necessary
if (t2 <= tmin)
{
t2 = t0 + 10.0;
ptAGA10.dTf = t2; ptD.Run(ref ptAGA10);
h2 = this.H(ref ptAGA10, ref ptD) - h0;
}
t1 = t0;
h1 = h2;
}
// check for failure to converge
if (i >= NG_Cal.MAX_NUM_OF_ITERATIONS) ptAGA10.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED;
}//HS_Mode()
/**************************************************************************
*Function:H()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:double
*Purpose:real gas specific enthalpy
*Revisions:
**************************************************************************/
double H(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
double Hinc; double x; int i;
//initialize integral
Hinc = 0.0;
//find ideal gas enthalpy
ptAGA10.dHo = Ho(ref ptAGA10);
//integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature
for (i = 0; i < GK_points; i++)
{
//calculate 1st and 2nd partial derivatives of Z wrt T
x = ptAGA10.dDf * (1.0 + GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x);
ptD.d2ZdT2(x);
Hinc += GK_weight[i] * ptD.ddZdT / x; if (i == 10) break;
x = ptAGA10.dDf * (1.0 - GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x); ptD.d2ZdT2(x);
Hinc += GK_weight[i] * ptD.ddZdT / x;
}
ptD.zdetail(ptAGA10.dDf); ptD.dZdT(ptAGA10.dDf); ptD.d2ZdT2(ptAGA10.dDf);
// calculate specific enthalpy
ptAGA10.dH = ptAGA10.dHo + 1000.0 * NG_Cal.RGAS * ptAGA10.dTf *
(ptAGA10.dZf - 1.0 - ptAGA10.dTf * Hinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
return (ptAGA10.dH);
} // H()
/**************************************************************************
*Function:S()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:double
*Purpose:real gas specific entropy
*Revisions:
**************************************************************************/
double S(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
double Sinc; double Smixing; double x;
int i;
//initialize integral
Sinc = 0.0;
//initialize entropy of mixing
Smixing = 0.0;
//integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature
for (i = 0; i < GK_points; i++)
{
//calculate 1st and 2nd partial derivatives of Z wrt T
x = ptAGA10.dDf * (1.0 + GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x); ptD.d2ZdT2(x);
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
if (i == 10) break;
x = ptAGA10.dDf * (1.0 - GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x); ptD.d2ZdT2(x);
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
}
//reset Z and partial deivatives dZdT and d2ZdT2
ptD.zdetail(ptAGA10.dDf);
ptD.dZdT(ptAGA10.dDf);
ptD.d2ZdT2(ptAGA10.dDf);
//find ideal gas entropy, but only if temperature or composition have changed
if (ptAGA10.dTf != dTold || ptAGA10.dMrx != dMrxold)
{
dSi = So(ref ptAGA10); dTold = ptAGA10.dTf; dMrxold = ptAGA10.dMrx;
}
//calculate entropy of mixing
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] != 0) Smixing += ptAGA10.adMixture[i] * Math.Log(ptAGA10.adMixture[i]);
}
Smixing *= NG_Cal.RGAS;
// calculate specific entropy
ptAGA10.dS = dSi - Smixing - 1000.0 * NG_Cal.RGAS * (Math.Log(ptAGA10.dPf / 101325.0) - Math.Log(ptAGA10.dZf) + Sinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
return (ptAGA10.dS);
} // S()
}
}

407
AGA8_10/UnitConvert.cs Normal file
View File

@ -0,0 +1,407 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NG_Tools
{
public class UnitConvert
{
public double Converter(string UnitName, double oldValue, int oldunit, int newunit, int Xsdws)
{
double returnValue = 0;
//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
//Dim strUnit() As String
double[] dataUnit = new double[] { 0 };
//ReDim strUnit(UnitNum)
//RereDim dataUnit(UnitNum)
switch (UnitName)
{
case "tj":
dataUnit = new double[8];
//strUnit(0) = "立方米(m3)"
//strUnit(1) = "升(L, dm3)"
//strUnit(2) = "立方厘米(cm3, ml, c.c)"
//strUnit(3) = "立方英尺(ft3)"
//strUnit(4) = "立方英寸(in3)"
//strUnit(5) = "英加仑(UKgal)"
//strUnit(6) = "美加仑(U.Sgal)"
//strUnit(7) = "美油桶(USbbl)"
dataUnit[0] = 1;
dataUnit[1] = 1000;
dataUnit[2] = 1000000;
dataUnit[3] = 35.3147;
dataUnit[4] = 61023.7;
dataUnit[5] = 219.969;
dataUnit[6] = 264.172;
dataUnit[7] = 6.28994;
break;
case "zl":
//strUnit(0) = "千克(公斤)(kg)"
//strUnit(1) = "克(g)"
//strUnit(2) = "毫克(mg)"
//strUnit(3) = "吨(t)"
//strUnit(4) = "英吨(长吨)(UKton)"
//strUnit(5) = "美吨(短吨)(U.Ston)"
//strUnit(6) = "磅(lb)"
//strUnit(7) = "盎司(oz)"
dataUnit = new double[8]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 1000;
dataUnit[2] = 1000000;
dataUnit[3] = 0.001;
dataUnit[4] = 0.000984207;
dataUnit[5] = 0.00110231;
dataUnit[6] = 2.20462;
dataUnit[7] = 35.274;
break;
case "rl":
//strUnit(0) = "焦耳(J)"
//strUnit(1) = "马力小时(Hp·h)"
//strUnit(2) = "公斤力·米(kgf·m)"
//strUnit(3) = "升·大气压(L·atm)"
//strUnit(4) = "尔格(erg)"
//strUnit(5) = "千卡(kacl)"
//strUnit(6) = "千瓦小时(kW·h)"
//strUnit(7) = "英马力小时(UKHp·h)"
//strUnit(8) = "英尺·磅力(ft·lbf)"
//strUnit(9) = "英热单位(BTU)"
dataUnit = new double[10]; // As Double
dataUnit[0] = 1;
dataUnit[1] = 0.000000377672;
dataUnit[2] = 0.101972;
dataUnit[3] = 0.00986923;
dataUnit[4] = 107;
dataUnit[5] = 0.000238846;
dataUnit[6] = 0.000000277778;
dataUnit[7] = 0.000000372506;
dataUnit[8] = 0.737562;
dataUnit[9] = 0.000947813;
break;
case "nlll":
//strUnit(0) = "兆焦/秒(MJ/s)"
//strUnit(1) = "兆焦/小时(MJ/h)"
//strUnit(2) = "兆焦/天(MJ/d)"
//strUnit(3) = "千卡/秒(kcal/s)"
//strUnit(4) = "千卡/小时(kcal/h)"
//strUnit(5) = "英热单位/秒(BTU/s)"
//strUnit(6) = "英热单位/小时(BTU/h)"
dataUnit = new double[7]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 3600;
dataUnit[2] = 86400;
dataUnit[3] = 238.846;
dataUnit[4] = 859845.6;
dataUnit[5] = 947.813;
dataUnit[6] = 3412126.8;
break;
case "zlll":
//strUnit(0) = "千克(公斤)/秒(kg/s)"
//strUnit(1) = "千克(公斤)/分(kg/Min)"
//strUnit(2) = "千克(公斤)/时(kg/h)"
//strUnit(3) = "磅/秒(lb/s)"
//strUnit(4) = "磅/分(lb/Min)"
//strUnit(5) = "磅/时(lb/h)"
//strUnit(6) = "吨/时(t/h)"
//strUnit(7) = "英吨(长吨)/时(UKton/h)"
//strUnit(8) = "美吨(短吨)/小时(U.Ston/h)"
dataUnit = new double[9]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 60;
dataUnit[2] = 3600;
dataUnit[3] = 2.20462;
dataUnit[4] = 132.2772;
dataUnit[5] = 7936.632;
dataUnit[6] = 3.6;
dataUnit[7] = 3.543145;
dataUnit[8] = 3.968316;
break;
case "tjll":
//strUnit(0) = "立方米/秒(m3/s)"
//strUnit(1) = "万立方米/天(m3/d)"
//strUnit(1) = "立方米/时(m3/h)"
//strUnit(2) = "立方米/分(m3/Min)"
//strUnit(3) = "升/时(L/h)"
//strUnit(4) = "升/分(L/Min)"
//strUnit(5) = "升/秒(L/s)"
//strUnit(6) = "立方英尺/时(ft3/h)"
//strUnit(7) = "立方英尺/分(ft3/Min)"
//strUnit(8) = "立方英尺/秒(ft3/s)"
//strUnit(9) = "立方英尺/秒(ft3/s)"
//strUnit(10) = "立方英尺/天(ft3/d)"
//strUnit(11) = "英加仑/秒(UKgal/s)"
//strUnit(12) = "美加仑/秒(U.Sgal/s)"
//strUnit(13) = "美油桶/秒(USbbl/s)"
dataUnit = new double[13]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 8.64;
dataUnit[2] = 3600;
dataUnit[3] = 60;
dataUnit[4] = 3600000;
dataUnit[5] = 60000;
dataUnit[6] = 1000;
dataUnit[7] = 127132.92;
dataUnit[8] = 2118.882;
dataUnit[9] = 0.0245240972222222;
dataUnit[10] = 35.3147;
dataUnit[11] = 219.969;
dataUnit[12] = 264.172;
break;
case "yl":
//strUnit(0) = "帕(Pa)"
//strUnit(1) = "千帕(kPa)"
//strUnit(2) = "兆帕(Mpa)"
//strUnit(3) = "标准大气压(atm)"
//strUnit(4) = "毫巴(mbar)"
//strUnit(5) = "巴(bar)"
//strUnit(6) = "千克力/平方米(kgf/m2)"
//strUnit(7) = "千克力/平方厘米(kgf/cm2)"
//strUnit(8) = "毫米汞柱(mmHg)"
//strUnit(9) = "毫米水柱4℃(mmH2O)"
//strUnit(10) = "磅/平方英寸(psi)"
dataUnit = new double[11]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 0.001;
dataUnit[2] = 0.000001;
dataUnit[3] = 0.00000986923266716013;
dataUnit[4] = 0.01;
dataUnit[5] = 0.00001;
dataUnit[6] = 0.101971621;
dataUnit[7] = 0.0000101972;
dataUnit[8] = 0.007500638;
dataUnit[9] = 0.101972;
dataUnit[10] = 0.000145038;
break;
case "wd":
switch (newunit)
{
case 0:
switch (oldunit)
{
case 0:
returnValue = oldValue;
break;
case 1: //K->℃
returnValue = oldValue - 273.15;
break;
case 2: //F->℃
returnValue = (oldValue - 32) / 1.8;
break;
case 3: //R->℃
returnValue = oldValue / 1.8 - 273.15;
break;
}
break;
case 1:
switch (oldunit)
{
case 0: //℃->K
returnValue = oldValue + 273.15;
break;
case 1:
returnValue = oldValue;
break;
case 2: //F->K
returnValue = (oldValue - 32) / 1.8 + 273.15;
break;
case 3: //R->K
returnValue = oldValue / 1.8;
break;
}
break;
case 2:
switch (oldunit)
{
case 0: //C->F
returnValue = oldValue * 1.8 + 32;
break;
case 1: //k->f
returnValue = (oldValue - 273.15) * 1.8 + 32;
break;
case 2:
returnValue = oldValue;
break;
case 3: //R->F
returnValue = oldValue - 273.15 * 1.8 + 32;
break;
}
break;
case 3:
switch (oldunit)
{
case 0: //C->R
returnValue = (oldValue + 273.15) * 1.8;
break;
case 1: //K->R
returnValue = oldValue * 1.8;
break;
case 2: //F->R
returnValue = (oldValue - 32) + 273.15 * 1.8;
break;
case 3:
returnValue = oldValue;
break;
}
break;
default:
break;
}
return returnValue;
case "cd":
//米(m)
//分米(dm)
//厘米(cm)
//毫米(mm)
//英尺(ft)
//英寸(in)
//英里(mile)
//英寻(fm)
//海里(nmile)
//埃(a)
//码(yd)
//密尔(mil)
//杆<(rad)
dataUnit = new double[14]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 10;
dataUnit[2] = 100;
dataUnit[3] = 1000;
dataUnit[5] = 3.28038;
dataUnit[4] = 39.3700787401575;
dataUnit[6] = 0.001;
dataUnit[7] = 0.000621504039776259;
dataUnit[8] = 0.546746856205577;
dataUnit[9] = 0.000539956803455;
dataUnit[10] = 10000000000.0D;
dataUnit[11] = 1.093613;
dataUnit[12] = 39370.0787401575;
dataUnit[13] = 0.198838781515947;
break;
case "mj":
//平方米m2
//平方分米dm2
//平方厘米cm2
//平方毫米mm2
//平方英尺ft2
//平方英寸in2
//平方公里km2
//公顷ha
//公亩are
//英亩acre
//平方英里sq -mile
//平方码yd2
dataUnit = new double[12]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 100;
dataUnit[2] = 10000;
dataUnit[3] = 1000000;
dataUnit[4] = 10.7608929444;
dataUnit[5] = 1550.0031;
dataUnit[6] = 0.000001;
dataUnit[7] = 0.0001;
dataUnit[8] = 0.01;
dataUnit[9] = 0.0002471;
dataUnit[10] = 0.000000386102158;
dataUnit[11] = 1.19599;
break;
//小时
//分钟
//天
//秒
case "sj":
dataUnit = new double[4]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 60;
dataUnit[2] = 0.0416666666666667;
dataUnit[3] = 3600;
break;
case "sd":
break;
//米每秒
//厘米每秒
//
}
if (newunit == oldunit)
{
return oldValue;
}
return SsWr(oldValue * dataUnit[newunit] / dataUnit[oldunit], Xsdws);
}
private double SsWr(double value, int weishu)
{
long tempValue = 0;
double SorR = 0;
try
{
tempValue = (long)(value * Math.Pow(10, weishu));
SorR = System.Convert.ToInt32((value * Math.Pow(10, weishu) - tempValue) * 10);
if (SorR >= 5)
{
tempValue++;
}
return tempValue / Math.Pow(10, weishu);
}
catch
{
return value;
}
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,10 @@
e:\ldy\documents\visual studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\AGA8_10.csprojResolveAssemblyReference.cache
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\AGA8_10.csprojResolveAssemblyReference.cache
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\AGA8_10.dll
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\AGA8_10.dll
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\AGA8_10.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\AGA8_10.pdb
E:\My Documents\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Cal.dll
E:\My Documents\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Cal.pdb
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Cal.dll
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Cal.pdb

Binary file not shown.

View File

@ -0,0 +1,13 @@
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Cal.dll
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Cal.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Cal.dll
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Cal.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Cal.csprojResolveAssemblyReference.cache
E:\ldy\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Cal.dll
E:\ldy\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Cal.pdb
E:\ldy\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Cal.dll
E:\ldy\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Cal.pdb
E:\My Documents\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Tools.dll
E:\My Documents\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Tools.pdb
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Tools.dll
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Tools.pdb

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
f7356ac4a88e5f88d3562e5b4a2aa538eab6c652

View File

@ -0,0 +1 @@
aa7b8fa9bf6992e64b927598d7523274d516d83e

View File

@ -0,0 +1,74 @@
E:\My Documents\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Tools.dll
E:\My Documents\Desktop\AGA8_10\AGA8_10\bin\Debug\NG_Tools.pdb
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Tools.dll
E:\My Documents\Desktop\AGA8_10\AGA8_10\obj\Debug\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Tools.dll
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Tools.tlb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Tools.dll
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Tools.pdb
C:\Users\Intouch\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Tools.dll
C:\Users\Intouch\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Tools.pdb
C:\Users\Intouch\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\bin\Debug\NG_Tools.tlb
C:\Users\Intouch\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Tools.dll
C:\Users\Intouch\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\AGA8_10\AGA8_10\obj\Debug\NG_Tools.csprojResolveAssemblyReference.cache
C:\Users\ldeyu\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Debug\NG_Tools.dll
C:\Users\ldeyu\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Debug\NG_Tools.pdb
C:\Users\ldeyu\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Debug\NG_Tools.tlb
C:\Users\ldeyu\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
C:\Users\ldeyu\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Debug\NG_Tools.dll
C:\Users\ldeyu\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Debug\NG_Tools.pdb
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Debug\NG_Tools.dll
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Debug\NG_Tools.pdb
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Debug\NG_Tools.tlb
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Debug\NG_Tools.dll
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Debug\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.dll
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.tlb
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.dll
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.pdb
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.dll
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.pdb
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.tlb
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.dll
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.pdb
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.pdb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\bin\Debug\NG_Tools.tlb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.csproj.CoreCompileInputs.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\NGTools\AGA8_10\obj\Debug\NG_Tools.pdb
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.dll
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.pdb
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.tlb
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.csproj.CoreCompileInputs.cache
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.dll
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.pdb
E:\My Document\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.pdb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.tlb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.csproj.CoreCompileInputs.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC(3)\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.pdb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.pdb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\NGToolsPC\bin\x86\Debug\NG_Tools.tlb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.csproj.CoreCompileInputs.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.pdb
D:\My Documents\Documents\Visual Studio 2019\Projects\NGToolsPC\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\NGToolsPC\bin\x86\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\NGToolsPC\bin\x86\Debug\NG_Tools.pdb
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\NGToolsPC\bin\x86\Debug\NG_Tools.tlb
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\AGA8_10\obj\Debug\NG_Tools.csprojAssemblyReference.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\AGA8_10\obj\Debug\NG_Tools.csproj.CoreCompileInputs.cache
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\AGA8_10\obj\Debug\NG_Tools.dll
D:\My Documents\Documents\Visual Studio 2019\Projects\FlowInstegrationMeter\AGA8_10\obj\Debug\NG_Tools.pdb

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
ac7dff52d59b5a0ed089bc9959ede1638673797d

View File

@ -0,0 +1,15 @@
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Release\NG_Tools.dll
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Release\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Release\NG_Tools.dll
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Release\NG_Tools.pdb
E:\ldy\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Release\NG_Tools.csprojAssemblyReference.cache
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Release\NG_Tools.dll
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\bin\Release\NG_Tools.pdb
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Release\NG_Tools.csprojAssemblyReference.cache
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Release\NG_Tools.dll
D:\MyDocument\Documents\Visual Studio 2019\projects\NGTools\AGA8_10\obj\Release\NG_Tools.pdb
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Release\NG_Tools.dll
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\bin\Release\NG_Tools.pdb
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Release\NG_Tools.csprojAssemblyReference.cache
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Release\NG_Tools.dll
E:\My Documents\Documents\Visual Studio 2013\Projects\NGTools\AGA8_10\obj\Release\NG_Tools.pdb

Binary file not shown.

Binary file not shown.

31
NGToolsPC.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1321
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NGToolsPC", "NGToolsPC\NGToolsPC.csproj", "{7A3AD680-49E7-4498-8565-38F69C2F7413}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Debug|x86.ActiveCfg = Debug|x86
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Debug|x86.Build.0 = Debug|x86
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Release|Any CPU.Build.0 = Release|Any CPU
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Release|x86.ActiveCfg = Release|x86
{7A3AD680-49E7-4498-8565-38F69C2F7413}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EC16CC88-BCFE-478A-B817-46F885B5BC17}
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.

42
NGToolsPC/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,42 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"WARNING01": "*********************************************************************************",
"WARNING02": "The C# extension was unable to automatically decode projects in the current",
"WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
"WARNING04": "been created as a placeholder.",
"WARNING05": "",
"WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
"WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
"WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
"WARNING09": "If this allows OmniSharp to now load your project then --",
"WARNING10": " * Delete this file",
"WARNING11": " * Open the Visual Studio Code command palette (View->Command Palette)",
"WARNING12": " * run the command: '.NET: Generate Assets for Build and Debug'.",
"WARNING13": "",
"WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
"WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
"WARNING16": "button at the bottom of this file.",
"WARNING17": "*********************************************************************************",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

199
NGToolsPC/AboutBox1.Designer.cs generated Normal file
View File

@ -0,0 +1,199 @@
namespace NGToolsPC
{
partial class AboutBox1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutBox1));
this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.logoPictureBox = new System.Windows.Forms.PictureBox();
this.labelProductName = new System.Windows.Forms.Label();
this.labelVersion = new System.Windows.Forms.Label();
this.labelCopyright = new System.Windows.Forms.Label();
this.labelCompanyName = new System.Windows.Forms.Label();
this.textBoxDescription = new System.Windows.Forms.TextBox();
this.okButton = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.tableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel
//
this.tableLayoutPanel.ColumnCount = 2;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67F));
this.tableLayoutPanel.Controls.Add(this.logoPictureBox, 0, 0);
this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0);
this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1);
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
this.tableLayoutPanel.Controls.Add(this.labelCompanyName, 1, 3);
this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 4);
this.tableLayoutPanel.Controls.Add(this.okButton, 1, 5);
this.tableLayoutPanel.Controls.Add(this.textBox1, 1, 6);
this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel.Location = new System.Drawing.Point(9, 8);
this.tableLayoutPanel.Name = "tableLayoutPanel";
this.tableLayoutPanel.RowCount = 7;
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.Size = new System.Drawing.Size(658, 285);
this.tableLayoutPanel.TabIndex = 0;
//
// logoPictureBox
//
this.logoPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.logoPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("logoPictureBox.Image")));
this.logoPictureBox.InitialImage = ((System.Drawing.Image)(resources.GetObject("logoPictureBox.InitialImage")));
this.logoPictureBox.Location = new System.Drawing.Point(3, 3);
this.logoPictureBox.Name = "logoPictureBox";
this.tableLayoutPanel.SetRowSpan(this.logoPictureBox, 7);
this.logoPictureBox.Size = new System.Drawing.Size(211, 279);
this.logoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.logoPictureBox.TabIndex = 12;
this.logoPictureBox.TabStop = false;
//
// labelProductName
//
this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelProductName.Location = new System.Drawing.Point(223, 0);
this.labelProductName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelProductName.MaximumSize = new System.Drawing.Size(0, 16);
this.labelProductName.Name = "labelProductName";
this.labelProductName.Size = new System.Drawing.Size(432, 16);
this.labelProductName.TabIndex = 19;
this.labelProductName.Text = "产品名称";
this.labelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelVersion
//
this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelVersion.Location = new System.Drawing.Point(223, 26);
this.labelVersion.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelVersion.MaximumSize = new System.Drawing.Size(0, 16);
this.labelVersion.Name = "labelVersion";
this.labelVersion.Size = new System.Drawing.Size(432, 16);
this.labelVersion.TabIndex = 0;
this.labelVersion.Text = "版本";
this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCopyright
//
this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCopyright.Location = new System.Drawing.Point(223, 52);
this.labelCopyright.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 16);
this.labelCopyright.Name = "labelCopyright";
this.labelCopyright.Size = new System.Drawing.Size(432, 16);
this.labelCopyright.TabIndex = 21;
this.labelCopyright.Text = "版权";
this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCompanyName
//
this.labelCompanyName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCompanyName.Location = new System.Drawing.Point(223, 78);
this.labelCompanyName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCompanyName.MaximumSize = new System.Drawing.Size(0, 16);
this.labelCompanyName.Name = "labelCompanyName";
this.labelCompanyName.Size = new System.Drawing.Size(432, 16);
this.labelCompanyName.TabIndex = 22;
this.labelCompanyName.Text = "公司名称";
this.labelCompanyName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// textBoxDescription
//
this.textBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxDescription.Location = new System.Drawing.Point(223, 107);
this.textBoxDescription.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
this.textBoxDescription.Multiline = true;
this.textBoxDescription.Name = "textBoxDescription";
this.textBoxDescription.ReadOnly = true;
this.textBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxDescription.Size = new System.Drawing.Size(432, 126);
this.textBoxDescription.TabIndex = 23;
this.textBoxDescription.TabStop = false;
this.textBoxDescription.Text = resources.GetString("textBoxDescription.Text");
//
// okButton
//
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.okButton.Location = new System.Drawing.Point(580, 239);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 20);
this.okButton.TabIndex = 24;
this.okButton.Text = "确定(&O)";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(220, 265);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(435, 21);
this.textBox1.TabIndex = 25;
//
// AboutBox1
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(676, 301);
this.Controls.Add(this.tableLayoutPanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AboutBox1";
this.Padding = new System.Windows.Forms.Padding(9, 8, 9, 8);
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "关于";
this.Load += new System.EventHandler(this.AboutBox1_Load);
this.tableLayoutPanel.ResumeLayout(false);
this.tableLayoutPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
private System.Windows.Forms.PictureBox logoPictureBox;
private System.Windows.Forms.Label labelProductName;
private System.Windows.Forms.Label labelVersion;
private System.Windows.Forms.Label labelCopyright;
private System.Windows.Forms.Label labelCompanyName;
private System.Windows.Forms.TextBox textBoxDescription;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.TextBox textBox1;
}
}

113
NGToolsPC/AboutBox1.cs Normal file
View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace NGToolsPC
{
partial class AboutBox1 : Form
{
public AboutBox1()
{
InitializeComponent();
this.Text = String.Format("关于 {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("版本 {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
//this.textBoxDescription.Text = AssemblyDescription;
}
#region 访
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
private void AboutBox1_Load(object sender, EventArgs e)
{
MachineInfo info = new MachineInfo();
string strCpu = info.GetCPUSerialNumber();
string strDisk = info.GetHardDiskSerialNumber();
this.textBox1.Text ="机器码:"+ strCpu + "@" + strDisk;
}
}
}

4200
NGToolsPC/AboutBox1.resx Normal file

File diff suppressed because it is too large Load Diff

1250
NGToolsPC/Detail.cs Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1826
NGToolsPC/FlowCal.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NGToolsPC
{
class FlowCalGB2624
{
}
}

179
NGToolsPC/GB11062.cs Normal file
View File

@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NG_Tools
{
public class GB11062
{
int iNCC;// number of components
int[] aiCID = new int[21];// component IDs
double[] dXi = new double[21];// mole fraction of component i
Detail ptDetail;
public GB11062()
{
ptDetail = new Detail();
for (int i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) dXi[i] = 0;
}// Detail()
public void Run(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
int i;
// Check for gas composition change
ptAGA10.bForceUpdate = (ptAGA10.bForceUpdate || ptDetail.compositionchange(ref ptAGA10));
// assign component IDs and values
if (ptAGA10.bForceUpdate)
{
iNCC = -1;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] > 0.0)
{
iNCC = iNCC + 1;
aiCID[iNCC] = i;
dXi[iNCC] = ptAGA10.adMixture[i];
}
}
iNCC = iNCC + 1;
//calculate composition dependent quantities; ported from original
//FORTRAN functions paramdl() and chardl()
GasPropsCal(ref ptAGA10);
}
}
void GasPropsCal(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double[] adTableMri = new double[NG_Cal.NUMBEROFCOMPONENTS] { 16.0430, 28.0135, 44.0100, 30.0700, 44.0970, 18.0153, 34.0820, 2.0159, 28.0100, 31.9988, 58.1230, 58.1230, 72.1500, 72.1500, 86.1770, 100.2040, 114.2310, 128.2580, 142.2850, 4.0026, 39.9480 };
double[] adTablePc = new double[NG_Cal.NUMBEROFCOMPONENTS] { 4.604, 3.399, 7.382, 4.88, 4.249, 22.118, 9.005, 1.297, 3.499, 5.081, 3.648, 3.797, 3.381, 3.369, 3.012, 2.736, 2.486, 0, 0, 0.2275, 4.876 };
double[] adTableTc = new double[NG_Cal.NUMBEROFCOMPONENTS] { 190.55, 126.1, 304.19, 305.43, 369.82, 647.3, 373.5, 33.2, 132.92, 154.7, 408.13, 425.16, 460.39, 469.6, 507.4, 540.2, 568.76, 0, 0, 5.2, 150.82 };
double[] adTableBzsx = new double[NG_Cal.NUMBEROFCOMPONENTS] { 15, 0, 0, 13, 9.5, 0, 45.5, 74.2, 74.2, 0, 8.4, 8.4, 8.3, 8.3, 7.7, 7.0, 0, 0, 0, 0, 0 };
double[] adTableBzxx = new double[NG_Cal.NUMBEROFCOMPONENTS] { 5.0, 0, 0, 2.9, 2.1, 0, 4.3, 4.0, 12.5, 0, 1.8, 1.8, 1.4, 1.4, 1.2, 1.0, 0.96, 0, 0, 0, 0 };
double[,] adTableZn = new double[3, NG_Cal.NUMBEROFCOMPONENTS]
{{0.9976,0.9995,0.9933,0.99,0.9789,0.93,0.99,1.0006,0.9993,0.999,0.958,0.9572,0.9377,0.918,0.892,0.83,0.742,0.613,0.434,1.0005,0.999},
{0.998,0.9997,0.9944,0.9915,0.9821,0.945,0.99,1.0006,0.9995,0.9992,0.968,0.965,0.948,0.937,0.913,0.866,0.802,0.71,0.584,1.0005,0.9992},
{0.9981,0.9997,0.9944,0.992,0.9834,0.952,0.99,1.0006,0.9996,0.9993,0.971,0.9682,0.953,0.945,0.919,0.876,0.817,0.735,0.623,1.0005,0.9993}};
double[,] adTableSqrtbj = new double[3, NG_Cal.NUMBEROFCOMPONENTS]
{{0.049,0.0224,0.0819,0.1,0.1453,0.2646,0.1,-0.004,0.0265,0.0316,0.2049,0.2069,0.251,0.2864,0.3286,0.4123,0.5079,0.6221,0.7523,0.0006,0.0316},
{0.0447,0.0173,0.0748,0.0922,0.1338,0.2345,0.1,-0.0048,0.0224,0.0283,0.1789,0.1871,0.228,0.251,0.295,0.3661,0.445,0.5385,0.645,0.0002,0.0283},
{0.0436,0.0173,0.0728,0.0894,0.1288,0.2191,0.1,-0.0051,0.02,0.0265,0.1703,0.1783,0.2168,0.2345,0.2846,0.3521,0.4278,0.5148,0.614,0,0.0265}};
double[,] adTableHhvMol = new double[4, NG_Cal.NUMBEROFCOMPONENTS]
{{892.97,0,0,1564.34,2224.01,45.074,562.94,286.63,282.8,0,2874.2,2883.82,3535.98,3542.89,4203.23,4862.87,5522.4,6182.91,6842.69,0,0},
{891.56,0,0,1562.14,2221.1,44.433,562.38,286.15,282.91,0,2870.58,2879.76,3531.68,3538.6,4198.24,4857.18,5516.01,6175.82,6834.9,0,0},
{891.09,0,0,1561.41,2220.13,44.224,562.19,285.99,282.95,0,2869.38,2878.57,3530.24,3537.17,4196.58,4855.29,5513.88,6173.46,6832.31,0,0},
{890.63,0,0,1560.69,2219.17,44.016,562.01,285.83,282.98,0,2868.2,2877.4,3528.83,3535.77,4194.95,4853.43,5511.8,6171.15,6829.77,0,0}};
double[,] adTableLhvMol = new double[4, NG_Cal.NUMBEROFCOMPONENTS]
{{802.82,0,0,1429.12,2043.71,0,517.87,241.56,282.8,0,2648.83,2658.45,3265.54,3272.45,3887.71,4502.28,5116.73,5732.17,6346.88,0,0},
{802.69,0,0,1428.84,2043.37,0,517.95,241.72,282.91,0,2648.42,2657.6,3265.08,3272,3887.21,4501.72,5116.11,5731.49,6346.14,0,0},
{802.65,0,0,1428.74,2043.23,0,517.97,241.76,282.95,0,2648.26,2657.45,3264.89,3271.83,3887.01,4501.49,5115.87,5731.22,6345.85,0,0},
{802.6,0,0,1428.64,2043.11,0,517.99,241.81,282.98,0,2648.12,2657.32,3264.73,3271.67,3886.84,4501.3,5115.66,5730.99,6345.59,0,0}};
int i;
double dMair = 28.9626;
double dZair = 0;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] != 0)
{
ptAGA10.Pc += adTablePc[i] * ptAGA10.adMixture[i];
ptAGA10.TC += adTableTc[i] * ptAGA10.adMixture[i];
if (adTableBzsx[i] != 0)
{
ptAGA10.Bzsx += ptAGA10.adMixture[i] / adTableBzsx[i];
ptAGA10.Bzxx += ptAGA10.adMixture[i] / adTableBzxx[i];
}
if (i >= 10 & i <= 18)
{
ptAGA10.C4j += ptAGA10.adMixture[i] * adTableMri[i];
}
if (i >= 12 & i <= 18)
{
ptAGA10.C5j += ptAGA10.adMixture[i] * adTableMri[i];
}
if (i >= 14 & i <= 18)
{
ptAGA10.C6j += ptAGA10.adMixture[i] * adTableMri[i];
}
if (i == 3)
{
ptAGA10.C2 += ptAGA10.adMixture[i] * adTableMri[i];
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dZb11062 += adTableSqrtbj[0, i] * ptAGA10.adMixture[i];
dZair = 0.99941;
break;
case 1:
ptAGA10.dZb11062 += adTableSqrtbj[1, i] * ptAGA10.adMixture[i];
dZair = 0.99958;
break;
case 0:
ptAGA10.dZb11062 += adTableSqrtbj[2, i] * ptAGA10.adMixture[i];
dZair = 0.99963;
break;
}
switch (ptAGA10.dCbtj_E)
{
case 0:
ptAGA10.dHhvMol += adTableHhvMol[0, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[0, i] * ptAGA10.adMixture[i];
break;
case 1:
ptAGA10.dHhvMol += adTableHhvMol[1, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[1, i] * ptAGA10.adMixture[i];
break;
case 2:
ptAGA10.dHhvMol += adTableHhvMol[2, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[2, i] * ptAGA10.adMixture[i];
break;
case 3:
ptAGA10.dHhvMol += adTableHhvMol[3, i] * ptAGA10.adMixture[i];
ptAGA10.dLhvMol += adTableLhvMol[3, i] * ptAGA10.adMixture[i];
break;
}
}
}
ptAGA10.Bzsx = ptAGA10.Bzsx == 0 ? 0 : 1 / ptAGA10.Bzsx;
ptAGA10.Bzxx = ptAGA10.Bzxx == 0 ? 0 : 1 / ptAGA10.Bzxx;
ptAGA10.dZb11062 = 1 - ptAGA10.dZb11062 * ptAGA10.dZb11062;
ptAGA10.dHhvm = ptAGA10.dHhvMol / ptAGA10.dMrx;
ptAGA10.dLhvm = ptAGA10.dLhvMol / ptAGA10.dMrx;
ptAGA10.dHhvv = ptAGA10.dHhvMol * ptAGA10.dPb / ptAGA10.dTb / 8314.510 / ptAGA10.dZb11062;
ptAGA10.dLhvv = ptAGA10.dLhvMol * ptAGA10.dPb / ptAGA10.dTb / 8314.510 / ptAGA10.dZb11062;
ptAGA10.dRD_Ideal11062 = ptAGA10.dMrx / dMair;
ptAGA10.dRD_Real11062 = ptAGA10.dRD_Ideal11062 * dZair / ptAGA10.dZb11062;
ptAGA10.dRhob11062 = ptAGA10.dMrx * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.dRhof11062 = ptAGA10.dMrx * ptAGA10.dPf / 8314.51 / ptAGA10.dTf / ptAGA10.dZf;
ptAGA10.dWobbeIndex = ptAGA10.dHhvv / Math.Sqrt(ptAGA10.dRD_Real11062);
ptAGA10.C3j = ptAGA10.C4j + ptAGA10.adMixture[4] * adTableMri[4];
ptAGA10.C2j = ptAGA10.C3j + ptAGA10.adMixture[3] * adTableMri[3];
ptAGA10.C3C4 = ptAGA10.adMixture[4] * adTableMri[4] + ptAGA10.adMixture[10] * adTableMri[10] + ptAGA10.adMixture[11] * adTableMri[11];
ptAGA10.TotalC = ptAGA10.C2j + ptAGA10.adMixture[0] * adTableMri[0];
ptAGA10.TotalC = ptAGA10.TotalC * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C2 = ptAGA10.C2 * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C3C4 = ptAGA10.C3C4 * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C2j = ptAGA10.C2j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C3j = ptAGA10.C3j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C4j = ptAGA10.C4j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C5j = ptAGA10.C5j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
ptAGA10.C6j = ptAGA10.C6j * ptAGA10.dPb / 8314.51 / ptAGA10.dTb / ptAGA10.dZb11062;
}
}
}

242
NGToolsPC/NGToolsPC.csproj Normal file
View File

@ -0,0 +1,242 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7A3AD680-49E7-4498-8565-38F69C2F7413}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>NGToolsPC</RootNamespace>
<AssemblyName>NGToolsPC</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<StartupObject>
</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="AxInterop.DSOFramer, Version=2.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\x86\Debug\AxInterop.DSOFramer.dll</HintPath>
</Reference>
<Reference Include="hasp_net_windows, Version=7.9.22426.60000, Culture=neutral, PublicKeyToken=56120be447701319, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Gemalto\Sentinel LDK 7.10\API\Runtime\DotNet\hasp_net_windows.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="NG_OCX, Version=1.0.4263.31079, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\x86\Debug\NG_OCX.dll</HintPath>
</Reference>
<Reference Include="NPOI, Version=2.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\x86\Debug\NPOI.dll</HintPath>
</Reference>
<Reference Include="NPOI.OOXML, Version=2.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\x86\Debug\NPOI.OOXML.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXml4Net, Version=2.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\x86\Debug\NPOI.OpenXml4Net.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXmlFormats, Version=2.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\x86\Debug\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AboutBox1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AboutBox1.Designer.cs">
<DependentUpon>AboutBox1.cs</DependentUpon>
</Compile>
<Compile Include="Detail.cs" />
<Compile Include="FlowCal.cs" />
<Compile Include="frmAddJld.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmAddJld.Designer.cs">
<DependentUpon>frmAddJld.cs</DependentUpon>
</Compile>
<Compile Include="frmInputNGCom.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmInputNGCom.Designer.cs">
<DependentUpon>frmInputNGCom.cs</DependentUpon>
</Compile>
<Compile Include="frmJdygl.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmJdygl.Designer.cs">
<DependentUpon>frmJdygl.cs</DependentUpon>
</Compile>
<Compile Include="frmLogin.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmLogin.Designer.cs">
<DependentUpon>frmLogin.cs</DependentUpon>
</Compile>
<Compile Include="frmNgTools.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmNgTools.Designer.cs">
<DependentUpon>frmNgTools.cs</DependentUpon>
</Compile>
<Compile Include="frmPrint.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmPrint.Designer.cs">
<DependentUpon>frmPrint.cs</DependentUpon>
</Compile>
<Compile Include="frmZjcs.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmZjcs.Designer.cs">
<DependentUpon>frmZjcs.cs</DependentUpon>
</Compile>
<Compile Include="GB11062.cs" />
<Compile Include="mldPublic.cs" />
<Compile Include="NG_Cal.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Therm.cs" />
<Compile Include="UnitConvert.cs" />
<EmbeddedResource Include="AboutBox1.resx">
<DependentUpon>AboutBox1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmAddJld.resx">
<DependentUpon>frmAddJld.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmInputNGCom.resx">
<DependentUpon>frmInputNGCom.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmJdygl.resx">
<DependentUpon>frmJdygl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmLogin.resx">
<DependentUpon>frmLogin.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmNgTools.resx">
<DependentUpon>frmNgTools.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmPrint.resx">
<DependentUpon>frmPrint.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmZjcs.resx">
<DependentUpon>frmZjcs.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<COMReference Include="ADODB">
<Guid>{2A75196C-D9EB-4129-B803-931327F72D5C}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>8</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="AxDSOFramer">
<Guid>{00460180-9E5E-11D5-B7C8-B8269041DD57}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
<COMReference Include="DSOFramer">
<Guid>{00460180-9E5E-11D5-B7C8-B8269041DD57}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="stdole">
<Guid>{00020430-0000-0000-C000-000000000046}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>zh-CN</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

530
NGToolsPC/NG_Cal.cs Normal file
View File

@ -0,0 +1,530 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace NG_Tools
{
public class NG_Cal
{
public const int NORMAL = 9000;
public const int NG_Cal_INITIALIZED = 9001;
public const int MEMORY_ALLOCATION_ERROR = 9002;
public const int GENERAL_CALCULATION_FAILURE = 9003;
public const int MAX_NUM_OF_ITERATIONS_EXCEEDED = 9004;
public const int NEGATIVE_DENSITY_DERIVATIVE = 9005;
public const int MAX_DENSITY_IN_BRAKET_EXCEEDED = 9006;
/* number of components */
public const int NUMBEROFCOMPONENTS = 21;
/* maximum number of tries within search routines */
public const int MAX_NUM_OF_ITERATIONS = 100;
/* default tolerance limits */
public const double P_CHG_TOL = 0.001; /* 0.001 Pa */
public const double T_CHG_TOL = 0.001; /* 0.001 of a Kelvin */
/* maximum allowable P & T */
public const double P_MAX = 1.379e8; // maximum pressure (Pa) ~= 20,000 psi
public const double P_MIN = 0.0; // maximum pressure = 0
public const double T_MAX = 473.15; // maximum temperature (K) ~= 392 F
public const double T_MIN = 143.0; // maximum temperature (K) ~= -200 F
/* universal gas constant, in two configurations */
public const double RGASKJ = 8.314510e-3; /* in kJ mol^-1 K^-1 */
public const double RGAS = 8.314510; /* in J mol^-1 K^-1 */
/* the main data structure used by this library */
public struct GasPropsSTRUCT
{ /* corresponds to the control group in meter classes */
public int lStatus; /* calculation status 计算状态 */
public bool bForceUpdate; /*执行全部计算的标志 signal to perform full calculation */
public double[] adMixture; /*气体摩尔组成 Composition in mole fraction */
public double[] adMixtureV; /*气体体积组成 Composition in mole fraction */
public double[] adMixtureD; /*气体质量组成 Composition in mole fraction */
public int dCbtj; //参比条件 101325 0,15,20
public int dCbtj_E; //燃烧参比条件 101325 0,15,20
public double dPb; /*参比压力 Contract base Pressure (Pa) */
public double dTb; /* 参比温度Contract base temperature (K) */
public double dPf; /*绝对压力 Absolute Pressure (Pa) */
public double dTf; /*工况温度 Flowing temperature (K) */
// basic output from AGA 8 Detail method
public double dMrx; /*分子量 mixture molar mass */
public double dZb; /* 标况压缩因子compressibility at contract base condition */
public double dZf; /* 工况压缩因子compressibility at flowing condition */
public double dFpv; /*超压缩系数 supercompressibility */
public double dDb; /* 标况摩尔密度molar density at contract base conditions (moles/dm3) */
public double dDf; /*工况摩尔密度 molar density at flowing conditions (moles/dm3) */
public double dRhob; /* 标况质量密度mass density at contract base conditions (kg/m3) */
public double dRhof; /*工况质量密度 mass density at flowing conditions (kg/m3) */
public double dRD_Ideal; /* 理想气体的相对密度ideal gas relative density */
public double dRD_Real; /* 真实气体的相对密度real gas relative density */
// additional output
public double dHo; /*理想气体的比焓 ideal gas specific enthalpy */
public double dH; /*真实气体的焓 real gas specific enthalpy (J/kg) */
public double dS; /* 真实气体的熵real gas specific entropy (J/kg-mol.K)*/
public double dCpi; /*理想气体定压热容 ideal gas constant pressure heat capacity (J/kg-mol.K)*/
public double dCp; /* 定压热容real gas constant pressure heat capacity (J/kg-mol.K)*/
public double dCv; /*定容积热容 real gas constant volume heat capacity (J/kg-mol.K)*/
public double dk; /* 比热比ratio of specific heats */
public double dKappa; /*等熵指数 isentropic exponent, denoted with Greek letter kappa */
public double dSOS; /* 声速speed of sound (m/s) */
public double dCstar; /*临界流函数 critical flow factor C* */
// 11062 输出
public double dHhvMol; //摩尔高位发热量
public double dLhvMol; //摩尔低位发热量
public double dHhvv; //体积高位发热量
public double dLhvv; //体积低位发热量
public double dHhvm; //质量高位发热量
public double dLhvm; //质量地位发热量
public double dZb11062; //标况压缩因子
public double dRhob11062; /* 标况质量密度mass density at contract base conditions (kg/m3) */
public double dRhof11062; /*工况质量密度 mass density at flowing conditions (kg/m3) */
public double dRD_Ideal11062; /* 理想气体的相对密度ideal gas relative density */
public double dRD_Real11062; /* 真实气体的相对密度real gas relative density */
public double dWobbeIndex; /* 真实气体的沃泊指数 */
public double Pc; // '临界压力
public double TC; /// '临界温度
public double Bzsx; // '爆炸上限
public double Bzxx; // '爆炸下限
public double TotalC; // '总炭含量 (kg/m3)
public double C2; // 'C2组分含量 (kg/m3)
public double C2j; // 'C2以上组分含量 (kg/m3)
public double C3j; // 'C3以上组分含量 (kg/m3)
public double C4j; // 'C4以上组分含量 (kg/m3)
public double C5j; // 'C5以上组分含量 (kg/m3)
public double C6j; // 'C6以上组分含量 (kg/m3)
public double C3C4; // 'C3C4组分含量 (kg/m3)
}
public struct FlowParStruct //流量相关参数
{
//流量计算输入参数信息
public int dFlowCalbz; //流量计算标准
public int dZcalbz; //压缩因子计算标准
public int dCbtj; //计量参比条件压力
public double dPb_M; //计量参比条件压力
public double dTb_M; //计量参比条件温度
public double dPb_E; //燃烧参比条件压力
public double dTb_E; //燃烧参比条件温度
public double dPatm;//当地大气压
public int dPatmUnit;//当地大气压单位
public double[] dNG_Compents;//天然气组分
public int dMeterType;// 流量计类别
public int dCoreType;//节流装置类型
public int dPtmode; //取压方式
public int dPipeType; // 管道类型
public double dPipeD; //管道内径
public int dLenUnit; //长度单位
public double dPipeDtemp; //管道内径参考温度
public int dPileDtempUint; //温度单位
public int dPipeMaterial; //管道材料
public double dOrificeD; //孔板孔径
public int dOrificeUnit; //长度单位
public double dOrificeDtemp; //孔板内径参考温度
public int dOrificeDtempUnit; //温度单位
public int dOrificeMaterial; //孔板材料
public int dOrificeSharpness; //锐利度系数计算方法
public double dOrificeRk; //孔板入口圆弧半径
public int dOrificeRkLenUint;//长度单位
public double dPf;//输入压力
public int dPfUnit;//压力单位
public int dPfType; //压力类型
public double dTf; //输入温度
public int dTfUnit;//温度单位
public double dDp; //输入差压
public int dDpUnit; //压力单位
public int dVFlowUnit; //体积流量单位
public int dMFlowUnit; //'NG_Par(33) = ComboBox15.SelectedIndex '质量流量单位
public int dEFlowUnit; //'NG_Par(34) = ComboBox16.SelectedIndex '能量流量单位
public double dCd;//流出系数
public double dCdCalMethod;//流出系数计算方法 0 检定证书 0回归公式
public double dMeterFactor;//仪表系数
public double dPulseNum;//脉冲数
public double dVFlowMax; //'NG_par(39)=’最大体积流量
public double dVFlowMin; //'NG_par(40)=’最小体积流量
public double dVFlowCon;//'NG_par(41)=’常用流量
public double dPfRangeMin; //'NG_par(42)=’压力量程
public double dPfRangeMax; //'NG_par(42)=’压力量程
public double dDpRangeMin; //'NG_par(43)=’差压量程
public double dDpRangeMax; //'NG_par(43)=’差压量程
public double dTfRangeMin; //'NG_par(44)=’温度计量程
public double dTfRangeMax; //'NG_par(44)=’温度计量程
//流量计算输出参数
public double dE; //'求渐近速度系数 E
public double dFG; //'求相对密度系数 FG
public double dFT; //'求流动温度系数 'FT
public double dDViscosity; //'求动力粘度 dlnd
public double dDExpCoefficient; //'求可膨胀系数
public double dRnPipe; //'管道雷诺数
public double dBk; //'孔板锐利度系数Bk
public double dRoughNessPipe; //'管道粗糙度系数 Gme
public double dCdCorrect; //'修正后的流出系数
public double dCdNozell; //'喷嘴的流出系数
public double dVFlowb;//'标况体积流量 m³、s
public double dVFlowf; //'工况体积流量
public double dMFlowb;//'标况质量流量
public double dEFlowb;//'标况能量流量
public double dVelocityFlow;//'管道内天然气流速
public double dPressLost;//'压力损失
public double dBeta;//'直径比
public double dKappa;//'等熵指数
}
//public struct SqgyParStruct //输气工艺相关参数
//{
// public int dCalName; //计算项目
// public int dPipleD; //管道内径mm
// public int dPipleDw; //管道内径外径mm
// public int dPipleBh; //管道壁厚 mm
// public double dPipleTotalLength; //管道总长度 km
// public double dPiplePointLength; //管道任意点长度 km
// public double dPstart; //起点压力终点压力MPa
// public double dPend; //终点压力MPa
// public double dFlow; //输气能力
// public double dRd;//相对密度
// public double dZf;//压缩因子
// public double[] dNG_Compents;//天然气组分
// public double dPavg;//管道平均压力
// public double dPavgPoint;//管道任意点的平均压力
//}
/* enumerations for tracking gas components */
enum gascomp
{
XiC1 = 0, XiN2, XiCO2, XiC2, XiC3,
XiH2O, XiH2S, XiH2, XiCO, XiO2, XiIC4, XiNC4,
XiIC5, XiNC5, XiNC6, XiNC7, XiNC8, XiNC9, XiNC10, XiHe, XiAr
};
/* FUNCTION PROTOTYPES */
/* prototypes for initialization */
// int NG_Cal_Init(void) ; /* initialize library */
// int NG_Cal_UnInit(void) ; /* un-initialize library */
///* function prototype for basic VOS calculation */
// double SOS(ref AGA10.GasPropsSTRUCT ) ;
///* function prototype for a C* calculation */
// double Crit(ref AGA10.GasPropsSTRUCT , double) ;
public Therm ptTherm;
public Detail ptDetail;
/**************************************************************************
* Function : NG_Cal_Init()
* Arguments : void
* Returns : int
* Purpose : Initializes library; creates required objects
* Revisions :
**************************************************************************/
public int NG_Cal_Init()
{
//create object for calculating density
if (null == (ptDetail = new Detail()))
{
return MEMORY_ALLOCATION_ERROR;
}
//create object for calculating thermodynamic properties
if (null == (ptTherm = new Therm()))
{
return MEMORY_ALLOCATION_ERROR;
}
return NG_Cal_INITIALIZED;
}// NG_Cal_Init
/**************************************************************************
* Function : NG_Cal_UnInit()
* Arguments : void
* Returns : int
* Purpose : Un-initializes library; deletes objects
* Revisions :
**************************************************************************/
public int NG_Cal_UnInit()
{
// delete the objects (if they exist)
ptDetail = null;
ptTherm = null;
return 0;
}// NG_Cal_UnInit
/**************************************************************************
* Function : SOS()
* Arguments : Pointers to external AGA10 data struct
* Returns : double
* Purpose : calculates speed of sound and other parameters
* Revisions :
**************************************************************************/
public double SOS(ref GasPropsSTRUCT ptAGA10)
{
// check if library is ready; initialize if necessary
if (null == ptDetail || null == ptTherm)
{
NG_Cal_UnInit();
NG_Cal_Init();
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 273.15;
break;
case 1:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 288.15;
break;
case 0:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 293.15;
break;
}
//Call function to calculate densities and thermodynamic properties
ptTherm.Run(ref ptAGA10, ref ptDetail);
//the basic sound speed calculation doesn't calculate C*; initialize to zero
ptAGA10.dCstar = 0.0;
//return the speed of sound to caller
return ptAGA10.dSOS;
}// VOS()
/**************************************************************************
* Function : Crit()
* Arguments : Pointers to external AGA10 data struct, Detail and Therm
* objects and a double precision float (gas velocity in plenum)
* Returns : double
* Purpose : calculates C*
* Revisions :
**************************************************************************/
public double Crit(ref NG_Cal.GasPropsSTRUCT ptAGA10, double dPlenumVelocity)
{
//variables local to function
double DH, DDH, S, H;
double tolerance = 1.0;
double R, P, T, Z;
int i;
//check objects for readiness; try to initialize if not
if (null == ptDetail || null == ptTherm)
{
NG_Cal_UnInit();
if (NG_Cal_INITIALIZED != NG_Cal_Init())
{
ptAGA10.lStatus = MEMORY_ALLOCATION_ERROR; return 0.0;
}
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 273.15;
break;
case 1:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 288.15;
break;
case 0:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 293.15;
break;
}
//begin by calculating densities and thermodynamic properties
ptTherm.Run(ref ptAGA10, ref ptDetail);
//DH is enthalpy change from plenum to throat; this is our initial guess
DH = (ptAGA10.dSOS * ptAGA10.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0;
//trap plenum conditions before we alter the data stucture's contents
S = ptAGA10.dS;
H = ptAGA10.dH;
R = ptAGA10.dRhof;
P = ptAGA10.dPf;
Z = ptAGA10.dZf;
T = ptAGA10.dTf;
//initialize delta of DH to an arbitrary value outside of
//convergence tolerance
DDH = 10.0;
//Via simple repetition, search for a pressure, temperature and sound speed
//at a nozzle throat which provide constant enthalpy, given the entropy known
//at the plenum. Abort if loop executes more than 100 times without convergence.
for (i = 1; i < MAX_NUM_OF_ITERATIONS; i++)
{
// calculate P and T to satisfy H and S
ptTherm.HS_Mode(ref ptAGA10, ref ptDetail, H - DH, S, true);
//calculate new thermo, including SOS
ptTherm.Run(ref ptAGA10, ref ptDetail);
//hold DH for tolerance check
DDH = DH;
// recalculate DH
DH = (ptAGA10.dSOS * ptAGA10.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0;
// end loop if tolerance reached
if (Math.Abs(DDH - DH) < tolerance) break;
}
//C* is the real gas critical flow constant (not to be confused with Cperf or CRi)
ptAGA10.dCstar = (ptAGA10.dRhof * ptAGA10.dSOS) / Math.Sqrt(R * P * Z);
//put the original plenum pressure and temperature back
ptAGA10.dPf = P;
ptAGA10.dTf = T;
//restore fluid props to plenum conditions
ptTherm.Run(ref ptAGA10, ref ptDetail);
GB11062 ptGB11062 = new GB11062();
ptGB11062.Run(ref ptAGA10);
//return the critical flow function to caller
return ptAGA10.dCstar;
}// Crit()
/**************************************************************************
* Function : Crit()
* Arguments : Pointers to external AGA10 data struct, Detail and Therm
* objects and a double precision float (gas velocity in plenum)
* Returns : double
* Purpose : calculates C*
* Revisions :
**************************************************************************/
public double Zcal(ref NG_Cal.GasPropsSTRUCT ptAGA10, double dPlenumVelocity)
{
//variables local to function
//check objects for readiness; try to initialize if not
if (null == ptDetail || null == ptTherm)
{
NG_Cal_UnInit();
if (NG_Cal_INITIALIZED != NG_Cal_Init())
{
ptAGA10.lStatus = MEMORY_ALLOCATION_ERROR; return 0.0;
}
}
switch (ptAGA10.dCbtj)
{
case 2:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 273.15;
break;
case 1:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 288.15;
break;
case 0:
ptAGA10.dPb = 101325;
ptAGA10.dTb = 293.15;
break;
}
//begin by calculating densities and thermodynamic properties
ptTherm.Run(ref ptAGA10, ref ptDetail);
GB11062 ptGB11062 = new GB11062();
ptGB11062.Run(ref ptAGA10);
//return the critical flow function to caller
return ptAGA10.dZf;
}// Z()
/**************************************************************************
* Function : Cperf()
* Arguments : pointer to external AGA10 data struct
* Returns : double
* Purpose : calculates isentropic perfect gas critical flow function
* Revisions :
**************************************************************************/
double Cperf(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double k, root, exponent;
k = ptAGA10.dKappa; root = 2.0 / (k + 1.0);
exponent = (k + 1.0) / (k - 1.0);
// isentropic perfect gas critical flow function C*i
return (Math.Sqrt(k * Math.Pow(root, exponent)));
}// Cperf
/**************************************************************************
* Function : CRi()
* Arguments : pointer to external AGA10 data struct
* Returns : double
* Purpose : calculates isentropic real gas critical flow function CRi
* Revisions :
**************************************************************************/
double CRi(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
return (Cperf(ref ptAGA10) / Math.Sqrt(ptAGA10.dZf));
}// CRi()
}
}

39
NGToolsPC/Program.cs Normal file
View File

@ -0,0 +1,39 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace NGToolsPC
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool createdNew;//返回是否赋予了使用线程的互斥体初始所属权
System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量
if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体
{
Application.Run(new frmNgTools());
instance.ReleaseMutex();
}
else
{
MessageBox.Show("已经有一个程序已经在运行,请不要同时运行多个程序!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("流量积算仪检定系统(天然气)")]
[assembly: AssemblyDescription("说明为用户提供天然气相关参数计算。计算标准采用GB/T11062 GB/T17747和GB/T 21446等标准算法计算孔板流量及天然气的物性参数。")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("流量积算仪检定系统(天然气)")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("7a3ad680-49e7-4498-8565-38f69c2f7413")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace NGToolsPC.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NGToolsPC.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,36 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace NGToolsPC.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\NGDATA.mdb")]
public string NGDATAConnectionString {
get {
return ((string)(this["NGDATAConnectionString"]));
}
}
}
}

View File

@ -0,0 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="NGToolsPC.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="NGDATAConnectionString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\NGDATA.mdb&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.OleDb&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\NGDATA.mdb</Value>
</Setting>
</Settings>
</SettingsFile>

534
NGToolsPC/Therm.cs Normal file
View File

@ -0,0 +1,534 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NG_Tools
{
public class Therm
{
// member data
//double dT;// current temperature, in Kelvins
//double dP;// current pressure, in Pascals
//double dD;// molar density, in moles/dm3
//double dRho;// mass density, in kg/m3
double dPdD;// partial deriv of P wrt D
double dPdT;// partial deriv of P wrt T
double dSi;// ideal gas specific entropy, kJ/kg.K
double dTold;// temperature previously used
double dMrxold;// mixture molar mass previously used
double[] GK_root = new double[5] { 0.14887433898163121088, 0.43339539412924719080, 0.67940956829902440263, 0.86506336668898451073, 0.97390652851717172008 };
double[] GK_weight = new double[5] { 0.29552422471475286217, 0.26926671930999634918, 0.21908636251598204295, 0.14945134915058059038, 0.066671344308688137179 };
//set the number of points for quadrature
int GK_points = 5;
//equation constants for ideal gas heat capacity, enthalpy and entropy
double[,] ThermConstants = new double[21, 11] {{-29776.4, 7.95454, 43.9417, 1037.09, 1.56373, 813.205, -24.9027, 1019.98,-10.1601, 1070.14,-20.0615},
{-3495.34, 6.95587, 0.272892, 662.738,-0.291318,-680.562, 1.78980, 1740.06, 0.0, 100.0, 4.49823},
{ 20.7307, 6.96237, 2.68645, 500.371,-2.56429,-530.443, 3.91921, 500.198, 2.13290, 2197.22, 5.81381},
{-37524.4, 7.98139, 24.3668, 752.320, 3.53990, 272.846, 8.44724, 1020.13,-13.2732, 869.510,-22.4010},
{-56072.1, 8.14319,37.0629,735.402,9.38159,247.190,13.4556, 1454.78,-11.7342, 984.518,-24.0426},
{-13773.1, 7.97183, 6.27078,2572.63,2.05010,1156.72,0.0,100.0,0.0,100.0,-3.24989},
{-10085.4, 7.94680,-0.08380,433.801,2.85539, 843.792,6.31595, 1481.43,-2.88457, 1102.23,-0.51551},
{-5565.60, 6.66789, 2.33458,2584.98,.749019, 559.656,0.0,100.0,0.0,100.0,-7.94821},
{-2753.49, 6.95854, 2.02441,1541.22,.096774, 3674.81,0.0,100.0,0.0,100.0,6.23387},
{-3497.45, 6.96302, 2.40013, 2522.05, 2.21752, 1154.15, 0.0,100.0,0.0,100.0,9.19749},
{-72387.0, 17.8143, 58.2062, 1787.39, 40.7621, 808.645, 0.0,100.0,0.0,100.0,-44.1341},
{-72674.8, 18.6383, 57.4178, 1792.73, 38.6599, 814.151, 0.0,100.0,0.0,100.0,-46.1938},
{-91505.5, 21.3861, 74.3410, 1701.58, 47.0587, 775.899, 0.0,100.0,0.0,100.0,-60.2474},
{-83845.2, 22.5012, 69.5789, 1719.58, 46.2164, 802.174, 0.0,100.0,0.0,100.0,-62.2197},
{-94982.5, 26.6225, 80.3819, 1718.49, 55.6598, 802.069, 0.0,100.0,0.0,100.0,-77.5366},
{-103353.0, 30.4029, 90.6941, 1669.32, 63.2028, 786.001, 0.0,100.0,0.0,100.0,-92.0164},
{-109674.0, 34.0847, 100.253, 1611.55, 69.7675, 768.847, 0.0,100.0,0.0,100.0,-106.149},
{-122599.0, 38.5014, 111.446, 1646.48, 80.5015, 781.588, 0.0,100.0,0.0,100.0,-122.444},
{-133564.0, 42.7143, 122.173, 1654.85, 90.2255, 785.564, 0.0,100.0,0.0,100.0,-138.006},
{0.0,4.9680,0.0,100.0,0.0,100.0,0.0,100.0,0.0,100.0,0.0},
{0.0,4.9680,0.0,100.0,0.0,100.0,0.0,100.0,0.0,100.0,0.0}};
// enumerations for indexing of coefficients
//public enum CoefficientList { coefA = 0, coefB, coefC, coefD, coefE, coefF, coefG, coefH, coefI, coefJ, coefK } ;
public int coefA = 0;
public int coefB = 1;
public int coefC = 2;
public int coefD = 3;
public int coefE = 4;
public int coefF = 5;
public int coefG = 6;
public int coefH = 7;
public int coefI = 8;
public int coefJ = 9;
public int coefK = 10;
// conversion constant for thermochemical calories to Joules: 1 cal(IT) = 4.1840 J
const double CalTH = 4.1840;
public Therm()
{
// initialize 3 history-sensitive variables
dSi = 0.0;
dTold = 0.0;
dMrxold = 0.0;
}//Therm()
/**************************************************************************
*Function:Math.Coth()
*Arguments:double
*Returns:double
*Purpose:calculate hyperbolic cotangent; used in Ho calculations
*Revisions:
*Notes:Not a Therm object class member, just a utility for this
*file. The C++ language has no intrinsic support for
*hyperbolic cotangent
**************************************************************************/
double coth(double x)
{
return Math.Cosh(x) / Math.Sinh(x);
}// Math.Coth()
/**************************************************************************
*Function:Run()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:void
*Purpose:overall execution control; top level math for SOS and k
*Revisions:
**************************************************************************/
public void Run(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
//local variables
double c, x, y, z;
//first run basic set of functions within AGA 8 (1994) Detail Method
ptD.Run(ref ptAGA10);
//find first partial derivative of Z wrt D
ptD.dZdD(ptAGA10.dDf);
//find real gas cv, cp, specific enthalpy and entropy
CprCvrHS(ref ptAGA10, ref ptD);
//ratio of real gas specific heats
ptAGA10.dk = ptAGA10.dCp / ptAGA10.dCv;
//solve c in three steps, for clarity and ease of debugging
x = ptAGA10.dk * NG_Cal.RGAS * 1000.0 * ptAGA10.dTf;
y = ptAGA10.dMrx;
z = ptAGA10.dZf + ptAGA10.dDf * ptD.ddZdD;
//calculate c, which is SOS^2
c = (x / y) * z;
//speed of sound
ptAGA10.dSOS = Math.Sqrt(c);
//calculate the real gas isentropic exponent
//using expression functionally equivalent to Equation 3.2
ptAGA10.dKappa = (c * ptAGA10.dRhof) / ptAGA10.dPf;
return;
}//Run()
/**************************************************************************
*Function:CpiMolar()
*Arguments:ref AGA10.GasPropsSTRUCT
*Returns:double
*Purpose:Calculate constant pressure ideal gas molar heat capacity
*in (J/mol-K), applying eqns from Aly, Lee, McFall
*Notes:For continuity, the original constants and eqn's have been
*retained. Conversion from thermochemical calories(th) to
*Joules is applied after the primary calculations are complete.
*Revisions:
**************************************************************************/
double CpiMolar(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double Cp = 0.0;
double Cpx;
double DT, FT, HT, JT;
double Dx, Fx, Hx, Jx;
double T;
int i;
//to maximize readability of this section, use intermediate variable T
T = ptAGA10.dTf;
//calculate heat capacity for each component
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
//skip species whose concentration is zero
if (ptAGA10.adMixture[i] <= 0.0) continue;
//initialize Cp of species to zero
Cpx = 0.0;
// calculate species intermediate terms
DT = ThermConstants[i, coefD] / T;
FT = ThermConstants[i, coefF] / T;
HT = ThermConstants[i, coefH] / T;
JT = ThermConstants[i, coefJ] / T;
// use intermediate terms to avoid redundant calcs
Dx = DT / Math.Sinh(DT);
Fx = FT / Math.Cosh(FT);
Hx = HT / Math.Sinh(HT);
Jx = JT / Math.Cosh(JT);
Cpx += ThermConstants[i, coefB];
Cpx += ThermConstants[i, coefC] * Dx * Dx;
Cpx += ThermConstants[i, coefE] * Fx * Fx;
Cpx += ThermConstants[i, coefG] * Hx * Hx;
Cpx += ThermConstants[i, coefI] * Jx * Jx;
//use current mole fraction to weight the contribution
Cpx *= ptAGA10.adMixture[i];
//add this contribution to the sum
Cp += Cpx;
}
// convert from cal(th)/mol-K to J/mol-K
Cp *= CalTH;
return Cp;
}//CpiMolar()
/**************************************************************************
*Function:Ho()
*Arguments:ref AGA10.GasPropsSTRUCT
*Returns:double
*Purpose:Calculate ideal gas specific enthalpy (J/kg)
*Notes:For continuity, the original constants and eqn's have been
*retained. Conversion from thermochemical calories(th) to
*Joules is applied after the primary calculations are complete.
*Revisions:
**************************************************************************/
double Ho(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double H = 0.0; double Hx;
double DT, FT, HT, JT;
double cothDT, tanhFT, cothHT, tanhJT; double T;
int i;
// to maximize readability of this section, use intermediate variable T
T = ptAGA10.dTf;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
// skip species whose concentration is zero
if (ptAGA10.adMixture[i] <= 0.0) continue;
Hx = 0.0;
// calculate species intermediate terms
DT = ThermConstants[i, coefD] / T;
FT = ThermConstants[i, coefF] / T; HT = ThermConstants[i, coefH] / T; JT = ThermConstants[i, coefJ] / T;
cothDT = coth(DT); tanhFT = Math.Tanh(FT); cothHT = coth(HT); tanhJT = Math.Tanh(JT);
Hx += ThermConstants[i, coefA];
Hx += ThermConstants[i, coefB] * T;
Hx += ThermConstants[i, coefC] * ThermConstants[i, coefD] * cothDT;
Hx -= ThermConstants[i, coefE] * ThermConstants[i, coefF] * tanhFT;
Hx += ThermConstants[i, coefG] * ThermConstants[i, coefH] * cothHT;
Hx -= ThermConstants[i, coefI] * ThermConstants[i, coefJ] * tanhJT;
//use current mole fraction to weight the contribution
Hx *= ptAGA10.adMixture[i];
//add this contribution to the sum
H += Hx;
}
//convert from cal(th)/g-mol to kJ/kg-mol
H *= CalTH;
//convert from kJ/kg-mol to J/kg
H /= ptAGA10.dMrx;
// return in J/kg
return H * 1.0e3;
}
// Ho()
/**************************************************************************
*Function:So()
*Arguments:ref AGA10.GasPropsSTRUCT
*Returns:double
*Purpose:ideal gas specific entropy (J/kg-K)
*Notes:For continuity, the original constants and eqn's have been
*retained. Conversion from thermochemical calories(th) to
*Joules is applied after the primary calculations are complete.
*Revisions:
**************************************************************************/
double So(ref NG_Cal.GasPropsSTRUCT ptAGA10)
{
double S = 0.0; double Sx;
double DT, FT, HT, JT;
double cothDT, tanhFT, cothHT, tanhJT; double sinhDT, coshFT, sinhHT, coshJT; double T;
int i;
// to improve readability of this section, use intermediate variable T
T = ptAGA10.dTf;
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
// skip species whose concentration is zero
if (ptAGA10.adMixture[i] <= 0.0) continue;
Sx = 0.0;
// calculate species intermediate terms
DT = ThermConstants[i, coefD] / T;
FT = ThermConstants[i, coefF] / T;
HT = ThermConstants[i, coefH] / T;
JT = ThermConstants[i, coefJ] / T;
cothDT = coth(DT); tanhFT = Math.Tanh(FT); cothHT = coth(HT);
tanhJT = Math.Tanh(JT);
sinhDT = Math.Sinh(DT); coshFT = Math.Cosh(FT); sinhHT = Math.Sinh(HT); coshJT = Math.Cosh(JT);
Sx += ThermConstants[i, coefK];
Sx += ThermConstants[i, coefB] * Math.Log(T);
Sx += ThermConstants[i, coefC] * (DT * cothDT - Math.Log(sinhDT));
Sx -= ThermConstants[i, coefE] * (FT * tanhFT - Math.Log(coshFT));
Sx += ThermConstants[i, coefG] * (HT * cothHT - Math.Log(sinhHT));
Sx -= ThermConstants[i, coefI] * (JT * tanhJT - Math.Log(coshJT));
//use current mole fraction to weight the contribution
Sx *= ptAGA10.adMixture[i];
//add this contribution to the sum
S += Sx;
}
//convert cal(th)/mol-K basis to to kJ/kg mol-K
S *= CalTH;
//convert from kJ/kg mol-K to kJ/kg-K
S /= ptAGA10.dMrx;
// return in J/kg-K
return S * 1.0e3;
}//So()
/**************************************************************************
*Function:CprCvrHS()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:void
*Purpose:reasonably efficient group calculation of Cp, Cv, H and S
*Revisions:
**************************************************************************/
void CprCvrHS(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
double Cvinc, Cvr, Cpr;
double Hinc;
double Sinc;
double Smixing;
double Cp, Si;
double a, b, x;
int i;
//initialize integrals to zero
Cvinc = 0.0;
Hinc = 0.0;
Sinc = 0.0;
//initialize entropy of mixing
Smixing = 0.0;
//find ideal gas Cp
Cp = CpiMolar(ref ptAGA10);
//find ideal gas enthalpy
ptAGA10.dHo = Ho(ref ptAGA10);
//find ideal gas entropy
Si = So(ref ptAGA10);
//calculate ideal gas specific heat capacity at constant pressure in J/kgK
ptAGA10.dCpi = (Cp * 1000.0) / ptAGA10.dMrx;
//integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature
for (i = 0; i < GK_points; i++)
{
// set calculation point at + abscissa
x = ptAGA10.dDf * (1.0 + GK_root[i]) / 2.0;
//get Z at D
ptD.zdetail(x);
ptD.dZdT(x);
ptD.d2ZdT2(x);
//gather contributions at + abscissa; applying weighting factor
Hinc += GK_weight[i] * ptD.ddZdT / x;
Cvinc += GK_weight[i] * (2.0 * ptD.ddZdT + ptAGA10.dTf * ptD.dd2ZdT2) / x;
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
//set calculation point at - abscissa
x = ptAGA10.dDf * (1.0 - GK_root[i]) / 2.0;
//get Z at D
ptD.zdetail(x);
//calculate 1st and 2nd partial derivatives of Z wrt T
ptD.dZdT(x);
ptD.d2ZdT2(x);
//gather contributions at - abscissa; applying weighting factor
Hinc += GK_weight[i] * ptD.ddZdT / x;
Cvinc += GK_weight[i] * (2.0 * ptD.ddZdT + ptAGA10.dTf * ptD.dd2ZdT2) / x;
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
}
//return Z and partial derivatives to full molar density
ptD.zdetail(ptAGA10.dDf);
ptD.dZdT(ptAGA10.dDf);
ptD.d2ZdT2(ptAGA10.dDf);
//complete Cv molar
Cvr = Cp - NG_Cal.RGAS * (1.0 + ptAGA10.dTf * Cvinc * 0.5 * ptAGA10.dDf);
//intermediate values for Cp, containing 2 partial derivatives
a = (ptAGA10.dZf + ptAGA10.dTf * ptD.ddZdT);
b = (ptAGA10.dZf + ptAGA10.dDf * ptD.ddZdD);
//calculate dPdT, the partial derivative of P wrt T, at D
dPdT = NG_Cal.RGAS * ptAGA10.dDf * a;
//calculate dPdD, the partial derivative of P wrt D, at T
dPdD = NG_Cal.RGAS * ptAGA10.dTf * b;
//equation completing molar Cp, cancelling appropriate terms
Cpr = Cvr + NG_Cal.RGAS * ((a * a) / b);
//change from molar to mass basis
Cpr /= ptAGA10.dMrx;
Cvr /= ptAGA10.dMrx;
// write to the data stucture
ptAGA10.dCv = Cvr * 1000.0; // convert from joules/kgK to kilojoules/kgK
ptAGA10.dCp = Cpr * 1000.0;
// calculate specific enthalpy
ptAGA10.dH = ptAGA10.dHo + 1000.0 * NG_Cal.RGAS * ptAGA10.dTf * (ptAGA10.dZf - 1.0 - ptAGA10.dTf * Hinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
// calculate entropy of mixing
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] != 0) Smixing += ptAGA10.adMixture[i] * Math.Log(ptAGA10.adMixture[i]);
}
Smixing *= NG_Cal.RGAS;
// calculate specific entropy
ptAGA10.dS = Si - Smixing - 1000.0 * NG_Cal.RGAS * (Math.Log(ptAGA10.dPf / 101325.0) - Math.Log(ptAGA10.dZf) + Sinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
return;
}//CprCvrHS()
/**************************************************************************
*Function:HS_Mode()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *, double, double, bool
*Returns:void
*Purpose:Calculates a pressure & temperature from known enthalpy & entropy,
*with or without prior estimates.This function has a role in the
*calculation of C*.
*Solution based on a doubly-nested trial & error algorithm and Newton's
*method.
*
*For illustrative purpose, two approaches are supported by this example.
*If you are starting without advance knowledge of P & T, set the input parm
*bGuess to false, thus specifying a conservative search approach.
*If, however, you have a basis for guessing P & T (plenum conditions of a
*critical flow nozzle, for example) set P & T via GasPropsSTRUCT and set
*bGuess = true. The initial guess allows the search function to be more
*aggressive and, typically, faster.
*
*Revisions:
**************************************************************************/
public void HS_Mode(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD, double H, double S, bool bGuess)
{
double s0, s1, s2, t0, t1, t2, tmin, tmax; double h0, h1, h2, p0, p1, p2, px, pmin, pmax; double delta1, delta2;
double tolerance = 0.001;// convergence tolerance (used for both H and S searches)
int i, j;
//s0and h0 are our real gas reference points
s0 = S;
h0 = H;
//calling function specifies whether search parameters are supplied thru ptAGA10 or unknown
if (bGuess)
{
t1 = ptAGA10.dTf; px = ptAGA10.dPf; pmax = px * 2.0; pmin = px * 0.1;
tmax = t1 * 1.5; tmin = t1 * 0.67;
}
else// use arbitrary, generic limits
{
t1 = 273.15;
px = 1013250.0; // 10 atmospheres
pmax = NG_Cal.P_MAX;
pmin = 10000.0; // 10 kPa
tmax = NG_Cal.T_MAX;
tmin = NG_Cal.T_MIN;
}
// set the temperature differential
t2 = t1 + 10.0;
///////////////////////////////////////////
//begin double trial-and-error, searching for T & P
//run the calculation with initial guesses
ptD.Run(ref ptAGA10);
//h1 is difference between h given and h@Tf, Pf
h1 = this.H(ref ptAGA10, ref ptD) - h0;
//outer loop: search for a t2 which will satisfy constant enthalpy
for (i = 0; i < NG_Cal.MAX_NUM_OF_ITERATIONS; i++)
{
ptAGA10.dTf = t2;
p1 = px;// reset one bracket
p2 = px * 0.1;// set other bracket to 0.1x the upper bracket
ptAGA10.dPf = p1;
ptD.Run(ref ptAGA10);
s1 = this.S(ref ptAGA10, ref ptD) - s0;
//inside loop: search for a p2 which will satisfy constant entropy
for (j = 0; j < NG_Cal.MAX_NUM_OF_ITERATIONS; j++)
{
ptAGA10.dPf = p2; ptD.Run(ref ptAGA10);
s2 = this.S(ref ptAGA10, ref ptD) - s0;
//calculate our proportional change
delta2 = Math.Abs(s1 - s2) / s0; // close enough?
if (delta2 < tolerance) break;
//revise our estimate to p2
p0 = p2;
p2 = (p1 * s2 - p2 * s1) / (s2 - s1);
//check for negative pressure and clamp to pmin for safety
if (p2 <= pmin)
{
p2 = pmin;
}
//check if we've created an unrealistic pressure
if (p2 >= pmax) p2 = pmax; // swap values
p1 = p0;
s1 = s2;
}
// check for failure to converge
if (j >= NG_Cal.MAX_NUM_OF_ITERATIONS) ptAGA10.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED;
//calc enthalpy at guessed P & current iter T
h2 = this.H(ref ptAGA10, ref ptD) - h0;
//calculate our proportional change
delta1 = Math.Abs(h1 - h2) / h0;
// close enough?
if (delta1 < tolerance && i > 0) break;
//revise our estimate to t2
t0 = t2;
t2 = (t1 * h2 - t2 * h1) / (h2 - h1);
//check if we've created an unrealistic temperature
if (t2 >= tmax) t2 = tmax;
//revise t2, if necessary
if (t2 <= tmin)
{
t2 = t0 + 10.0;
ptAGA10.dTf = t2; ptD.Run(ref ptAGA10);
h2 = this.H(ref ptAGA10, ref ptD) - h0;
}
t1 = t0;
h1 = h2;
}
// check for failure to converge
if (i >= NG_Cal.MAX_NUM_OF_ITERATIONS) ptAGA10.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED;
}//HS_Mode()
/**************************************************************************
*Function:H()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:double
*Purpose:real gas specific enthalpy
*Revisions:
**************************************************************************/
double H(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
double Hinc; double x; int i;
//initialize integral
Hinc = 0.0;
//find ideal gas enthalpy
ptAGA10.dHo = Ho(ref ptAGA10);
//integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature
for (i = 0; i < GK_points; i++)
{
//calculate 1st and 2nd partial derivatives of Z wrt T
x = ptAGA10.dDf * (1.0 + GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x);
ptD.d2ZdT2(x);
Hinc += GK_weight[i] * ptD.ddZdT / x; if (i == 10) break;
x = ptAGA10.dDf * (1.0 - GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x); ptD.d2ZdT2(x);
Hinc += GK_weight[i] * ptD.ddZdT / x;
}
ptD.zdetail(ptAGA10.dDf); ptD.dZdT(ptAGA10.dDf); ptD.d2ZdT2(ptAGA10.dDf);
// calculate specific enthalpy
ptAGA10.dH = ptAGA10.dHo + 1000.0 * NG_Cal.RGAS * ptAGA10.dTf *
(ptAGA10.dZf - 1.0 - ptAGA10.dTf * Hinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
return (ptAGA10.dH);
} // H()
/**************************************************************************
*Function:S()
*Arguments:ref AGA10.GasPropsSTRUCT , Detail *
*Returns:double
*Purpose:real gas specific entropy
*Revisions:
**************************************************************************/
double S(ref NG_Cal.GasPropsSTRUCT ptAGA10, ref Detail ptD)
{
double Sinc; double Smixing; double x;
int i;
//initialize integral
Sinc = 0.0;
//initialize entropy of mixing
Smixing = 0.0;
//integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature
for (i = 0; i < GK_points; i++)
{
//calculate 1st and 2nd partial derivatives of Z wrt T
x = ptAGA10.dDf * (1.0 + GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x); ptD.d2ZdT2(x);
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
if (i == 10) break;
x = ptAGA10.dDf * (1.0 - GK_root[i]) / 2.0; ptD.zdetail(x);
ptD.dZdT(x); ptD.d2ZdT2(x);
Sinc += GK_weight[i] * (ptD.dZ + ptAGA10.dTf * ptD.ddZdT - 1.0) / x;
}
//reset Z and partial deivatives dZdT and d2ZdT2
ptD.zdetail(ptAGA10.dDf);
ptD.dZdT(ptAGA10.dDf);
ptD.d2ZdT2(ptAGA10.dDf);
//find ideal gas entropy, but only if temperature or composition have changed
if (ptAGA10.dTf != dTold || ptAGA10.dMrx != dMrxold)
{
dSi = So(ref ptAGA10); dTold = ptAGA10.dTf; dMrxold = ptAGA10.dMrx;
}
//calculate entropy of mixing
for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++)
{
if (ptAGA10.adMixture[i] != 0) Smixing += ptAGA10.adMixture[i] * Math.Log(ptAGA10.adMixture[i]);
}
Smixing *= NG_Cal.RGAS;
// calculate specific entropy
ptAGA10.dS = dSi - Smixing - 1000.0 * NG_Cal.RGAS * (Math.Log(ptAGA10.dPf / 101325.0) - Math.Log(ptAGA10.dZf) + Sinc * 0.5 * ptAGA10.dDf) / ptAGA10.dMrx;
return (ptAGA10.dS);
} // S()
}
}

407
NGToolsPC/UnitConvert.cs Normal file
View File

@ -0,0 +1,407 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NG_Tools
{
public class UnitConvert
{
public double Converter(string UnitName, double oldValue, int oldunit, int newunit, int Xsdws)
{
double returnValue = 0;
//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
//Dim strUnit() As String
double[] dataUnit = new double[] { 0 };
//ReDim strUnit(UnitNum)
//RereDim dataUnit(UnitNum)
switch (UnitName)
{
case "tj":
dataUnit = new double[8];
//strUnit(0) = "立方米(m3)"
//strUnit(1) = "升(L, dm3)"
//strUnit(2) = "立方厘米(cm3, ml, c.c)"
//strUnit(3) = "立方英尺(ft3)"
//strUnit(4) = "立方英寸(in3)"
//strUnit(5) = "英加仑(UKgal)"
//strUnit(6) = "美加仑(U.Sgal)"
//strUnit(7) = "美油桶(USbbl)"
dataUnit[0] = 1;
dataUnit[1] = 1000;
dataUnit[2] = 1000000;
dataUnit[3] = 35.3147;
dataUnit[4] = 61023.7;
dataUnit[5] = 219.969;
dataUnit[6] = 264.172;
dataUnit[7] = 6.28994;
break;
case "zl":
//strUnit(0) = "千克(公斤)(kg)"
//strUnit(1) = "克(g)"
//strUnit(2) = "毫克(mg)"
//strUnit(3) = "吨(t)"
//strUnit(4) = "英吨(长吨)(UKton)"
//strUnit(5) = "美吨(短吨)(U.Ston)"
//strUnit(6) = "磅(lb)"
//strUnit(7) = "盎司(oz)"
dataUnit = new double[8]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 1000;
dataUnit[2] = 1000000;
dataUnit[3] = 0.001;
dataUnit[4] = 0.000984207;
dataUnit[5] = 0.00110231;
dataUnit[6] = 2.20462;
dataUnit[7] = 35.274;
break;
case "rl":
//strUnit(0) = "焦耳(J)"
//strUnit(1) = "马力小时(Hp·h)"
//strUnit(2) = "公斤力·米(kgf·m)"
//strUnit(3) = "升·大气压(L·atm)"
//strUnit(4) = "尔格(erg)"
//strUnit(5) = "千卡(kacl)"
//strUnit(6) = "千瓦小时(kW·h)"
//strUnit(7) = "英马力小时(UKHp·h)"
//strUnit(8) = "英尺·磅力(ft·lbf)"
//strUnit(9) = "英热单位(BTU)"
dataUnit = new double[10]; // As Double
dataUnit[0] = 1;
dataUnit[1] = 0.000000377672;
dataUnit[2] = 0.101972;
dataUnit[3] = 0.00986923;
dataUnit[4] = 107;
dataUnit[5] = 0.000238846;
dataUnit[6] = 0.000000277778;
dataUnit[7] = 0.000000372506;
dataUnit[8] = 0.737562;
dataUnit[9] = 0.000947813;
break;
case "nlll":
//strUnit(0) = "兆焦/秒(MJ/s)"
//strUnit(1) = "兆焦/小时(MJ/h)"
//strUnit(2) = "兆焦/天(MJ/d)"
//strUnit(3) = "千卡/秒(kcal/s)"
//strUnit(4) = "千卡/小时(kcal/h)"
//strUnit(5) = "英热单位/秒(BTU/s)"
//strUnit(6) = "英热单位/小时(BTU/h)"
dataUnit = new double[7]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 3600;
dataUnit[2] = 86400;
dataUnit[3] = 238.846;
dataUnit[4] = 859845.6;
dataUnit[5] = 947.813;
dataUnit[6] = 3412126.8;
break;
case "zlll":
//strUnit(0) = "千克(公斤)/秒(kg/s)"
//strUnit(1) = "千克(公斤)/分(kg/Min)"
//strUnit(2) = "千克(公斤)/时(kg/h)"
//strUnit(3) = "磅/秒(lb/s)"
//strUnit(4) = "磅/分(lb/Min)"
//strUnit(5) = "磅/时(lb/h)"
//strUnit(6) = "吨/时(t/h)"
//strUnit(7) = "英吨(长吨)/时(UKton/h)"
//strUnit(8) = "美吨(短吨)/小时(U.Ston/h)"
dataUnit = new double[9]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 60;
dataUnit[2] = 3600;
dataUnit[3] = 2.20462;
dataUnit[4] = 132.2772;
dataUnit[5] = 7936.632;
dataUnit[6] = 3.6;
dataUnit[7] = 3.543145;
dataUnit[8] = 3.968316;
break;
case "tjll":
//strUnit(0) = "立方米/秒(m3/s)"
//strUnit(1) = "万立方米/天(m3/d)"
//strUnit(1) = "立方米/时(m3/h)"
//strUnit(2) = "立方米/分(m3/Min)"
//strUnit(3) = "升/时(L/h)"
//strUnit(4) = "升/分(L/Min)"
//strUnit(5) = "升/秒(L/s)"
//strUnit(6) = "立方英尺/时(ft3/h)"
//strUnit(7) = "立方英尺/分(ft3/Min)"
//strUnit(8) = "立方英尺/秒(ft3/s)"
//strUnit(9) = "立方英尺/秒(ft3/s)"
//strUnit(10) = "立方英尺/天(ft3/d)"
//strUnit(11) = "英加仑/秒(UKgal/s)"
//strUnit(12) = "美加仑/秒(U.Sgal/s)"
//strUnit(13) = "美油桶/秒(USbbl/s)"
dataUnit = new double[13]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 8.64;
dataUnit[2] = 3600;
dataUnit[3] = 60;
dataUnit[4] = 3600000;
dataUnit[5] = 60000;
dataUnit[6] = 1000;
dataUnit[7] = 127132.92;
dataUnit[8] = 2118.882;
dataUnit[9] = 0.0245240972222222;
dataUnit[10] = 35.3147;
dataUnit[11] = 219.969;
dataUnit[12] = 264.172;
break;
case "yl":
//strUnit(0) = "帕(Pa)"
//strUnit(1) = "千帕(kPa)"
//strUnit(2) = "兆帕(Mpa)"
//strUnit(3) = "标准大气压(atm)"
//strUnit(4) = "毫巴(mbar)"
//strUnit(5) = "巴(bar)"
//strUnit(6) = "千克力/平方米(kgf/m2)"
//strUnit(7) = "千克力/平方厘米(kgf/cm2)"
//strUnit(8) = "毫米汞柱(mmHg)"
//strUnit(9) = "毫米水柱4℃(mmH2O)"
//strUnit(10) = "磅/平方英寸(psi)"
dataUnit = new double[11]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 0.001;
dataUnit[2] = 0.000001;
dataUnit[3] = 0.00000986923266716013;
dataUnit[4] = 0.01;
dataUnit[5] = 0.00001;
dataUnit[6] = 0.101971621;
dataUnit[7] = 0.0000101972;
dataUnit[8] = 0.007500638;
dataUnit[9] = 0.101972;
dataUnit[10] = 0.000145038;
break;
case "wd":
switch (newunit)
{
case 0:
switch (oldunit)
{
case 0:
returnValue = oldValue;
break;
case 1: //K->℃
returnValue = oldValue - 273.15;
break;
case 2: //F->℃
returnValue = (oldValue - 32) / 1.8;
break;
case 3: //R->℃
returnValue = oldValue / 1.8 - 273.15;
break;
}
break;
case 1:
switch (oldunit)
{
case 0: //℃->K
returnValue = oldValue + 273.15;
break;
case 1:
returnValue = oldValue;
break;
case 2: //F->K
returnValue = (oldValue - 32) / 1.8 + 273.15;
break;
case 3: //R->K
returnValue = oldValue / 1.8;
break;
}
break;
case 2:
switch (oldunit)
{
case 0: //C->F
returnValue = oldValue * 1.8 + 32;
break;
case 1: //k->f
returnValue = (oldValue - 273.15) * 1.8 + 32;
break;
case 2:
returnValue = oldValue;
break;
case 3: //R->F
returnValue = oldValue - 273.15 * 1.8 + 32;
break;
}
break;
case 3:
switch (oldunit)
{
case 0: //C->R
returnValue = (oldValue + 273.15) * 1.8;
break;
case 1: //K->R
returnValue = oldValue * 1.8;
break;
case 2: //F->R
returnValue = (oldValue - 32) + 273.15 * 1.8;
break;
case 3:
returnValue = oldValue;
break;
}
break;
default:
break;
}
return returnValue;
case "cd":
//米(m)
//分米(dm)
//厘米(cm)
//毫米(mm)
//英尺(ft)
//英寸(in)
//英里(mile)
//英寻(fm)
//海里(nmile)
//埃(a)
//码(yd)
//密尔(mil)
//杆<(rad)
dataUnit = new double[14]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 10;
dataUnit[2] = 100;
dataUnit[3] = 1000;
dataUnit[5] = 3.28038;
dataUnit[4] = 39.3700787401575;
dataUnit[6] = 0.001;
dataUnit[7] = 0.000621504039776259;
dataUnit[8] = 0.546746856205577;
dataUnit[9] = 0.000539956803455;
dataUnit[10] = 10000000000.0D;
dataUnit[11] = 1.093613;
dataUnit[12] = 39370.0787401575;
dataUnit[13] = 0.198838781515947;
break;
case "mj":
//平方米m2
//平方分米dm2
//平方厘米cm2
//平方毫米mm2
//平方英尺ft2
//平方英寸in2
//平方公里km2
//公顷ha
//公亩are
//英亩acre
//平方英里sq -mile
//平方码yd2
dataUnit = new double[12]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 100;
dataUnit[2] = 10000;
dataUnit[3] = 1000000;
dataUnit[4] = 10.7608929444;
dataUnit[5] = 1550.0031;
dataUnit[6] = 0.000001;
dataUnit[7] = 0.0001;
dataUnit[8] = 0.01;
dataUnit[9] = 0.0002471;
dataUnit[10] = 0.000000386102158;
dataUnit[11] = 1.19599;
break;
//小时
//分钟
//天
//秒
case "sj":
dataUnit = new double[4]; //As Double
dataUnit[0] = 1;
dataUnit[1] = 60;
dataUnit[2] = 0.0416666666666667;
dataUnit[3] = 3600;
break;
case "sd":
break;
//米每秒
//厘米每秒
//
}
if (newunit == oldunit)
{
return oldValue;
}
return SsWr(oldValue * dataUnit[newunit] / dataUnit[oldunit], Xsdws);
}
private double SsWr(double value, int weishu)
{
long tempValue = 0;
double SorR = 0;
try
{
tempValue = (long)(value * Math.Pow(10, weishu));
SorR = System.Convert.ToInt32((value * Math.Pow(10, weishu) - tempValue) * 10);
if (SorR >= 5)
{
tempValue++;
}
return tempValue / Math.Pow(10, weishu);
}
catch
{
return value;
}
}
}
}

578
NGToolsPC/XMLHelper.cs Normal file
View File

@ -0,0 +1,578 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace NGToolsPC
{
/// <summary>
/// XMLHelper XML文档操作管理器
/// </summary>
public class XMLHelper
{
public XMLHelper()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region XML文档节点查询和读取
/// <summary>
/// 选择匹配XPath表达式的第一个节点XmlNode.
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名")</param>
/// <returns>返回XmlNode</returns>
public static XmlNode GetXmlNodeByXpath(string xmlFileName, string xpath)
{
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
return xmlNode;
}
catch (Exception ex)
{
return null;
//throw ex; //这里可以定义你自己的异常处理
}
}
/// <summary>
/// 选择匹配XPath表达式的节点列表XmlNodeList.
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名")</param>
/// <returns>返回XmlNodeList</returns>
public static XmlNodeList GetXmlNodeListByXpath(string xmlFileName, string xpath)
{
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNodeList xmlNodeList = xmlDoc.SelectNodes(xpath);
return xmlNodeList;
}
catch (Exception ex)
{
return null;
//throw ex; //这里可以定义你自己的异常处理
}
}
/// <summary>
/// 选择匹配XPath表达式的第一个节点的匹配xmlAttributeName的属性XmlAttribute.
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
/// <returns>返回xmlAttributeName</returns>
public static XmlAttribute GetXmlAttribute(string xmlFileName, string xpath, string xmlAttributeName)
{
string content = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
XmlAttribute xmlAttribute = null;
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
if (xmlNode.Attributes.Count > 0)
{
xmlAttribute = xmlNode.Attributes[xmlAttributeName];
}
}
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return xmlAttribute;
}
/// <summary>
/// 选择匹配XPath表达式的第一个节点的匹配xmlAttributeName的属性XmlAttribute.
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="name">要匹配xmlAttributeName的属性的子节点名称</param>
/// <param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
/// <param name="xmlAttributeValues">要匹配xmlAttributeName的属性值</param>
/// <returns>返回xmlAttributeName的属性的子节点名称InnerText</returns>
public static string GetXmlByAttribute(string xmlFileName, string xpath, string name, string xmlAttributeName, string xmlAttributeValues)
{
string content = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
//主要
XmlNodeList xlist = xmlDoc.SelectNodes(xpath);
XmlNode xmlNode = xlist.Cast<XmlNode>().Where(o => o.Attributes.Cast<XmlAttribute>().FirstOrDefault(a => a.Name == xmlAttributeName && a.Value == xmlAttributeValues) != null).FirstOrDefault();
//XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
foreach (XmlNode node in xmlNode.ChildNodes)
{
if (node.Name.ToLower() == name.ToLower())
{
//存在此节点则返回InnerText
content = node.InnerText;
break;
}
}
}
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return content;
}
/// <summary>
/// 选择匹配XPath表达式的第一个节点的匹配xmlAttributeName的属性XmlAttribute.
/// </summary>
/// <param name="xmlFileName"></param>
/// <param name="xpath"></param>
/// <param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
/// <param name="xmlAttributeValues">要匹配xmlAttributeName的属性值</param>
/// <returns>返回节点InnerText</returns>
public static string GetXmlByAttribute(string xmlFileName, string xpath, string xmlAttributeName, string xmlAttributeValues)
{
string content = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
//主要
XmlNodeList xlist = xmlDoc.SelectNodes(xpath);
XmlNode xmlNode = xlist.Cast<XmlNode>().Where(o => o.Attributes.Cast<XmlAttribute>().FirstOrDefault(a => a.Name == xmlAttributeName && a.Value == xmlAttributeValues) != null).FirstOrDefault();
//XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
content = xmlNode.InnerText;
}
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return content;
}
#endregion
#region XML文档创建和节点或属性的添加
/// <summary>
/// 创建一个XML文档
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="rootNodeName">XML文档根节点名称(须指定一个根节点名称)</param>
/// <param name="version">XML文档版本号(必须为:"1.0")</param>
/// <param name="encoding">XML文档编码方式</param>
/// <param name="standalone">该值必须是"yes"或"no",如果为null,Save方法不在XML声明上写出独立属性</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool CreateXmlDocument(string xmlFileName, string rootNodeName, string version, string encoding, string standalone)
{
bool isSuccess = false;
try
{
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration(version, encoding, standalone);
XmlNode root = xmlDoc.CreateElement(rootNodeName);
xmlDoc.AppendChild(xmlDeclaration);
xmlDoc.AppendChild(root);
xmlDoc.Save(xmlFileName);
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 依据匹配XPath表达式的第一个节点来创建它的子节点(如果此节点已存在则追加一个新的同名节点
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlNodeName">要匹配xmlNodeName的节点名称</param>
/// <param name="innerText">节点文本值</param>
/// <param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
/// <param name="value">属性值</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool CreateXmlNodeByXPath(string xmlFileName, string xpath, string xmlNodeName, string innerText, string xmlAttributeName, string value)
{
bool isSuccess = false;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//存不存在此节点都创建
XmlElement subElement = xmlDoc.CreateElement(xmlNodeName);
subElement.InnerXml = innerText;
//如果属性和值参数都不为空则在此新节点上新增属性
if (!string.IsNullOrEmpty(xmlAttributeName) && !string.IsNullOrEmpty(value))
{
XmlAttribute xmlAttribute = xmlDoc.CreateAttribute(xmlAttributeName);
xmlAttribute.Value = value;
subElement.Attributes.Append(xmlAttribute);
}
xmlNode.AppendChild(subElement);
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 依据匹配XPath表达式的第一个节点来创建或更新它的子节点(如果节点存在则更新,不存在则创建)
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlNodeName">要匹配xmlNodeName的节点名称</param>
/// <param name="innerText">节点文本值</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool CreateOrUpdateXmlNodeByXPath(string xmlFileName, string xpath, string xmlNodeName, string innerText)
{
bool isSuccess = false;
bool isExistsNode = false;//标识节点是否存在
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
//XmlNodeList xlist = xmlDoc.SelectNodes(xpath);
//XmlNode xmlNode = xlist.Cast<XmlNode>().Where(o => o.InnerText == innerText).FirstOrDefault();
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//遍历xpath节点下的所有子节点
foreach (XmlNode node in xmlNode.ChildNodes)
{
//XmlAttribute att = node.Attributes.Cast<XmlAttribute>().Where(o => o.Name == innerText).FirstOrDefault();
if (node.Name.ToLower() == xmlNodeName.ToLower())
{
//存在此节点则更新
node.InnerXml = innerText;
isExistsNode = true;
break;
}
}
if (!isExistsNode)
{
//不存在此节点则创建
XmlElement subElement = xmlDoc.CreateElement(xmlNodeName);
subElement.InnerXml = innerText;
xmlNode.AppendChild(subElement);
}
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 依据匹配XPath表达式的第一个节点来创建或更新它的子节点(如果节点存在则更新,不存在则创建)
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlNodeName">要匹配xmlNodeName的节点名称</param>
/// <param name="innerText">节点文本值</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool CreateOrUpdateXmlNodeByXPath(string xmlFileName, string xpath, string xmlNodeName, string innerText, string XmlAttributeName, string XmlAttributeValues)
{
bool isSuccess = false;
bool isExistsNode = false;//标识节点是否存在
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//遍历xpath节点下的所有子节点
foreach (XmlNode node in xmlNode.ChildNodes)
{
XmlAttribute att = node.Attributes.Cast<XmlAttribute>().Where(o => o.Name == XmlAttributeName && o.Value == XmlAttributeValues).FirstOrDefault();
if (att != null && node.Name.ToLower() == xmlNodeName.ToLower())
{
//存在此节点则更新
node.InnerXml = innerText;
isExistsNode = true;
#region //遍历xpath节点中的所有属性
bool isExistsAttribute = false;
foreach (XmlAttribute attribute in node.Attributes)
{
if (attribute.Name.ToLower() == XmlAttributeName.ToLower())
{
//节点中存在此属性则更新
attribute.Value = XmlAttributeValues;
isExistsAttribute = true;
break;
}
}
if (!isExistsAttribute)
{
//节点中不存在此属性则创建
XmlAttribute xmlAttribute = xmlDoc.CreateAttribute(XmlAttributeName);
xmlAttribute.Value = XmlAttributeValues;
node.Attributes.Append(xmlAttribute);
}
#endregion
break;
}
}
if (!isExistsNode)
{
//不存在此节点则创建
XmlElement subElement = xmlDoc.CreateElement(xmlNodeName);
subElement.InnerXml = innerText;
XmlAttribute xmlAttribute = xmlDoc.CreateAttribute(XmlAttributeName);
xmlAttribute.Value = XmlAttributeValues;
subElement.Attributes.Append(xmlAttribute);
xmlNode.AppendChild(subElement);
}
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 依据匹配XPath表达式的第一个节点来创建或更新它的子节点(如果节点存在则更新,不存在则创建)
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlNodeName">要匹配xmlNodeName的节点名称</param>
/// <param name="innerText">节点文本值</param>
/// <param name="parentinnerText">指定父节点文本值</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool CreateOrUpdateXmlNodeByXPath(string xmlFileName, string xpath, string xmlNodeName, string innerText, string parentAttributevalues)
{
bool isSuccess = false;
bool isExistsNode = false;//标识节点是否存在
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNodeList xlist = xmlDoc.SelectNodes(xpath);
//主要
XmlNode xmlNode = xlist.Cast<XmlNode>().Where(o => o.Attributes.Cast<XmlAttribute>().FirstOrDefault(a => a.Name == "Name" && a.Value == parentAttributevalues) != null).FirstOrDefault();
//XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//遍历xpath节点下的所有子节点
foreach (XmlNode node in xmlNode.ChildNodes)
{
if (node.Name.ToLower() == xmlNodeName.ToLower())
{
//存在此节点则更新
node.InnerXml = innerText;
isExistsNode = true;
break;
}
}
if (!isExistsNode)
{
//不存在此节点则创建
XmlElement subElement = xmlDoc.CreateElement(xmlNodeName);
subElement.InnerXml = innerText;
xmlNode.AppendChild(subElement);
}
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 依据匹配XPath表达式的第一个节点来创建或更新它的属性(如果属性存在则更新,不存在则创建)
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
/// <param name="value">属性值</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool CreateOrUpdateXmlAttributeByXPath(string xmlFileName, string xpath, string xmlAttributeName, string value)
{
bool isSuccess = false;
bool isExistsAttribute = false;//标识属性是否存在
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//遍历xpath节点中的所有属性
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
if (attribute.Name.ToLower() == xmlAttributeName.ToLower())
{
//节点中存在此属性则更新
attribute.Value = value;
isExistsAttribute = true;
break;
}
}
if (!isExistsAttribute)
{
//节点中不存在此属性则创建
XmlAttribute xmlAttribute = xmlDoc.CreateAttribute(xmlAttributeName);
xmlAttribute.Value = value;
xmlNode.Attributes.Append(xmlAttribute);
}
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
#endregion
#region XML文档节点或属性的删除
/// <summary>
/// 删除匹配XPath表达式的第一个节点(节点中的子元素同时会被删除)
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool DeleteXmlNodeByXPath(string xmlFileName, string xpath)
{
bool isSuccess = false;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//删除节点
xmlNode.ParentNode.RemoveChild(xmlNode);
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 删除匹配XPath表达式的第一个节点中的匹配参数xmlAttributeName的属性
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <param name="xmlAttributeName">要删除的xmlAttributeName的属性名称</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool DeleteXmlAttributeByXPath(string xmlFileName, string xpath, string xmlAttributeName)
{
bool isSuccess = false;
bool isExistsAttribute = false;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
XmlAttribute xmlAttribute = null;
if (xmlNode != null)
{
//遍历xpath节点中的所有属性
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
if (attribute.Name.ToLower() == xmlAttributeName.ToLower())
{
//节点中存在此属性
xmlAttribute = attribute;
isExistsAttribute = true;
break;
}
}
if (isExistsAttribute)
{
//删除节点中的属性
xmlNode.Attributes.Remove(xmlAttribute);
}
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
/// <summary>
/// 删除匹配XPath表达式的第一个节点中的所有属性
/// </summary>
/// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
/// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool DeleteAllXmlAttributeByXPath(string xmlFileName, string xpath)
{
bool isSuccess = false;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(xmlFileName); //加载XML文档
XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
if (xmlNode != null)
{
//遍历xpath节点中的所有属性
xmlNode.Attributes.RemoveAll();
}
xmlDoc.Save(xmlFileName); //保存到XML文档
isSuccess = true;
}
catch (Exception ex)
{
throw ex; //这里可以定义你自己的异常处理
}
return isSuccess;
}
#endregion
}
}

10
NGToolsPC/app.config Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="NGToolsPC.Properties.Settings.NGDATAConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\NGDATA.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
</configuration>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="NGToolsPC.Properties.Settings.NGDATAConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\NGDATA.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
</configuration>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More