ccs-sim
Version:
Modelling CCS systems
84 lines (83 loc) • 3.98 kB
JavaScript
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 element_1 = require("./element");
const transport_1 = __importDefault(require("./transport"));
const fluid_1 = require("./fluid");
const physical_quantities_1 = require("physical-quantities");
class Inlet extends transport_1.default {
constructor(name, physical) {
super(name, physical, 'Inlet');
this.temperature = new physical_quantities_1.Temperature(10, physical_quantities_1.TemperatureUnits.Kelvin);
}
applyInletProperties(pressure, temperature, flowrate, skipProcess = false) {
return __awaiter(this, void 0, void 0, function* () {
const newFluid = yield fluid_1.defaultFluidConstructor(pressure, temperature, flowrate);
this.fluid = newFluid;
this.temperature = this.fluid.temperature;
if (skipProcess)
return;
return this.process(this.fluid);
});
}
searchInletPressure() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const lowLimit = new physical_quantities_1.Pressure(1, physical_quantities_1.PressureUnits.Bara);
const highLimit = new physical_quantities_1.Pressure(140, physical_quantities_1.PressureUnits.Bara);
let low = lowLimit.pascal;
let high = highLimit.pascal;
let mid = 0;
let guesses = 0;
const maxGuesses = 25;
let pressureSolution = element_1.PressureSolution.Low;
if (!this.fluid) {
throw new Error(`Inlet has no fluid`);
}
while (pressureSolution !== element_1.PressureSolution.Ok) {
if (guesses++ > maxGuesses - 1) {
break;
}
mid = (low + high) / 2;
pressureSolution = (_a = (yield this.applyInletProperties(new physical_quantities_1.Pressure(mid, physical_quantities_1.PressureUnits.Pascal), this.temperature, this.fluid.flowrate))) === null || _a === void 0 ? void 0 : _a.pressureSolution;
if (pressureSolution === element_1.PressureSolution.Low) {
low = mid;
}
else if (pressureSolution === element_1.PressureSolution.High) {
high = mid;
}
}
return {
pressure: new physical_quantities_1.Pressure(mid, physical_quantities_1.PressureUnits.Pascal),
pressureSolution,
};
});
}
setDestination(dest) {
this.destination = dest;
dest.source = this;
}
process(fluid) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.destination)
return {
pressureSolution: element_1.PressureSolution.Ok,
pressure: fluid.pressure,
target: null,
};
return yield this.destination.process(fluid);
});
}
}
exports.default = Inlet;
;