package com.ruoyi.ngCalTools.controller; // GasController.java import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.ngCalTools.model.GasProps; import com.ruoyi.ngCalTools.model.FlowProps; import com.ruoyi.ngCalTools.service.DetailService; import com.ruoyi.ngCalTools.service.GBT11062Service; import com.ruoyi.ngCalTools.service.ThermService; import com.ruoyi.ngCalTools.utils.GasConstants; import com.ruoyi.system.controller.SysUnitConvertController; import com.ruoyi.system.controller.UnitConvert; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/NGCalcTools") public class GasController { private final UnitConvert unitConvert; public ThermService thermService; public DetailService detailService; public GBT11062Service gbt11062Service; public GasController(UnitConvert unitConvert) { this.unitConvert = unitConvert; } @PostMapping ("/ngCalc") public AjaxResult ngCalc(@RequestBody FlowProps flowProps) { thermService = new ThermService(); detailService = new DetailService(); gbt11062Service = new GBT11062Service(); GasProps gasProps = new GasProps(); //大气压力转换成Pa double tempPatm = unitConvert.ConvertUniter("pressure", flowProps.getdPatm(), flowProps.getdPatmUnit(), 0); //压力转换成Pa double tempPf = unitConvert.ConvertUniter("pressure", flowProps.getdPf(), flowProps.getdPfUnit(), 0); //温度转换成K double tempTf = unitConvert.ConvertUniter("temperature", flowProps.getdTf(), flowProps.getdTfUnit(), 2); if (flowProps.getdPfType() == 0) //0是表压 { gasProps.dPf = tempPatm + tempPf; } else { gasProps.dPf = tempPf; } gasProps.dTf = tempTf; gasProps.dCbtj = flowProps.getdCbtj(); String[] stringArray = flowProps.getdngComponents().split("_"); double[] doubleArray = new double[stringArray.length]; // 遍历字符串数组,将每个元素转换为 double 类型 for (int i = 0; i < stringArray.length; i++) { try { doubleArray[i] = Double.parseDouble(stringArray[i]) / 100; } catch (NumberFormatException e) { // 处理转换异常 System.err.println("无法将字符串 " + stringArray[i] + " 转换为 double 类型: " + e.getMessage()); } } gasProps.adMixture = doubleArray; Crit(gasProps, 0); //计算临界流函数所有参数都计算了 return AjaxResult.success(gasProps); } public void ngCalcVoid( FlowProps flowProps,GasProps gasProps) { thermService = new ThermService(); detailService = new DetailService(); gbt11062Service = new GBT11062Service(); Crit(gasProps, 0); //计算临界流函数所有参数都计算了 } public int NG_Cal_Init() { //create object for calculating density if (null == (detailService=new DetailService())) { return GasConstants.MEMORY_ALLOCATION_ERROR; } //create object for calculating thermodynamic properties if (null == (thermService=new ThermService())) { return GasConstants.MEMORY_ALLOCATION_ERROR; } return GasConstants.NG_Cal_INITIALIZED; }// NG_Cal_Init public int NG_Cal_UnInit() { // delete the objects (if they exist) detailService = null; thermService = null; return 0; } public double Crit(GasProps gasProps, 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 == detailService || null == thermService) { NG_Cal_UnInit(); if (GasConstants.NG_Cal_INITIALIZED != NG_Cal_Init()) { gasProps.lStatus =GasConstants. MEMORY_ALLOCATION_ERROR; return 0.0; } } switch (gasProps.dCbtj) { case 2: gasProps.dPb = 101325; gasProps.dTb = 273.15; break; case 1: gasProps.dPb = 101325; gasProps.dTb = 288.15; break; case 0: gasProps.dPb = 101325; gasProps.dTb = 293.15; break; } //begin by calculating densities and thermodynamic properties thermService.Run(gasProps, detailService); //DH is enthalpy change from plenum to throat; this is our initial guess DH = (gasProps.dSOS * gasProps.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0; //trap plenum conditions before we alter the data stucture's contents S = gasProps.dS; H = gasProps.dH; R = gasProps.dRhof; P = gasProps.dPf; Z = gasProps.dZf; T = gasProps.dTf; DDH = 10.0; for (i = 1; i < GasConstants.MAX_NUM_OF_ITERATIONS; i++) { thermService.HS_Mode( gasProps, detailService, H - DH, S, true); thermService.Run( gasProps, detailService); DDH = DH; DH = (gasProps.dSOS * gasProps.dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0; if (Math.abs(DDH - DH) < tolerance) break; } gasProps.dCstar = (gasProps.dRhof * gasProps.dSOS) / Math.sqrt(R * P * Z); gasProps.dPf = P; gasProps.dTf = T; thermService.Run(gasProps, detailService); gbt11062Service.Run(gasProps ); return gasProps.dCstar; } }