ccs-sim
Version:
Modelling CCS systems
101 lines (100 loc) • 4.58 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 transport_1 = __importDefault(require("./transport"));
const fluid_1 = require("./fluid");
const element_1 = require("./element");
const physical_quantities_1 = require("physical-quantities");
class PipeSeg extends transport_1.default {
constructor(pipeDef) {
super(pipeDef.name, pipeDef, 'PipeSeg');
this.physical = pipeDef;
}
get effectiveArea() {
return this.physical.diameters
.map((d) => (Math.PI / 4) * Math.pow(d, 2))
.reduce((acc, a) => (acc += a), 0);
}
removeLine(size) {
if (!this.physical.diameters.includes(size)) {
throw new Error(`Pipe does not have a line of size ${size}`);
}
if (this.physical.diameters.length === 1) {
throw new Error(`Pipe only has one line`);
}
this.physical.diameters.splice(this.physical.diameters.indexOf(size), 1);
}
addLine(size) {
this.physical.diameters.push(size);
}
setDestination(dest) {
this.destination = dest;
dest.source = this;
}
get height() {
if (!this.destination)
throw new Error('No destination');
return this.destination.physical.elevation - this.physical.elevation;
}
endPressure() {
if (!this.fluid)
throw new Error('Pipe segment has no fluid - unable to calculate end pressure');
const w = this.fluid.flowrate;
const D = Math.sqrt(this.effectiveArea / Math.PI) * 2;
const A = this.effectiveArea;
const ρ = this.fluid.density;
const v = 1 / ρ;
const L = this.physical.length;
const P1 = this.fluid.pressure;
// Friction factor
const u = w.kgps / (A * ρ);
const μ = this.fluid.viscosity;
const Re = (ρ * u * D) / μ;
const ε = 4.5e-5;
const f = 0.25 / Math.pow(Math.log10((ε * 1000) / (3.7 * D * 1000) + 5.74 / Math.pow(Re, 0.9)), 2);
const g = 9.807;
const elevationLoss = g * this.height * ρ;
let endP = Math.pow((A * Math.sqrt(D)), -1) *
Math.sqrt(P1.pascal) *
Math.sqrt(Math.pow(A, 2) * D * P1.pascal - f * L * v * Math.pow(w.kgps, 2)) -
elevationLoss;
endP = isNaN(endP) ? 0 : endP;
const limit = new physical_quantities_1.Pressure(13500000, physical_quantities_1.PressureUnits.Pascal);
const capped = Math.max(Math.min(endP, limit.pascal), 0);
return new physical_quantities_1.Pressure(capped, physical_quantities_1.PressureUnits.Pascal);
}
process(fluid) {
return __awaiter(this, void 0, void 0, function* () {
this.fluid = fluid;
// TODO: remove this after adding reservoirs to tests
if (!this.destination)
return {
pressureSolution: element_1.PressureSolution.Ok,
pressure: this.fluid.pressure,
target: null,
};
const p = this.endPressure();
const lowPressureLimit = new physical_quantities_1.Pressure(1000, physical_quantities_1.PressureUnits.Pascal).pascal;
if (p.pascal < lowPressureLimit)
return {
pressureSolution: element_1.PressureSolution.Low,
pressure: p,
target: null,
};
const endFluid = yield fluid_1.defaultFluidConstructor(p, fluid.temperature, fluid.flowrate);
return yield this.destination.process(endFluid);
});
}
}
exports.default = PipeSeg;
;