UNPKG

ccs-sim

Version:
137 lines (136 loc) 4.22 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== 'function' && b !== null) throw new TypeError( 'Class extends value ' + String(b) + ' is not a constructor or null', ); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __()); }; })(); import Point from './point'; import { postOrder } from './traversal'; var PipeSegment = /** @class */ (function (_super) { __extends(PipeSegment, _super); function PipeSegment(props) { if (props === void 0) { props = { name: 'pipeseg' }; } var _this = _super.call(this, props) || this; _this.properties = { diameter: props.diameter || 2, length: props.length || 200, roughness: props.roughness || 0, flowrate: props.flowrate || 0, start: { pressure: (props.start && props.start.pressure) || 2e6, viscosity: (props.start && props.start.viscosity) || 0, temperature: (props.start && props.start.temperature) || 10, x: (props.start && props.start.x) || 0, y: (props.start && props.start.y) || 0, }, }; return _this; } PipeSegment.prototype.inflow = function () { var sum = 0; var addFlow = function (node) { return (sum += node.properties.flowrate); }; postOrder(this, addFlow); return sum; }; PipeSegment.prototype.density = function () { // ρ=(Pμ)/(RT) var μ = 0.044; var R = 8.31462; return Number( (this.properties.start.pressure * μ) / (R * this.properties.start.temperature), ); }; PipeSegment.prototype.viscosity = function () { var μ0 = 0.000018; // Ref viscosity var T0 = 373; // Ref temperature var C = 240; // Southerland constant var T = this.properties.start.temperature; return μ0 * ((T0 + C) / (T + C)) * Math.pow(T / T0, 3 / 2); }; PipeSegment.prototype.endPressure = function () { var w = this.properties.flowrate; var D = this.properties.diameter; var A = 0.25 * Math.PI * Math.pow(this.properties.diameter, 2); var ρ = this.density(); var v = 1 / ρ; var L = this.properties.length; var P1 = this.properties.start.pressure; // Friction factor var u = w / (A * ρ); var μ = this.viscosity(); var Re = (ρ * u * D) / μ; var f = Re < 2000 ? 64 / Re : 0.094 / Math.pow(D * 1000, 1 / 3); return ( Math.pow(A * Math.sqrt(D), -1) * Math.sqrt(P1) * Math.sqrt(Math.pow(A, 2) * D * P1 - f * L * v * Math.pow(w, 2)) ); }; Object.defineProperty(PipeSegment.prototype, 'pressureDrop', { get: function () { return this.properties.start.pressure - this.endPressure(); }, enumerable: false, configurable: true, }); Object.defineProperty(PipeSegment.prototype, 'pressure', { get: function () { return this.endPressure(); }, enumerable: false, configurable: true, }); Object.defineProperty(PipeSegment.prototype, 'temperature', { get: function () { return this.properties.start.temperature; }, enumerable: false, configurable: true, }); Object.defineProperty(PipeSegment.prototype, 'flowrate', { get: function () { return this.inflow(); }, enumerable: false, configurable: true, }); PipeSegment.prototype.pressureContinuity = function () { return this.destination.properties.start.pressure === this.pressure; }; PipeSegment.prototype.addSource = function (node) { _super.prototype.addSource.call(this, node); this.properties.start.pressure = this.calcPressure(); }; return PipeSegment; })(Point); export default PipeSegment;