added gravity function for calculating local g updated config for faster testing and changed the symbols at physical pos
This commit is contained in:
@@ -3,11 +3,61 @@ const customRefs = require('./refData.js');
|
||||
|
||||
class CoolPropWrapper {
|
||||
constructor() {
|
||||
|
||||
this.initialized = false;
|
||||
this.defaultRefrigerant = null;
|
||||
this.defaultTempUnit = 'K'; // K, C, F
|
||||
this.defaultPressureUnit = 'Pa' // Pa, kPa, bar, psi
|
||||
this.customRef = false;
|
||||
this.PropsSI = this._propsSI.bind(this);
|
||||
|
||||
|
||||
// 🔹 Wastewater correction options (defaults)
|
||||
this._ww = {
|
||||
enabled: true,
|
||||
tss_g_per_L: 3.5, // default MLSS / TSS
|
||||
density_k: 2e-4, // +0.02% per g/L
|
||||
viscosity_k: 0.07, // +7% per g/L (clamped)
|
||||
viscosity_max_gpl: 4 // cap effect at 4 g/L
|
||||
};
|
||||
|
||||
this._initPromise = null;
|
||||
this._autoInit({ refrigerant: 'Water' });
|
||||
|
||||
}
|
||||
|
||||
_isWastewaterFluid(fluidRaw) {
|
||||
if (!fluidRaw) return false;
|
||||
const token = String(fluidRaw).trim().toLowerCase();
|
||||
return token === 'wastewater' || token.startsWith('wastewater:');
|
||||
}
|
||||
|
||||
_parseWastewaterFluid(fluidRaw) {
|
||||
if (!this._isWastewaterFluid(fluidRaw)) return null;
|
||||
const ww = { ...this._ww };
|
||||
const [, tail] = String(fluidRaw).split(':');
|
||||
if (tail) {
|
||||
tail.split(',').forEach(pair => {
|
||||
const [key, value] = pair.split('=').map(s => s.trim().toLowerCase());
|
||||
if (key === 'tss' && !Number.isNaN(Number(value))) {
|
||||
ww.tss_g_per_L = Number(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return ww;
|
||||
}
|
||||
|
||||
_applyWastewaterCorrection(outputKey, baseValue, ww) {
|
||||
if (!Number.isFinite(baseValue) || !ww || !ww.enabled) return baseValue;
|
||||
switch (outputKey.toUpperCase()) {
|
||||
case 'D': // density
|
||||
return baseValue * (1 + ww.density_k * ww.tss_g_per_L);
|
||||
case 'V': // viscosity
|
||||
const effTss = Math.min(ww.tss_g_per_L, ww.viscosity_max_gpl);
|
||||
return baseValue * (1 + ww.viscosity_k * effTss);
|
||||
default:
|
||||
return baseValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Temperature conversion helpers
|
||||
@@ -407,13 +457,31 @@ class CoolPropWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
// Direct access to CoolProp functions
|
||||
async getPropsSI() {
|
||||
if(!this.initialized) {
|
||||
await coolprop.init();
|
||||
_autoInit(defaults) {
|
||||
if (!this._initPromise) {
|
||||
this._initPromise = this.init(defaults);
|
||||
}
|
||||
return coolprop.PropsSI;
|
||||
return this._initPromise;
|
||||
}
|
||||
|
||||
_propsSI(outputKey, inKey1, inVal1, inKey2, inVal2, fluidRaw) {
|
||||
if (!this.initialized) {
|
||||
// Start init if no one else asked yet
|
||||
this._autoInit({ refrigerant: this.defaultRefrigerant || 'Water' });
|
||||
throw new Error('CoolProp is still warming up, retry PropsSI in a moment');
|
||||
}
|
||||
const ww = this._parseWastewaterFluid(fluidRaw);
|
||||
const fluid = ww ? 'Water' : (this.customRefString || fluidRaw);
|
||||
const baseValue = coolprop.PropsSI(outputKey, inKey1, inVal1, inKey2, inVal2, fluid);
|
||||
return ww ? this._applyWastewaterCorrection(outputKey, baseValue, ww) : baseValue;
|
||||
}
|
||||
|
||||
//Access to coolprop
|
||||
async getPropsSI() {
|
||||
await this._ensureInit({ refrigerant: this.defaultRefrigerant || 'Water' });
|
||||
return this.PropsSI;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new CoolPropWrapper();
|
||||
|
||||
Reference in New Issue
Block a user