package com.ruoyi.ngCalTools.controller; // GasController.java import com.ruoyi.ngCalTools.model.GasProps; 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 org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/NGCalcTools") public class GasController { public ThermService thermService; public DetailService detailService; public GBT11062Service gbt11062Service; @PostMapping ("/calculate") public GasProps calculateProperties(@RequestBody GasProps tempPar) { Zcal(tempPar, 0); return tempPar; } public int NG_Cal_Init() { //create object for calculating density if (null == detailService) { return GasConstants.MEMORY_ALLOCATION_ERROR; } //create object for calculating thermodynamic properties if (null == 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 SOS(GasProps gasProps) { // check if library is ready; initialize if necessary if (null == detailService || null == thermService) { NG_Cal_UnInit(); NG_Cal_Init(); } 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; } detailService.run(gasProps); gasProps.dCstar = 0; return gasProps.dSOS; } 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; } public double Zcal(GasProps gasProps, double dPlenumVelocity) { 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; } thermService.Run( gasProps, detailService); gbt11062Service.Run( gasProps); return gasProps.dZf; } double Cperf(GasProps gasProps) { double k, root, exponent; k = gasProps.dKappa; root = 2.0 / (k + 1.0); exponent = (k + 1.0) / (k - 1.0); return (Math.sqrt(k * Math.pow(root, exponent))); } double CRi(GasProps gasProps) { return (Cperf(gasProps) / Math.sqrt(gasProps.dZf)); } }