commit cf901b1bbdc4fbd5acc9187edd47ba50837970c3 Author: ldeyun Date: Fri Sep 13 16:34:08 2024 +0800 添加一年的SSL证书 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/out/artifacts/ngtools_jar/ngtools.jar b/out/artifacts/ngtools_jar/ngtools.jar new file mode 100644 index 0000000..f74d25d Binary files /dev/null and b/out/artifacts/ngtools_jar/ngtools.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b4440d4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + com.ng + ngtools + 0.0.1-SNAPSHOT + ng + ng + + 1.8 + UTF-8 + UTF-8 + 2.6.13 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + io.swagger + swagger-annotations + 1.5.13 + + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.ng.ngtools.NgApplication + + + + + repackage + + repackage + + + + + + + + diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6b84a7d --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.ng.ngtools.NgApplication + diff --git a/src/main/java/com/ng/ngtools/NgApplication.java b/src/main/java/com/ng/ngtools/NgApplication.java new file mode 100644 index 0000000..3bd1326 --- /dev/null +++ b/src/main/java/com/ng/ngtools/NgApplication.java @@ -0,0 +1,71 @@ +package com.ng.ngtools; + +import org.apache.catalina.connector.Connector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.core.env.Environment; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +@SpringBootApplication(scanBasePackages="com.ng.ngtools.modules") +@ComponentScan(basePackages = {"com.ng.ngtools.tangible","com.ng.ngtools.Tools"}) +@EnableScheduling +@EnableAsync +@EnableCaching +public class NgApplication { + + public final static Logger log = LoggerFactory.getLogger(NgApplication.class); + + public static void main(String[] args) { + ConfigurableApplicationContext application = SpringApplication.run(NgApplication.class, args); + Environment env = application.getEnvironment(); + String ip = null; String httpsport =""; + String httpport =""; + try { + ip = InetAddress.getLocalHost().getHostAddress(); + httpsport= env.getProperty("server.port"); + httpport= env.getProperty("myhttp-port"); + + } catch (UnknownHostException e) { + + } + log.info("\n----------------------------------------------------------\n\t" + + "程序启动成功! URLs:\n\t" + + "http: \t\thttp://"+ip+":" + httpport +"\n\t" + + "https: \t\thttps://"+ip +":"+ httpsport +"\n\t" + + "\n----------------------------------------------------------\n\t" + ); + + } + + @Value("${myhttp-port}") + private Integer httpPort; + /*SpringBoot 2.x版本(以及更高版本)使用下面的代码*/ + @Bean + public ServletWebServerFactory servletcontainer(){ + TomcatServletWebServerFactory tomcat =new TomcatServletWebServerFactory(); + tomcat.addAdditionalTomcatConnectors(createHTTPConnector()); + return tomcat; + } + private Connector createHTTPConnector(){ + Connector connector =new Connector("org.apache.coyote.http11.Http11NioProtocol"); + connector.setScheme("http"); + connector.setSecure(false); + connector.setPort(httpPort); + return connector; + } + + +} diff --git a/src/main/java/com/ng/ngtools/Tools/NG_Cal.java b/src/main/java/com/ng/ngtools/Tools/NG_Cal.java new file mode 100644 index 0000000..3bdc922 --- /dev/null +++ b/src/main/java/com/ng/ngtools/Tools/NG_Cal.java @@ -0,0 +1,1356 @@ +package com.ng.ngtools.Tools; + +import com.ng.ngtools.common.Result; +import com.ng.ngtools.modules.FlowCal; +import com.ng.ngtools.modules.UnitConvert; +import com.ng.ngtools.tangible.RefObject; +import org.springframework.web.bind.annotation.*; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static javax.xml.bind.DatatypeConverter.parseDouble; +import static javax.xml.bind.DatatypeConverter.parseString; + +@RestController +public class NG_Cal { + + @ResponseBody + @GetMapping (value="testCal") + public Result testCal(@RequestParam(name="par" ) String par) { + + return Result.ok(par); + } + + @ResponseBody + @GetMapping (value="KBFlowcal") + public Result KBFlowcal(@RequestParam(name="par" ) String [] par) + { + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.FlowParStruct flPar = new com.ng.ngtools.modules.NG_Cal.FlowParStruct(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + + flPar.dMeterType = (int)tempPar[0]; //流量计类别 + flPar.dCoreType = (int)tempPar[1]; //节流装置类型 + flPar.dFlowCalbz = (int)tempPar[2]; //流量计算标准 + flPar.dZcalbz = (int)tempPar[3]; //压缩因子计算标准 + flPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + flPar.dPb_M = tempPar[5]; //计量参比条件压力 + flPar.dTb_M = tempPar[6]; //计量参比条件温度 + flPar.dPb_E = tempPar[7]; //燃烧参比条件压力 + flPar.dTb_E = tempPar[8]; //燃烧参比条件温度 + flPar.dPatmUnit = (int)tempPar[10]; //当地大气压单位 + flPar.dPatm = MyConvert.Converter("yl", tempPar[9], flPar.dPatmUnit, 0, 4); + //当地大气压 + flPar.dNG_Compents = gasPar.adMixture; //天然气组分 + flPar.dPtmode = (int)tempPar[12]; //取压方式 + flPar.dPipeType = (int)tempPar[13]; //管道类型 + flPar.dPipeD = tempPar[14]; //管道内径 + flPar.dLenUnit = (int)tempPar[15]; //长度单位 + flPar.dPipeDtemp = tempPar[16]; //管道内径参考温度 + flPar.dPileDtempUint = (int)tempPar[17]; //温度单位 + flPar.dPipeMaterial = tempPar[18]; //管道材料 + flPar.dOrificeD = tempPar[19]; //孔板孔径 + flPar.dOrificeUnit = (int)tempPar[20]; //长度单位 + flPar.dOrificeDtemp = tempPar[21]; //孔板内径参考温度 + flPar.dOrificeDtempUnit = (int)tempPar[22]; //温度单位 + flPar.dOrificeMaterial = tempPar[23]; //孔板材料 + flPar.dOrificeSharpness = (int)tempPar[24]; //锐利度系数计算方法 + flPar.dOrificeRk = tempPar[25]; //孔板入口圆弧半径 + flPar.dOrificeRkLenUint = (int)tempPar[26]; //长度单位 + flPar.dPfUnit = (int)tempPar[28]; //压力单位 + flPar.dPf = MyConvert.Converter("yl", tempPar[27], flPar.dPfUnit, 0, 4); //输入压力 + flPar.dPfType = (int)tempPar[29]; //压力类型 + flPar.dTfUnit = (int)tempPar[31]; //温度单位 + flPar.dTf = MyConvert.Converter("wd", tempPar[30], flPar.dTfUnit, 1, 4); //输入温度 + flPar.dDpUnit = (int)tempPar[33]; //压力单位 + flPar.dDp = MyConvert.Converter("yl", tempPar[32], flPar.dDpUnit, 0, 4); //输入压力; //输入差压 + flPar.dVFlowUnit = (int)tempPar[34]; //体积流量单位 + flPar.dMFlowUnit = (int)tempPar[35]; //质量流量单位 + flPar.dEFlowUnit = (int)tempPar[36]; //能量流量单位 + + //将压力换算为绝压 + if (flPar.dPfType == 0) + { + flPar.dPf = flPar.dPf + flPar.dPatm; + } + + gasPar.dCbtj = flPar.dCbtj; + gasPar.dPf = flPar.dPf; + gasPar.dTf = flPar.dTf; + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Crit(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + RefObject tempRef_gasPar2 = new RefObject(gasPar); + RefObject tempRef_flPar = new RefObject(flPar); + NGFLOW.OFlowCal(tempRef_gasPar2, tempRef_flPar); + flPar = tempRef_flPar.argValue; + gasPar = tempRef_gasPar2.argValue; + + + tempPar[45] = flPar.dCd; + tempPar[46] = flPar.dE; + tempPar[47] = flPar.dFG; + tempPar[48] = flPar.dFT; + tempPar[49] = flPar.dDViscosity; + tempPar[50] = flPar.dDExpCoefficient; + tempPar[51] = flPar.dRnPipe; + tempPar[52] = flPar.dBk; + tempPar[53] = flPar.dRoughNessPipe; + tempPar[54] = flPar.dCdCorrect; + tempPar[55] = 0; +// tempPar[56] = flPar.dVFlowb * 86400; +// tempPar[57] = flPar.dVFlowf * 3600; + tempPar[56] = flPar.dVFlowb ; + tempPar[57] = flPar.dVFlowf ; + tempPar[58] = flPar.dMFlowb; + tempPar[59] = flPar.dEFlowb; + tempPar[60] = flPar.dVelocityFlow; + tempPar[61] = flPar.dPressLost; + tempPar[62] = flPar.dBeta; + + tempPar[63] = gasPar.dMrx; + tempPar[64] = gasPar.dZb; + tempPar[65] = gasPar.dZf; + tempPar[66] = gasPar.dFpv; + tempPar[67] = gasPar.dDb; + tempPar[68] = gasPar.dDf; + tempPar[69] = gasPar.dRhob; + tempPar[70] = gasPar.dRhof; + tempPar[71] = gasPar.dRD_Ideal; + tempPar[72] = gasPar.dRD_Real; + tempPar[73] = gasPar.dHo; + tempPar[74] = gasPar.dH; + tempPar[75] = gasPar.dS; + tempPar[76] = gasPar.dCpi; + tempPar[77] = gasPar.dCp; + tempPar[78] = gasPar.dCv; + tempPar[79] = gasPar.dk; + tempPar[80] = gasPar.dKappa; + tempPar[81] = gasPar.dSOS; + tempPar[82] = gasPar.dCstar; + tempPar[83] = gasPar.dHhvMol; + tempPar[84] = gasPar.dLhvMol; + tempPar[85] = gasPar.dHhvv; + tempPar[86] = gasPar.dLhvv; + tempPar[87] = gasPar.dHhvm; + tempPar[88] = gasPar.dLhvm; + tempPar[89] = gasPar.dZb11062; + tempPar[90] = gasPar.dRhob11062; + tempPar[91] = gasPar.dRhof11062; + tempPar[92] = gasPar.dRD_Ideal11062; + tempPar[93] = gasPar.dRD_Real11062; + tempPar[94] = gasPar.dWobbeIndex; + tempPar[95] = gasPar.Pc; + tempPar[96] = gasPar.TC; + tempPar[97] = gasPar.Bzsx; + tempPar[98] = gasPar.Bzxx; + tempPar[99] = gasPar.TotalC; + tempPar[100] = gasPar.C2; + tempPar[101] = gasPar.C2j; + tempPar[102] = gasPar.C3j; + tempPar[103] = gasPar.C4j; + tempPar[104] = gasPar.C5j; + tempPar[105] = gasPar.C6j; + tempPar[106] = gasPar.C3C4; + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(tempPar[i] + ","); + } + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + + return Result.ok(json); + + } + + @ResponseBody + @GetMapping (value="SDFlowcal") + public Result SDFlowcal(@RequestParam(name="par" ) String [] par) + { + + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.FlowParStruct flPar = new com.ng.ngtools.modules.NG_Cal.FlowParStruct(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + + flPar.dMeterType = (int)tempPar[0]; //流量计类别 + flPar.dCoreType = (int)tempPar[1]; //节流装置类型 + flPar.dFlowCalbz = (int)tempPar[2]; //流量计算标准 + flPar.dZcalbz = (int)tempPar[3]; //压缩因子计算标准 + flPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + flPar.dPb_M = tempPar[5]; //计量参比条件压力 + flPar.dTb_M = tempPar[6]; //计量参比条件温度 + flPar.dPb_E = tempPar[7]; //燃烧参比条件压力 + flPar.dTb_E = tempPar[8]; //燃烧参比条件温度 + flPar.dPatmUnit = (int)tempPar[10]; //当地大气压单位 + flPar.dPatm = MyConvert.Converter("yl", tempPar[9], flPar.dPatmUnit, 0, 4); + //当地大气压 + flPar.dNG_Compents = gasPar.adMixture; //天然气组分 + flPar.dPtmode = (int)tempPar[12]; //取压方式 + flPar.dPipeType = (int)tempPar[13]; //管道类型 + flPar.dPipeD = tempPar[14]; //管道内径 + flPar.dLenUnit = (int)tempPar[15]; //长度单位 + flPar.dPipeDtemp = tempPar[16]; //管道内径参考温度 + flPar.dPileDtempUint = (int)tempPar[17]; //温度单位 + flPar.dPipeMaterial = (int)tempPar[18]; //管道材料 + flPar.dOrificeD = tempPar[19]; //孔板孔径 + flPar.dOrificeUnit = (int)tempPar[20]; //长度单位 + flPar.dOrificeDtemp = tempPar[21]; //孔板内径参考温度 + flPar.dOrificeDtempUnit = (int)tempPar[22]; //温度单位 + flPar.dOrificeMaterial = (int)tempPar[23]; //孔板材料 + flPar.dOrificeSharpness = (int)tempPar[24]; //锐利度系数计算方法 + flPar.dOrificeRk = tempPar[25]; //孔板入口圆弧半径 + flPar.dOrificeRkLenUint = (int)tempPar[26]; //长度单位 + flPar.dPfUnit = (int)tempPar[28]; //压力单位 + flPar.dPf = MyConvert.Converter("yl", tempPar[27], flPar.dPfUnit, 0, 4); //输入压力 + flPar.dPfType = (int)tempPar[29]; //压力类型 + flPar.dTfUnit = (int)tempPar[31]; //温度单位 + flPar.dTf = MyConvert.Converter("wd", tempPar[30], flPar.dTfUnit, 1, 4); //输入温度 + flPar.dMeterFactor = (int)tempPar[37]; //仪表系数 + flPar.dPulseNum = tempPar[32]; //脉冲数 + flPar.dVFlowUnit = (int)tempPar[34]; //体积流量单位 + flPar.dMFlowUnit = (int)tempPar[35]; //质量流量单位 + flPar.dEFlowUnit = (int)tempPar[36]; //能量流量单位 + + + + //将压力换算为绝压 + if (flPar.dPfType == 0) + { + flPar.dPf = flPar.dPf + flPar.dPatm; + } + + gasPar.dCbtj = flPar.dCbtj; + gasPar.dPf = flPar.dPf; + gasPar.dTf = flPar.dTf; + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar); + NG_Cal.Crit(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar2 = new RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar); + RefObject< com.ng.ngtools.modules.NG_Cal.FlowParStruct> tempRef_flPar = new RefObject< com.ng.ngtools.modules.NG_Cal.FlowParStruct>(flPar); + NGFLOW.SdFlowCal(tempRef_gasPar2, tempRef_flPar); + flPar = tempRef_flPar.argValue; + gasPar = tempRef_gasPar2.argValue; + + tempPar[56] = flPar.dVFlowb ; + tempPar[57] = flPar.dVFlowf ; + +// tempPar[56] = flPar.dVFlowb * 86400; +// tempPar[57] = flPar.dVFlowf * 3600; + tempPar[58] = flPar.dMFlowb; + tempPar[59] = flPar.dEFlowb; + tempPar[64] = gasPar.dZb; + tempPar[65] = gasPar.dZf; + + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(tempPar[i] + ","); + } + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + return Result.ok(json); + + } + + @ResponseBody + @GetMapping (value="PZFlowcal") + public Result PZFlowcal(@RequestParam(name="par" ) String [] par) { + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.FlowParStruct flPar = new com.ng.ngtools.modules.NG_Cal.FlowParStruct(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + + flPar.dMeterType = (int)tempPar[0]; //流量计类别 + flPar.dCoreType = (int)tempPar[1]; //节流装置类型 + flPar.dFlowCalbz = (int)tempPar[2]; //流量计算标准 + flPar.dZcalbz = (int)tempPar[3]; //压缩因子计算标准 + flPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + flPar.dPb_M = tempPar[5]; //计量参比条件压力 + flPar.dTb_M = tempPar[6]; //计量参比条件温度 + flPar.dPb_E = tempPar[7]; //燃烧参比条件压力 + flPar.dTb_E = tempPar[8]; //燃烧参比条件温度 + flPar.dPatmUnit = (int)tempPar[10]; //当地大气压单位 + flPar.dPatm = MyConvert.Converter("yl", tempPar[9], flPar.dPatmUnit, 0, 4); + //当地大气压 + flPar.dNG_Compents = gasPar.adMixture; //天然气组分 + flPar.dPtmode = (int)tempPar[12]; //取压方式 + flPar.dPipeType = (int)tempPar[13]; //管道类型 + flPar.dPipeD = tempPar[14] / 1000; //管道内径 + flPar.dLenUnit = (int)tempPar[15]; //长度单位 + flPar.dPipeDtemp = tempPar[16]; //管道内径参考温度 + flPar.dPileDtempUint = (int)tempPar[17]; //温度单位 + flPar.dPipeMaterial = (int)tempPar[18]; //管道材料 + flPar.dOrificeD = tempPar[19] / 1000; //喷嘴喉径换算成米 + flPar.dOrificeUnit = (int)tempPar[20]; //长度单位 + flPar.dOrificeDtemp = tempPar[21]; //孔板内径参考温度 + flPar.dOrificeDtempUnit = (int)tempPar[22]; //温度单位 + flPar.dOrificeMaterial = (int)tempPar[23]; //孔板材料 + flPar.dOrificeSharpness = (int)tempPar[24]; //锐利度系数计算方法 + flPar.dOrificeRk = tempPar[25]; //孔板入口圆弧半径 + flPar.dOrificeRkLenUint = (int)tempPar[26]; //长度单位 + flPar.dPfUnit = (int)tempPar[28]; //压力单位 + flPar.dPf = MyConvert.Converter("yl", tempPar[27], flPar.dPfUnit, 0, 4); //输入压力 + flPar.dPfType = (int)tempPar[29]; //压力类型 + flPar.dTfUnit = (int)tempPar[31]; //温度单位 + flPar.dTf = MyConvert.Converter("wd", tempPar[30], flPar.dTfUnit, 1, 4); //输入温度 + flPar.dDpUnit = (int)tempPar[33]; //压力单位 + flPar.dDp = MyConvert.Converter("yl", tempPar[32], flPar.dDpUnit, 0, 4); //输入压力; //输入差压 + flPar.dVFlowUnit = (int)tempPar[34]; //体积流量单位 + flPar.dMFlowUnit = (int)tempPar[35]; //质量流量单位 + flPar.dEFlowUnit = (int)tempPar[36]; //能量流量单位 + flPar.dCd = tempPar[37]; //流出系数 + + + //将压力换算为绝压 + if (flPar.dPfType == 0) + { + flPar.dPf = flPar.dPf + flPar.dPatm; + } + + gasPar.dCbtj = flPar.dCbtj; + gasPar.dPf = flPar.dPf; + gasPar.dTf = flPar.dTf; + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Crit(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + RefObject tempRef_gasPar2 = new RefObject(gasPar); + RefObject tempRef_flPar = new RefObject(flPar); + NGFLOW.NozellFLowCal(tempRef_gasPar2, tempRef_flPar); + flPar = tempRef_flPar.argValue; + gasPar = tempRef_gasPar2.argValue; + + tempPar[56] = flPar.dVFlowb ; + tempPar[57] = flPar.dVFlowf; +// tempPar[56] = flPar.dVFlowb * 86400; +// tempPar[57] = flPar.dVFlowf * 3600; + tempPar[58] = flPar.dMFlowb; + tempPar[59] = flPar.dEFlowb; + + tempPar[64] = gasPar.dZb; + tempPar[65] = gasPar.dZf; + tempPar[80] = gasPar.dKappa; + tempPar[82] = gasPar.dCstar; + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(tempPar[i] + ","); + } + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + return Result.ok(json); + } + + @ResponseBody + @GetMapping (value="ParCal") + private Result ParCal(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + + int dPfUnit = (int)tempPar[28]; //压力单位 + gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力 + int dPfType = (int)tempPar[29]; //压力类型 + int dTfUnit = (int)tempPar[31]; //温度单位 + gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度 + + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + + //将压力换算为绝压 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NGCal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NGCal.Crit(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + tempPar[63] = gasPar.dMrx; + tempPar[64] = gasPar.dZb; + tempPar[65] = gasPar.dZf; + tempPar[66] = gasPar.dFpv; + tempPar[67] = gasPar.dDb; + tempPar[68] = gasPar.dDf; + tempPar[69] = gasPar.dRhob; + tempPar[70] = gasPar.dRhof; + tempPar[71] = gasPar.dRD_Ideal; + tempPar[72] = gasPar.dRD_Real; + tempPar[73] = gasPar.dHo; + tempPar[74] = gasPar.dH; + tempPar[75] = gasPar.dS; + tempPar[76] = gasPar.dCpi; + tempPar[77] = gasPar.dCp; + tempPar[78] = gasPar.dCv; + tempPar[79] = gasPar.dk; + tempPar[80] = gasPar.dKappa; + tempPar[81] = gasPar.dSOS; + tempPar[82] = gasPar.dCstar; + tempPar[83] = gasPar.dHhvMol; + tempPar[84] = gasPar.dLhvMol; + tempPar[85] = gasPar.dHhvv; + tempPar[86] = gasPar.dLhvv; + tempPar[87] = gasPar.dHhvm; + tempPar[88] = gasPar.dLhvm; + tempPar[89] = gasPar.dZb11062; + tempPar[90] = gasPar.dRhob11062; + tempPar[91] = gasPar.dRhof11062; + tempPar[92] = gasPar.dRD_Ideal11062; + tempPar[93] = gasPar.dRD_Real11062; + tempPar[94] = gasPar.dWobbeIndex; + tempPar[95] = gasPar.Pc; + tempPar[96] = gasPar.TC; + tempPar[97] = gasPar.Bzsx; + tempPar[98] = gasPar.Bzxx; + tempPar[99] = gasPar.TotalC; + tempPar[100] = gasPar.C2; + tempPar[101] = gasPar.C2j; + tempPar[102] = gasPar.C3j; + tempPar[103] = gasPar.C4j; + tempPar[104] = gasPar.C5j; + tempPar[105] = gasPar.C6j; + tempPar[106] = gasPar.C3C4; + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(String.valueOf(tempPar[i]) + ","); + } + + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + return Result.ok(json); + } + + @ResponseBody + @GetMapping (value="GSCVCal") + private Result GSCVCal(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + + int dPfUnit = (int)tempPar[28]; //压力单位 + gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力 + int dPfType = (int)tempPar[29]; //压力类型 + int dTfUnit = (int)tempPar[31]; //温度单位 + gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度 + + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + + //将压力换算为绝压 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + double dV = tempPar[37]; + double dVCNG = dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb); + + tempPar[63] = dVCNG; + tempPar[64] = dVCNG * gasPar.dRhob; + + + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(String.valueOf(tempPar[i]) + ","); + } + + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + return Result.ok(json); + } + @ResponseBody + @GetMapping (value="GSCVTCal") + private Result GSCVTCal(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + int dPfUnit = (int)tempPar[28]; //压力单位 + int dTfUnit = (int)tempPar[31]; //温度单位 + int dPfType = (int)tempPar[29]; //压力类型 + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + + + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + + double dPstart = tempPar[27]; + double dTstart = tempPar[30]; + + double dV = tempPar[37]; + + double dPend = tempPar[40]; + double dTend = tempPar[41]; + double dPjg = tempPar[38]; + double dTjg = tempPar[39]; + + + int Ccount =Integer.parseInt(String.valueOf(Math.round((dPend - dPstart) / dPjg ))) +1; + int Rcount = Integer.parseInt( String.valueOf(Math.round((dTend - dTstart) / dTjg))) + 1; + + double[] arrP = new double[Ccount]; + double[] arrT = new double[Rcount]; + + String [][] arrGSCV=new String[Rcount+1][Ccount+1]; +arrGSCV[0][0]="T-V-P"; + + for (int i = 0; i < Ccount; i++) + { + arrP[i] = dPstart + i * dPjg; + arrGSCV[0][i+1]=String.valueOf(arrP[i]) + " MPa"; + } + for (int i = 0; i < Rcount; i++) + { + arrT[i] = dTstart + i * dTjg; + } + + int totalNum = Ccount * Rcount; + int jsnum = 0; + int dbPerJd = 0; + + + for (int i = 0; i < Rcount; i++) + { + + arrGSCV[i+1][0]= arrT[i] + " ℃"; + + for (int j = 0; j < Ccount; j++) + { + //将压力换算为绝压 + gasPar.dPf = MyConvert.Converter("yl", arrP[j], dPfUnit, 0, 4); //输入压力 + gasPar.dTf = MyConvert.Converter("wd", arrT[i], dTfUnit, 1, 4); //输入温度 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + DecimalFormat df=new DecimalFormat("0.####"); + arrGSCV[i+1][j+1]= (String.valueOf(df.format(dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb)))); + jsnum += 1; + dbPerJd = jsnum * 100 / totalNum; + } + } + + return Result.ok(arrGSCV); + } + @ResponseBody + @GetMapping (value="ZTCal") + private Result ZTCal(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + gasPar.adMixture = ngCom; + UnitConvert MyConvert = new UnitConvert(); + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + int dPfUnit = (int)tempPar[28]; //压力单位 + int dTfUnit = (int)tempPar[31]; //温度单位 + int dPfType = (int)tempPar[29]; //压力类型 + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + double dPstart = tempPar[27]; + double dTstart = tempPar[30]; + + + double dPend = tempPar[39]; + double dTend = tempPar[40]; + double dPjg = tempPar[37]; + double dTjg = tempPar[38]; + + int Ccount =Integer.parseInt(String.valueOf(Math.round((dPend - dPstart) / dPjg ))) +1; + int Rcount = Integer.parseInt( String.valueOf(Math.round((dTend - dTstart) / dTjg))) + 1; + + double[] arrP = new double[Ccount]; + double[] arrT = new double[Rcount]; + + String [][] arrZ=new String[Rcount+1][Ccount+1]; + +arrZ[0][0]="T_Z_P"; + + for (int i = 0; i < Ccount; i++) + { + arrP[i] = dPstart + i * dPjg; + arrZ[0][i+1]= arrP[i] + " MPa"; + } + for (int i = 0; i < Rcount; i++) + { + arrT[i] = dTstart + i * dTjg; + } + + int totalNum = Ccount * Rcount; + int jsnum = 0; + float dbPerJd = 0; + for (int i = 0; i < Rcount; i++) + { + arrZ[i+1][0]= (String.valueOf(arrT[i])) + " ℃"; + for (int j = 0; j < Ccount; j++) + { + //将压力换算为绝压 + gasPar.dPf = MyConvert.Converter("yl", arrP[j], dPfUnit, 0, 4); //输入压力 + gasPar.dTf = MyConvert.Converter("wd", arrT[i], dTfUnit, 1, 4); //输入温度 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + DecimalFormat df=new DecimalFormat("0.####"); + arrZ[i+1][j+1]= (String.valueOf(df.format( gasPar.dZf))); + jsnum += 1; + dbPerJd = jsnum * 100 / totalNum; + + + } + } + return Result.ok(arrZ); + } + + @ResponseBody + @GetMapping (value="ZXCCal") + private Result ZXCCal(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + + int dPfUnit = (int)tempPar[28]; //压力单位 + int dPfType = (int)tempPar[29]; //压力类型 + int dTfUnit = (int)tempPar[31]; //温度单位 + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力 + gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度 + + + //将压力换算为绝压 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + double dV = tempPar[37]; + + double dVNG = dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb); + + //最终压力温度计算 + gasPar.dPf = MyConvert.Converter("yl", tempPar[38], dPfUnit, 0, 4); //输入压力 + gasPar.dTf = MyConvert.Converter("wd", tempPar[39], dTfUnit, 1, 4); //输入温度 + + + //将压力换算为绝压 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + RefObject tempRef_gasPar2 = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar2, 0.0); + gasPar = tempRef_gasPar2.argValue; + + double dVNGe = dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb); + + + tempPar[63] = dVNGe - dVNG; + tempPar[64] = (dVNGe - dVNG) * gasPar.dRhob; + + + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(String.valueOf(tempPar[i]) + ","); + } + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + return Result.ok(json); + } + + @ResponseBody + @GetMapping (value="LNGQhjs") + private Result LNGQhjs(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + FlowCal NGFLOW = new FlowCal(); + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + + gasPar.adMixture = ngCom; + + UnitConvert MyConvert = new UnitConvert(); + + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + + int dPfUnit = (int)tempPar[28]; //压力单位 + int dPfType = (int)tempPar[29]; //压力类型 + int dTfUnit = (int)tempPar[31]; //温度单位 + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力 + gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度 + + + //将压力换算为绝压 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + double dMLNG = tempPar[37]; + double dVLNG=dMLNG/gasPar.dRhob; + + + tempPar[63] = dVLNG; + tempPar[69] = gasPar.dRhob; + + + + StringBuilder Json = new StringBuilder(); + Json.append("["); + for (int i = 0; i < tempPar.length; i++) + { + Json.append(String.valueOf(tempPar[i]) + ","); + } + String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString(); + return Result.ok(json); + } + + + + @ResponseBody + @GetMapping (value="SQGYjs") + private Result SQGYjs(String[] par) + { + + double[] ngCom = new double[21]; + double[] tempPar = new double[110]; + for (int i = 0; i < par.length; i++) + { + if (i != 11) + { + tempPar[i] = Double.parseDouble(par[i]); + } + else + { + for (int j = 0; j < 21; j++) + { + ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100; + } + } + } + com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT(); + gasPar.adMixture = ngCom; + UnitConvert MyConvert = new UnitConvert(); + gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件 + int dPfUnit = (int)tempPar[28]; //压力单位 + int dPfType = (int)tempPar[29]; //压力类型 + int dTfUnit = (int)tempPar[31]; //温度单位 + int dPatmUnit = (int)tempPar[10]; //当地大气压单位 + double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4); + ; //当地大气压 + gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力 + gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度 + + + //将压力换算为绝压 + if (dPfType == 0) + { + gasPar.dPf = gasPar.dPf + dPatm; + } + + switch (gasPar.dCbtj) + { + case 2: + gasPar.dPb = 101325; + gasPar.dTb = 273.15; + break; + case 1: + gasPar.dPb = 101325; + gasPar.dTb = 288.15; + break; + case 0: + gasPar.dPb = 101325; + gasPar.dTb = 293.15; + break; + } + + com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal(); + RefObject tempRef_gasPar = new RefObject(gasPar); + NG_Cal.Zcal(tempRef_gasPar, 0.0); + gasPar = tempRef_gasPar.argValue; + + double pipleDw=Double.parseDouble(par[40]) ; //管道外径 + double pipleBh=Double.parseDouble(par[41]) ; //管道壁厚 + double pipleDn=(pipleDw-2*pipleBh)/10; + double pipleL=Double.parseDouble(par[42]) ; //管道长度 + double startP=Double.parseDouble(par[43]) ; //起点压力 + double endP=Double.parseDouble(par[44]) ; //终点压力 + double flowSq=Double.parseDouble(par[45]); //输气量 + String JSGS= par[38]; //计算公式 + double exlxs=XLXS(pipleDw); + + double ZRDTL = gasPar.dZf * gasPar.dRD_Real * gasPar.dTf * pipleL; + double ZRDTL051 = gasPar.dZf * Math.pow(gasPar.dRD_Real, 0.961) * gasPar.dTf * pipleL; + double PowZRDTL05 = Math.pow(ZRDTL, 0.5); + double PowZRDTL051 = Math.pow(ZRDTL051, 0.51); + double powDn83 = Math.pow(pipleDn, 8 / 3); + double powDn253 = Math.pow(pipleDn, 2.53); + double powDn27 = Math.pow(pipleDn, 2.7); + double powDn26 = Math.pow(pipleDn, 2.6); + double powPsPe05 = Math.pow((startP * startP - endP * endP), 0.5); + double powPsPe051 = Math.pow((startP * startP - endP * endP), 0.51); + double result=0; + String jsCs=par[37]; + switch (jsCs) + { + case "0": //输气能力 + switch (JSGS) { + case "0": ////10.8432=5033/10^(8/3) + result = 5033 * powDn83 * powPsPe05 / PowZRDTL05; + break; + case "1": //24.8244=11522/10^(8/3) + //alert(Exlxs + "_" + powDn253 + "_" + powPsPe051 + "_" + PowZRDTL051 + "_" + L + "_" + Z + "_" + Dn + "_" + Q); + result = 11522 * exlxs * powDn253 * powPsPe051 / PowZRDTL051; + break; + case "2": //24.8244=11522/10^(8/3) + result = 4464.2 * powDn27 * powPsPe05 / PowZRDTL05; + break; + case "3": //24.8244=11522/10^(8/3) + result = 6775.6 * exlxs * 1 * powDn26 * powPsPe05 / PowZRDTL05; + break; + default: + } + break; + case "1": //管道内径计算 + + switch (JSGS) { + case "0": //10.8432=5033/10^(8/3) + result = Math.pow(flowSq / (5033 * powPsPe05 / PowZRDTL05), (double) 3 / 8) * 10; //* Math.pow(Dn, 8 / 3) + break; + case "1": //24.8244=11522/10^(8/3) + + //result = Math.pow(Q / (11522 * powPsPe051 / PowZRDTL051), 1 / 2.53)*10; //* Math.pow(Dn, 2.53) + //Exlxs = XLXS(parseFloat(result)); + result = Math.pow(flowSq / (11522 * exlxs * powPsPe051 / PowZRDTL051), 1 / 2.53) * 10; //* Math.pow(Dn, 2.53) + + break; + case "2": //24.8244=11522/10^(8/3) + result = Math.pow(flowSq / (4464.2 * powPsPe05 / PowZRDTL05), 1 / 2.7) * 10; //* Math.pow(Dn, 2.7) + break; + case "3": //24.8244=11522/10^(8/3) + result = Math.pow(flowSq / (6775.6 * exlxs * 1 * powPsPe05 / PowZRDTL05), 1 / 2.6) * 10; //* Math.pow(Dn, 2.6) + break; + + + default: + } + break; + + case "2": //管道长度 + + + switch (JSGS) { + case "0": //10.8432=5033/10^(8/3) + result = Math.pow(5033 * powDn83 * powPsPe05 / PowZRDTL05 / flowSq, 2); + break; + case "1": //24.8244=11522/10^(8/3) + result = Math.pow(11522 * exlxs * powDn253 * powPsPe051 / PowZRDTL051 / flowSq, 1 / 0.51); + break; + case "2": //24.8244=11522/10^(8/3) + result = Math.pow(4464.2 * powDn27 * powPsPe05 / PowZRDTL05 / flowSq, 2); + break; + case "3": //24.8244=11522/10^(8/3) + result = Math.pow(6775.6 * exlxs * 1 * powDn26 * powPsPe05 / PowZRDTL05 / flowSq, 2); + break; + + + default: + } + + break; + + + case "3": //起点压力 + + //var powPsPe05 = Math.pow((Ps * Ps - Pe * Pe), 0.5); + //var powPsPe051 = Math.pow((Ps * Ps - Pe * Pe), 0.51); + + switch (JSGS) { + case "0": //10.8432=5033/10^(8/3) + result = Math.sqrt(Math.pow(flowSq / (5033 * powDn83 / PowZRDTL05), 2) + endP * endP); + break; + case "1": //24.8244=11522/10^(8/3) + result = Math.sqrt(Math.pow(flowSq / (11522 * exlxs * powDn253 / PowZRDTL051), 1 / 0.51) + endP * endP);; + break; + case "2": //24.8244=11522/10^(8/3) + result = Math.sqrt(Math.pow(flowSq / (4464.2 * powDn27 / PowZRDTL05), 2) + endP * endP); + break; + case "3": //24.8244=11522/10^(8/3) + result = Math.sqrt(Math.pow(flowSq / (6775.6 * exlxs * 1 * powDn26 / PowZRDTL05), 2) + endP * endP); + break; + + + default: + } + + result = result - 0.101325; + + break; + + case "4": //终点压力 + + + + switch (JSGS) { + case "0": //10.8432=5033/10^(8/3) + result = Math.sqrt(startP * startP - Math.pow(flowSq / (5033 * powDn83 / PowZRDTL05), 2)); + break; + case "1": //24.8244=11522/10^(8/3) + result = Math.sqrt(startP * startP - Math.pow(flowSq / (11522 * exlxs * powDn253 / PowZRDTL051), 1 / 0.51)); + break; + case "2": //24.8244=11522/10^(8/3) + result = Math.sqrt(startP * startP - Math.pow(flowSq / (4464.2 * powDn27 / PowZRDTL05), 2)); + break; + case "3": //24.8244=11522/10^(8/3) + result = Math.sqrt(startP * startP - Math.pow(flowSq / (6775.6 * exlxs * 1 * powDn26 / PowZRDTL05), 2)); + break; + + + default: + } + + result = result - 0.101325; + + break; + + case "5": //管存量 + double pipleV = 3.1415926 * pipleDn * pipleDn * pipleL * 1000 / 40000; + //alert(Dn +"_"+V); + result = pipleV * ((startP + endP) / 2) * gasPar.dZb * 293.15 / gasPar.dZf / gasPar.dTf / 0.101325; + } + return Result.ok(String.valueOf(result)); + } + + private double XLXS(double pD){ + + //alert(pD); + if (pD > 0 & pD < 300) { + return 0.84; + } + else if (pD >= 300 & pD < 400) { + return 0.85; + } + else if (pD >= 400 & pD < 500) { + return 0.84; + } + else if (pD >= 500 & pD < 600) { + return 0.87; + } + else if (pD >= 700 & pD < 800) { + return 0.9; + } + else if (pD >= 800 & pD < 1000) { + return 0.91; + } + else { + return 0.85; + } + + + + + } + +} diff --git a/src/main/java/com/ng/ngtools/Tools/testAPI.java b/src/main/java/com/ng/ngtools/Tools/testAPI.java new file mode 100644 index 0000000..c41c37a --- /dev/null +++ b/src/main/java/com/ng/ngtools/Tools/testAPI.java @@ -0,0 +1,45 @@ +package com.ng.ngtools.Tools; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +/* + * API支持HTTPS/HTTP测试* + * + * @author JustryDeng + * @DATE 2018年9月13日上午8:36:29 + */ +@RestController +public class testAPI { + /* + *HTTP/HTTPS发送get请求 + * + *@DATE 2018年9月13日上午10:21:07*/ + @GetMapping("/get") + public String testMethodGet(HttpServletRequest request) {//获取URL协议 + String requestURL = request.getRequestURL().toString(); + String protocol = requestURL.split("://")[0];//获取当前URL连接中的端口 + Integer port = request.getServerPort(); + return "get --->" + protocol + "\t" + port; + } + + //HTTP/HTTPS发送post请求 + //@DATE 2018年9月13日上午10:21:43 + + @PostMapping("/post") + public String testMethodPost(HttpServletRequest request,@RequestBody String bodystring){ +//获取URL协议 + String requestURL =request.getRequestURL().toString(); + String protocol =requestURL.split("://")[0]; +//获取当前URL连接中的端口 + Integer port =request.getServerPort(); + return "post --->"+protocol +"\t"+port +"\n"+bodystring; + } + + +} + + diff --git a/src/main/java/com/ng/ngtools/common/Result.java b/src/main/java/com/ng/ngtools/common/Result.java new file mode 100644 index 0000000..4f49ca5 --- /dev/null +++ b/src/main/java/com/ng/ngtools/common/Result.java @@ -0,0 +1,103 @@ +package com.ng.ngtools.common; + +import com.ng.ngtools.common.constant.CommonConstant; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +@ApiModel(value="接口返回对象", description="接口返回对象") +public class Result implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 成功标志 + */ + @ApiModelProperty(value = "成功标志") + private boolean success = true; + + /** + * 返回处理消息 + */ + @ApiModelProperty(value = "返回处理消息") + private String message = "操作成功!"; + + /** + * 返回代码 + */ + @ApiModelProperty(value = "返回代码") + private Integer code = 0; + + /** + * 返回数据对象 data + */ + @ApiModelProperty(value = "返回数据对象") + private T result; + + /** + * 时间戳 + */ + @ApiModelProperty(value = "时间戳") + private long timestamp = System.currentTimeMillis(); + + public Result() { + + } + public Result success(String message) { + this.message = message; + this.code = CommonConstant.SC_OK_200; + this.success = true; + return this; + } + + + public static Result ok() { + Result r = new Result(); + r.setSuccess(true); + r.setCode(CommonConstant.SC_OK_200); + r.setMessage("成功"); + return r; + } + + public static Result ok(String msg) { + Result r = new Result(); + r.setSuccess(true); + r.setCode(CommonConstant.SC_OK_200); + r.setResult(msg); + r.setMessage(msg); + return r; + } + + public static Result ok(Object data) { + Result r = new Result(); + r.setSuccess(true); + r.setCode(CommonConstant.SC_OK_200); + r.setResult(data); + return r; + } + + public static Result error(String msg) { + return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg); + } + + public static Result error(int code, String msg) { + Result r = new Result(); + r.setCode(code); + r.setMessage(msg); + r.setSuccess(false); + return r; + } + + public Result error500(String message) { + this.message = message; + this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500; + this.success = false; + return this; + } + + + + +} diff --git a/src/main/java/com/ng/ngtools/common/constant/CommonConstant.java b/src/main/java/com/ng/ngtools/common/constant/CommonConstant.java new file mode 100644 index 0000000..09cefb6 --- /dev/null +++ b/src/main/java/com/ng/ngtools/common/constant/CommonConstant.java @@ -0,0 +1,8 @@ +package com.ng.ngtools.common.constant; + +public interface CommonConstant { + /** {@code 200 OK} (HTTP/1.0 - RFC 1945) */ + Integer SC_OK_200 = 200; + /** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */ + Integer SC_INTERNAL_SERVER_ERROR_500 = 500; +} diff --git a/src/main/java/com/ng/ngtools/demos/web/BasicController.java b/src/main/java/com/ng/ngtools/demos/web/BasicController.java new file mode 100644 index 0000000..172fcdd --- /dev/null +++ b/src/main/java/com/ng/ngtools/demos/web/BasicController.java @@ -0,0 +1,67 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ng.ngtools.demos.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class BasicController { + + // http://127.0.0.1:8080/hello?name=lisi + @RequestMapping("/hello") + @ResponseBody + public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) { + return "Hello " + name; + } + + // http://127.0.0.1:8080/user + @RequestMapping("/user") + @ResponseBody + public User user() { + User user = new User(); + user.setName("theonefx"); + user.setAge(666); + return user; + } + + // http://127.0.0.1:8080/save_user?name=newName&age=11 + @RequestMapping("/save_user") + @ResponseBody + public String saveUser(User u) { + return "user will save: name=" + u.getName() + ", age=" + u.getAge(); + } + + // http://127.0.0.1:8080/html + @RequestMapping("/html") + public String html(){ + return "index.html"; + } + + @ModelAttribute + public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name + , @RequestParam(name = "age", defaultValue = "12") Integer age, User user) { + user.setName("zhangsan"); + user.setAge(18); + } +} diff --git a/src/main/java/com/ng/ngtools/modules/Detail.java b/src/main/java/com/ng/ngtools/modules/Detail.java new file mode 100644 index 0000000..ed8cf41 --- /dev/null +++ b/src/main/java/com/ng/ngtools/modules/Detail.java @@ -0,0 +1,1546 @@ +package com.ng.ngtools.modules; + + /************************************************************************* + * File:detail.h + * Description:Header file for the 'Detail' class + *See 'detail.cpp' for the implementation. + * Version:ver 1.72002.11.17 + * Author:W.B. Peterson + *Revisions: + *Copyright (c) 2002 American Gas Association + **************************************************************************/ + + + public class Detail + { + + + + // member data + private int iNCC; // number of components + private final int[] aiCID = new int[21]; // component IDs + //five history variables are used to improve efficiency during repeated calculations + private double dOldMixID; // mixture ID from previous calc + private double dOldPb; // Pb from previous calc + private double dOldTb; // Tb from previous calc + private double dOldPf; // Pf from previous calc + private double dOldTf; // Tf from previous calc + //EOS parameters from table 4, column 1 + private final double[] adAn = new double[58]; + private final double[] adUn = new double[58]; + // characterization parameters from table 5 + private final double[] dMri = new double[21]; // molecular weight of ith component + private final double[] dEi = new double[21]; // characteristic energy parameter for ith component + private final double[] dKi = new double[21]; // size parameter for ith component - m^3/kg-mol ^1/3 + private final double[] dGi = new double[21]; // orientation parameter + private final double[] dQi = new double[21]; // quadrupole parameter + private final double[] dFi = new double[21]; // high temperature parameter + private final double[] dSi = new double[21]; // dipole parameter + private final double[] dWi = new double[21]; // association parameter + private final double[][] dEij = new double[21][21]; // virial coefficient energy binary interaction parm + private final double[][] dUij = new double[21][21]; // binary interaction parameter for conformal energy + private final double[][] dKij = new double[21][21]; // binary interaction parameter for size + private final double[][] dGij = new double[21][21]; // binary interaction parameter for orientation + private final double[][] adTable6Eij = new double[21][21]; // Table 6 constants + private final double[][] adTable6Uij = new double[21][21]; // Table 6 constants + private final double[][] adTable6Kij = new double[21][21]; // Table 6 constants + private final double[][] adTable6Gij = new double[21][21]; // Table 6 constants + private final double[] adTable5Qi = new double[21]; // table 5 constants + private final double[] adTable5Fi = new double[21]; // table 5 constants + private final double[] adTable5Si = new double[21]; // table 5 constants + private final double[] adTable5Wi = new double[21]; // table 5 constants + private final double[] dXi = new double[21]; // mole fraction of component i + private double dPCalc; // pressure calculated by pdetail() + private double dT; // current temperature + private double dP; // current pressure + private double dRhoTP; // molar density at T & P + private double dB; // 2nd virial coefficient, B + private final double[] adBcoef = new double[18]; // 18 coefficients to calculate B + private final double[] adFn = new double[58]; // function for coefficients of density + private final double[] fx = new double[58]; // modified coefficients used for 3 derivs + private double dU; // mixture energy parameter + private double dKp3; // mixture size parameter ^3 + private double dW; // mixture orientation parameter + private double dQp2; // mixture quadrupole parameter ^2 + private double dF; // high temperature parameter + private double dRho; // molar density + private double dRhoL; // low density used in braket function + private double dRhoH; // high density used in braket function + private double dPRhoL; // low pressure used in braket function + private double dPRhoH; // high pressure used in braket function + + //public variables also used for advanced fluid property calculations + public double dZ; // current compressibility + public double ddZdT; // first partial derivative of Z wrt T + + public double dd2ZdT2; // second partial derivative of Z wrt T + public double ddZdD; // first partial derivative of Z wrt molar density + public double ddBdT; // first partial derivative of B wrt T + public double dd2BdT2; // second partial derivative of B wrt T + + + /************************************************************************** + *Function:Detail() + *Arguments:void + *Returns: + *Purpose:default constructor; includes initialization of + *history-sensitive variables & data tables 4 and 6 + *Revisions: + **************************************************************************/ + public Detail() + { + //initialize history-sensitive variables + dOldMixID = 0.0; // mixture ID from previous calc + dOldPb = 0.0; // base pressure from previous calc + dOldTb = 0.0; // base temperature from previous calc + dOldPf = 0.0; // flowing pressure from previous calc + dOldTf = 0.0; // flowing temperature from previous calc + + //initialize gas component array used within this class + for (int i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + dXi[i] = 0; + } + // function table() populates tables of static constants + table(); + + } // Detail() + + + /************************************************************************** + *Function:compositionchange() + *Arguments:GasPropsSTRUCT * + *Returns:void + *Purpose:Compares new composition to old by creating a semi-unique + *numerical ID. It is possible but very unlikely that 2 + *sequential & different compositions will produce the same ID + *Revisions: + **************************************************************************/ + + public final boolean compositionchange( com.ng.ngtools.tangible.RefObject ptAGA10) + { + double dMixID = 0.0; + int i; + + // generate the numerical ID for the composition + + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + dMixID += ((i + 2) * ptAGA10.argValue.adMixture[i]); + } + + // update the history variable, if different from previous + if (dMixID != dOldMixID) + { + dOldMixID = dMixID; + return true; + } + else + { + return false; + } + + } // compositionchange() + + + /************************************************************************** + + *Function:Run() + *Arguments:GasPropsSTRUCT * + *Returns:void + *Purpose:public method to coordinate and run the full calc sequence + *Revisions: + **************************************************************************/ + + public final void Run(com.ng.ngtools.tangible.RefObject ptAGA10) + { + int i; + // Check for gas composition change + ptAGA10.argValue.bForceUpdate = (ptAGA10.argValue.bForceUpdate || compositionchange(ptAGA10)); + // assign component IDs and values + if (ptAGA10.argValue.bForceUpdate) + { + iNCC = -1; + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + if (ptAGA10.argValue.adMixture[i] > 0.0) + { + iNCC = iNCC + 1; + aiCID[iNCC] = i; + dXi[iNCC] = ptAGA10.argValue.adMixture[i]; + } + } + iNCC = iNCC + 1; + //calculate composition dependent quantities; ported from original + //FORTRAN functions paramdl() and chardl() + paramdl(); + chardl(ptAGA10); + } + + //evaluate T & P dependent parms at base pressure and temperature, + //but only if necessary + if ((Math.abs(ptAGA10.argValue.dPb - dOldPb) > NG_Cal.P_CHG_TOL) || (Math.abs(ptAGA10.argValue.dTb - dOldTb) > NG_Cal.T_CHG_TOL) || (ptAGA10.argValue.bForceUpdate)) + { + dP = ptAGA10.argValue.dPb * 1.0e-6; // AGA 8 uses MPa internally + dT = ptAGA10.argValue.dTb; + //calculate temperature dependent parms + temp(); + //determine molar density + ddetail(ptAGA10); + ptAGA10.argValue.dDb = dRho; + //determine compressibility + ptAGA10.argValue.dZb = zdetail(dRho); // calculate mass density + dRhoTP = (dP * ptAGA10.argValue.dMrx) / (ptAGA10.argValue.dZb * NG_Cal.RGASKJ * dT); + //calculate relative density + relativedensity(ptAGA10); + //copy density to data structure member + ptAGA10.argValue.dRhob = dRhoTP; + //update history and clear the ForceUpdate flag + dOldTb = ptAGA10.argValue.dTb; + dOldPb = ptAGA10.argValue.dPb; + ptAGA10.argValue.bForceUpdate = true; + } + //repeat the process using flowing conditions + //begin by loading P & T from data structure + //AGA 8 uses MPa internally; converted from Pa here + dP = ptAGA10.argValue.dPf * 1.0e-6; + dT = ptAGA10.argValue.dTf; + //check whether to calculate temperature dependent parms + if ((Math.abs(ptAGA10.argValue.dTf - dOldTf) > NG_Cal.T_CHG_TOL) || (ptAGA10.argValue.bForceUpdate)) + { + //if temperature has changed, we must follow through + temp(); + //force ForceUpdate flag to true + ptAGA10.argValue.bForceUpdate = true; + } + + // check whether to calculate other parms + + if ((Math.abs(ptAGA10.argValue.dPf - dOldPf) > NG_Cal.P_CHG_TOL) || (ptAGA10.argValue.bForceUpdate)) + { + //determine molar density + ddetail(ptAGA10); + ptAGA10.argValue.dDf = dRho; + //determine compressibility + ptAGA10.argValue.dZf = zdetail(dRho); + //calculate mass density + dRhoTP = (dP * ptAGA10.argValue.dMrx) / (ptAGA10.argValue.dZf * NG_Cal.RGASKJ * dT); + //copy density to data structure member + ptAGA10.argValue.dRhof = dRhoTP; + //update history + dOldTf = ptAGA10.argValue.dTf; + dOldPf = ptAGA10.argValue.dPf; + } + + //calculate legacy factor Fpv + //NOTE: as implemented here, Fpv is not constrained to 14.73 psi and 60F + if ((ptAGA10.argValue.dZb > 0.0) && (ptAGA10.argValue.dZf > 0.0)) + { + ptAGA10.argValue.dFpv = Math.sqrt(ptAGA10.argValue.dZb / ptAGA10.argValue.dZf); + } + + else + { + //if either Zb or Zf is zero at this point, we have a serious unexpected problem + ptAGA10.argValue.dFpv = ptAGA10.argValue.dZb = ptAGA10.argValue.dZf = 0.0; + ptAGA10.argValue.lStatus = NG_Cal.GENERAL_CALCULATION_FAILURE; + } + + //we are now up to date; toggle off the update flag + + ptAGA10.argValue.bForceUpdate = false; + } // Run() + + /************************************************************************** + + *Function:table() + *Arguments:void + *Returns:void + *Purpose:builds tables of constants + *Revisions: + **************************************************************************/ + + //Tables 4 and 6 are filled only during object initialization. + + // + //component ID's, mapped to each species supported by AGA Report#8 + //1- methane8- hydrogen15- n-hexane + //2- nitrogen9- carbon monoxide16- n-heptane + //3- carbon dioxide10- oxygen17- n-octane + //4- ethane11- i-butane18- n-nonane + //5- propane12- n-butane19- n-decane + //6- water13- i-pentane20- helium + //7- hydrogen sulfide14- n-pentane21- argon + + public final void table() + { + int j, k; + + // 58 constants from table 4 - column A(n) + adAn[0] = 0.153832600; + adAn[1] = 1.341953000; + adAn[2] = -2.998583000; + adAn[3] = -0.048312280; + adAn[4] = 0.375796500; + adAn[5] = -1.589575000; + adAn[6] = -0.053588470; + adAn[7] = 0.886594630; + adAn[8] = -0.710237040; + adAn[9] = -1.471722000; + adAn[10] = 1.321850350; + adAn[11] = -0.786659250; + adAn[12] = 2.29129E-09; + adAn[13] = 0.157672400; + adAn[14] = -0.436386400; + adAn[15] = -0.044081590; + adAn[16] = -0.003433888; + adAn[17] = 0.032059050; + adAn[18] = 0.024873550; + adAn[19] = 0.073322790; + adAn[20] = -0.001600573; + adAn[21] = 0.642470600; + adAn[22] = -0.416260100; + adAn[23] = -0.066899570; + adAn[24] = 0.279179500; + adAn[25] = -0.696605100; + adAn[26] = -0.002860589; + adAn[27] = -0.008098836; + adAn[28] = 3.150547000; + adAn[29] = 0.007224479; + adAn[30] = -0.705752900; + adAn[31] = 0.534979200; + adAn[32] = -0.079314910; + adAn[33] = -1.418465000; + adAn[34] = -5.99905E-17; + adAn[35] = 0.105840200; + adAn[36] = 0.034317290; + adAn[37] = -0.007022847; + adAn[38] = 0.024955870; + adAn[39] = 0.042968180; + adAn[40] = 0.746545300; + adAn[41] = -0.291961300; + adAn[42] = 7.294616000; + adAn[43] = -9.936757000; + adAn[44] = -0.005399808; + adAn[45] = -0.243256700; + adAn[46] = 0.049870160; + adAn[47] = 0.003733797; + adAn[48] = 1.874951000; + adAn[49] = 0.002168144; + adAn[50] = -0.658716400; + adAn[51] = 0.000205518; + adAn[52] = 0.009776195; + adAn[53] = -0.020487080; + adAn[54] = 0.015573220; + adAn[55] = 0.006862415; + adAn[56] = -0.001226752; + adAn[57] = 0.002850908; + + // 58 constants from table 4 - column Un + adUn[0] = 0.0; + adUn[1] = 0.5; + adUn[2] = 1.0; + adUn[3] = 3.5; + adUn[4] = -0.5; + adUn[5] = 4.5; + adUn[6] = 0.5; + adUn[7] = 7.5; + adUn[8] = 9.5; + adUn[9] = 6.0; + adUn[10] = 12.0; + adUn[11] = 12.5; + adUn[12] = -6.0; + adUn[13] = 2.0; + adUn[14] = 3.0; + adUn[15] = 2.0; + adUn[16] = 2.0; + adUn[17] = 11.0; + adUn[18] = -0.5; + adUn[19] = 0.5; + adUn[20] = 0.0; + adUn[21] = 4.0; + adUn[22] = 6.0; + adUn[23] = 21.0; + adUn[24] = 23.0; + adUn[25] = 22.0; + adUn[26] = -1.0; + adUn[27] = -0.5; + adUn[28] = 7.0; + adUn[29] = -1.0; + adUn[30] = 6.0; + adUn[31] = 4.0; + adUn[32] = 1.0; + adUn[33] = 9.0; + adUn[34] = -13.0; + adUn[35] = 21.0; + adUn[36] = 8.0; + adUn[37] = -0.5; + adUn[38] = 0.0; + adUn[39] = 2.0; + adUn[40] = 7.0; + adUn[41] = 9.0; + adUn[42] = 22.0; + adUn[43] = 23.0; + adUn[44] = 1.0; + adUn[45] = 9.0; + adUn[46] = 3.0; + adUn[47] = 8.0; + adUn[48] = 23.0; + adUn[49] = 1.5; + adUn[50] = 5.0; + adUn[51] = -0.5; + adUn[52] = 4.0; + adUn[53] = 7.0; + adUn[54] = 3.0; + adUn[55] = 0.0; + adUn[56] = 1.0; + adUn[57] = 0.0; + //Most of the tables are filled with 1.0 or 0.0 + //It is up to us to set non-zero values + for (j = 0; j < NG_Cal.NUMBEROFCOMPONENTS; j++) + { + for (k = j; k < NG_Cal.NUMBEROFCOMPONENTS; k++) + { + adTable6Eij[j][k] = 1.0; + adTable6Uij[j][k] = 1.0; + adTable6Kij[j][k] = 1.0; + adTable6Gij[j][k] = 1.0; + } + } + //Lnsert the 132 items of non-zero and non-1.0 data + //This looks more cumbersome than it is, considering table 6 has 1764 members + adTable6Eij[0][1] = 0.971640; + adTable6Eij[0][2] = 0.960644; + adTable6Eij[0][4] = 0.994635; + adTable6Eij[0][5] = 0.708218; + adTable6Eij[0][6] = 0.931484; + adTable6Eij[0][7] = 1.170520; + adTable6Eij[0][8] = 0.990126; + adTable6Eij[0][10] = 1.019530; + adTable6Eij[0][11] = 0.989844; + adTable6Eij[0][12] = 1.002350; + adTable6Eij[0][13] = 0.999268; + adTable6Eij[0][14] = 1.107274; + adTable6Eij[0][15] = 0.880880; + adTable6Eij[0][16] = 0.880973; + adTable6Eij[0][17] = 0.881067; + adTable6Eij[0][18] = 0.881161; + adTable6Eij[1][2] = 1.022740; + adTable6Eij[1][3] = 0.970120; + adTable6Eij[1][4] = 0.945939; + adTable6Eij[1][5] = 0.746954; + adTable6Eij[1][6] = 0.902271; + adTable6Eij[1][7] = 1.086320; + adTable6Eij[1][8] = 1.005710; + adTable6Eij[1][9] = 1.021000; + adTable6Eij[1][10] = 0.946914; + adTable6Eij[1][11] = 0.973384; + adTable6Eij[1][12] = 0.959340; + adTable6Eij[1][13] = 0.945520; + adTable6Eij[2][3] = 0.925053; + adTable6Eij[2][4] = 0.960237; + adTable6Eij[2][5] = 0.849408; + adTable6Eij[2][6] = 0.955052; + adTable6Eij[2][7] = 1.281790; + adTable6Eij[2][8] = 1.500000; + adTable6Eij[2][10] = 0.906849; + adTable6Eij[2][11] = 0.897362; + adTable6Eij[2][12] = 0.726255; + adTable6Eij[2][13] = 0.859764; + adTable6Eij[2][14] = 0.855134; + adTable6Eij[2][15] = 0.831229; + adTable6Eij[2][16] = 0.808310; + adTable6Eij[2][17] = 0.786323; + adTable6Eij[2][18] = 0.765171; + adTable6Eij[3][4] = 1.022560; + adTable6Eij[3][5] = 0.693168; + adTable6Eij[3][6] = 0.946871; + adTable6Eij[3][7] = 1.164460; + adTable6Eij[3][11] = 1.013060; + adTable6Eij[3][13] = 1.005320; + adTable6Eij[4][7] = 1.034787; + adTable6Eij[4][11] = 1.004900; + adTable6Eij[6][14] = 1.008692; + adTable6Eij[6][15] = 1.010126; + adTable6Eij[6][16] = 1.011501; + adTable6Eij[6][17] = 1.012821; + adTable6Eij[6][18] = 1.014089; + adTable6Eij[7][8] = 1.100000; + adTable6Eij[7][10] = 1.300000; + adTable6Eij[7][11] = 1.300000; + adTable6Uij[0][1] = 0.886106; + adTable6Uij[0][2] = 0.963827; + adTable6Uij[0][4] = 0.990877; + adTable6Uij[0][6] = 0.736833; + adTable6Uij[0][7] = 1.156390; + adTable6Uij[0][11] = 0.992291; + adTable6Uij[0][13] = 1.003670; + adTable6Uij[0][14] = 1.302576; + adTable6Uij[0][15] = 1.191904; + adTable6Uij[0][16] = 1.205769; + adTable6Uij[0][17] = 1.219634; + adTable6Uij[0][18] = 1.233498; + adTable6Uij[1][2] = 0.835058; + adTable6Uij[1][3] = 0.816431; + adTable6Uij[1][4] = 0.915502; + adTable6Uij[1][6] = 0.993476; + adTable6Uij[1][7] = 0.408838; + adTable6Uij[1][11] = 0.993556; + adTable6Uij[2][3] = 0.969870; + adTable6Uij[2][6] = 1.045290; + adTable6Uij[2][8] = 0.900000; + adTable6Uij[2][14] = 1.066638; + adTable6Uij[2][15] = 1.077634; + adTable6Uij[2][16] = 1.088178; + adTable6Uij[2][17] = 1.098291; + adTable6Uij[2][18] = 1.108021; + adTable6Uij[3][4] = 1.065173; + adTable6Uij[3][6] = 0.971926; + adTable6Uij[3][7] = 1.616660; + adTable6Uij[3][10] = 1.250000; + adTable6Uij[3][11] = 1.250000; + adTable6Uij[3][12] = 1.250000; + adTable6Uij[3][13] = 1.250000; + adTable6Uij[6][14] = 1.028973; + adTable6Uij[6][15] = 1.033754; + adTable6Uij[6][16] = 1.038338; + adTable6Uij[6][17] = 1.042735; + adTable6Uij[6][18] = 1.046966; + adTable6Kij[0][1] = 1.003630; + adTable6Kij[0][2] = 0.995933; + adTable6Kij[0][4] = 1.007619; + adTable6Kij[0][6] = 1.000080; + adTable6Kij[0][7] = 1.023260; + adTable6Kij[0][11] = 0.997596; + adTable6Kij[0][13] = 1.002529; + adTable6Kij[0][14] = 0.982962; + adTable6Kij[0][15] = 0.983565; + adTable6Kij[0][16] = 0.982707; + adTable6Kij[0][17] = 0.981849; + adTable6Kij[0][18] = 0.980991; + adTable6Kij[1][2] = 0.982361; + adTable6Kij[1][3] = 1.007960; + adTable6Kij[1][6] = 0.942596; + adTable6Kij[1][7] = 1.032270; + adTable6Kij[2][3] = 1.008510; + adTable6Kij[2][6] = 1.007790; + adTable6Kij[2][14] = 0.910183; + adTable6Kij[2][15] = 0.895362; + adTable6Kij[2][16] = 0.881152; + adTable6Kij[2][17] = 0.867520; + adTable6Kij[2][18] = 0.854406; + adTable6Kij[3][4] = 0.986893; + adTable6Kij[3][6] = 0.999969; + adTable6Kij[3][7] = 1.020340; + adTable6Kij[6][14] = 0.968130; + adTable6Kij[6][15] = 0.962870; + adTable6Kij[6][16] = 0.957828; + adTable6Kij[6][17] = 0.952441; + adTable6Kij[6][18] = 0.948338; + adTable6Gij[0][2] = 0.807653; + adTable6Gij[0][7] = 1.957310; + adTable6Gij[1][2] = 0.982746; + adTable6Gij[2][3] = 0.370296; + adTable6Gij[2][5] = 1.673090; + } // table() + /************************************************************************** + *Function:paramdl() + *Arguments:void + *Returns:void + *Purpose:sets up characterization & binary interaction parameters + *Revisions: + **************************************************************************/ + + public final void paramdl() + { + + int j, k; + // table 5 parameters; declared locally to this function + double[] adTable5Mri = new double[] {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[] adTable5Ei = new double[] {151.318300, 99.737780, 241.960600, 244.166700, 298.118300, 514.015600, 296.355000, 26.957940, 105.534800, 122.766700, 324.068900, 337.638900, 365.599900, 370.682300, 402.636293, 427.722630, 450.325022, 470.840891, 489.558373, 2.610111, 119.629900}; + double[] adTable5Ki = new double[] {0.4619255, 0.4479153, 0.4557489, 0.5279209, 0.5837490, 0.3825868, 0.4618263, 0.3514916, 0.4533894, 0.4186954, 0.6406937, 0.6341423, 0.6738577, 0.6798307, 0.7175118, 0.7525189, 0.7849550, 0.8152731, 0.8437826, 0.3589888, 0.4216551}; + double[] adTable5Gi = new double[] {0.000000, 0.027815, 0.189065, 0.079300, 0.141239, 0.332500, 0.088500, 0.034369, 0.038953, 0.021000, 0.256692, 0.281835, 0.332267, 0.366911, 0.289731, 0.337542, 0.383381, 0.427354, 0.469659, 0.000000, 0.000000}; + //most of the table 5 parameters are zero + for (j = 0; j < NG_Cal.NUMBEROFCOMPONENTS; j++) + { + adTable5Qi[j] = 0.0; + adTable5Fi[j] = 0.0; + adTable5Si[j] = 0.0; + adTable5Wi[j] = 0.0; + } + //a small number of exceptions + adTable5Qi[2] = 0.690000; + adTable5Qi[5] = 1.067750; + adTable5Qi[6] = 0.633276; + adTable5Fi[7] = 1.0000; + adTable5Si[5] = 1.5822; + adTable5Si[6] = 0.3900; + adTable5Wi[5] = 1.0000; + // setup characterization parameters for non-zero components + for (j = iNCC - 1; j >= 0; j--) + { + dMri[j] = adTable5Mri[aiCID[j]]; + dKi[j] = adTable5Ki[aiCID[j]]; + } + for (j = 0; j < iNCC; j++) + { + dGi[j] = adTable5Gi[aiCID[j]]; + dEi[j] = adTable5Ei[aiCID[j]]; + } + for (j = 0; j < iNCC; j++) + { + dQi[j] = adTable5Qi[aiCID[j]]; + dFi[j] = 0.0; + if (aiCID[j] == 7) + { + dFi[j] = adTable5Fi[7]; + } + dSi[j] = adTable5Si[aiCID[j]]; + dWi[j] = adTable5Wi[aiCID[j]]; + } + + // Binary interaction parameters for arrays: eij, kij, wij, uij + for (j = 0; j < iNCC; j++) + { + for (k = j; k < iNCC; k++) + { + dUij[j][k] = adTable6Uij[aiCID[j]][aiCID[k]]; + dKij[j][k] = adTable6Kij[aiCID[j]][aiCID[k]]; + dEij[j][k] = adTable6Eij[aiCID[j]][aiCID[k]]; + dGij[j][k] = adTable6Gij[aiCID[j]][aiCID[k]]; + } + } + } // paramdl() + + /************************************************************************** + *Function:chardl() + *Arguments:GasPropsSTRUCT * + *Returns:void + *Purpose:computes composition-dependent quantities + *Revisions: + **************************************************************************/ + public final void chardl(com.ng.ngtools.tangible.RefObject ptAGA10) + { + //variables local to function + int i, j; + double tmfrac, k5p0, k2p5, u5p0, u2p5, q1p0; + double Xij, Eij, Gij, e0p5, e2p0, e3p0, e3p5, e4p5, e6p0; + double e7p5, e9p5, e12p0, e12p5; + double e11p0, s3; + //normalize mole fractions and calculate molar mass + tmfrac = 0.0; + for (j = 0; j < iNCC; j++) + { + tmfrac = tmfrac + dXi[j]; + } + for (j = 0; j < iNCC; j++) + { + dXi[j] = dXi[j] / tmfrac; + } + // reset virial coefficients + for (j = 0; j < 18; j++) + { + adBcoef[j] = 0.0; + } + // initialize a key subset of the local variables + k5p0 = 0.0; + k2p5 = 0.0; + u5p0 = 0.0; + u2p5 = 0.0; + dW = 0.0; + q1p0 = 0.0; + dF = 0.0; + // calculate gas molecular weight + ptAGA10.argValue.dMrx = 0.0; + for (j = 0; j < iNCC; j++) + { + ptAGA10.argValue.dMrx = ptAGA10.argValue.dMrx + dXi[j] * dMri[j]; + } + // calculate the composition-dependent quantities, applying a nested loop + for (i = 0; i < iNCC; i++) + { + k2p5 = k2p5 + dXi[i] * dKi[i] * dKi[i] * Math.sqrt(dKi[i]); + u2p5 = u2p5 + dXi[i] * dEi[i] * dEi[i] * Math.sqrt(dEi[i]); + dW = dW + dXi[i] * dGi[i]; + q1p0 = q1p0 + dXi[i] * dQi[i]; + dF = dF + dXi[i] * dXi[i] * dFi[i]; + for (j = i; j < iNCC; j++) + { + if (i != j) + { + Xij = 2.0 * dXi[i] * dXi[j]; + } + else + { + Xij = dXi[i] * dXi[j]; + } + // proceed while skipping interaction terms which equal 1.0 + if (dKij[i][j] != 1.0) + { + k5p0 += Xij * (Math.pow(dKij[i][j], 5.0) - 1.0) * Math.pow((Math.pow(dKi[i], 5.0) * Math.pow(dKi[j], 5.0)), 0.5); + } + if (dUij[i][j] != 1.0) + { + u5p0 += Xij * (Math.pow(dUij[i][j], 5.0) - 1.0) * Math.pow((Math.pow(dEi[i], 5.0) * Math.pow(dEi[j], 5.0)), 0.5); + } + if (dGij[i][j] != 1.0) + { + dW += Xij * (dGij[i][j] - 1.0) * ((dGi[i] + dGi[j]) / 2.0); + } + // calculate terms required for second virial coefficient, B + Eij = dEij[i][j] * Math.sqrt(dEi[i] * dEi[j]); + Gij = dGij[i][j] * (dGi[i] + dGi[j]) / 2.0; + e0p5 = Math.sqrt(Eij); + e2p0 = Eij * Eij; + e3p0 = Eij * e2p0; + e3p5 = e3p0 * e0p5; + e4p5 = Eij * e3p5; + e6p0 = e3p0 * e3p0; + e11p0 = e4p5 * e4p5 * e2p0; + e7p5 = e4p5 * Eij * e2p0; + e9p5 = e7p5 * e2p0; + e12p0 = e11p0 * Eij; + e12p5 = e12p0 * e0p5; + s3 = Xij * Math.pow((Math.pow(dKi[i], 3.0) * Math.pow(dKi[j], 3)), 0.5); + adBcoef[0] = adBcoef[0] + s3; + adBcoef[1] = adBcoef[1] + s3 * e0p5; + adBcoef[2] = adBcoef[2] + s3 * Eij; + adBcoef[3] = adBcoef[3] + s3 * e3p5; + adBcoef[4] = adBcoef[4] + s3 * Gij / e0p5; + adBcoef[5] = adBcoef[5] + s3 * Gij * e4p5; + adBcoef[6] = adBcoef[6] + s3 * dQi[i] * dQi[j] * e0p5; + adBcoef[7] = adBcoef[7] + s3 * dSi[i] * dSi[j] * e7p5; + adBcoef[8] = adBcoef[8] + s3 * dSi[i] * dSi[j] * e9p5; + adBcoef[9] = adBcoef[9] + s3 * dWi[i] * dWi[j] * e6p0; + adBcoef[10] = adBcoef[10] + s3 * dWi[i] * dWi[j] * e12p0; + adBcoef[11] = adBcoef[11] + s3 * dWi[i] * dWi[j] * e12p5; + adBcoef[12] = adBcoef[12] + s3 * dFi[i] * dFi[j] / e6p0; + adBcoef[13] = adBcoef[13] + s3 * e2p0; + adBcoef[14] = adBcoef[14] + s3 * e3p0; + adBcoef[15] = adBcoef[15] + s3 * dQi[i] * dQi[j] * e2p0; + adBcoef[16] = adBcoef[16] + s3 * e2p0; + adBcoef[17] = adBcoef[17] + s3 * e11p0; + } + } + + //grab the first 18 constants from table 4, completing Bnij + for (i = 0; i < 18; i++) + { + adBcoef[i] *= adAn[i]; + } + //final products of chardl are mixture size parameter K, energy parameter U, + //and quadrupole parameter Q + dKp3 = Math.pow((k5p0 + k2p5 * k2p5), 0.6); + dU = Math.pow((u5p0 + u2p5 * u2p5), 0.2); + dQp2 = q1p0 * q1p0; + } // chardl() + + /************************************************************************** + + *Function:bvir() + *Arguments:void + *Returns:void + *Purpose:computes 2nd virial coefficient & partial derivs thereof + *Revisions: + **************************************************************************/ + public final void bvir() + { + //variables local to function + double t0p5, t2p0, t3p0, t3p5, t4p5, t6p0, t11p0; + double t7p5, t9p5, t12p0, t12p5; + double t1p5, t4p0; + double[] Bx = new double[18]; + int i; + //reset B and partial devivatives to 0.0 + dB = ddBdT = dd2BdT2 = 0.0; + //pre-calculate Math .Powers of T + t0p5 = Math.sqrt(dT); + t2p0 = dT * dT; + t3p0 = dT * t2p0; + t3p5 = t3p0 * t0p5; + t4p5 = dT * t3p5; + t6p0 = t3p0 * t3p0; + t11p0 = t4p5 * t4p5 * t2p0; + t7p5 = t6p0 * dT * t0p5; + t9p5 = t7p5 * t2p0; + t12p0 = t9p5 * t0p5 * t2p0; + t12p5 = t12p0 * t0p5; + t1p5 = dT * t0p5; + t4p0 = t2p0 * t2p0; + //coefficients for B + Bx[0] = adBcoef[0]; + Bx[1] = adBcoef[1] / t0p5; + Bx[2] = adBcoef[2] / dT; + Bx[3] = adBcoef[3] / t3p5; + Bx[4] = adBcoef[4] * t0p5; + Bx[5] = adBcoef[5] / t4p5; + Bx[6] = adBcoef[6] / t0p5; + Bx[7] = adBcoef[7] / t7p5; + Bx[8] = adBcoef[8] / t9p5; + Bx[9] = adBcoef[9] / t6p0; + Bx[10] = adBcoef[10] / t12p0; + Bx[11] = adBcoef[11] / t12p5; + Bx[12] = adBcoef[12] * t6p0; + Bx[13] = adBcoef[13] / t2p0; + Bx[14] = adBcoef[14] / t3p0; + Bx[15] = adBcoef[15] / t2p0; + Bx[16] = adBcoef[16] / t2p0; + Bx[17] = adBcoef[17] / t11p0; + //sum up the pieces for second virial coefficient, B + for (i = 0; i < 18; i++) + { + dB += Bx[i]; + } + //calculate terms for first derivative of B, wrt T + for (i = 0; i < 18; i++) + { + if (adUn[i] != 0) + { + Bx[i] *= adUn[i]; + } + } + //sum up the pieces of first derivative of B + //note div by dT; changes exponent of T + for (i = 0; i < 18; i++) + { + if (adUn[i] != 0) + { + ddBdT += Bx[i] / dT; + } + } + //sign change here + ddBdT = -ddBdT; + //calculate terms for second derivative of B, wrt T + for (i = 0; i < 18; i++) + { + if (adUn[i] != 0 && adUn[i] != -1.0) + { + Bx[i] *= (adUn[i] + 1.0); + } + } + //sum up the pieces of second derivative of B + //note division by dT, thereby changing the exponent of T + //loop will ignore Bx[0] which is = 0.0 + for (i = 0; i < 18; i++) + { + if (adUn[i] != 0 && adUn[i] != -1.0) + { + dd2BdT2 += Bx[i] / t2p0; + } + } + } // bvir() + + /************************************************************************** + *Function:temp() + *Arguments:void + *Returns:void + *Purpose:computes temperature-dependent quantities + *Revisions: + **************************************************************************/ + public final void temp() + { + //Note: this function was ported from the AGA Report No.8 FORTRAN listing, + //retaining as much of the original content as possible + //variables local to function + double tr0p5, tr1p5, tr2p0, tr3p0, tr4p0, tr5p0, tr6p0; + double tr7p0, tr8p0, tr9p0, tr11p0, tr13p0, tr21p0; + double tr22p0, tr23p0, tr; + /*calculate second virial coefficient B*/ + bvir(); + //calculate adFn(12) through adFn(57) + //adFn(0)-adFn(11) do not contribute to csm terms + tr = dT / (dU); + tr0p5 = Math.sqrt(tr); + tr1p5 = tr * tr0p5; + tr2p0 = tr * tr; + tr3p0 = tr * tr2p0; + tr4p0 = tr * tr3p0; + tr5p0 = tr * tr4p0; + tr6p0 = tr * tr5p0; + tr7p0 = tr * tr6p0; + tr8p0 = tr * tr7p0; + tr9p0 = tr * tr8p0; + tr11p0 = tr6p0 * tr5p0; + tr13p0 = tr6p0 * tr7p0; + tr21p0 = tr9p0 * tr9p0 * tr3p0; + tr22p0 = tr * tr21p0; + tr23p0 = tr * tr22p0; + adFn[12] = adAn[12] * dF * tr6p0; + adFn[13] = adAn[13] / tr2p0; + adFn[14] = adAn[14] / tr3p0; + adFn[15] = adAn[15] * dQp2 / tr2p0; + adFn[16] = adAn[16] / tr2p0; + adFn[17] = adAn[17] / tr11p0; + adFn[18] = adAn[18] * tr0p5; + adFn[19] = adAn[19] / tr0p5; + adFn[20] = adAn[20]; + + adFn[21] = adAn[21] / tr4p0; + adFn[22] = adAn[22] / tr6p0; + adFn[23] = adAn[23] / tr21p0; + adFn[24] = adAn[24] * dW / tr23p0; + adFn[25] = adAn[25] * dQp2 / tr22p0; + adFn[26] = adAn[26] * dF * tr; + adFn[27] = adAn[27] * dQp2 * tr0p5; + adFn[28] = adAn[28] * dW / tr7p0; + adFn[29] = adAn[29] * dF * tr; + adFn[30] = adAn[30] / tr6p0; + adFn[31] = adAn[31] * dW / tr4p0; + adFn[32] = adAn[32] * dW / tr; + adFn[33] = adAn[33] * dW / tr9p0; + adFn[34] = adAn[34] * dF * tr13p0; + adFn[35] = adAn[35] / tr21p0; + adFn[36] = adAn[36] * dQp2 / tr8p0; + adFn[37] = adAn[37] * tr0p5; + adFn[38] = adAn[38]; + adFn[39] = adAn[39] / tr2p0; + adFn[40] = adAn[40] / tr7p0; + adFn[41] = adAn[41] * dQp2 / tr9p0; + adFn[42] = adAn[42] / tr22p0; + adFn[43] = adAn[43] / tr23p0; + adFn[44] = adAn[44] / tr; + adFn[45] = adAn[45] / tr9p0; + adFn[46] = adAn[46] * dQp2 / tr3p0; + adFn[47] = adAn[47] / tr8p0; + adFn[48] = adAn[48] * dQp2 / tr23p0; + adFn[49] = adAn[49] / tr1p5; + adFn[50] = adAn[50] * dW / tr5p0; + adFn[51] = adAn[51] * dQp2 * tr0p5; + adFn[52] = adAn[52] / tr4p0; + adFn[53] = adAn[53] * dW / tr7p0; + adFn[54] = adAn[54] / tr3p0; + adFn[55] = adAn[55] * dW; + adFn[56] = adAn[56] / tr; + adFn[57] = adAn[57] * dQp2; + } // temp() + + + + /************************************************************************** + *Function:ddetail() + *Arguments:GasPropsSTRUCT * + *Returns:void + *Purpose:calculates density + *Revisions: + **************************************************************************/ + + //Note: this function was ported from the AGA Report No.8 FORTRAN listing, + + //retaining as much of the original content as possible + + public final void ddetail(com.ng.ngtools.tangible.RefObject ptAGA10) + { + int imax, i; + double epsp, epsr, epsmin; + double x1, x2, x3, y1, y2, y3; + double delx, delprv, delmin, delbis, xnumer, xdenom, sgndel; + double y2my3, y3my1, y1my2, boundn; + //initialize convergence tolerances + imax = 150; + epsp = 1.0e-6; + epsr = 1.0e-6; + epsmin = 1.0e-7; + dRho = 0.0; + //call subroutine braket to bracket density solution + braket(ptAGA10); + //check value of "lStatus" returned from subroutine braket + if (ptAGA10.argValue.lStatus == NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED || ptAGA10.argValue.lStatus == NG_Cal.NEGATIVE_DENSITY_DERIVATIVE) + { + return; + } + //set up to start Brent's method + //x is the independent variable, y the dependent variable + //delx is the current iteration change in x + //delprv is the previous iteration change in x + x1 = dRhoL; + x2 = dRhoH; + y1 = dPRhoL - dP; + y2 = dPRhoH - dP; + delx = x1 - x2; + delprv = delx; + //solution is bracketed between x1 and x2 + //a third point x3 is introduced for quadratic interpolation + x3 = x1; + y3 = y1; + for (i = 0; i < imax; i++) + { + //y3 must be opposite in sign from y2 so solution between x2,x3 + if (y2 * y3 > 0.0) + { + x3 = x1; + y3 = y1; + delx = x1 - x2; + delprv = delx; + } + + //y2 must be value of y closest to y=0.0, then x2new=x2old+delx + + if (Math.abs(y3) < Math.abs(y2)) + { + x1 = x2; + x2 = x3; + x3 = x1; + y1 = y2; + y2 = y3; + y3 = y1; + } + + //delmin is minimum allowed step size for unconverged iteration + delmin = epsmin * Math.abs(x2); + //if procedure is not converging or if delprv is less than delmin + //use bisection instead + //delbis = 0.5d0*(x3 - x2) is the bisection delx + delbis = 0.5 * (x3 - x2); + // tests to select numerical method for current iteration + + if (Math.abs(delprv) < delmin || Math.abs(y1) < Math.abs(y2)) + { + // use bisection + delx = delbis; + delprv = delbis; + } + else + { + if (x3 != x1) + { + // use inverse quadratic interpolation + y2my3 = y2 - y3; + y3my1 = y3 - y1; + y1my2 = y1 - y2; + xdenom = -(y1my2) * (y2my3) * (y3my1); + xnumer = x1 * y2 * y3 * (y2my3) + x2 * y3 * y1 * (y3my1) + x3 * y1 * y2 * (y1my2) - x2 * xdenom; + } + else + { + // use inverse linear interpolation + xnumer = (x2 - x1) * y2; + xdenom = y1 - y2; + } + // before calculating delx check delx=xnumer/xdenom is not out of bounds + if (2.0 * Math.abs(xnumer) < Math.abs(delprv * xdenom)) + { + // procedure converging, use interpolation + delprv = delx; + delx = xnumer / xdenom; + } + else + { + // procedure diverging, use bisection + delx = delbis; + delprv = delbis; + } + } + + // check for convergence + if ((Math.abs(y2) < epsp * dP) && (Math.abs(delx) < epsr * Math.abs(x2))) + { + dRho = x2 + delx; + return; + } + + //when unconverged, abs(delx) must be greater than delmin + //minimum allowed magnitude of change in x2 is 1.0000009*delmin + //sgndel, the sign of change in x2 is sign of delbis + + if (Math.abs(delx) < delmin) + { + sgndel = delbis / Math.abs(delbis); + delx = 1.0000009 * sgndel * delmin; + delprv = delx; + } + + //final check to insure that new x2 is in range of old x2 and x3 + //boundn is negative if new x2 is in range of old x2 and x3 + boundn = delx * (x2 + delx - x3); + if (boundn > 0.0) + { + + // procedure stepping out of bounds, use bisection + delx = delbis; + delprv = delbis; + } + //relable variables for next iteration + //x1new = x2old, y1new=y2old + x1 = x2; + y1 = y2; + // next iteration values for x2, y2 + x2 = x2 + delx; + pdetail(x2); + y2 = dPCalc - dP; + } + // ddetail: maximum number of iterations exceeded + ptAGA10.argValue.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED; + dRho = x2; + } // ddetail() + + + + /************************************************************************** + *Function:braket() + *Arguments:GasPropsSTRUCT * + *Returns:void + *Purpose:brackets density solution + *Revisions: + **************************************************************************/ + + //Note: this function was ported from the AGA Report No.8 FORTRAN listing, + + //retaining as much of the original content as possible + + public final void braket(com.ng.ngtools.tangible.RefObject ptAGA10) + { + //variables local to function + int imax, it; + double del, rhomax, videal; + double rho1, rho2, p1, p2; + //initialize + imax = 200; + rho1 = 0.0; + p1 = 0.0; + rhomax = 1.0 / dKp3; + if (dT > 1.2593 * dU) + { + rhomax = 20.0 * rhomax; + } + videal = NG_Cal.RGASKJ * dT / dP; + if (Math.abs(dB) < (0.167 * videal)) + { + rho2 = 0.95 / (videal + dB); + } + else + { + rho2 = 1.15 / videal; + } + del = rho2 / 20.0; + // start iterative density search loop + for (it = 0; it < imax; it++) + { + if (rho2 > rhomax && ptAGA10.argValue.lStatus != NG_Cal.MAX_DENSITY_IN_BRAKET_EXCEEDED) + { + // density in braket exceeds maximum allowable density + ptAGA10.argValue.lStatus = NG_Cal.MAX_DENSITY_IN_BRAKET_EXCEEDED; + del = 0.01 * (rhomax - rho1) + (dP / (NG_Cal.RGASKJ * dT)) / 20.0; + rho2 = rho1 + del; + continue; + } + //calculate pressure p2 at density rho2 + pdetail(rho2); + p2 = dPCalc; + //test value of p2 relative to p and relative to p1 + if (p2 > dP) + { + //the density root is bracketed (p1

p) + dRhoL = rho1; + dPRhoL = p1; + dRhoH = rho2; + dPRhoH = p2; + ptAGA10.argValue.lStatus = NG_Cal.NORMAL; + return; + + } + else if (p2 > p1) + { + if (ptAGA10.argValue.lStatus == NG_Cal.MAX_DENSITY_IN_BRAKET_EXCEEDED) + { + del *= 2.0; + } + rho1 = rho2; + p1 = p2; + rho2 = rho1 + del; + continue; + } + else + { + + //lStatus= NEGATIVE_DENSITY_DERIVATIVEindicates that + //pressure has a negative density derivative, since p2 is less than + //some previous pressure + + ptAGA10.argValue.lStatus = NG_Cal.NEGATIVE_DENSITY_DERIVATIVE; + dRho = rho1; + return; + } + } + // maximum number of iterations exceeded if we fall through the bottom + ptAGA10.argValue.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED; + dRho = rho2; + } // braket() + + + /************************************************************************** + *Function:pdetail() + *Arguments:double + *Returns:void + *Purpose:calculates pressure, given D and T. Calls zdetail() + *Revisions: + **************************************************************************/ + public final void pdetail(double dD) + { + dPCalc = zdetail(dD) * dD * NG_Cal.RGASKJ * dT; + } // pdetail() + + /************************************************************************** + *Function:zdetail() + *Arguments:double + *Returns:void + *Purpose:calculates compressibility + *Revisions: + **************************************************************************/ + + public final double zdetail(double d) + { + // variables local to function + double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4; + // Math .Powers of reduced density + D1 = dKp3 * d; + D2 = D1 * D1; + D3 = D2 * D1; + D4 = D3 * D1; + D5 = D4 * D1; + D6 = D5 * D1; + D7 = D6 * D1; + D8 = D7 * D1; + D9 = D8 * D1; + + exp1 = Math.exp(-D1); + exp2 = Math.exp(-D2); + exp3 = Math.exp(-D3); + exp4 = Math.exp(-D4); + + // the following expression for Z was adopted from FORTRAN example in AGA8 + dZ = 1.0 + dB * d + adFn[12] * D1 * (exp3 - 1.0 - 3.0 * D3 * exp3) + (adFn[13] + adFn[14] + adFn[15]) * D1 * (exp2 - 1.0 - 2.0 * D2 * exp2) + (adFn[16] + adFn[17]) * D1 * (exp4 - 1.0 - 4.0 * D4 * exp4) + (adFn[18] + adFn[19]) * D2 * 2.0 + (adFn[20] + adFn[21] + adFn[22]) * D2 * (2.0 - 2.0 * D2) * exp2 + (adFn[23] + adFn[24] + adFn[25]) * D2 * (2.0 - 4.0 * D4) * exp4 + adFn[26] * D2 * (2.0 - 4.0 * D4) * exp4 + adFn[27] * D3 * 3.0 + (adFn[28] + adFn[29]) * D3 * (3.0 - D1) * exp1 + (adFn[30] + adFn[31]) * D3 * (3.0 - 2.0 * D2) * exp2 + (adFn[32] + adFn[33]) * D3 * (3.0 - 3.0 * D3) * exp3 + (adFn[34] + adFn[35] + adFn[36]) * D3 * (3.0 - 4.0 * D4) * exp4 + (adFn[37] + adFn[38]) * D4 * 4.0 + (adFn[39] + adFn[40] + adFn[41]) * D4 * (4.0 - 2.0 * D2) * exp2 + (adFn[42] + adFn[43]) * D4 * (4.0 - 4.0 * D4) * exp4 + adFn[44] * D5 * 5.0 + (adFn[45] + adFn[46]) * D5 * (5.0 - 2.0 * D2) * exp2 + (adFn[47] + adFn[48]) * D5 * (5.0 - 4.0 * D4) * exp4 + adFn[49] * D6 * 6.0 + adFn[50] * D6 * (6.0 - 2.0 * D2) * exp2 + adFn[51] * D7 * 7.0 + adFn[52] * D7 * (7.0 - 2.0 * D2) * exp2 + adFn[53] * D8 * (8.0 - D1) * exp1 + (adFn[54] + adFn[55]) * D8 * (8.0 - 2.0 * D2) * exp2 + (adFn[56] + adFn[57]) * D9 * (9.0 - 2.0 * D2) * exp2; + return dZ; + + } // zdetail() + + /************************************************************************** + *Function:dZdT() + *Arguments:double + *Returns:double + *Purpose:calculates the first partial derivative of Z wrt T + *Revisions: + **************************************************************************/ + + public final double dZdT(double d) + { + //variables local to function + double tmp; + int i; + double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4; + //set up Math .Powers of reduced density + D1 = dKp3 * d; + D2 = D1 * D1; + D3 = D2 * D1; + D4 = D3 * D1; + D5 = D4 * D1; + D6 = D5 * D1; + D7 = D6 * D1; + D8 = D7 * D1; + D9 = D8 * D1; + exp1 = Math.exp(-D1); + exp2 = Math.exp(-D2); + exp3 = Math.exp(-D3); + exp4 = Math.exp(-D4); + // create terms uC*T^-(un+1) from coefficients we've already computed (An[n]) + for (i = 12; i < 58; i++) + { + if (adUn[i] != 0 && adFn[i] != 0) + { + fx[i] = (adFn[i] * adUn[i] * D1) / dT; + } + else + { + fx[i] = 0.0; + } + } + //initial part of equation + ddZdT = d * ddBdT; + //n=13 evaluates to zero except for hydrogen, for whom fn = 1 + if (dF != 0) + { + ddZdT += fx[12] - (fx[12] * (1.0 - 3.0 * D3) * exp3); + } + tmp = (1.0 - 2.0 * D2) * exp2; + ddZdT += (fx[13] - (fx[13] * tmp)); + ddZdT += fx[14] - (fx[14] * tmp); + ddZdT += fx[15] - (fx[15] * tmp); + tmp = (1.0 - 4.0 * D4) * exp4; + ddZdT += fx[16] - (fx[16] * tmp); + ddZdT += fx[17] - (fx[17] * tmp); + ddZdT = ddZdT - (fx[18] + fx[19]) * D1 * 2.0 - (fx[21] + fx[22]) * D1 * (2.0 - 2.0 * D2) * exp2 - (fx[23] + fx[24] + fx[25]) * D1 * (2.0 - 4.0 * D4) * exp4 - fx[26] * D1 * (2.0 - 4.0 * D4) * exp4 - fx[27] * D2 * 3.0 - (fx[28] + fx[29]) * D2 * (3.0 - D1) * exp1 - (fx[30] + fx[31]) * D2 * (3.0 - 2.0 * D2) * exp2 - (fx[32] + fx[33]) * D2 * (3.0 - 3.0 * D3) * exp3 - (fx[34] + fx[35] + fx[36]) * D2 * (3.0 - 4.0 * D4) * exp4 - fx[37] * D3 * 4.0 - (fx[39] + fx[40] + fx[41]) * D3 * (4.0 - 2.0 * D2) * exp2 - (fx[42] + fx[43]) * D3 * (4.0 - 4.0 * D4) * exp4 - fx[44] * D4 * 5.0 - (fx[45] + fx[46]) * D4 * (5.0 - 2.0 * D2) * exp2 - (fx[47] + fx[48]) * D4 * (5.0 - 4.0 * D4) * exp4 - fx[49] * D5 * 6.0 - fx[50] * D5 * (6.0 - 2.0 * D2) * exp2 - fx[51] * D6 * 7.0 - fx[52] * D6 * (7.0 - 2.0 * D2) * exp2 - fx[53] * D7 * (8.0 - D1) * exp1 - fx[54] * D7 * (8.0 - 2.0 * D2) * exp2 - fx[56] * D8 * (9.0 - 2.0 * D2) * exp2; + return ddZdT; + + } // dDdT() + + + + /************************************************************************** + *Function:d2ZdT2() + *Arguments:double + *Returns:double + *Purpose:calculates the second partial derivative of Z wrt T + *Revisions: + **************************************************************************/ + public final double d2ZdT2(double d) + { + //variables local to function + double tmp; + int i; + double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4; + //set up Math .Powers of reduced density + D1 = dKp3 * d; + D2 = D1 * D1; + D3 = D2 * D1; + D4 = D3 * D1; + D5 = D4 * D1; + D6 = D5 * D1; + D7 = D6 * D1; + D8 = D7 * D1; + D9 = D8 * D1; + exp1 = Math.exp(-D1); + exp2 = Math.exp(-D2); + exp3 = Math.exp(-D3); + exp4 = Math.exp(-D4); + // create terms uC*T^-(un+1) from coefficients we've already computed (An[n]) + for (i = 12; i < 58; i++) + { + if (adUn[i] != 0 && adFn[i] != 0) + { + + fx[i] = (adFn[i] * D1 * adUn[i] * (adUn[i] + 1.0)) / (dT * dT); + } + else + { + + fx[i] = 0.0; + + } + + } + //initial part of equation + dd2ZdT2 = d * dd2BdT2; + + //n=13 evaluates to zero except for hydrogen, for whom fn = 1 + if (dF != 0) + { + dd2ZdT2 += fx[12] - (fx[12] * (1.0 - 3.0 * D3) * exp3); + } + tmp = (1.0 - 2.0 * D2) * exp2; + dd2ZdT2 += -fx[13] + (fx[13] * tmp); + dd2ZdT2 += -fx[14] + (fx[14] * tmp); + dd2ZdT2 += -fx[15] + (fx[15] * tmp); + tmp = (1.0 - 4.0 * D4) * exp4; + dd2ZdT2 += -fx[16] + (fx[16] * tmp); + dd2ZdT2 += -fx[17] + (fx[17] * tmp); + dd2ZdT2 = dd2ZdT2 + (fx[18] + fx[19]) * D1 * 2.0 + (fx[21] + fx[22]) * D1 * (2.0 - 2.0 * D2) * exp2 + (fx[23] + fx[24] + fx[25]) * D1 * (2.0 - 4.0 * D4) * exp4 + fx[26] * D1 * (2.0 - 4.0 * D4) * exp4 + fx[27] * D2 * 3.0 + (fx[28] + fx[29]) * D2 * (3.0 - D1) * exp1 + (fx[30] + fx[31]) * D2 * (3.0 - 2.0 * D2) * exp2 + (fx[32] + fx[33]) * D2 * (3.0 - 3.0 * D3) * exp3 + (fx[34] + fx[35] + fx[36]) * D2 * (3.0 - 4.0 * D4) * exp4 + fx[37] * D3 * 4.0 + (fx[39] + fx[40] + fx[41]) * D3 * (4.0 - 2.0 * D2) * exp2 + (fx[42] + fx[43]) * D3 * (4.0 - 4.0 * D4) * exp4 + fx[44] * D4 * 5.0 + (fx[45] + fx[46]) * D4 * (5.0 - 2.0 * D2) * exp2 + (fx[47] + fx[48]) * D4 * (5.0 - 4.0 * D4) * exp4 + fx[49] * D5 * 6.0 + fx[50] * D5 * (6.0 - 2.0 * D2) * exp2 + fx[51] * D6 * 7.0 + fx[52] * D6 * (7.0 - 2.0 * D2) * exp2 + fx[53] * D7 * (8.0 - D1) * exp1 + fx[54] * D7 * (8.0 - 2.0 * D2) * exp2 + fx[56] * D8 * (9.0 - 2.0 * D2) * exp2; + + return dd2ZdT2; + + } // d2ZdT2() + + + /************************************************************************** + *Function:dZdD() + *Arguments:double + *Returns:double + *Purpose:calculates the first partial derivative of Z wrt D + *Revisions: + **************************************************************************/ + + //For efficiency and continuity with AGA 8 code example, each term + + //is evaluated individually rather than through looping through tables. + + //Temporary storage is used to hold portions of complex equations and + //to facilitate debugging. Additional speed optimization is possible. + + public final double dZdD(double d) + { + double temp, temp1, temp2, temp3; + int i; + double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4; + // set up Math .Powers of reduced density + D1 = dKp3 * d; + D2 = D1 * D1; + D3 = D2 * D1; + D4 = D3 * D1; + D5 = D4 * D1; + D6 = D5 * D1; + D7 = D6 * D1; + D8 = D7 * D1; + D9 = D8 * D1; + exp1 = Math.exp(-D1); + exp2 = Math.exp(-D2); + exp3 = Math.exp(-D3); + exp4 = Math.exp(-D4); + //create terms uC*T^-(un+1) from coefficients we've already computed (An[n]) + for (i = 12; i < 58; i++) + { + fx[i] = adFn[i]; + } + //initial part of equation + ddZdD = dB / dKp3; + //evaluate all remaining terms, simplifying where possible + + //n=13 evaluates to zero except for hydrogen, for whom fn = 1 + if (dF != 0) + { + temp1 = -9.0 * D3 * exp3; + temp2 = (1.0 - 3.0 * D3) * exp3; + temp3 = -temp2 * 3.0 * D6; + temp = temp1 + temp2 + temp3; + ddZdD += -fx[12] + fx[12] * temp; + } + //n = 14..16 + temp1 = -4.0 * D2 * exp2; + temp2 = (1.0 - 2.0 * D2) * exp2; + temp3 = -temp2 * 2.0 * D2; + temp = temp1 + temp2 + temp3; + ddZdD += -fx[13] + fx[13] * temp; + ddZdD += -fx[14] + fx[14] * temp; + ddZdD += -fx[15] + fx[15] * temp; + // n =17..18 + temp1 = -16.0 * D4 * exp4; + temp2 = (1.0 - 4.0 * D4) * exp4; + temp3 = -temp2 * 4.0 * D4; + temp = temp1 + temp2 + temp3; + ddZdD += -fx[16] + fx[16] * temp; + ddZdD += -fx[17] + fx[17] * temp; + // n = 19..20 + temp = 4.0 * D1; + ddZdD += fx[18] * temp; + ddZdD += fx[19] * temp; + // n =21..23 + temp1 = -4.0 * D3 * exp2; + temp2 = (2.0 - 2.0 * D2) * 2.0 * D1 * exp2; + temp3 = -temp2 * D2; + temp = temp1 + temp2 + temp3; + ddZdD += fx[20] * temp; + ddZdD += fx[21] * temp; + ddZdD += fx[22] * temp; + // n =24..27 + temp1 = -16.0 * D5 * exp4; + temp2 = (2.0 - 4.0 * D4) * 2.0 * D1 * exp4; + temp3 = -temp2 * 2.0 * D4; + temp = temp1 + temp2 + temp3; + ddZdD += fx[23] * temp; + ddZdD += fx[24] * temp; + ddZdD += fx[25] * temp; + ddZdD += fx[26] * temp; + // n =28 + temp = 9.0 * D2; + ddZdD += fx[27] * temp; + // n =29..30 + temp = -D3 * exp1 + (3.0 - D1) * 3.0 * D2 * exp1; + temp -= (3.0 - D1) * D3 * exp1; + ddZdD += fx[28] * temp; + ddZdD += fx[29] * temp; + // n =31..32 + temp1 = -4.0 * D4 * exp2; + temp2 = (3.0 - 2.0 * D2) * 3.0 * D2 * exp2; + temp3 = -(3.0 - 2.0 * D2) * 2.0 * D4 * exp2; + temp = temp1 + temp2 + temp3; + ddZdD += fx[30] * temp; + ddZdD += fx[31] * temp; + // n =33..34 + temp1 = -9.0 * D5 * exp3; + temp2 = (3.0 - 3.0 * D3) * 3.0 * D2 * exp3; + temp3 = -(3.0 - 3.0 * D3) * 3.0 * D5 * exp3; + temp = temp1 + temp2 + temp3; + ddZdD += fx[32] * temp; + ddZdD += fx[33] * temp; + // n =35..37 + temp1 = -16.0 * D6 * exp4; + temp2 = (3.0 - 4.0 * D4) * 3.0 * D2 * exp4; + temp3 = -(3.0 - 4.0 * D4) * D6 * 4.0 * exp4; + temp = temp1 + temp2 + temp3; + ddZdD += fx[34] * temp; + ddZdD += fx[35] * temp; + ddZdD += fx[36] * temp; + //n = 38..39 + temp = 16.0 * D3; + ddZdD += fx[37] * temp; + ddZdD += fx[38] * temp; + //n = 40..42 + temp1 = -4.0 * D5 * exp2; + temp2 = (4.0 - 2.0 * D2) * 4.0 * D3 * exp2; + temp3 = -(4.0 - 2.0 * D2) * 2.0 * D5 * exp2; + temp = temp1 + temp2 + temp3; + ddZdD += fx[39] * temp; + ddZdD += fx[40] * temp; + ddZdD += fx[41] * temp; + // n =43..44 + temp = -16.0 * D7 * exp4 + (4.0 - 4.0 * D4) * 4.0 * D3 * exp4; + temp -= (4.0 - 4.0 * D4) * D7 * 4.0 * exp4; + ddZdD += fx[42] * temp; + ddZdD += fx[43] * temp; + // n =45 + temp = 25.0 * D4; + ddZdD += fx[44] * temp; + // n =46..47 + temp = -4.0 * D6 * exp2 + (5.0 - 2.0 * D2) * 5.0 * D4 * exp2; + temp -= (5.0 - 2.0 * D2) * D6 * 2.0 * exp2; + ddZdD += fx[45] * temp; + ddZdD += fx[46] * temp; + // n =48..49 + temp = -16.0 * D8 * exp4 + (5.0 - 4.0 * D4) * 5.0 * D4 * exp4; + temp -= (5.0 - 4.0 * D4) * D8 * 4.0 * exp4; + ddZdD += fx[47] * temp; + ddZdD += fx[48] * temp; + // n =50 + temp = 36.0 * D5; + ddZdD += fx[49] * temp; + // n =51 + temp = -4.0 * D7 * exp2 + (6.0 - 2.0 * D2) * 6.0 * D5 * exp2; + temp -= (6.0 - 2.0 * D2) * D7 * 2.0 * exp2; + ddZdD += fx[50] * temp; + // n =52 + temp = 49.0 * D6; + ddZdD += fx[51] * temp; + // n =53 + temp = -4.0 * D8 * exp2 + (7.0 - 2.0 * D2) * 7.0 * D6 * exp2; + temp -= (7.0 - 2.0 * D2) * D8 * 2.0 * exp2; + ddZdD += fx[52] * temp; + // n =54 + temp = -1.0 * D8 * exp1 + (8.0 - D1) * 8.0 * D7 * exp1; + temp -= (8.0 - D1) * D8 * exp1; + ddZdD += fx[53] * temp; + // n =55..56 + temp = -4.0 * D1 * D8 * exp2 + (8.0 - 2.0 * D2) * 8.0 * D7 * exp2; + temp -= (8.0 - 2.0 * D2) * D8 * 2.0 * D1 * exp2; + ddZdD += fx[54] * temp; + ddZdD += fx[55] * temp; + // n =57..58 + temp = -4.0 * D2 * D8 * exp2 + (9.0 - 2.0 * D2) * 9.0 * D8 * exp2; + temp -= (9.0 - 2.0 * D2) * D2 * D8 * 2.0 * exp2; + ddZdD += fx[56] * temp; + ddZdD += fx[57] * temp; + ddZdD *= dKp3; + return ddZdD; + } // dZdD() + + + + + /************************************************************************** + *Function:relativedensity() + *Arguments:GasPropsSTRUCT * + *Returns:void + *Purpose:calculates relative density via methods listed in AGA 8 + *Revisions: + **************************************************************************/ + public final void relativedensity(com.ng.ngtools.tangible.RefObject ptAGA10) + { + double dBX, dZa; + final double dMWair = 28.96256; + // calculate second virial coefficient for air + dBX = -0.12527 + 5.91e-4 * ptAGA10.argValue.dTb - 6.62e-7 * ptAGA10.argValue.dTb * ptAGA10.argValue.dTb; + // calculate compressibility of air + dZa = 1.0 + (dBX * dP) / (NG_Cal.RGASKJ * ptAGA10.argValue.dTb); + // calculate ideal gas and real gas relative densities + ptAGA10.argValue.dRD_Ideal = ptAGA10.argValue.dMrx / dMWair; + ptAGA10.argValue.dRD_Real = ptAGA10.argValue.dRD_Ideal * (dZa / ptAGA10.argValue.dZb); + } // relativedensity() + + + } \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/modules/FlowCal.java b/src/main/java/com/ng/ngtools/modules/FlowCal.java new file mode 100644 index 0000000..454b36d --- /dev/null +++ b/src/main/java/com/ng/ngtools/modules/FlowCal.java @@ -0,0 +1,1784 @@ +package com.ng.ngtools.modules; + +import com.ng.ngtools.tangible.RefObject; + +import javax.swing.*; + +public class FlowCal +{ + /** + 标准孔板流量计算 + + @param FlowPar + @param GasPar + @return + */ + public final double OFlowCal(RefObject GasPar, RefObject FlowPar) + { + + + //将压力 温度 差压 当地大气压 压力量程 温度量程 和差压量程都换算到标准计算所使用的单位下的值 + + + // 考虑膨胀系数后的管道直径 + // 考虑膨胀系数后的喉部直径 + //直径比 + FlowPar.argValue.dOrificeD = FlowPar.argValue.dOrificeD * (1 + 0.000001 * (FlowPar.argValue.dOrificeMaterial) * (FlowPar.argValue.dTf - 293.15)); + FlowPar.argValue.dPipeD = FlowPar.argValue.dPipeD * (1 + 0.000001 * (FlowPar.argValue.dPipeMaterial) * (FlowPar.argValue.dTf - 293.15)); + FlowPar.argValue.dBeta = FlowPar.argValue.dOrificeD / FlowPar.argValue.dPipeD; + +// FlowPar.argValue.dOrificeD = 150.24; +// FlowPar.argValue.dPipeD = 259.37; +// FlowPar.argValue.dBeta = 0.5792; + + + //求渐近速度系数 E + FlowPar.argValue.dE = 1 / Math.pow((1 - Math.pow(FlowPar.argValue.dBeta, 4)), 0.5); +// FlowPar.argValue.dE = 1.0615; + + //求相对密度系数 FG + // LiuTiType = 1 + FlowPar.argValue.dFG = Math.pow((1 / GasPar.argValue.dRD_Real), 0.5); +// FlowPar.argValue.dFG = 1.2531; + //求流动温度系数 'FT + FlowPar.argValue.dFT = Math.pow((293.15 / FlowPar.argValue.dTf), 0.5); +// FlowPar.argValue.dFT = 1.0086; + //求等熵指数????????????????????????????????? + + FlowPar.argValue.dKappa = GasPar.argValue.dKappa; +// FlowPar.argValue.dKappa = 1.357; + + //求动力粘度 dlnd + FlowPar.argValue.dDViscosity = Dlndjs(FlowPar.argValue.dPf, FlowPar.argValue.dTf, 2, 1); +// FlowPar.argValue.dDViscosity = 0.01096; + + //求可膨胀系数 + FlowPar.argValue.dDExpCoefficient = KePenZhang_JiSuan(FlowPar.argValue.dPf / 1e6, FlowPar.argValue.dDp, FlowPar.argValue.dBeta, FlowPar.argValue.dKappa, FlowPar.argValue.dCoreType, 0); +// FlowPar.argValue.dDExpCoefficient = 0.9977; + //迭代计算流量和流出系数 + + double conQvA = 0; + conQvA = 0.0000031795 * (1530000.0D * GasPar.argValue.dRD_Real / (FlowPar.argValue.dDViscosity * FlowPar.argValue.dOrificeD)) * FlowPar.argValue.dE * Math.pow(FlowPar.argValue.dOrificeD, 2) * GasPar.argValue.dFpv * FlowPar.argValue.dFG * FlowPar.argValue.dDExpCoefficient * FlowPar.argValue.dFT * Math.sqrt(FlowPar.argValue.dPf * FlowPar.argValue.dDp / 1e6); + double[] XQv = new double[4]; + double[] CQv = new double[4]; + double[] dQv = new double[4]; + double Qn = 0; + int n = 0; + XQv[0] = 1000000.0F; + boolean xhFlag=true; + _100000: + + while(xhFlag) { + for (n = 1; n <= 2; n++) { + CQv[n] = C_JiSuan(FlowPar.argValue.dOrificeD, FlowPar.argValue.dBeta, XQv[n - 1], conQvA, FlowPar.argValue.dPtmode, FlowPar.argValue.dCoreType, 0); + XQv[n] = conQvA * CQv[n]; + dQv[n] = XQv[n] - XQv[n - 1]; + } + if (XQv[2] == XQv[1] || dQv[2] == dQv[1]) { + Qn = conQvA * FlowPar.argValue.dDViscosity * FlowPar.argValue.dOrificeD * CQv[2] / (1530000.0D * GasPar.argValue.dRD_Real); + //管道雷诺数 + FlowPar.argValue.dRnPipe = XQv[2]; + //流出系数 + FlowPar.argValue.dCd = CQv[2]; + + } + if (Math.abs((conQvA - XQv[2] / CQv[1]) / conQvA) > 0.00000000000000005) { + XQv[0] = XQv[n - 1] - dQv[n - 1] * ((XQv[n - 1] - XQv[n - 2]) / (dQv[n - 1] - dQv[n - 2])); +//C# TO JAVA CONVERTER TODO TASK: There is no 'goto' in Java: + continue _100000; + } + else + { + xhFlag=false; + } + } + + //孔板锐利度系数Bk + FlowPar.argValue.dOrificeSharpness = 1; + if (FlowPar.argValue.dCoreType == 0) + { + FlowPar.argValue.dBk = (FlowPar.argValue.dOrificeSharpness == 0) ? (BkTable(FlowPar.argValue.dOrificeRk, FlowPar.argValue.dOrificeD, 1)) : (FlowPar.argValue.dOrificeSharpness); + } + else + { + FlowPar.argValue.dBk = 1; + } + + + //管道粗糙度系数 Gme + FlowPar.argValue.dRoughNessPipe = CcdXsjs(FlowPar.argValue.dPipeType, FlowPar.argValue.dPipeD, FlowPar.argValue.dBeta, FlowPar.argValue.dRnPipe); + //修正后的流出系数 + FlowPar.argValue.dCd = FlowPar.argValue.dCd * FlowPar.argValue.dBk * FlowPar.argValue.dRoughNessPipe; + //标况体积流量 m³、s + FlowPar.argValue.dVFlowb = Qn * FlowPar.argValue.dBk * FlowPar.argValue.dRoughNessPipe; + //工况体积流量 + FlowPar.argValue.dVFlowf = FlowConvert_BaseToWork(FlowPar, GasPar); + //标况质量流量 + FlowPar.argValue.dMFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dRhob; + //标况能量流量 + FlowPar.argValue.dEFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dHhvv; + //管道内天然气流速 + FlowPar.argValue.dVelocityFlow = FlowPar.argValue.dVFlowf / (3.1415926 * Math.pow((FlowPar.argValue.dPipeD / 2000), 2)); + //压力损失 + FlowPar.argValue.dPressLost = YaLiSunShi(FlowPar.argValue.dCd, FlowPar.argValue.dBeta, FlowPar.argValue.dDp, FlowPar.argValue.dCoreType); + + return FlowPar.argValue.dVFlowb; + + } + + /** + 标准孔板流量计算 + + @param GasPar + @param FlowPar + @return + */ + public final double SdFlowCal(RefObject GasPar, RefObject FlowPar) + { + //工况体积流量 m³、s + FlowPar.argValue.dVFlowf = FlowPar.argValue.dPulseNum / FlowPar.argValue.dMeterFactor; + + //标况体积流量 m³、s + FlowPar.argValue.dVFlowb = FlowConvert_WorkToBase(FlowPar, GasPar); + + //标况质量流量 + FlowPar.argValue.dMFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dRhob; + //标况能量流量 + FlowPar.argValue.dEFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dHhvm; + + + return FlowPar.argValue.dVFlowb; + + } + + /** + 天然气音速喷嘴流量计算 + + @return + */ + public final double NozellFLowCal(RefObject ptAGA10, RefObject flPar) + { + double dAnt; // 喷嘴喉部面积 + //double dCR;//临界流系数 + double dP1Z; //滞止压力 + double dT1Z; //滞止温度 + //double dPbeta;//上下游压力比 + double dDcorrect; // 考虑膨胀系数后的管道直径 + double ddcorrect; // 考虑膨胀系数后的喉部直径 + double dBeta; //直径比 + double dQm; + try + { + ddcorrect = flPar.argValue.dOrificeD * (1 + 0.000001 * (flPar.argValue.dOrificeMaterial) * (flPar.argValue.dTf - 293.15)); + dDcorrect = flPar.argValue.dPipeD * (1 + 0.000001 * (flPar.argValue.dOrificeMaterial) * (flPar.argValue.dTf - 293.15)); + dBeta = ddcorrect / dDcorrect; + dAnt = 3.1415926 * (ddcorrect / 2) * (ddcorrect / 2); + //ptNGcal.SOS(ref ptAGA10); + + //dCR = ptAGA10.dCstar * Math.Sqrt(ptAGA10.dZf); + dP1Z = flPar.argValue.dPf * (1 + ptAGA10.argValue.dKappa / 2 * Math.pow((2 / (ptAGA10.argValue.dKappa + 1)), ((ptAGA10.argValue.dKappa + 1) / (ptAGA10.argValue.dKappa - 1))) * Math.pow(dBeta, 4)); + dT1Z = flPar.argValue.dTf * (1 + (ptAGA10.argValue.dKappa - 1) / 2 * (2 / Math.pow((ptAGA10.argValue.dKappa + 1), ((ptAGA10.argValue.dKappa + 1) / (ptAGA10.argValue.dKappa - 1)))) * Math.pow(dBeta, 4)); + // dQm = dAnt * flPar.dCd * ptAGA10.dCstar * dP1Z / Math.Sqrt(8314.51 * dT1Z / ptAGA10.dMrx); + dQm = dAnt * flPar.argValue.dCd * ptAGA10.argValue.dCstar * Math.sqrt(ptAGA10.argValue.dZf * dP1Z * ptAGA10.argValue.dRhof); + + if (dBeta > 0.25) + { + dQm = dQm * BetaG25(dP1Z, dT1Z, dBeta, ptAGA10); + } + flPar.argValue.dMFlowb = dQm; + flPar.argValue.dVFlowb = flPar.argValue.dMFlowb / ptAGA10.argValue.dRhob; + //标况能量流量 + flPar.argValue.dEFlowb = flPar.argValue.dVFlowb * ptAGA10.argValue.dHhvm; + flPar.argValue.dVFlowf = FlowConvert_BaseToWork(flPar, ptAGA10); + return flPar.argValue.dVFlowb; + } + catch (RuntimeException ex) + { + return 0.0; + } + } + + private double BetaG25(double P0, double T0, double BetaB, RefObject ptAGA10) + { + double[] nik0 = new double[9]; + double[] Sik0 = new double[9]; + double[] Tik0 = new double[9]; + double[] nik1 = new double[9]; + double[] Sik1 = new double[9]; + double[] Tik1 = new double[9]; + double C0 = 0; + double C1 = 0; + double Pai = 0; + double Tuo = 0; + double b = 0; + double F0 = 0; + double F1 = 0; + double Rf = 0.65; + // 直径比大于0.25的修正因子 + nik0[0] = 1.068826e-3; + nik0[1] = 1.199593e-2; + nik0[2] = -1.48292e-3; + nik0[3] = 2.764799e-4; + nik0[4] = 7.920711e-5; + nik0[5] = 1.11278e-3; + nik0[6] = -6.815626e-5; + nik0[7] = 3.86249e-8; + + nik1[0] = -3.46148e-3; + nik1[1] = 5.28029e-3; + nik1[2] = 1.195016e-2; + nik1[3] = 1.664232e-3; + nik1[4] = 1.159371e-3; + nik1[5] = 7.260461e-3; + nik1[6] = -7.541933e-4; + nik1[7] = 2.613967e-7; + + Sik0[0] = 0; + Sik0[1] = 0; + Sik0[2] = 0.5; + Sik0[3] = 1; + Sik0[4] = 2; + Sik0[5] = 3; + Sik0[6] = 5; + Sik0[7] = 10; + + Sik1[0] = 0; + Sik1[1] = 0; + Sik1[2] = 0; + Sik1[3] = 1; + Sik1[4] = 1.5; + Sik1[5] = 3; + Sik1[6] = 5; + Sik1[7] = 10; + + Tik0[0] = -1; + Tik0[1] = 0; + Tik0[2] = -6; + Tik0[3] = -1; + Tik0[4] = -2; + Tik0[5] = -8; + Tik0[6] = -10; + Tik0[7] = -18; + + Tik1[0] = -3; + Tik1[1] = -1; + Tik1[2] = 0; + Tik1[3] = -2; + Tik1[4] = -4; + Tik1[5] = -10; + Tik1[6] = -12; + Tik1[7] = -15; + + Pai = P0 / (ptAGA10.argValue.Pc * 1000000); + Tuo = T0 / ptAGA10.argValue.TC; + for (int i = 0; i <= 7; i += 1) + { + C0 = C0 + nik0[i] * Math.pow(Pai, Sik0[i]) * Math.pow(Tuo, Tik0[i]); + C1 = C1 + nik1[i] * Math.pow(Pai, Sik1[i]) * Math.pow(Tuo, Tik1[i]); + } + b = 25.879 * Math.pow(BetaB, 6) - 32.693 * Math.pow(BetaB, 5) + 34.276 * Math.pow(BetaB, 4) - 6.0199 * Math.pow(BetaB, 3) - 1.1156 * Math.pow(BetaB, 2) - 0.1122 * BetaB + 0.0047; + F0 = 1 + b * C0; + F1 = 1 + b * C1; + return (1 - Rf) * F0 + Rf * F1; + } + /** + 材料膨胀系数计算 + + @param tempCaiLiao + @return + */ + public static double CaiLiaoPzxs(int tempCaiLiao) + { + double CaiLiaoPzxs = 0; + // 孔板和管道材料的膨胀系数 + // 0 A3、15号钢 + // 1 10 号钢 + // 2 20 号钢 + // 3 45 号钢 + // 4 1 Cr13?2Cr13 + // 5 Cr17 + // 6 12 CrMoV + // 7 10 CrMo910 + // 8 Cr6SiMo + // 9 X20CrMoV121 + // 10 1 Cr18Ni9Ti + // 11 普通碳钢 + // 12 工业用铜 + // 13 黄铜 + // 14 红铜 + switch (tempCaiLiao) + { + case 0: + CaiLiaoPzxs = 11.75; + break; + + case 1: + CaiLiaoPzxs = 11.6; + break; + + case 2: + CaiLiaoPzxs = 11.16; + break; + + case 3: + CaiLiaoPzxs = 11.59; + break; + + case 4: + CaiLiaoPzxs = 10.5; + break; + + case 5: + CaiLiaoPzxs = 10D; + break; + + case 6: + CaiLiaoPzxs = 10.2; + break; + + case 7: + CaiLiaoPzxs = 15.5; + break; + + case 8: + CaiLiaoPzxs = 11.5; + break; + + case 9: + CaiLiaoPzxs = 10.8; + break; + + case 10: + CaiLiaoPzxs = 16.6; + break; + + case 11: + CaiLiaoPzxs = 11.4; + break; + + case 12: + CaiLiaoPzxs = 16.55; + break; + + case 13: + CaiLiaoPzxs = 17.8; + break; + + case 14: + CaiLiaoPzxs = 17.2; + break; + } + return CaiLiaoPzxs; + } + + /** + 计算重复性 + + @param data + @param DataAver + @return + */ + + public static double DataEr(RefObject DataAver, double[] data) + { + return DataEr(DataAver, data, 0); + } + +//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: +//ORIGINAL LINE: public static double DataEr(ref double DataAver, double[] data, int Num = 0) + public static double DataEr(RefObject DataAver, double[] data, int Num) // = 0.0 + { + double DataEr = 0; + int n = 0; + int i = 0; + double DataSum = 0; + // 重复性计算 + + if (Num == 0) + { + n = data.length - 1 + 1; + } + else + { + n = Num; + } + if (n <= 1) + { + return DataEr; + } + DataSum = 0; + for (i = 0; i <= n - 1; i += 1) + { + DataSum = DataSum + data[i]; + } + DataAver.argValue = DataSum / n; + + DataSum = 0; + for (i = 0; i <= n - 1; i += 1) + { + DataSum = DataSum + Math.pow((data[i] - DataAver.argValue), 2); + } + + DataSum = Math.sqrt(DataSum / (n - 1)); + + DataEr = DataSum * 100 / DataAver.argValue; // 重复性 + return DataEr; + } + /** + 计算平均值 + + @param data + @return + */ + public static double DataAVG(double[] data) + { + double DataAVG = 0; + int n = 0; + int i = 0; + double DataSum = 0; + // 平均值 + DataAVG = 0; + n = data.length - 1 + 1; + DataSum = 0; + for (i = 0; i <= n - 1; i += 1) + { + DataSum = DataSum + data[i]; + } + DataAVG = DataSum / n; + + return DataAVG; + } + + /** + 获取数组中的最大值 + + @param MyArray + @param NumMin + @return + */ + public static double GetMax(double[] MyArray, RefObject NumMin) + { + int gIterations = 0; + int Index = 0; + double temp = 0; + int NextElement = 0; + // 获得一个数组中的最大值 + NextElement = 0; + while ((NextElement < MyArray.length - 1)) + { + Index = MyArray.length - 1; + while ((Index > NextElement)) + { + if (MyArray[Index] >= MyArray[Index - 1]) + { + temp = MyArray[Index]; + MyArray[Index] = MyArray[Index - 1]; + MyArray[Index - 1] = temp; + } + Index = Index - 1; + gIterations = gIterations + 1; + } + NextElement = NextElement + 1; + gIterations = gIterations + 1; + } + NumMin.argValue = MyArray[MyArray.length - 1]; + return MyArray[0]; + } + + // ######################################################################### + // ######################'流量转换 标况转工况############################## + // ######################################################################## + public static double FlowConvert_BaseToWork(RefObject flPar, RefObject ptAGA10) + { + double tempPn = 0; + double tempTn = 0; + + try + { + + if (ptAGA10.argValue.dZf == 0 || ptAGA10.argValue.dZb == 0) + { + return 0.0; + } + + + switch (ptAGA10.argValue.dCbtj) + { + case 2: + tempPn = 101325; + tempTn = 273.15; + break; + + case 1: + tempPn = 101325; + tempTn = 288.15; + break; + + case 0: + tempPn = 101325; + tempTn = 293.15; + break; + + case 3: + tempPn = 10155981; + tempTn = 288.7055555; + break; + } + + + flPar.argValue.dVFlowf = flPar.argValue.dVFlowb * (tempPn * flPar.argValue.dTf * ptAGA10.argValue.dZf) / (flPar.argValue.dPf * tempTn * ptAGA10.argValue.dZb); + return flPar.argValue.dVFlowf; + // WARNING: ErrDo: is not supported + } + catch (RuntimeException exc) + { + return 0.0; + + } + } + + // ######################################################################### + // ######################流量转换工况转标况############################## + // ######################################################################## + public static double FlowConvert_WorkToBase(RefObject flPar, RefObject ptAGA10) + { + double tempPn = 0; + double tempTn = 0; + + // WARNING: On Error GOTO ErrDo is not supported + try + { + + switch (ptAGA10.argValue.dCbtj) + { + case 2: + tempPn = 101325; + tempTn = 273.15; + break; + + case 1: + tempPn = 101325; + tempTn = 288.15; + break; + + case 0: + tempPn = 101325; + tempTn = 293.15; + break; + + case 3: + tempPn = 0.10155981; + tempTn = 288.7055555; + break; + } + flPar.argValue.dVFlowb = flPar.argValue.dVFlowf * (flPar.argValue.dPf * tempTn * ptAGA10.argValue.dZb) / (tempPn * flPar.argValue.dTf * ptAGA10.argValue.dZf); + return flPar.argValue.dVFlowb; + // WARNING: ErrDo: is not supported + } + catch (RuntimeException exc) + { + return 0.0; + } + + } + //压力损失计算 + public final double YaLiSunShi(double tempLiuChuXiShu, double tempZjb, double tempDp, int JieLiuZhuangZhi) + { + double ylss = 0; + switch (JieLiuZhuangZhi) + { + case 0: + ylss = (tempDp * (Math.sqrt(1 - tempZjb) - tempLiuChuXiShu * Math.pow(tempZjb, 2)) / (Math.sqrt(1 - tempZjb) + tempLiuChuXiShu * Math.pow(tempZjb, 2))); + break; + case 1: + ylss = (tempDp * (Math.sqrt(1 - tempZjb) - tempLiuChuXiShu * Math.pow(tempZjb, 2)) / (Math.sqrt(1 - tempZjb) + tempLiuChuXiShu * Math.pow(tempZjb, 2))); + break; + case 2: + ylss = (tempDp * (Math.sqrt(1 - tempZjb) - tempLiuChuXiShu * Math.pow(tempZjb, 2)) / (Math.sqrt(1 - tempZjb) + tempLiuChuXiShu * Math.pow(tempZjb, 2))); + break; + } + return ylss; + } + //查表计算粘度μ + // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#. + private final double[][] Dlndjs_Dlnd_Data = new double[8][11]; + private final double[] Dlndjs_Dlnd_T = new double[8]; + private final double[] Dlndjs_Dlnd_P = new double[11]; + + public final double Dlndjs(double tempP_jy, double tempT, int PU, int TU) + { + // static double[,] Dlnd_Data = new double[8, 11]; //VBConversions Note: Static variable moved to class level and renamed Dlndjs_Dlnd_Data. Local static variables are not supported in C#. + // static double[] Dlnd_T = new double[8]; //VBConversions Note: Static variable moved to class level and renamed Dlndjs_Dlnd_T. Local static variables are not supported in C#. + // static double[] Dlnd_P = new double[11]; //VBConversions Note: Static variable moved to class level and renamed Dlndjs_Dlnd_P. Local static variables are not supported in C#. + double s1 = 0; + double s2 = 0; + double ky = 0; + double kx = 0; + int i = 0; + int m = 0; + int n = 0; + //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C# + Dlndjs_Dlnd_T[0] = -15 + 273.15; + Dlndjs_Dlnd_T[1] = 0 + 273.15; + Dlndjs_Dlnd_T[2] = 15 + 273.15; + Dlndjs_Dlnd_T[3] = 30 + 273.15; + Dlndjs_Dlnd_T[4] = 45 + 273.15; + Dlndjs_Dlnd_T[5] = 60 + 273.15; + Dlndjs_Dlnd_T[6] = 75 + 273.15; + Dlndjs_Dlnd_T[7] = 90 + 273.15; + + Dlndjs_Dlnd_P[0] = 0.1F; + Dlndjs_Dlnd_P[1] = 1; + Dlndjs_Dlnd_P[2] = 2; + Dlndjs_Dlnd_P[3] = 3; + Dlndjs_Dlnd_P[4] = 4; + Dlndjs_Dlnd_P[5] = 5; + Dlndjs_Dlnd_P[6] = 6; + Dlndjs_Dlnd_P[7] = 7; + Dlndjs_Dlnd_P[8] = 8; + Dlndjs_Dlnd_P[9] = 9; + Dlndjs_Dlnd_P[10] = 10; + Dlndjs_Dlnd_Data[0][0] = 976; + Dlndjs_Dlnd_Data[1][0] = 1027; + Dlndjs_Dlnd_Data[2][0] = 1071; + Dlndjs_Dlnd_Data[3][0] = 1123; + Dlndjs_Dlnd_Data[4][0] = 1167; + Dlndjs_Dlnd_Data[5][0] = 1213; + Dlndjs_Dlnd_Data[6][0] = 1260; + Dlndjs_Dlnd_Data[7][0] = 1303; + Dlndjs_Dlnd_Data[0][1] = 991; + Dlndjs_Dlnd_Data[1][1] = 1040; + Dlndjs_Dlnd_Data[2][1] = 1082; + Dlndjs_Dlnd_Data[3][1] = 1135; + Dlndjs_Dlnd_Data[4][1] = 1178; + Dlndjs_Dlnd_Data[5][1] = 1224; + Dlndjs_Dlnd_Data[6][1] = 1270; + Dlndjs_Dlnd_Data[7][1] = 1312; + Dlndjs_Dlnd_Data[0][2] = 1014; + Dlndjs_Dlnd_Data[1][2] = 1063; + Dlndjs_Dlnd_Data[2][2] = 1106; + Dlndjs_Dlnd_Data[3][2] = 1153; + Dlndjs_Dlnd_Data[4][2] = 1196; + Dlndjs_Dlnd_Data[5][2] = 1239; + Dlndjs_Dlnd_Data[6][2] = 1281; + Dlndjs_Dlnd_Data[7][2] = 1323; + Dlndjs_Dlnd_Data[0][3] = 1044; + Dlndjs_Dlnd_Data[1][3] = 1091; + Dlndjs_Dlnd_Data[2][3] = 1127; + Dlndjs_Dlnd_Data[3][3] = 1174; + Dlndjs_Dlnd_Data[4][3] = 1216; + Dlndjs_Dlnd_Data[5][3] = 1257; + Dlndjs_Dlnd_Data[6][3] = 1297; + Dlndjs_Dlnd_Data[7][3] = 1338; + Dlndjs_Dlnd_Data[0][4] = 1073; + Dlndjs_Dlnd_Data[1][4] = 1118; + Dlndjs_Dlnd_Data[2][4] = 1149; + Dlndjs_Dlnd_Data[3][4] = 1195; + Dlndjs_Dlnd_Data[4][4] = 1236; + Dlndjs_Dlnd_Data[5][4] = 1275; + Dlndjs_Dlnd_Data[6][4] = 1313; + Dlndjs_Dlnd_Data[7][4] = 1352; + Dlndjs_Dlnd_Data[0][5] = 1114; + Dlndjs_Dlnd_Data[1][5] = 1151; + Dlndjs_Dlnd_Data[2][5] = 1180; + Dlndjs_Dlnd_Data[3][5] = 1224; + Dlndjs_Dlnd_Data[4][5] = 1261; + Dlndjs_Dlnd_Data[5][5] = 1297; + Dlndjs_Dlnd_Data[6][5] = 1333; + Dlndjs_Dlnd_Data[7][5] = 1372; + Dlndjs_Dlnd_Data[0][6] = 1156; + Dlndjs_Dlnd_Data[1][6] = 1185; + Dlndjs_Dlnd_Data[2][6] = 1211; + Dlndjs_Dlnd_Data[3][6] = 1253; + Dlndjs_Dlnd_Data[4][6] = 1287; + Dlndjs_Dlnd_Data[5][6] = 1320; + Dlndjs_Dlnd_Data[6][6] = 1352; + Dlndjs_Dlnd_Data[7][6] = 1391; + Dlndjs_Dlnd_Data[0][7] = 1207; + Dlndjs_Dlnd_Data[1][7] = 1230; + Dlndjs_Dlnd_Data[2][7] = 1250; + Dlndjs_Dlnd_Data[3][7] = 1289; + Dlndjs_Dlnd_Data[4][7] = 1318; + Dlndjs_Dlnd_Data[5][7] = 1346; + Dlndjs_Dlnd_Data[6][7] = 1374; + Dlndjs_Dlnd_Data[7][7] = 1412; + Dlndjs_Dlnd_Data[0][8] = 1261; + Dlndjs_Dlnd_Data[1][8] = 1276; + Dlndjs_Dlnd_Data[2][8] = 1289; + Dlndjs_Dlnd_Data[3][8] = 1324; + Dlndjs_Dlnd_Data[4][8] = 1350; + Dlndjs_Dlnd_Data[5][8] = 1373; + Dlndjs_Dlnd_Data[6][8] = 1396; + Dlndjs_Dlnd_Data[7][8] = 1432; + Dlndjs_Dlnd_Data[0][9] = 1331; + Dlndjs_Dlnd_Data[1][9] = 1331; + Dlndjs_Dlnd_Data[2][9] = 1335; + Dlndjs_Dlnd_Data[3][9] = 1366; + Dlndjs_Dlnd_Data[4][9] = 1385; + Dlndjs_Dlnd_Data[5][9] = 1403; + Dlndjs_Dlnd_Data[6][9] = 1424; + Dlndjs_Dlnd_Data[7][9] = 1456; + Dlndjs_Dlnd_Data[0][10] = 1405; + Dlndjs_Dlnd_Data[1][10] = 1389; + Dlndjs_Dlnd_Data[2][10] = 1383; + Dlndjs_Dlnd_Data[3][10] = 1409; + Dlndjs_Dlnd_Data[4][10] = 1421; + Dlndjs_Dlnd_Data[5][10] = 1435; + Dlndjs_Dlnd_Data[6][10] = 1451; + Dlndjs_Dlnd_Data[7][10] = 1482; + + if (tempT < Dlndjs_Dlnd_T[0]) + { + tempT = Dlndjs_Dlnd_T[0]; + } + if (tempT > Dlndjs_Dlnd_T[7]) + { + tempT = Dlndjs_Dlnd_T[7]; + } + if (tempP_jy < Dlndjs_Dlnd_P[0]) + { + tempP_jy = Dlndjs_Dlnd_P[0]; + } + if (tempP_jy > Dlndjs_Dlnd_P[10]) + { + tempP_jy = Dlndjs_Dlnd_P[10]; + } + + for ( i = 0; i <= 6; i++) + { + if (tempT >= Dlndjs_Dlnd_T[i] && tempT <= Dlndjs_Dlnd_T[i + 1]) + { + m = i; + break; + } + } + + for (i = 0; i <= 9; i++) + { + if (tempP_jy >= Dlndjs_Dlnd_P[i] && tempP_jy <= Dlndjs_Dlnd_P[i + 1]) + { + n = i; + break; + } + } + + if (Dlndjs_Dlnd_P[n + 1] - Dlndjs_Dlnd_P[n] != 0) + { + ky = (tempP_jy - Dlndjs_Dlnd_P[n]) / (Dlndjs_Dlnd_P[n + 1] - Dlndjs_Dlnd_P[n]); + } + else + { + ky = 0; + } + if (Dlndjs_Dlnd_T[m + 1] - Dlndjs_Dlnd_T[m] != 0) + { + kx = (tempT - Dlndjs_Dlnd_T[m]) / (Dlndjs_Dlnd_T[m + 1] - Dlndjs_Dlnd_T[m]); + } + else + { + kx = 0; + } + s1 = Dlndjs_Dlnd_Data[m][n] + (Dlndjs_Dlnd_Data[m][n + 1] - Dlndjs_Dlnd_Data[m][n]) * ky; + s2 = Dlndjs_Dlnd_Data[m + 1][n] + (Dlndjs_Dlnd_Data[m + 1][n + 1] - Dlndjs_Dlnd_Data[m + 1][n]) * ky; + return (s1 + (s2 - s1) * kx) / 100000.0D; + } + //可膨胀系数计算 + private double KePenZhang_JiSuan(double tempP_jy_MPa, double tempDp_Pa, double tempZjb, double tempDszs, int JIeliuType, int JiSuanBiaoZhun) // 求可膨胀系数 + { + double returnValue = 0; + //0标准孔板 + //1ISA1932喷嘴 + //2长径喷嘴 + //3文丘里喷嘴 + //4粗铸收缩段经典文丘里管 + //5机械加工收缩段经典文丘里管 + //6粗焊铁板收缩段经典文丘里管 + //7 1/4圆孔板 + + double tuo = 0; + switch (JIeliuType) + { + case 0: //孔板流量计算 + switch (JiSuanBiaoZhun) + { + case 0: //6143-2004 + tuo = (tempP_jy_MPa * 1000000.0D - tempDp_Pa) / (tempP_jy_MPa * 1000000.0D); + returnValue = 1 - (0.351 + 0.256 * Math.pow(tempZjb, 4) + 0.93 * Math.pow(tempZjb, 8)) * (1 - Math.pow(tuo, (1 / tempDszs))); + break; + case 1: //6143-1996 + returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs); + break; + + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + switch (JiSuanBiaoZhun) + { + case 0: + + //标准喷嘴 iso5167-2002 + tuo = (tempP_jy_MPa * 10000000.0D - tempDp_Pa) / (tempP_jy_MPa * 10000000.0D); + returnValue = Math.pow((((tempDszs * Math.pow(tuo, (2 / tempDszs))) / (tempDszs - 1)) * ((1 - Math.pow(tempZjb, 4)) / (1 - Math.pow(tempZjb, 4) * Math.pow(tuo, (2 / tempDszs)))) * ((1 - Math.pow(tuo, ((tempDszs - 1) / tempDszs))) / (1 - tuo))), 0.5); + break; + + case 1: //iso5167-93 + returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs); + break; + } + break; + case 7: //1/4圆孔板 + returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs); + break; + case 8: //锥形入口孔板 + tuo = (tempP_jy_MPa * 1000000.0D - tempDp_Pa) / (tempP_jy_MPa * 1000000.0D); + returnValue = 1 - (0.351 + 0.256 * Math.pow(tempZjb, 4) + 0.93 * Math.pow(tempZjb, 8)) * (1 - Math.pow(tuo, (1 / tempDszs))); + + tuo = (tempP_jy_MPa * 10000000.0D - tempDp_Pa) / (tempP_jy_MPa * 10000000.0D); + + returnValue = 0.5 * (returnValue + Math.pow((((tempDszs * Math.pow(tuo, (2 / tempDszs))) / (tempDszs - 1)) * ((1 - Math.pow(tempZjb, 4)) / (1 - Math.pow(tempZjb, 4) * Math.pow(tuo, (2 / tempDszs)))) * ((1 - Math.pow(tuo, ((tempDszs - 1) / tempDszs))) / (1 - tuo))), 0.5)); + break; + case 9: //偏心孔板 + returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs); + break; + + } + return returnValue; + } + //流出系数计算 + public final double C_JiSuan(double tempGj, double tempZjb, double tempReD, double tempconQvA, int tempQyfs, int JieLiuType, int JiSuanBiaoZhun) + { + double returnValue = 0; + //流出系数计算函数 + //输入:直径比,雷诺数,取压方式,节流装置类型,计算采用标准 + //输出:流出系数 + + //jieliutype + + //0标准孔板 + //1ISA1932喷嘴 + //2长径喷嘴 + //3文丘里喷嘴 + //4粗铸收缩段经典文丘里管 + //5机械加工收缩段经典文丘里管 + //6粗焊铁板收缩段经典文丘里管 + + double L1 = 0; + double L2 = 0; + switch (JieLiuType) + { + case 0: //孔板 + switch (tempQyfs) + { + case 0: + L1 = 25.4 / tempGj; + L2 = L1; + break; + case 1: + L1 = 0; + L2 = 0; + break; + case 2: + L1 = 1; + L2 = 0.47F; + break; + } + + switch (JiSuanBiaoZhun) + { + case 0: //6143-2004 + if (tempGj >= 71.12) + { + returnValue = 0.5961 + 0.0261 * Math.pow(tempZjb, 2) - 0.216 * Math.pow(tempZjb, 8) + 0.000521 * Math.pow((1000000.0D * tempZjb / tempReD), 0.7) + (0.0188 + 0.0063 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * Math.pow(tempZjb, 3.5) * Math.pow((1000000.0D / tempReD), 0.3) + (0.043 + 0.08 * Math.exp(-10 * L1) - 0.123 * Math.exp(-7 * L1)) * (1 - 0.11 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * (Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1))) - 0.031 * (2 * L2 / (1 - tempZjb) - 0.8 * Math.pow((2 * L2 / (1 - tempZjb)), 1.1)) * Math.pow(tempZjb, 1.3); + + } + else if (tempGj < 71.12) + { + returnValue = (0.5961 + 0.0261 * Math.pow(tempZjb, 2) - 0.216 * Math.pow(tempZjb, 8) + 0.000521 * Math.pow((1000000.0D * tempZjb / tempReD), 0.7) + (0.0188 + 0.0063 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * Math.pow(tempZjb, 3.5) * Math.pow((1000000.0D / tempReD), 0.3) + (0.043 + 0.08 * Math.exp(-10 * L1) - 0.123 * Math.exp(-7 * L1)) * (1 - 0.11 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1)) - 0.031 * (2 * L2 / (1 - tempZjb) - 0.8 * Math.pow((2 * L2 * (1 - tempZjb)), 1.1)) * Math.pow(tempZjb, 1.3) + 0.011 * (0.75 - tempZjb) * (2.8 - tempGj / 25.4)); + } + break; + case 1: //6143-1996 + if (0.09 * L1 >= 0.039) + { + returnValue = 0.5959 + 0.0312 * Math.pow(tempZjb, (2.1)) - 0.184 * Math.pow(tempZjb, 8) + 0.0029 * Math.pow(tempZjb, 2.5) * Math.pow((1000000.0D / tempReD), 0.75) + 0.039 * Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1)) - 0.0337 * L1 * Math.pow(tempZjb, 3); + } + else if (0.09 * L1 < 0.039) + { + returnValue = (0.5959 + 0.0312 * Math.pow(tempZjb, (2.1)) - 0.184 * Math.pow(tempZjb, 8) + 0.0029 * Math.pow(tempZjb, 2.5) * Math.pow((1000000.0D / tempReD), 0.75) + 0.09 * L1 * Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1)) - 0.0337 * L1 * Math.pow(tempZjb, 3)); + } + break; + } + break; + + + + case 1: //ISA1932喷嘴 + returnValue = (0.99 - 0.2262 * Math.pow(tempZjb, 4.1) - (0.00175 * Math.pow(tempZjb, 2) - 0.0033 * Math.pow(tempZjb, 4.15)) * (1000000.0D / Math.pow(tempReD, 1.15))); + break; + + case 2: //长径喷嘴 + returnValue = (0.9965 - 0.00653 * Math.pow(tempZjb, 0.5) * Math.pow((1000000.0D / tempReD), 0.5)); + break; + case 3: //文丘里喷嘴 + returnValue = (0.9858 - 0.196 * Math.pow(tempZjb, 4.5)); + break; + case 4: //粗铸收缩段经典文丘里管 + returnValue = (0.984F); + break; + case 5: //机械加工收缩段经典文丘里管 + returnValue = (0.995F); + break; + case 6: //粗焊铁板收缩段经典文丘里管 + returnValue = (0.985F); + break; + case 7: //1/4圆孔板 + returnValue = 0.73823 - 0.3309 * tempZjb - 1.1615 * Math.pow(tempZjb, 2) + 1.5084 * Math.pow(tempZjb, 3); + break; + case 8: //锥形入口孔板 + returnValue = (0.734F); + break; + case 9: //偏心孔板 + returnValue = 0.9355 - 1.6889 * tempZjb + 3.0428 * Math.pow(tempZjb, 2) - 1.7989 * Math.pow(tempZjb, 3); + + + break; + } + double tempRed1 = 0; + switch (JieLiuType) + { + case 0: //孔板流量计算 + tempRed1 = tempconQvA * returnValue; + switch (JieLiuType) + { + case 0: + if (tempRed1 < (170 * Math.pow(tempZjb, 2) * tempGj)) + { + JOptionPane.showMessageDialog(null, "雷诺数超过标准孔板的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + return returnValue; + } + break; + case 1: + if (tempZjb >= 0.1 & tempZjb <= 0.56) + { + if (tempRed1 < 5000) + { + JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + return returnValue; + } + } + if (tempZjb > 0.56) + { + if (tempRed1 < (16000 * Math.pow(tempZjb, 2) * tempGj)) + { + JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + return returnValue; + } + } + break; + } + break; + + case 1: //标准喷嘴 + tempRed1 = tempconQvA * returnValue; + if (tempZjb >= 0.3 & tempZjb < 0.44) + { + if (tempRed1 < 70000 | tempRed1 > 10000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + } + } + if (tempZjb >= 0.44 & tempZjb < 0.8) + { + if (tempRed1 < 20000 | tempRed1 > 10000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + } + } + break; + + + case 2: //长径喷嘴 + tempRed1 = tempconQvA * returnValue; + if (tempRed1 < 10000.0D | tempRed1 > 10000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过长径喷嘴的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + } + break; + case 3: //文丘里喷嘴 + tempRed1 = tempconQvA * returnValue; + if (tempRed1 < 150000.0D | tempRed1 > 2000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过文丘里喷嘴的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + } + break; + case 4: //粗铸收缩段经典文丘里管 + tempRed1 = tempconQvA * returnValue; + if (tempRed1 < 200000.0D | tempRed1 > 2000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过粗铸收缩段经典文丘里管的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + return returnValue; + } + break; + case 5: //机械加工收缩段经典文丘里管 + tempRed1 = tempconQvA * returnValue; + if (tempRed1 < 200000.0D | tempRed1 > 1000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过机械加工收缩段经典文丘里管的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + } + break; + case 6: //粗焊铁板收缩段经典文丘里管 + tempRed1 = tempconQvA * returnValue; + if (tempRed1 < 200000.0D | tempRed1 > 2000000.0D) + { + JOptionPane.showMessageDialog(null, "雷诺数超过粗焊铁板收缩段经典文丘里管的使用范围!停止计算!", "提示", JOptionPane.PLAIN_MESSAGE); + } + break; + + //标准孔板 + //ISA1932喷嘴 + //长径喷嘴 + //文丘里喷嘴 + //粗铸收缩段经典文丘里管 + //机械加工收缩段经典文丘里管 + //粗焊铁板收缩段经典文丘里管 + + + + + } + return returnValue; + } + //管道 孔板膨胀后尺寸计算 + private double Work_Cd(int tempCaiLiao, double tempWd_C, double tempCD20) + { + //孔板和管道材料的膨胀系数 6143标准 + //0 A3、15号钢 + //1 10 号钢 + //2 20 号钢 + //3 45 号钢 + //4 1 Cr13?2Cr13 + //5 Cr17 + //6 12 CrMoV + //7 10 CrMo910 + //8 Cr6SiMo + //9 X20CrMoV121 + //10 1 Cr18Ni9Ti + //11 普通碳钢 + //12 工业用铜 + //13 黄铜 + //14 红铜 + double CaiLiaoPzxs = 0; + switch (tempCaiLiao) + { + case 0: + CaiLiaoPzxs = 11.75F; + + CaiLiaoPzxs = 11.6F; + break; + case 2: + CaiLiaoPzxs = 11.16F; + + CaiLiaoPzxs = 11.59F; + break; + case 4: + CaiLiaoPzxs = 10.5F; + + CaiLiaoPzxs = 10.0F; + break; + case 6: + CaiLiaoPzxs = 10.2F; + + CaiLiaoPzxs = 15.5F; + break; + case 8: + CaiLiaoPzxs = 11.5F; + + CaiLiaoPzxs = 10.8F; + break; + case 10: + CaiLiaoPzxs = 16.6F; + + CaiLiaoPzxs = 11.4F; + break; + case 12: + CaiLiaoPzxs = 16.55F; + + CaiLiaoPzxs = 17.8F; + break; + case 14: + CaiLiaoPzxs = 17.2F; + break; + } + return tempCD20 * (1 + 0.000001 * CaiLiaoPzxs * (tempWd_C - 20)); + } + //查表计算孔板尖锐度系数bk + // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#. + private final double[] BkTable_x = new double[10]; + private final double[] BkTable_Y = new double[10]; + + private double BkTable(double temPrk, double tempKj, int tempBkjsff) + { + + //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C# + + if (tempBkjsff == 1) + { + + double tempRkBiKj = 0; + tempRkBiKj = temPrk / tempKj; + + // static double[] x = new double[10]; //VBConversions Note: Static variable moved to class level and renamed BkTable_x. Local static variables are not supported in C#. + // static double[] Y = new double[10]; //VBConversions Note: Static variable moved to class level and renamed BkTable_Y. Local static variables are not supported in C#. + int i = 0; + int xIndex = 0; + //If x(0) = 0 Then + BkTable_x[0] = 0.0004F; + BkTable_x[1] = 0.001F; + BkTable_x[2] = 0.002F; + BkTable_x[3] = 0.004F; + BkTable_x[4] = 0.006F; + BkTable_x[5] = 0.008F; + BkTable_x[6] = 0.01F; + BkTable_x[7] = 0.012F; + BkTable_x[8] = 0.014F; + BkTable_x[9] = 0.015F; + + BkTable_Y[0] = 1; + BkTable_Y[1] = 1.005F; + BkTable_Y[2] = 1.012F; + BkTable_Y[3] = 1.022F; + BkTable_Y[4] = 1.032F; + BkTable_Y[5] = 1.04F; + BkTable_Y[6] = 1.048F; + BkTable_Y[7] = 1.055F; + BkTable_Y[8] = 1.062F; + BkTable_Y[9] = 1.065F; + //End If + + if (tempRkBiKj <= 0.0004) + { + return 1; + + } + if (tempRkBiKj > 0.015) + { + return 1.065F; + + } + + for (i = 0; i <= 8; i++) + { + if (tempRkBiKj >= BkTable_x[i] && tempRkBiKj <= BkTable_x[i + 1]) + { + xIndex = i; + break; + } + } + return BkTable_Y[xIndex] + (tempRkBiKj - BkTable_x[xIndex]) * (BkTable_Y[xIndex + 1] - BkTable_Y[xIndex]) / (BkTable_x[xIndex + 1] - BkTable_x[xIndex]); + } + return 0; + } + //管道粗糙度计算 + private double CcdXsjs(double tempPipeType, double tempGj, double tempZjb, double TempRed) + { + double returnValue = 0; + //粗糙度系数计算 + double Jdccd = 0; //绝对粗糙度 + double Xdccd = 0; //相对粗糙度 + //Dim CcdXs As single + double s1 = 0; + double s2 = 0; + double ky = 0; + double kx = 0; + int i = 0; + int m = 0; + int n = 0; + if (tempPipeType == 0) + { + Jdccd = 0.029F; + + Jdccd = 0.075F; + } + else if (tempPipeType == 2) + { + Jdccd = 0.075F; + + Jdccd = 0.075F; + } + else if (tempPipeType == 4) + { + Jdccd = 0.1F; + + Jdccd = 0.15F; + } + else if (tempPipeType == 6) + { + Jdccd = 1; + + Jdccd = 2.1F; + } + else if (tempPipeType == 8) + { + Jdccd = 0.04F; + + Jdccd = 0.15F; + } + else if (tempPipeType == 10) + { + Jdccd = 0.13F; + + Jdccd = 0.25F; + } + Xdccd = tempGj / Jdccd; + if (Xdccd < 400) + { + JOptionPane.showMessageDialog(null, "粗糙度取得太高,粗略计算", "提示", JOptionPane.PLAIN_MESSAGE); + Xdccd = 400; + } + if (Xdccd >= 3400) + { + Xdccd = 3400; + } + + if (Xdccd < 3200 & Math.pow(tempZjb, 2) > 0.1 & Math.pow(tempZjb, 2) < 0.64) + { + + int[] Xdccdb = new int[10]; + double[] Btf = new double[8]; + double[][] CcdXsb = new double[10][8]; + + Xdccdb[0] = 400; + Xdccdb[1] = 800; + Xdccdb[2] = 1200; + Xdccdb[3] = 1600; + Xdccdb[4] = 2000; + Xdccdb[5] = 2400; + Xdccdb[6] = 2800; + Xdccdb[7] = 3200; + Xdccdb[8] = 3400; + + Btf[0] = 0.1F; + Btf[1] = 0.2F; + Btf[2] = 0.3F; + Btf[3] = 0.4F; + Btf[4] = 0.5F; + Btf[5] = 0.6F; + Btf[6] = 0.64F; + + CcdXsb[0][0] = 1.002; + CcdXsb[1][0] = 1; + CcdXsb[2][0] = 1; + CcdXsb[3][0] = 1; + CcdXsb[4][0] = 1; + CcdXsb[5][0] = 1; + CcdXsb[6][0] = 1; + CcdXsb[7][0] = 1; + CcdXsb[8][0] = 1; + CcdXsb[0][1] = 1.003; + CcdXsb[1][1] = 1.002; + CcdXsb[2][1] = 1.001; + CcdXsb[3][1] = 1; + CcdXsb[4][1] = 1; + CcdXsb[5][1] = 1; + CcdXsb[6][1] = 1; + CcdXsb[7][1] = 1; + CcdXsb[8][0] = 1; + CcdXsb[0][2] = 1.006; + CcdXsb[1][2] = 1.004; + CcdXsb[2][2] = 1.002; + CcdXsb[3][2] = 1.001; + CcdXsb[4][2] = 1; + CcdXsb[5][2] = 1; + CcdXsb[6][2] = 1; + CcdXsb[7][2] = 1; + CcdXsb[8][0] = 1; + CcdXsb[0][3] = 1.009; + CcdXsb[1][3] = 1.006; + CcdXsb[2][3] = 1.004; + CcdXsb[3][3] = 1.002; + CcdXsb[4][3] = 1.001; + CcdXsb[5][3] = 1; + CcdXsb[6][3] = 1; + CcdXsb[7][3] = 1; + CcdXsb[8][0] = 1; + CcdXsb[0][4] = 1.014; + CcdXsb[1][4] = 1.009; + CcdXsb[2][4] = 1.006; + CcdXsb[3][4] = 1.004; + CcdXsb[4][4] = 1.002; + CcdXsb[5][4] = 1.001; + CcdXsb[6][4] = 1; + CcdXsb[7][4] = 1; + CcdXsb[8][0] = 1; + CcdXsb[0][5] = 1.02; + CcdXsb[1][5] = 1.013; + CcdXsb[2][5] = 1.009; + CcdXsb[3][5] = 1.006; + CcdXsb[4][5] = 1.003; + CcdXsb[5][5] = 1.002; + CcdXsb[6][5] = 1; + CcdXsb[7][5] = 1; + CcdXsb[8][0] = 1; + CcdXsb[0][6] = 1.024; + CcdXsb[1][6] = 1.016; + CcdXsb[2][6] = 1.011; + CcdXsb[3][6] = 1.007; + CcdXsb[4][6] = 1.004; + CcdXsb[5][6] = 1.002; + CcdXsb[6][6] = 1.002; + CcdXsb[7][6] = 1; + CcdXsb[8][0] = 1; + + for (i = 0; i <= 8; i++) + { + if (Xdccd >= Xdccdb[i] && Xdccd <= Xdccdb[i + 1]) + { + m = i; + break; + } + } + for (i = 0; i <= 6; i++) + { + if (Math.pow(tempZjb, 2) >= Btf[i] && Math.pow(tempZjb, 2) <= Btf[i + 1]) + { + n = i; + break; + } + } + + ky = (Btf[n + 1] - Btf[n] != 0) ? ((Math.pow(tempZjb, 2) - Btf[n]) / (Btf[n + 1] - Btf[n])) : 0; + + kx = (Xdccdb[m + 1] - Xdccdb[m] != 0) ? ((Xdccd - Xdccdb[m]) / (Xdccdb[m + 1] - Xdccdb[m])) : 0; + + s1 = CcdXsb[m][n] + (CcdXsb[m][n + 1] - CcdXsb[m][n]) * ky; + s2 = CcdXsb[m + 1][n] + (CcdXsb[m + 1][n + 1] - CcdXsb[m + 1][n]) * ky; + returnValue = s1 + (s2 - s1) * kx; + + returnValue = TempRed > 1000000.0 ? returnValue : ((returnValue - 1) * Math.pow((Math.log10(TempRed) / 2), 2) + 1); + + } + else + { + returnValue = 1; + } + return returnValue; + } + //流量换算 工况 标况转寰 + public final double LiuLiang_Zhuanghuan(double tempQ, double tempP_jy_MPa, double tempT_Kai, double tempZn, double tempZ, int ZhuanHuanFangXiang, double tempPn, double tempTn) + { + //流量转换 + + + double temp = 0; + + + //double tempPn = 0; + //double tempTn = 0; + //switch (tempCbtj) + //{ + // case 0: + // tempPn = (double) (0.101325F); + // tempTn = (double) (293.15F); + // break; + // case 1: + // tempPn = (double) (0.101325F); + // tempTn = (double) (288.15F); + // break; + // case 2: + // tempPn = (double) (0.101325F); + // tempTn = (double) (273.15F); + // break; + // case 3: + // tempPn = (double) (0.10155981F); + // tempTn = (double) (288.7055555F); + // break; + // // Case 4 + // // LlCs6143.Qn = LlCs6143.Qn * tempLiuChuXiShubT * 0.101325 * llcs6143.ZnZdy / (293.15 * tempLiuChuXiShubP * llcs6143.Zn) + //} + + switch (ZhuanHuanFangXiang) + { + case 0: //工况转标况 + temp = tempQ * (tempP_jy_MPa * tempTn * tempZn) / (tempPn * tempT_Kai * tempZ); + break; + case 1: + temp = tempQ * (tempPn * tempT_Kai * tempZ) / (tempP_jy_MPa * tempTn * tempZn); + break; + } + return temp; + } + //计算等熵指数 + public final double Dszs(RefObject Pjy, RefObject T, RefObject PU, RefObject TU) + { + return Cpjs(Pjy, T, PU.argValue, TU.argValue) / Cvjs(Pjy, T, PU.argValue, TU.argValue); + } + //查表计算甲烷的定压比热Cv + // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#. + private final double[][] Cvjs_Cv_Data = new double[8][11]; + private final double[] Cvjs_Cv_T = new double[8]; + private final double[] Cvjs_Cv_P = new double[11]; + + public final double Cvjs(RefObject tempP_jy, RefObject tempT, int PU, int TU) + { + // static double[,] Cv_Data = new double[8, 11]; //VBConversions Note: Static variable moved to class level and renamed Cvjs_Cv_Data. Local static variables are not supported in C#. + // static double[] Cv_T = new double[8]; //VBConversions Note: Static variable moved to class level and renamed Cvjs_Cv_T. Local static variables are not supported in C#. + // static double[] Cv_P = new double[11]; //VBConversions Note: Static variable moved to class level and renamed Cvjs_Cv_P. Local static variables are not supported in C#. + double s1 = 0; + double s2 = 0; + double ky = 0; + double kx = 0; + int i = 0; + int m = 0; + int n = 0; + //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C# + Cvjs_Cv_T[0] = -20 + 273.15; + Cvjs_Cv_T[1] = -10 + 273.15; + Cvjs_Cv_T[2] = 0 + 273.15; + Cvjs_Cv_T[3] = 10 + 273.15; + Cvjs_Cv_T[4] = 20 + 273.15; + Cvjs_Cv_T[5] = 30 + 273.15; + Cvjs_Cv_T[6] = 40 + 273.15; + Cvjs_Cv_T[7] = 50 + 273.15; + + Cvjs_Cv_P[0] = 0.1F; + Cvjs_Cv_P[1] = 1; + Cvjs_Cv_P[2] = 2; + Cvjs_Cv_P[3] = 3; + Cvjs_Cv_P[4] = 4; + Cvjs_Cv_P[5] = 5; + Cvjs_Cv_P[6] = 6; + Cvjs_Cv_P[7] = 7; + Cvjs_Cv_P[8] = 8; + Cvjs_Cv_P[9] = 9; + Cvjs_Cv_P[10] = 10; + Cvjs_Cv_Data[0][0] = 1.537; + Cvjs_Cv_Data[1][0] = 1.583; + Cvjs_Cv_Data[2][0] = 1.624; + Cvjs_Cv_Data[3][0] = 1.666; + Cvjs_Cv_Data[4][0] = 1.704; + Cvjs_Cv_Data[5][0] = 1.746; + Cvjs_Cv_Data[6][0] = 1.788; + Cvjs_Cv_Data[7][0] = 1.825; + Cvjs_Cv_Data[0][1] = 1.5491; + Cvjs_Cv_Data[1][1] = 1.5951; + Cvjs_Cv_Data[2][1] = 1.641; + Cvjs_Cv_Data[3][1] = 1.683; + Cvjs_Cv_Data[4][1] = 1.725; + Cvjs_Cv_Data[5][1] = 1.771; + Cvjs_Cv_Data[6][1] = 1.804; + Cvjs_Cv_Data[7][1] = 1.842; + Cvjs_Cv_Data[0][2] = 1.5492; + Cvjs_Cv_Data[1][2] = 1.5952; + Cvjs_Cv_Data[2][2] = 1.649; + Cvjs_Cv_Data[3][2] = 1.695; + Cvjs_Cv_Data[4][2] = 1.745; + Cvjs_Cv_Data[5][2] = 1.787; + Cvjs_Cv_Data[6][2] = 1.825; + Cvjs_Cv_Data[7][2] = 1.859; + Cvjs_Cv_Data[0][3] = 1.5493; + Cvjs_Cv_Data[1][3] = 1.599; + Cvjs_Cv_Data[2][3] = 1.6621; + Cvjs_Cv_Data[3][3] = 1.712; + Cvjs_Cv_Data[4][3] = 1.766; + Cvjs_Cv_Data[5][3] = 1.808; + Cvjs_Cv_Data[6][3] = 1.842; + Cvjs_Cv_Data[7][3] = 1.871; + Cvjs_Cv_Data[0][4] = 1.581; + Cvjs_Cv_Data[1][4] = 1.623; + Cvjs_Cv_Data[2][4] = 1.6622; + Cvjs_Cv_Data[3][4] = 1.716; + Cvjs_Cv_Data[4][4] = 1.775; + Cvjs_Cv_Data[5][4] = 1.817; + Cvjs_Cv_Data[6][4] = 1.854; + Cvjs_Cv_Data[7][4] = 1.887; + Cvjs_Cv_Data[0][5] = 1.614; + Cvjs_Cv_Data[1][5] = 1.632; + Cvjs_Cv_Data[2][5] = 1.678; + Cvjs_Cv_Data[3][5] = 1.732; + Cvjs_Cv_Data[4][5] = 1.783; + Cvjs_Cv_Data[5][5] = 1.821; + Cvjs_Cv_Data[6][5] = 1.859; + Cvjs_Cv_Data[7][5] = 1.892; + Cvjs_Cv_Data[0][6] = 1.616; + Cvjs_Cv_Data[1][6] = 1.644; + Cvjs_Cv_Data[2][6] = 1.687; + Cvjs_Cv_Data[3][6] = 1.753; + Cvjs_Cv_Data[4][6] = 1.803; + Cvjs_Cv_Data[5][6] = 1.841; + Cvjs_Cv_Data[6][6] = 1.871; + Cvjs_Cv_Data[7][6] = 1.9; + Cvjs_Cv_Data[0][7] = 1.769; + Cvjs_Cv_Data[1][7] = 1.645; + Cvjs_Cv_Data[2][7] = 1.672; + Cvjs_Cv_Data[3][7] = 1.735; + Cvjs_Cv_Data[4][7] = 1.785; + Cvjs_Cv_Data[5][7] = 1.831; + Cvjs_Cv_Data[6][7] = 1.864; + Cvjs_Cv_Data[7][7] = 1.901; + Cvjs_Cv_Data[0][8] = 1.746; + Cvjs_Cv_Data[1][8] = 1.619; + Cvjs_Cv_Data[2][8] = 1.648; + Cvjs_Cv_Data[3][8] = 1.722; + Cvjs_Cv_Data[4][8] = 1.784; + Cvjs_Cv_Data[5][8] = 1.833; + Cvjs_Cv_Data[6][8] = 1.871; + Cvjs_Cv_Data[7][8] = 1.905; + Cvjs_Cv_Data[0][9] = 1.708; + Cvjs_Cv_Data[1][9] = 1.549; + Cvjs_Cv_Data[2][9] = 1.627; + Cvjs_Cv_Data[3][9] = 1.71; + Cvjs_Cv_Data[4][9] = 1.78; + Cvjs_Cv_Data[5][9] = 1.834; + Cvjs_Cv_Data[6][9] = 1.875; + Cvjs_Cv_Data[7][9] = 1.912; + Cvjs_Cv_Data[0][10] = 1.767; + Cvjs_Cv_Data[1][10] = 1.566; + Cvjs_Cv_Data[2][10] = 1.603; + Cvjs_Cv_Data[3][10] = 1.697; + Cvjs_Cv_Data[4][10] = 1.779; + Cvjs_Cv_Data[5][10] = 1.837; + Cvjs_Cv_Data[6][10] = 1.883; + Cvjs_Cv_Data[7][10] = 1.917; + + if (tempT.argValue < Cvjs_Cv_T[0]) + { + tempT.argValue = Cvjs_Cv_T[0]; + } + if (tempT.argValue > Cvjs_Cv_T[7]) + { + tempT.argValue = Cvjs_Cv_T[7]; + } + if (tempP_jy.argValue < Cvjs_Cv_P[0]) + { + tempP_jy.argValue = Cvjs_Cv_P[0]; + } + if (tempP_jy.argValue > Cvjs_Cv_P[10]) + { + tempP_jy.argValue = Cvjs_Cv_P[10]; + } + + for (i = 0; i <= 6; i++) + { + if (tempT.argValue >= Cvjs_Cv_T[i] && tempT.argValue <= Cvjs_Cv_T[i + 1]) + { + m = i; + break; + } + } + + for (i = 0; i <= 9; i++) + { + if (tempP_jy.argValue >= Cvjs_Cv_P[i] && tempP_jy.argValue <= Cvjs_Cv_P[i + 1]) + { + n = i; + break; + } + } + + if (Cvjs_Cv_P[n + 1] - Cvjs_Cv_P[n] != 0) + { + ky = (tempP_jy.argValue - Cvjs_Cv_P[n]) / (Cvjs_Cv_P[n + 1] - Cvjs_Cv_P[n]); + } + else + { + ky = 0; + } + if (Cvjs_Cv_T[m + 1] - Cvjs_Cv_T[m] != 0) + { + kx = (tempT.argValue - Cvjs_Cv_T[m]) / (Cvjs_Cv_T[m + 1] - Cvjs_Cv_T[m]); + } + else + { + kx = 0; + } + s1 = Cvjs_Cv_Data[m][n] + (Cvjs_Cv_Data[m][n + 1] - Cvjs_Cv_Data[m][n]) * ky; + s2 = Cvjs_Cv_Data[m + 1][n] + (Cvjs_Cv_Data[m + 1][n + 1] - Cvjs_Cv_Data[m + 1][n]) * ky; + return s1 + (s2 - s1) * kx; + } + //查表计算甲烷的定压比热Cp + // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#. + private final double[][] Cpjs_Cp_Data = new double[8][11]; + private final double[] Cpjs_Cp_T = new double[8]; + private final double[] Cpjs_Cp_P = new double[11]; + + public final double Cpjs(RefObject tempP_jy, RefObject tempT, int PU, int TU) + { + + // static double[,] Cp_Data = new double[8, 11]; //VBConversions Note: Static variable moved to class level and renamed Cpjs_Cp_Data. Local static variables are not supported in C#. + // static double[] Cp_T = new double[8]; //VBConversions Note: Static variable moved to class level and renamed Cpjs_Cp_T. Local static variables are not supported in C#. + // static double[] Cp_P = new double[11]; //VBConversions Note: Static variable moved to class level and renamed Cpjs_Cp_P. Local static variables are not supported in C#. + double Cp1 = 0; + double Cp2 = 0; + double ky = 0; + double kx = 0; + int i = 0; + int m = 0; + int n = 0; + //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C# + Cpjs_Cp_T[0] = -20 + 273.15; + Cpjs_Cp_T[1] = -10 + 273.15; + Cpjs_Cp_T[2] = 0 + 273.15; + Cpjs_Cp_T[3] = 10 + 273.15; + Cpjs_Cp_T[4] = 20 + 273.15; + Cpjs_Cp_T[5] = 30 + 273.15; + Cpjs_Cp_T[6] = 40 + 273.15; + Cpjs_Cp_T[7] = 50 + 273.15; + + Cpjs_Cp_P[0] = 0.1F; + Cpjs_Cp_P[1] = 1; + Cpjs_Cp_P[2] = 2; + Cpjs_Cp_P[3] = 3; + Cpjs_Cp_P[4] = 4; + Cpjs_Cp_P[5] = 5; + Cpjs_Cp_P[6] = 6; + Cpjs_Cp_P[7] = 7; + Cpjs_Cp_P[8] = 8; + Cpjs_Cp_P[9] = 9; + Cpjs_Cp_P[10] = 10; + Cpjs_Cp_Data[0][0] = 2.064; + Cpjs_Cp_Data[1][0] = 2.11; + Cpjs_Cp_Data[2][0] = 2.152; + Cpjs_Cp_Data[3][0] = 2.194; + Cpjs_Cp_Data[4][0] = 2.231; + Cpjs_Cp_Data[5][0] = 2.273; + Cpjs_Cp_Data[6][0] = 2.315; + Cpjs_Cp_Data[7][0] = 2.357; + Cpjs_Cp_Data[0][1] = 2.147; + Cpjs_Cp_Data[1][1] = 2.184; + Cpjs_Cp_Data[2][1] = 2.222; + Cpjs_Cp_Data[3][1] = 2.26; + Cpjs_Cp_Data[4][1] = 2.298; + Cpjs_Cp_Data[5][1] = 2.335; + Cpjs_Cp_Data[6][1] = 2.369; + Cpjs_Cp_Data[7][1] = 2.403; + Cpjs_Cp_Data[0][2] = 2.242; + Cpjs_Cp_Data[1][2] = 2.267; + Cpjs_Cp_Data[2][2] = 2.305; + Cpjs_Cp_Data[3][2] = 2.338; + Cpjs_Cp_Data[4][2] = 2.376; + Cpjs_Cp_Data[5][2] = 2.406; + Cpjs_Cp_Data[6][2] = 2.435; + Cpjs_Cp_Data[7][2] = 2.46; + Cpjs_Cp_Data[0][3] = 2.357; + Cpjs_Cp_Data[1][3] = 2.366; + Cpjs_Cp_Data[2][3] = 2.391; + Cpjs_Cp_Data[3][3] = 2.421; + Cpjs_Cp_Data[4][3] = 2.455; + Cpjs_Cp_Data[5][3] = 2.48; + Cpjs_Cp_Data[6][3] = 2.501; + Cpjs_Cp_Data[7][3] = 2.518; + Cpjs_Cp_Data[0][4] = 2.492; + Cpjs_Cp_Data[1][4] = 2.481; + Cpjs_Cp_Data[2][4] = 2.486; + Cpjs_Cp_Data[3][4] = 2.507; + Cpjs_Cp_Data[4][4] = 2.533; + Cpjs_Cp_Data[5][4] = 2.55; + Cpjs_Cp_Data[6][4] = 2.563; + Cpjs_Cp_Data[7][4] = 2.576; + Cpjs_Cp_Data[0][5] = 2.664; + Cpjs_Cp_Data[1][5] = 2.604; + Cpjs_Cp_Data[2][5] = 2.593; + Cpjs_Cp_Data[3][5] = 2.606; + Cpjs_Cp_Data[4][5] = 2.615; + Cpjs_Cp_Data[5][5] = 2.624; + Cpjs_Cp_Data[6][5] = 2.629; + Cpjs_Cp_Data[7][5] = 2.638; + Cpjs_Cp_Data[0][6] = 2.868; + Cpjs_Cp_Data[1][6] = 2.728; + Cpjs_Cp_Data[2][6] = 2.696; + Cpjs_Cp_Data[3][6] = 2.696; + Cpjs_Cp_Data[4][6] = 2.696; + Cpjs_Cp_Data[5][6] = 2.695; + Cpjs_Cp_Data[6][6] = 2.694; + Cpjs_Cp_Data[7][6] = 2.692; + Cpjs_Cp_Data[0][7] = 3.311; + Cpjs_Cp_Data[1][7] = 3.001; + Cpjs_Cp_Data[2][7] = 2.906; + Cpjs_Cp_Data[3][7] = 2.872; + Cpjs_Cp_Data[4][7] = 2.849; + Cpjs_Cp_Data[5][7] = 2.834; + Cpjs_Cp_Data[6][7] = 2.814; + Cpjs_Cp_Data[7][7] = 2.803; + Cpjs_Cp_Data[0][8] = 3.485; + Cpjs_Cp_Data[1][8] = 3.128; + Cpjs_Cp_Data[2][8] = 3.005; + Cpjs_Cp_Data[3][8] = 2.956; + Cpjs_Cp_Data[4][8] = 2.924; + Cpjs_Cp_Data[5][8] = 2.9; + Cpjs_Cp_Data[6][8] = 2.875; + Cpjs_Cp_Data[7][8] = 2.859; + Cpjs_Cp_Data[0][9] = 3.633; + Cpjs_Cp_Data[1][9] = 3.236; + Cpjs_Cp_Data[2][9] = 3.092; + Cpjs_Cp_Data[3][9] = 3.034; + Cpjs_Cp_Data[4][9] = 2.994; + Cpjs_Cp_Data[5][9] = 2.954; + Cpjs_Cp_Data[6][9] = 2.932; + Cpjs_Cp_Data[7][9] = 2.904; + Cpjs_Cp_Data[0][10] = 3.778; + Cpjs_Cp_Data[1][10] = 3.347; + Cpjs_Cp_Data[2][10] = 3.179; + Cpjs_Cp_Data[3][10] = 3.109; + Cpjs_Cp_Data[4][10] = 3.06; + Cpjs_Cp_Data[5][10] = 3.018; + Cpjs_Cp_Data[6][10] = 2.986; + Cpjs_Cp_Data[7][10] = 2.953; + + if (tempT.argValue < Cpjs_Cp_T[0]) + { + tempT.argValue = Cpjs_Cp_T[0]; + } + if (tempT.argValue > Cpjs_Cp_T[7]) + { + tempT.argValue = Cpjs_Cp_T[7]; + } + if (tempP_jy.argValue < Cpjs_Cp_P[0]) + { + tempP_jy.argValue = Cpjs_Cp_P[0]; + } + if (tempP_jy.argValue > Cpjs_Cp_P[10]) + { + tempP_jy.argValue = Cpjs_Cp_P[10]; + } + for (i = 0; i <= 6; i++) + { + if (tempT.argValue >= Cpjs_Cp_T[i] && tempT.argValue <= Cpjs_Cp_T[i + 1]) + { + m = i; + break; + } + } + for (i = 0; i <= 9; i++) + { + if (tempP_jy.argValue >= Cpjs_Cp_P[i] && tempP_jy.argValue <= Cpjs_Cp_P[i + 1]) + { + n = i; + break; + } + } + if (Cpjs_Cp_P[n + 1] - Cpjs_Cp_P[n] != 0) + { + ky = (tempP_jy.argValue - Cpjs_Cp_P[n]) / (Cpjs_Cp_P[n + 1] - Cpjs_Cp_P[n]); + } + else + { + ky = 0; + } + if (Cpjs_Cp_T[m + 1] - Cpjs_Cp_T[m] != 0) + { + kx = (tempT.argValue - Cpjs_Cp_T[m]) / (Cpjs_Cp_T[m + 1] - Cpjs_Cp_T[m]); + } + else + { + kx = 0; + } + Cp1 = Cpjs_Cp_Data[m][n] + (Cpjs_Cp_Data[m][n + 1] - Cpjs_Cp_Data[m][n]) * ky; + Cp2 = Cpjs_Cp_Data[m + 1][n] + (Cpjs_Cp_Data[m + 1][n + 1] - Cpjs_Cp_Data[m + 1][n]) * ky; + return Cp1 + (Cp2 - Cp1) * kx; + } + +} \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/modules/GB11062.java b/src/main/java/com/ng/ngtools/modules/GB11062.java new file mode 100644 index 0000000..cb9f6fb --- /dev/null +++ b/src/main/java/com/ng/ngtools/modules/GB11062.java @@ -0,0 +1,167 @@ +package com.ng.ngtools.modules; + + public class GB11062 + { + + private int iNCC; // number of components + private final int[] aiCID = new int[21]; // component IDs + private final double[] dXi = new double[21]; // mole fraction of component i + private final Detail ptDetail; + public GB11062() + { + + ptDetail = new Detail(); + for (int i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + dXi[i] = 0; + } + + + } // Detail() + public final void Run(com.ng.ngtools.tangible.RefObject ptAGA10) + { + int i; + // Check for gas composition change + ptAGA10.argValue.bForceUpdate = (ptAGA10.argValue.bForceUpdate || ptDetail.compositionchange(ptAGA10)); + // assign component IDs and values + if (ptAGA10.argValue.bForceUpdate) + { + iNCC = -1; + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + if (ptAGA10.argValue.adMixture[i] > 0.0) + { + iNCC = iNCC + 1; + aiCID[iNCC] = i; + dXi[iNCC] = ptAGA10.argValue.adMixture[i]; + } + } + iNCC = iNCC + 1; + //calculate composition dependent quantities; ported from original + //FORTRAN functions paramdl() and chardl() + GasPropsCal(ptAGA10); + } + } + + private void GasPropsCal(com.ng.ngtools.tangible.RefObject ptAGA10) + { + double[] adTableMri = new double[] {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[] {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[] {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[] {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[] {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[][] + { + {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[][] + { + {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[][] + { + {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[][] + { + {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.argValue.adMixture[i] != 0) + { + ptAGA10.argValue.Pc += adTablePc[i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.TC += adTableTc[i] * ptAGA10.argValue.adMixture[i]; + if (adTableBzsx[i] != 0) + { + ptAGA10.argValue.Bzsx += ptAGA10.argValue.adMixture[i] / adTableBzsx[i]; + ptAGA10.argValue.Bzxx += ptAGA10.argValue.adMixture[i] / adTableBzxx[i]; + } + + if (i >= 10 & i <= 18) + { + ptAGA10.argValue.C4j += ptAGA10.argValue.adMixture[i] * adTableMri[i]; + } + if (i >= 12 & i <= 18) + { + ptAGA10.argValue.C5j += ptAGA10.argValue.adMixture[i] * adTableMri[i]; + } + if (i >= 14 & i <= 18) + { + ptAGA10.argValue.C6j += ptAGA10.argValue.adMixture[i] * adTableMri[i]; + } + if (i == 3) + { + ptAGA10.argValue.C2 += ptAGA10.argValue.adMixture[i] * adTableMri[i]; + } + + switch (ptAGA10.argValue.dCbtj) + { + case 2: + ptAGA10.argValue.dZb11062 += adTableSqrtbj[0][i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.dHhvMol += adTableHhvMol[0][i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.dLhvMol += adTableLhvMol[0][i] * ptAGA10.argValue.adMixture[i]; + dZair = 0.99941; + break; + case 1: + ptAGA10.argValue.dZb11062 += adTableSqrtbj[1][i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.dHhvMol += adTableHhvMol[1][i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.dLhvMol += adTableLhvMol[1][i] * ptAGA10.argValue.adMixture[i]; + dZair = 0.99958; + break; + case 0: + ptAGA10.argValue.dZb11062 += adTableSqrtbj[2][i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.dHhvMol += adTableHhvMol[2][i] * ptAGA10.argValue.adMixture[i]; + ptAGA10.argValue.dLhvMol += adTableLhvMol[2][i] * ptAGA10.argValue.adMixture[i]; + dZair = 0.99963; + break; + } + } + } + ptAGA10.argValue.Bzsx = ptAGA10.argValue.Bzsx == 0?0: 1 / ptAGA10.argValue.Bzsx; + ptAGA10.argValue.Bzxx = ptAGA10.argValue.Bzxx == 0?0: 1 / ptAGA10.argValue.Bzxx; + + + ptAGA10.argValue.dZb11062 = 1 - ptAGA10.argValue.dZb11062 * ptAGA10.argValue.dZb11062; + ptAGA10.argValue.dHhvm = ptAGA10.argValue.dHhvMol / ptAGA10.argValue.dMrx; + ptAGA10.argValue.dLhvm = ptAGA10.argValue.dLhvMol / ptAGA10.argValue.dMrx; + ptAGA10.argValue.dHhvv = ptAGA10.argValue.dHhvMol * ptAGA10.argValue.dPb / ptAGA10.argValue.dTb / 8314.510 / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.dLhvv = ptAGA10.argValue.dLhvMol * ptAGA10.argValue.dPb / ptAGA10.argValue.dTb / 8314.510 / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.dRD_Ideal11062 = ptAGA10.argValue.dMrx / dMair; + ptAGA10.argValue.dRD_Real11062 = ptAGA10.argValue.dRD_Ideal11062 * dZair / ptAGA10.argValue.dZb11062; + + ptAGA10.argValue.dRhob11062 = ptAGA10.argValue.dMrx * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.dRhof11062 = ptAGA10.argValue.dMrx * ptAGA10.argValue.dPf / 8314.51 / ptAGA10.argValue.dTf / ptAGA10.argValue.dZf; + ptAGA10.argValue.dWobbeIndex = ptAGA10.argValue.dHhvv / Math.sqrt(ptAGA10.argValue.dRD_Real11062); + ptAGA10.argValue.C3j = ptAGA10.argValue.C4j + ptAGA10.argValue.adMixture[4] * adTableMri[4]; + ptAGA10.argValue.C2j = ptAGA10.argValue.C3j + ptAGA10.argValue.adMixture[3] * adTableMri[3]; + ptAGA10.argValue.C3C4 = ptAGA10.argValue.adMixture[4] * adTableMri[4] + ptAGA10.argValue.adMixture[10] * adTableMri[10] + ptAGA10.argValue.adMixture[11] * adTableMri[11]; + ptAGA10.argValue.TotalC = ptAGA10.argValue.C2j + ptAGA10.argValue.adMixture[0] * adTableMri[0]; + + ptAGA10.argValue.TotalC = ptAGA10.argValue.TotalC * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C2 = ptAGA10.argValue.C2 * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C3C4 = ptAGA10.argValue.C3C4 * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C2j = ptAGA10.argValue.C2j * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C3j = ptAGA10.argValue.C3j * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C4j = ptAGA10.argValue.C4j * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C5j = ptAGA10.argValue.C5j * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + ptAGA10.argValue.C6j = ptAGA10.argValue.C6j * ptAGA10.argValue.dPb / 8314.51 / ptAGA10.argValue.dTb / ptAGA10.argValue.dZb11062; + + } + } \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/modules/NG_Cal.java b/src/main/java/com/ng/ngtools/modules/NG_Cal.java new file mode 100644 index 0000000..4dbed07 --- /dev/null +++ b/src/main/java/com/ng/ngtools/modules/NG_Cal.java @@ -0,0 +1,741 @@ +package com.ng.ngtools.modules; + +public class NG_Cal +{ + public static final int NORMAL = 9000; + public static final int NG_Cal_INITIALIZED = 9001; + public static final int MEMORY_ALLOCATION_ERROR = 9002; + public static final int GENERAL_CALCULATION_FAILURE = 9003; + public static final int MAX_NUM_OF_ITERATIONS_EXCEEDED = 9004; + public static final int NEGATIVE_DENSITY_DERIVATIVE = 9005; + public static final int MAX_DENSITY_IN_BRAKET_EXCEEDED = 9006; + /* number of components */ + public static final int NUMBEROFCOMPONENTS = 21; + /* maximum number of tries within search routines */ + public static final int MAX_NUM_OF_ITERATIONS = 100; + /* default tolerance limits */ + public static final double P_CHG_TOL = 0.001; // 0.001 Pa + public static final double T_CHG_TOL = 0.001; // 0.001 of a Kelvin + /* maximum allowable P & T */ + public static final double P_MAX = 1.379e8; // maximum pressure (Pa) ~= 20,000 psi + public static final double P_MIN = 0.0; // maximum pressure = 0 + public static final double T_MAX = 473.15; // maximum temperature (K) ~= 392 F + public static final double T_MIN = 143.0; // maximum temperature (K) ~= -200 F + /* universal gas constant, in two configurations */ + public static final double RGASKJ = 8.314510e-3; // in kJ mol^-1 K^-1 + public static final double RGAS = 8.314510; // in J mol^-1 K^-1 + public Therm ptTherm; + public Detail ptDetail; + + //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;//管道任意点的平均压力 + + + //} + + public static void main(String[] args){ + System.out.println("ngtools"); + } + + + /* 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) ; + + /************************************************************************** + + * Function : NG_Cal_Init() + * Arguments : void + * Returns : int + * Purpose : Initializes library; creates required objects + * Revisions : + **************************************************************************/ + + public final 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 final 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 final double SOS(com.ng.ngtools.tangible.RefObject ptAGA10) + { + // check if library is ready; initialize if necessary + if (null == ptDetail || null == ptTherm) + { + NG_Cal_UnInit(); + NG_Cal_Init(); + + } + + switch (ptAGA10.argValue.dCbtj) + { + case 2: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 273.15; + break; + case 1: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 288.15; + break; + case 0: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 293.15; + break; + } + + + //Call function to calculate densities and thermodynamic properties + com.ng.ngtools.tangible.RefObject tempRef_ptDetail = new com.ng.ngtools.tangible.RefObject(ptDetail); + ptTherm.Run(ptAGA10, tempRef_ptDetail); + ptDetail = tempRef_ptDetail.argValue; + + //the basic sound speed calculation doesn't calculate C*; initialize to zero + ptAGA10.argValue.dCstar = 0.0; + + //return the speed of sound to caller + + return ptAGA10.argValue.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 final double Crit(com.ng.ngtools.tangible.RefObject 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.argValue.lStatus = MEMORY_ALLOCATION_ERROR; + return 0.0; + + } + } + switch (ptAGA10.argValue.dCbtj) + { + case 2: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 273.15; + break; + case 1: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 288.15; + break; + case 0: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 293.15; + break; + + + } + //begin by calculating densities and thermodynamic properties + com.ng.ngtools.tangible.RefObject tempRef_ptDetail = new com.ng.ngtools.tangible.RefObject(ptDetail); + ptTherm.Run(ptAGA10, tempRef_ptDetail); + ptDetail = tempRef_ptDetail.argValue; + + //DH is enthalpy change from plenum to throat; this is our initial guess + + DH = (ptAGA10.argValue.dSOS * ptAGA10.argValue.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0; + + //trap plenum conditions before we alter the data stucture's contents + S = ptAGA10.argValue.dS; + H = ptAGA10.argValue.dH; + R = ptAGA10.argValue.dRhof; + P = ptAGA10.argValue.dPf; + Z = ptAGA10.argValue.dZf; + T = ptAGA10.argValue.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 + com.ng.ngtools.tangible.RefObject tempRef_ptDetail2 = new com.ng.ngtools.tangible.RefObject(ptDetail); + ptTherm.HS_Mode(ptAGA10, tempRef_ptDetail2, H - DH, S, true); + ptDetail = tempRef_ptDetail2.argValue; + + //calculate new thermo, including SOS + com.ng.ngtools.tangible.RefObject tempRef_ptDetail3 = new com.ng.ngtools.tangible.RefObject(ptDetail); + ptTherm.Run(ptAGA10, tempRef_ptDetail3); + ptDetail = tempRef_ptDetail3.argValue; + + //hold DH for tolerance check + + DDH = DH; + + // recalculate DH + + DH = (ptAGA10.argValue.dSOS * ptAGA10.argValue.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.argValue.dCstar = (ptAGA10.argValue.dRhof * ptAGA10.argValue.dSOS) / Math.sqrt(R * P * Z); + + //put the original plenum pressure and temperature back + + ptAGA10.argValue.dPf = P; + ptAGA10.argValue.dTf = T; + + //restore fluid props to plenum conditions + com.ng.ngtools.tangible.RefObject tempRef_ptDetail4 = new com.ng.ngtools.tangible.RefObject(ptDetail); + ptTherm.Run(ptAGA10, tempRef_ptDetail4); + ptDetail = tempRef_ptDetail4.argValue; + + GB11062 ptGB11062 = new GB11062(); + + ptGB11062.Run(ptAGA10); + + //return the critical flow function to caller + return ptAGA10.argValue.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 final double Zcal(com.ng.ngtools.tangible.RefObject 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.argValue.lStatus = MEMORY_ALLOCATION_ERROR; + return 0.0; + } + } + switch (ptAGA10.argValue.dCbtj) + { + case 0: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 293.15; + break; + case 1: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 288.15; + break; + case 2: + ptAGA10.argValue.dPb = 101325; + ptAGA10.argValue.dTb = 273.15; + break; + + + + + } + //begin by calculating densities and thermodynamic properties + com.ng.ngtools.tangible.RefObject tempRef_ptDetail = new com.ng.ngtools.tangible.RefObject(ptDetail); + ptTherm.Run(ptAGA10, tempRef_ptDetail); + ptDetail = tempRef_ptDetail.argValue; + + + GB11062 ptGB11062 = new GB11062(); + + ptGB11062.Run(ptAGA10); + + //return the critical flow function to caller + return ptAGA10.argValue.dZf; + + } // Z() + + /************************************************************************** + * Function : Cperf() + * Arguments : pointer to external AGA10 data struct + * Returns : double + * Purpose : calculates isentropic perfect gas critical flow function + * Revisions : + **************************************************************************/ + + private double Cperf(com.ng.ngtools.tangible.RefObject ptAGA10) + { + + double k, root, exponent; + + k = ptAGA10.argValue.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 : + **************************************************************************/ + + private double CRi(com.ng.ngtools.tangible.RefObject ptAGA10) + { + return (Cperf(ptAGA10) / Math.sqrt(ptAGA10.argValue.dZf)); + } // CRi() + + /* enumerations for tracking gas components */ + private enum gascomp + { + XiC1(0), + XiN2(1), + XiCO2(2), + XiC2(3), + XiC3(4), + XiH2O(5), + XiH2S(6), + XiH2(7), + XiCO(8), + XiO2(9), + XiIC4(10), + XiNC4(11), + XiIC5(12), + XiNC5(13), + XiNC6(14), + XiNC7(15), + XiNC8(16), + XiNC9(17), + XiNC10(18), + XiHe(19), + XiAr(20); + + public static final int SIZE = Integer.SIZE; + private static java.util.HashMap mappings; + private final int intValue; + gascomp(int value) + { + intValue = value; + getMappings().put(value, this); + } + + private static java.util.HashMap getMappings() + { + if (mappings == null) + { + synchronized (gascomp.class) + { + if (mappings == null) + { + mappings = new java.util.HashMap(); + } + } + } + return mappings; + } + + public static gascomp forValue(int value) + { + return getMappings().get(value); + } + + public int getValue() + { + return intValue; + } + } + + /* the main data structure used by this library */ +//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class will differ from the original: +//ORIGINAL LINE: public struct GasPropsSTRUCT + public final static class GasPropsSTRUCT + { // corresponds to the control group in meter classes + + public int lStatus; // calculation status 计算状态 + public boolean 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 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 GasPropsSTRUCT clone() + { + GasPropsSTRUCT varCopy = new GasPropsSTRUCT(); + + varCopy.lStatus = this.lStatus; + varCopy.bForceUpdate = this.bForceUpdate; + varCopy.adMixture = this.adMixture; + varCopy.adMixtureV = this.adMixtureV; + varCopy.adMixtureD = this.adMixtureD; + varCopy.dCbtj = this.dCbtj; + varCopy.dPb = this.dPb; + varCopy.dTb = this.dTb; + varCopy.dPf = this.dPf; + varCopy.dTf = this.dTf; + varCopy.dMrx = this.dMrx; + varCopy.dZb = this.dZb; + varCopy.dZf = this.dZf; + varCopy.dFpv = this.dFpv; + varCopy.dDb = this.dDb; + varCopy.dDf = this.dDf; + varCopy.dRhob = this.dRhob; + varCopy.dRhof = this.dRhof; + varCopy.dRD_Ideal = this.dRD_Ideal; + varCopy.dRD_Real = this.dRD_Real; + varCopy.dHo = this.dHo; + varCopy.dH = this.dH; + varCopy.dS = this.dS; + varCopy.dCpi = this.dCpi; + varCopy.dCp = this.dCp; + varCopy.dCv = this.dCv; + varCopy.dk = this.dk; + varCopy.dKappa = this.dKappa; + varCopy.dSOS = this.dSOS; + varCopy.dCstar = this.dCstar; + varCopy.dHhvMol = this.dHhvMol; + varCopy.dLhvMol = this.dLhvMol; + varCopy.dHhvv = this.dHhvv; + varCopy.dLhvv = this.dLhvv; + varCopy.dHhvm = this.dHhvm; + varCopy.dLhvm = this.dLhvm; + varCopy.dZb11062 = this.dZb11062; + varCopy.dRhob11062 = this.dRhob11062; + varCopy.dRhof11062 = this.dRhof11062; + varCopy.dRD_Ideal11062 = this.dRD_Ideal11062; + varCopy.dRD_Real11062 = this.dRD_Real11062; + varCopy.dWobbeIndex = this.dWobbeIndex; + varCopy.Pc = this.Pc; + varCopy.TC = this.TC; + varCopy.Bzsx = this.Bzsx; + varCopy.Bzxx = this.Bzxx; + varCopy.TotalC = this.TotalC; + varCopy.C2 = this.C2; + varCopy.C2j = this.C2j; + varCopy.C3j = this.C3j; + varCopy.C4j = this.C4j; + varCopy.C5j = this.C5j; + varCopy.C6j = this.C6j; + varCopy.C3C4 = this.C3C4; + + return varCopy; + } + } + +//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class will differ from the original: +//ORIGINAL LINE: public struct FlowParStruct + public final static class 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 double dPipeMaterial; //管道材料 + + public double dOrificeD; //孔板孔径 + public int dOrificeUnit; //长度单位 + public double dOrificeDtemp; //孔板内径参考温度 + public int dOrificeDtempUnit; //温度单位 + public double 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 dVGsc;// 管束车水容积 + + + //流量计算输出参数 + 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 double dVCNG; //'CNG体积 + + + + public FlowParStruct clone() + { + FlowParStruct varCopy = new FlowParStruct(); + + varCopy.dFlowCalbz = this.dFlowCalbz; + varCopy.dZcalbz = this.dZcalbz; + varCopy.dCbtj = this.dCbtj; + varCopy.dPb_M = this.dPb_M; + varCopy.dTb_M = this.dTb_M; + varCopy.dPb_E = this.dPb_E; + varCopy.dTb_E = this.dTb_E; + varCopy.dPatm = this.dPatm; + varCopy.dPatmUnit = this.dPatmUnit; + varCopy.dNG_Compents = this.dNG_Compents; + varCopy.dMeterType = this.dMeterType; + varCopy.dCoreType = this.dCoreType; + varCopy.dPtmode = this.dPtmode; + varCopy.dPipeType = this.dPipeType; + varCopy.dPipeD = this.dPipeD; + varCopy.dLenUnit = this.dLenUnit; + varCopy.dPipeDtemp = this.dPipeDtemp; + varCopy.dPileDtempUint = this.dPileDtempUint; + varCopy.dPipeMaterial = this.dPipeMaterial; + varCopy.dOrificeD = this.dOrificeD; + varCopy.dOrificeUnit = this.dOrificeUnit; + varCopy.dOrificeDtemp = this.dOrificeDtemp; + varCopy.dOrificeDtempUnit = this.dOrificeDtempUnit; + varCopy.dOrificeMaterial = this.dOrificeMaterial; + varCopy.dOrificeSharpness = this.dOrificeSharpness; + varCopy.dOrificeRk = this.dOrificeRk; + varCopy.dOrificeRkLenUint = this.dOrificeRkLenUint; + varCopy.dPf = this.dPf; + varCopy.dPfUnit = this.dPfUnit; + varCopy.dPfType = this.dPfType; + varCopy.dTf = this.dTf; + varCopy.dTfUnit = this.dTfUnit; + varCopy.dDp = this.dDp; + varCopy.dDpUnit = this.dDpUnit; + varCopy.dVFlowUnit = this.dVFlowUnit; + varCopy.dMFlowUnit = this.dMFlowUnit; + varCopy.dEFlowUnit = this.dEFlowUnit; + varCopy.dCd = this.dCd; + varCopy.dCdCalMethod = this.dCdCalMethod; + varCopy.dMeterFactor = this.dMeterFactor; + varCopy.dPulseNum = this.dPulseNum; + varCopy.dVFlowMax = this.dVFlowMax; + varCopy.dVFlowMin = this.dVFlowMin; + varCopy.dVFlowCon = this.dVFlowCon; + varCopy.dPfRangeMin = this.dPfRangeMin; + varCopy.dPfRangeMax = this.dPfRangeMax; + varCopy.dDpRangeMin = this.dDpRangeMin; + varCopy.dDpRangeMax = this.dDpRangeMax; + varCopy.dTfRangeMin = this.dTfRangeMin; + varCopy.dTfRangeMax = this.dTfRangeMax; + varCopy.dVGsc = this.dVGsc; + + varCopy.dE = this.dE; + varCopy.dFG = this.dFG; + varCopy.dFT = this.dFT; + varCopy.dDViscosity = this.dDViscosity; + varCopy.dDExpCoefficient = this.dDExpCoefficient; + varCopy.dRnPipe = this.dRnPipe; + varCopy.dBk = this.dBk; + varCopy.dRoughNessPipe = this.dRoughNessPipe; + varCopy.dCdCorrect = this.dCdCorrect; + varCopy.dCdNozell = this.dCdNozell; + varCopy.dVFlowb = this.dVFlowb; + varCopy.dVFlowf = this.dVFlowf; + varCopy.dMFlowb = this.dMFlowb; + varCopy.dEFlowb = this.dEFlowb; + varCopy.dVelocityFlow = this.dVelocityFlow; + varCopy.dPressLost = this.dPressLost; + varCopy.dBeta = this.dBeta; + varCopy.dKappa = this.dKappa; + varCopy.dVCNG = this.dVCNG; + + + return varCopy; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/modules/Therm.java b/src/main/java/com/ng/ngtools/modules/Therm.java new file mode 100644 index 0000000..e91f65d --- /dev/null +++ b/src/main/java/com/ng/ngtools/modules/Therm.java @@ -0,0 +1,607 @@ +package com.ng.ngtools.modules; + + 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 + private double dPdD; // partial deriv of P wrt D + private double dPdT; // partial deriv of P wrt T + private double dSi; // ideal gas specific entropy, kJ/kg.K + private double dTold; // temperature previously used + private double dMrxold; // mixture molar mass previously used + private final double[] GK_root = new double[] {0.14887433898163121088, 0.43339539412924719080, 0.67940956829902440263, 0.86506336668898451073, 0.97390652851717172008}; + private final double[] GK_weight = new double[] {0.29552422471475286217, 0.26926671930999634918, 0.21908636251598204295, 0.14945134915058059038, 0.066671344308688137179}; + //set the number of points for quadrature + private final int GK_points = 5; + //equation constants for ideal gas heat capacity, enthalpy and entropy + private final double[][] ThermConstants = new double[][] + { + {-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 + private static final 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 + **************************************************************************/ + private 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 final void Run(com.ng.ngtools.tangible.RefObject ptAGA10, com.ng.ngtools.tangible.RefObject ptD) + { + //local variables + double c, x, y, z; + //first run basic set of functions within AGA 8 (1994) Detail Method + ptD.argValue.Run(ptAGA10); + //find first partial derivative of Z wrt D + ptD.argValue.dZdD(ptAGA10.argValue.dDf); + //find real gas cv, cp, specific enthalpy and entropy + CprCvrHS(ptAGA10, ptD); + //ratio of real gas specific heats + ptAGA10.argValue.dk = ptAGA10.argValue.dCp / ptAGA10.argValue.dCv; + //solve c in three steps, for clarity and ease of debugging + x = ptAGA10.argValue.dk * NG_Cal.RGAS * 1000.0 * ptAGA10.argValue.dTf; + y = ptAGA10.argValue.dMrx; + z = ptAGA10.argValue.dZf + ptAGA10.argValue.dDf * ptD.argValue.ddZdD; + //calculate c, which is SOS^2 + c = (x / y) * z; + //speed of sound + ptAGA10.argValue.dSOS = Math.sqrt(c); + //calculate the real gas isentropic exponent + //using expression functionally equivalent to Equation 3.2 + ptAGA10.argValue.dKappa = (c * ptAGA10.argValue.dRhof) / ptAGA10.argValue.dPf; + } //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: + **************************************************************************/ + private double CpiMolar(com.ng.ngtools.tangible.RefObject 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.argValue.dTf; + //calculate heat capacity for each component + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + //skip species whose concentration is zero + if (ptAGA10.argValue.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.argValue.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: + **************************************************************************/ + private double Ho(com.ng.ngtools.tangible.RefObject 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.argValue.dTf; + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + // skip species whose concentration is zero + if (ptAGA10.argValue.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.argValue.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.argValue.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: + **************************************************************************/ + private double So(com.ng.ngtools.tangible.RefObject 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.argValue.dTf; + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + // skip species whose concentration is zero + if (ptAGA10.argValue.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.argValue.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.argValue.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: + **************************************************************************/ + private void CprCvrHS(com.ng.ngtools.tangible.RefObject ptAGA10, com.ng.ngtools.tangible.RefObject 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(ptAGA10); + //find ideal gas enthalpy + ptAGA10.argValue.dHo = Ho(ptAGA10); + //find ideal gas entropy + Si = So(ptAGA10); + //calculate ideal gas specific heat capacity at constant pressure in J/kgK + ptAGA10.argValue.dCpi = (Cp * 1000.0) / ptAGA10.argValue.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.argValue.dDf * (1.0 + GK_root[i]) / 2.0; + //get Z at D + ptD.argValue.zdetail(x); + ptD.argValue.dZdT(x); + ptD.argValue.d2ZdT2(x); + //gather contributions at + abscissa; applying weighting factor + Hinc += GK_weight[i] * ptD.argValue.ddZdT / x; + Cvinc += GK_weight[i] * (2.0 * ptD.argValue.ddZdT + ptAGA10.argValue.dTf * ptD.argValue.dd2ZdT2) / x; + Sinc += GK_weight[i] * (ptD.argValue.dZ + ptAGA10.argValue.dTf * ptD.argValue.ddZdT - 1.0) / x; + //set calculation point at - abscissa + x = ptAGA10.argValue.dDf * (1.0 - GK_root[i]) / 2.0; + //get Z at D + ptD.argValue.zdetail(x); + //calculate 1st and 2nd partial derivatives of Z wrt T + ptD.argValue.dZdT(x); + ptD.argValue.d2ZdT2(x); + //gather contributions at - abscissa; applying weighting factor + Hinc += GK_weight[i] * ptD.argValue.ddZdT / x; + Cvinc += GK_weight[i] * (2.0 * ptD.argValue.ddZdT + ptAGA10.argValue.dTf * ptD.argValue.dd2ZdT2) / x; + Sinc += GK_weight[i] * (ptD.argValue.dZ + ptAGA10.argValue.dTf * ptD.argValue.ddZdT - 1.0) / x; + } + //return Z and partial derivatives to full molar density + ptD.argValue.zdetail(ptAGA10.argValue.dDf); + ptD.argValue.dZdT(ptAGA10.argValue.dDf); + ptD.argValue.d2ZdT2(ptAGA10.argValue.dDf); + //complete Cv molar + Cvr = Cp - NG_Cal.RGAS * (1.0 + ptAGA10.argValue.dTf * Cvinc * 0.5 * ptAGA10.argValue.dDf); + //intermediate values for Cp, containing 2 partial derivatives + a = (ptAGA10.argValue.dZf + ptAGA10.argValue.dTf * ptD.argValue.ddZdT); + b = (ptAGA10.argValue.dZf + ptAGA10.argValue.dDf * ptD.argValue.ddZdD); + //calculate dPdT, the partial derivative of P wrt T, at D + dPdT = NG_Cal.RGAS * ptAGA10.argValue.dDf * a; + //calculate dPdD, the partial derivative of P wrt D, at T + dPdD = NG_Cal.RGAS * ptAGA10.argValue.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.argValue.dMrx; + Cvr /= ptAGA10.argValue.dMrx; + // write to the data stucture + ptAGA10.argValue.dCv = Cvr * 1000.0; // convert from joules/kgK to kilojoules/kgK + ptAGA10.argValue.dCp = Cpr * 1000.0; + // calculate specific enthalpy + ptAGA10.argValue.dH = ptAGA10.argValue.dHo + 1000.0 * NG_Cal.RGAS * ptAGA10.argValue.dTf * (ptAGA10.argValue.dZf - 1.0 - ptAGA10.argValue.dTf * Hinc * 0.5 * ptAGA10.argValue.dDf) / ptAGA10.argValue.dMrx; + // calculate entropy of mixing + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + if (ptAGA10.argValue.adMixture[i] != 0) + { + Smixing += ptAGA10.argValue.adMixture[i] * Math.log(ptAGA10.argValue.adMixture[i]); + } + } + Smixing *= NG_Cal.RGAS; + // calculate specific entropy + ptAGA10.argValue.dS = Si - Smixing - 1000.0 * NG_Cal.RGAS * (Math.log(ptAGA10.argValue.dPf / 101325.0) - Math.log(ptAGA10.argValue.dZf) + Sinc * 0.5 * ptAGA10.argValue.dDf) / ptAGA10.argValue.dMrx; + } //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 final void HS_Mode(com.ng.ngtools.tangible.RefObject ptAGA10, com.ng.ngtools.tangible.RefObject ptD, double H, double S, boolean 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.argValue.dTf; + px = ptAGA10.argValue.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.argValue.Run(ptAGA10); + //h1 is difference between h given and h@Tf, Pf + h1 = this.H(ptAGA10, 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.argValue.dTf = t2; + p1 = px; // reset one bracket + p2 = px * 0.1; // set other bracket to 0.1x the upper bracket + ptAGA10.argValue.dPf = p1; + ptD.argValue.Run(ptAGA10); + s1 = this.S(ptAGA10, 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.argValue.dPf = p2; + ptD.argValue.Run(ptAGA10); + s2 = this.S(ptAGA10, 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.argValue.lStatus = NG_Cal.MAX_NUM_OF_ITERATIONS_EXCEEDED; + } + //calc enthalpy at guessed P & current iter T + h2 = this.H(ptAGA10, 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.argValue.dTf = t2; + ptD.argValue.Run(ptAGA10); + h2 = this.H(ptAGA10, ptD) - h0; + } + t1 = t0; + h1 = h2; + } + // check for failure to converge + if (i >= NG_Cal.MAX_NUM_OF_ITERATIONS) + { + ptAGA10.argValue.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: + **************************************************************************/ + private double H(com.ng.ngtools.tangible.RefObject ptAGA10, com.ng.ngtools.tangible.RefObject ptD) + { + double Hinc; + double x; + int i; + //initialize integral + Hinc = 0.0; + //find ideal gas enthalpy + ptAGA10.argValue.dHo = Ho(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.argValue.dDf * (1.0 + GK_root[i]) / 2.0; + ptD.argValue.zdetail(x); + ptD.argValue.dZdT(x); + ptD.argValue.d2ZdT2(x); + Hinc += GK_weight[i] * ptD.argValue.ddZdT / x; + if (i == 10) + { + break; + } + x = ptAGA10.argValue.dDf * (1.0 - GK_root[i]) / 2.0; + ptD.argValue.zdetail(x); + ptD.argValue.dZdT(x); + ptD.argValue.d2ZdT2(x); + Hinc += GK_weight[i] * ptD.argValue.ddZdT / x; + } + ptD.argValue.zdetail(ptAGA10.argValue.dDf); + ptD.argValue.dZdT(ptAGA10.argValue.dDf); + ptD.argValue.d2ZdT2(ptAGA10.argValue.dDf); + // calculate specific enthalpy + ptAGA10.argValue.dH = ptAGA10.argValue.dHo + 1000.0 * NG_Cal.RGAS * ptAGA10.argValue.dTf * (ptAGA10.argValue.dZf - 1.0 - ptAGA10.argValue.dTf * Hinc * 0.5 * ptAGA10.argValue.dDf) / ptAGA10.argValue.dMrx; + return (ptAGA10.argValue.dH); + } // H() + /************************************************************************** + *Function:S() + *Arguments:ref AGA10.GasPropsSTRUCT , Detail * + *Returns:double + *Purpose:real gas specific entropy + *Revisions: + **************************************************************************/ + private double S(com.ng.ngtools.tangible.RefObject ptAGA10, com.ng.ngtools.tangible.RefObject 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.argValue.dDf * (1.0 + GK_root[i]) / 2.0; + ptD.argValue.zdetail(x); + ptD.argValue.dZdT(x); + ptD.argValue.d2ZdT2(x); + Sinc += GK_weight[i] * (ptD.argValue.dZ + ptAGA10.argValue.dTf * ptD.argValue.ddZdT - 1.0) / x; + if (i == 10) + { + break; + } + x = ptAGA10.argValue.dDf * (1.0 - GK_root[i]) / 2.0; + ptD.argValue.zdetail(x); + ptD.argValue.dZdT(x); + ptD.argValue.d2ZdT2(x); + Sinc += GK_weight[i] * (ptD.argValue.dZ + ptAGA10.argValue.dTf * ptD.argValue.ddZdT - 1.0) / x; + } + //reset Z and partial deivatives dZdT and d2ZdT2 + ptD.argValue.zdetail(ptAGA10.argValue.dDf); + ptD.argValue.dZdT(ptAGA10.argValue.dDf); + ptD.argValue.d2ZdT2(ptAGA10.argValue.dDf); + //find ideal gas entropy, but only if temperature or composition have changed + if (ptAGA10.argValue.dTf != dTold || ptAGA10.argValue.dMrx != dMrxold) + { + dSi = So(ptAGA10); + dTold = ptAGA10.argValue.dTf; + dMrxold = ptAGA10.argValue.dMrx; + } + //calculate entropy of mixing + for (i = 0; i < NG_Cal.NUMBEROFCOMPONENTS; i++) + { + if (ptAGA10.argValue.adMixture[i] != 0) + { + Smixing += ptAGA10.argValue.adMixture[i] * Math.log(ptAGA10.argValue.adMixture[i]); + } + } + Smixing *= NG_Cal.RGAS; + // calculate specific entropy + ptAGA10.argValue.dS = dSi - Smixing - 1000.0 * NG_Cal.RGAS * (Math.log(ptAGA10.argValue.dPf / 101325.0) - Math.log(ptAGA10.argValue.dZf) + Sinc * 0.5 * ptAGA10.argValue.dDf) / ptAGA10.argValue.dMrx; + return (ptAGA10.argValue.dS); + } // S() + } \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/modules/UnitConvert.java b/src/main/java/com/ng/ngtools/modules/UnitConvert.java new file mode 100644 index 0000000..08e26b1 --- /dev/null +++ b/src/main/java/com/ng/ngtools/modules/UnitConvert.java @@ -0,0 +1,403 @@ +package com.ng.ngtools.modules; + +import com.ng.ngtools.tangible.FloatingPointToInteger; + +public class UnitConvert + { + public final 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[8] = 0.0245240972222222; + dataUnit[9] = 35.3147; + dataUnit[10] = 219.969; + dataUnit[11] = 264.172; + dataUnit[12] = 6.28994; + 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[4] = 3.28038; + dataUnit[5] = 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 = FloatingPointToInteger.ToInt32((value * Math.pow(10, weishu) - tempValue) * 10); + if (SorR >= 5) + { + tempValue++; + } + return tempValue / Math.pow(10, weishu); + } + catch (Exception e) + { + + return value; + + } + } + + + + + + + + } \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/tangible/FloatingPointToInteger.java b/src/main/java/com/ng/ngtools/tangible/FloatingPointToInteger.java new file mode 100644 index 0000000..a8c07cf --- /dev/null +++ b/src/main/java/com/ng/ngtools/tangible/FloatingPointToInteger.java @@ -0,0 +1,75 @@ +package com.ng.ngtools.tangible; + +//---------------------------------------------------------------------------------------- +// Copyright © 2007 - 2017 Tangible Software Solutions Inc. +// This class can be used by anyone provided that the copyright notice remains intact. +// +// This class is used to convert System.Convert methods which convert from +// floating point types to integral types. +//---------------------------------------------------------------------------------------- +public class FloatingPointToInteger +{ + public static byte ToSByte(double source) + { + byte floor = (byte)Math.floor(source); + if (Math.abs(source - floor) == 0.5) + { + if (floor % 2 == 0) + return floor; + else + return (byte)Math.ceil(source); + } + else if (Math.abs(source - floor) < 0.5) + return floor; + else + return (byte)Math.ceil(source); + } + + public static short ToInt16(double source) + { + short floor = (short)Math.floor(source); + if (Math.abs(source - floor) == 0.5) + { + if (floor % 2 == 0) + return floor; + else + return (short)Math.ceil(source); + } + else if (Math.abs(source - floor) < 0.5) + return floor; + else + return (short)Math.ceil(source); + } + + public static int ToInt32(double source) + { + int floor = (int)Math.floor(source); + if (Math.abs(source - floor) == 0.5) + { + if (floor % 2 == 0) + return floor; + else + return (int)Math.ceil(source); + } + else if (Math.abs(source - floor) < 0.5) + return floor; + else + return (int)Math.ceil(source); + } + + public static long ToInt64(double source) + { + long floor = (long)Math.floor(source); + if (Math.abs(source - floor) == 0.5) + { + if (floor % 2 == 0) + return floor; + else + return (long)Math.ceil(source); + } + else if (Math.abs(source - floor) < 0.5) + return floor; + else + return (long)Math.ceil(source); + } +} \ No newline at end of file diff --git a/src/main/java/com/ng/ngtools/tangible/RefObject.java b/src/main/java/com/ng/ngtools/tangible/RefObject.java new file mode 100644 index 0000000..85a1bfb --- /dev/null +++ b/src/main/java/com/ng/ngtools/tangible/RefObject.java @@ -0,0 +1,16 @@ +package com.ng.ngtools.tangible; + +//---------------------------------------------------------------------------------------- +// Copyright © 2007 - 2017 Tangible Software Solutions Inc. +// This class can be used by anyone provided that the copyright notice remains intact. +// +// This class is used to replicate the ability to pass arguments by reference in Java. +//---------------------------------------------------------------------------------------- +public class RefObject +{ + public T argValue; + public RefObject(T refArg) + { + argValue = refArg; + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6b84a7d --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.ng.ngtools.NgApplication + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..4293860 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,27 @@ +# 开发环境配置 +server: + address: 0.0.0.0 + ###配置https + port: 8443 + #开启https,配置跟证书一一对应 + ssl: + enabled: true + #指定证书 + key-store: classpath:ngtools.cn.jks + key-store-type: JKS + #密码 + key-store-password: kvp09gai + protocol: TLS + + # key-alias: ngtools +# key-store: classpath:ngtools.cn.pfx +# key-store-type: PKCS12 +# key-store-password: 9tbr2ybr + + + + servlet: + context-path: + + +myhttp-port: 8888 \ No newline at end of file diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..9a0ac93 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,24 @@ +### ??### +log4j.rootLogger = debug,stdout,D,E + +### ???????? ### +log4j.appender.stdout = org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target = System.out #???????????????? System.err? +log4j.appender.stdout.layout = org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n + +### ??DEBUG ????????=/home/duqi/logs/debug.log ### +log4j.appender.D = org.apache.log4j.DailyRollingFileAppender +log4j.appender.D.File = /home/duqi/logs/debug.log +log4j.appender.D.Append = true +log4j.appender.D.Threshold = DEBUG +log4j.appender.D.layout = org.apache.log4j.PatternLayout +log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n + +### ??ERROR ????????=/home/admin/logs/error.log ### +log4j.appender.E = org.apache.log4j.DailyRollingFileAppender +log4j.appender.E.File =/home/admin/logs/error.log +log4j.appender.E.Append = true +log4j.appender.E.Threshold = ERROR +log4j.appender.E.layout = org.apache.log4j.PatternLayout +log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n diff --git a/src/main/resources/ngtools.cn.jks b/src/main/resources/ngtools.cn.jks new file mode 100644 index 0000000..9804c70 Binary files /dev/null and b/src/main/resources/ngtools.cn.jks differ diff --git a/src/main/resources/rebel.xml b/src/main/resources/rebel.xml new file mode 100644 index 0000000..7632bd8 --- /dev/null +++ b/src/main/resources/rebel.xml @@ -0,0 +1,16 @@ + + + + + + ngtools + + +

+ + + + diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html new file mode 100644 index 0000000..e2d94a2 --- /dev/null +++ b/src/main/resources/static/index.html @@ -0,0 +1,6 @@ + + +

hello word!!!

+

this is a html page

+ + \ No newline at end of file diff --git a/src/test/java/com/ng/ngtools/NgApplicationTests.java b/src/test/java/com/ng/ngtools/NgApplicationTests.java new file mode 100644 index 0000000..4db8851 --- /dev/null +++ b/src/test/java/com/ng/ngtools/NgApplicationTests.java @@ -0,0 +1,13 @@ +package com.ng.ngtools; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class NgApplicationTests { + + @Test + void contextLoads() { + } + +}