psychart
Version:
View air conditions on a psychrometric chart
101 lines (100 loc) • 5.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PsyState = void 0;
var SMath = require("smath");
var Psychrolib = require("psychrolib");
/**
* Represents a single air condition using several states.
*/
var PsyState = /** @class */ (function () {
/**
* Initialize a new psychrometric state.
*/
function PsyState(state, options) {
var _a, _b, _c, _d, _e;
this.state = state;
this.options = options;
Psychrolib.SetUnitSystem(options.unitSystem === 'IP' ? Psychrolib.IP : Psychrolib.SI);
this.atm = Psychrolib.GetStandardAtmPressure(options.altitude);
this.hrMax = Psychrolib.GetHumRatioFromTDewPoint(options.dpMax, this.atm);
this.db = state.db;
switch (state.measurement) {
case ('dbrh'): {
this.rh = state.other;
_a = Psychrolib.CalcPsychrometricsFromRelHum(state.db, state.other, this.atm), this.hr = _a[0], this.wb = _a[1], this.dp = _a[2], this.vp = _a[3], this.h = _a[4], this.v = _a[5], this.s = _a[6];
break;
}
case ('dbwb'): {
this.wb = state.other;
_b = Psychrolib.CalcPsychrometricsFromTWetBulb(state.db, state.other, this.atm), this.hr = _b[0], this.dp = _b[1], this.rh = _b[2], this.vp = _b[3], this.h = _b[4], this.v = _b[5], this.s = _b[6];
break;
}
case ('dbdp'): {
this.dp = state.other;
_c = Psychrolib.CalcPsychrometricsFromTDewPoint(state.db, state.other, this.atm), this.hr = _c[0], this.wb = _c[1], this.rh = _c[2], this.vp = _c[3], this.h = _c[4], this.v = _c[5], this.s = _c[6];
break;
}
case ('dbhr'): {
this.dp = Psychrolib.GetTDewPointFromHumRatio(state.db, state.other, this.atm);
_d = Psychrolib.CalcPsychrometricsFromTDewPoint(state.db, this.dp, this.atm), this.hr = _d[0], this.wb = _d[1], this.rh = _d[2], this.vp = _d[3], this.h = _d[4], this.v = _d[5], this.s = _d[6];
if (!SMath.approx(this.hr, state.other) && Math.abs(SMath.error(this.hr, state.other)) > PsyState.TOL) {
throw new Error("Error in psychrolib computation. Expected \"".concat(state.other, "\" but found \"").concat(this.hr, "\" for ").concat(state.measurement, "."));
}
break;
}
case ('dbh'): {
this.hr = Psychrolib.GetHumRatioFromEnthalpyAndTDryBulb(state.other, state.db);
this.dp = Psychrolib.GetTDewPointFromHumRatio(state.db, this.hr, this.atm);
_e = Psychrolib.CalcPsychrometricsFromTDewPoint(state.db, this.dp, this.atm), this.hr = _e[0], this.wb = _e[1], this.rh = _e[2], this.vp = _e[3], this.h = _e[4], this.v = _e[5], this.s = _e[6];
if (!SMath.approx(this.h, state.other) && Math.abs(SMath.error(this.h, state.other)) > PsyState.TOL) {
throw new Error("Error in psychrolib computation. Expected \"".concat(state.other, "\" but found \"").concat(this.h, "\" for ").concat(state.measurement, "."));
}
break;
}
default: {
throw new Error("Invalid measurement type ".concat(state.measurement, "."));
}
}
}
/**
* Convert this psychrometric state to an X-Y coordinate on a psychrometric chart.
*/
PsyState.prototype.toXY = function () {
// Determine if additional padding is needed to show axis names
var fontPad = this.options.showAxisNames ? (1.5 * this.options.font.size) : 0;
// The lower-left location
var origin = {
x: this.options.padding.x + (this.options.flipXY ? fontPad : 0),
y: this.options.padding.y + (this.options.flipXY ? fontPad : 0),
};
// The upper-right location
var bound = {
x: this.options.size.x - this.options.padding.x - (this.options.flipXY ? 0 : fontPad),
y: this.options.size.y - this.options.padding.y - (this.options.flipXY ? 0 : fontPad),
};
if (this.options.flipXY) {
return {
x: SMath.clamp(SMath.translate(this.hr, 0, this.hrMax, origin.x, bound.x), origin.x, bound.x),
y: SMath.clamp(SMath.translate(this.db, this.options.dbMin, this.options.dbMax, bound.y, origin.y), origin.y, bound.y)
};
}
else {
return {
x: SMath.clamp(SMath.translate(this.db, this.options.dbMin, this.options.dbMax, origin.x, bound.x), origin.x, bound.x),
y: SMath.clamp(SMath.translate(this.hr, 0, this.hrMax, bound.y, origin.y), origin.y, bound.y)
};
}
};
/**
* Calculate the dry bulb temperature of dry air with enthalpy `h`
*/
PsyState.getDryBulbWithEnthalpy = function (h) {
return Psychrolib.GetTDryBulbFromEnthalpyAndHumRatio(h, 0);
};
/**
* Calculation tolerance
*/
PsyState.TOL = 0.01;
return PsyState;
}());
exports.PsyState = PsyState;