UNPKG

ccs-sim

Version:
76 lines (75 loc) 3.85 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const physical_quantities_1 = require("physical-quantities"); const element_1 = require("./element"); const transport_1 = __importDefault(require("./transport")); const binaryTargetSearch_1 = __importDefault(require("../utils/binaryTargetSearch")); const fluid_1 = require("./fluid"); class Compressor extends transport_1.default { constructor(name, physical, outputPressure) { super(name, physical, 'PressureChanger'); this.isentropicEfficiency = 0.7; this.idealWork = 0; this.actualWork = 0; this.outletEnthalpy = 0; this.outputPressure = outputPressure; } setDestination(dest) { this.destination = dest; dest.source = this; } getNewFluid() { return __awaiter(this, void 0, void 0, function* () { if (!this.fluid) { throw new Error(`No incoming fluid`); } const entropyTarget = this.fluid.entropy; const minT = -50; const maxT = 200; let fluid; const testTempIdeal = (temp) => __awaiter(this, void 0, void 0, function* () { fluid = yield fluid_1.defaultFluidConstructor(this.outputPressure, new physical_quantities_1.Temperature(temp, physical_quantities_1.TemperatureUnits.Celsius), this.fluid.flowrate); return fluid.entropy; }); yield binaryTargetSearch_1.default({ min: minT, max: maxT }, entropyTarget, 2, testTempIdeal); this.idealWork = fluid.enthalpy - this.fluid.enthalpy; this.actualWork = this.idealWork / this.isentropicEfficiency; this.outletEnthalpy = this.fluid.enthalpy + this.actualWork; const testTempActual = (temp) => __awaiter(this, void 0, void 0, function* () { fluid = yield fluid_1.defaultFluidConstructor(this.outputPressure, new physical_quantities_1.Temperature(temp, physical_quantities_1.TemperatureUnits.Celsius), this.fluid.flowrate); return fluid.enthalpy; }); yield binaryTargetSearch_1.default({ min: minT, max: maxT }, this.outletEnthalpy, 2, testTempActual); if (fluid.temperature.celsius > 120) { throw new Error(`Fluid temperature is greater than 120°C: ${fluid.temperature.celsius}°C`); } return fluid; }); } process(fluid) { return __awaiter(this, void 0, void 0, function* () { this.fluid = fluid; if (!this.destination) return { pressureSolution: element_1.PressureSolution.Ok, pressure: this.fluid.pressure, target: null, }; const newFluid = yield this.getNewFluid(); return yield this.destination.process(newFluid); }); } } exports.default = Compressor;