UNPKG

jalhyd

Version:

JaLHyd, a Javascript Library for Hydraulics

262 lines 11.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParSimulation = exports.ParFlowRegime = void 0; const internal_modules_1 = require("../internal_modules"); const internal_modules_2 = require("../internal_modules"); const internal_modules_3 = require("../internal_modules"); const internal_modules_4 = require("../internal_modules"); const internal_modules_5 = require("../internal_modules"); const internal_modules_6 = require("../internal_modules"); const internal_modules_7 = require("../internal_modules"); var ParFlowRegime; (function (ParFlowRegime) { /** Free flow (unsubmerged) */ ParFlowRegime[ParFlowRegime["FREE"] = 0] = "FREE"; /** Submerged flow */ ParFlowRegime[ParFlowRegime["SUBMERGED"] = 1] = "SUBMERGED"; })(ParFlowRegime = exports.ParFlowRegime || (exports.ParFlowRegime = {})); class ParSimulation extends internal_modules_6.Par { constructor(prms, dbg = false) { super(prms, dbg); this.setCalculatorType(internal_modules_1.CalculatorType.ParSimulation); this.prms.ha.visible = false; // show ZD1 instead } get prms() { return this._prms; } get parType() { return this.getPropValue("parType"); } set parType(e) { this.setPropValue("parType", e); } Calc(sVarCalc, rInit) { // possible error result const r = new internal_modules_3.Result(new internal_modules_5.ResultElement()); let hasError = false; // If P is given, check it against standard value if (this.prms.P.v !== undefined) { const standardP = this.parCalc.CalcP(); const minP = standardP * 0.9; const maxP = standardP * 1.05; if ((0, internal_modules_7.isLowerThan)(this.prms.P.v, minP) || (0, internal_modules_7.isGreaterThan)(this.prms.P.v, maxP)) { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_PAR_P_DEVIATES_MORE_THAN_10_5_PCT); m.extraVar.stdP = standardP; r.resultElement.addMessage(m); hasError = true; } } // else will be calculated and displayed in results // Check admissible values for S, L, N, a, M const status = this.parCalc.checkInput(); if (status.fatal) { for (const m of status.messages) { r.resultElement.addMessage(m); } hasError = true; } // Check elevations: ZR1 / ZD1 and ZR2 / ZD2 const czRes1 = this.checkZrZd(this.prms.ZR1, this.prms.ZD1); const mzrd1 = czRes1.message; if (mzrd1 !== undefined) { r.resultElement.addMessage(mzrd1); hasError = true; } const czRes2 = this.checkZrZd(this.prms.ZR2, this.prms.ZD2); const mzrd2 = czRes2.message; if (mzrd2 !== undefined) { r.resultElement.addMessage(mzrd2); hasError = true; } // Check Nb const nb = this.CalcNb(czRes1.expectedZD, czRes2.expectedZD); // reference value if (this.prms.Nb.v === undefined) { this.prms.Nb.v = nb; this.prms.Nb.singleValue = (0, internal_modules_7.round)(nb, 3); } else { if (nb !== this.prms.Nb.v) { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_PAR_NB_INCONSISTENT); m.extraVar.stdNb = String(nb); // to prevent "14.000" r.resultElement.addMessage(m); hasError = true; } } // else will be calculated and displayed in results // Check that input data is in the range given by abacuses if (this.calculatedParam === this.prms.Z1) { // check qStar const qStar = this.parCalc.CalcQStar(); if ((0, internal_modules_7.isLowerThan)(qStar, this.parCalc.minQstar) || (0, internal_modules_7.isGreaterThan)(qStar, this.parCalc.maxQstar)) { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_PAR_QSTAR_OUT_OF_RANGE); m.extraVar.val = this.prms.Q.V; m.extraVar.min = this.parCalc.CalcQFromQStar(this.parCalc.minQstar); m.extraVar.max = this.parCalc.CalcQFromQStar(this.parCalc.maxQstar); r.resultElement.addMessage(m); hasError = true; } } else if (this.calculatedParam === this.prms.Q) { const m = this.checkHaAbacus(); if (m !== undefined) { r.resultElement.addMessage(m); hasError = true; } } // if any fatal error occurred if (hasError) { this.currentResultElement = r; return this.result; } this.nubCalc(sVarCalc, rInit); // add checkInput()'s non fatal warnings to current result if (!status.fatal) { for (const m of status.messages) { this.result.resultElement.addMessage(m); } } // extra results this.parCalc.addExtraResults(this.result, false); this.result.resultElement.values.ha = this.parCalc.ha; this.result.resultElement.values.Nb = nb; // add expected values for elevations that were not given if (this.prms.ZR1.v === undefined) { this.result.resultElement.values.ZR1 = czRes1.expectedZR; } else { // remove ZR1 systematically calculated by ParType.addExtraResults() delete this.result.resultElement.values.ZR1; } if (this.prms.ZR2.v === undefined) { this.result.resultElement.values.ZR2 = czRes2.expectedZR; } if (this.prms.ZD1.v === undefined) { this.result.resultElement.values.ZD1 = czRes1.expectedZD; } if (this.prms.ZD2.v === undefined) { this.result.resultElement.values.ZD2 = czRes2.expectedZD; } // do we have a fall at downstream baffle level ? if (this.prms.Z2.v !== undefined) { const ZD2 = this.prms.ZD2.v || this.result.resultElement.values.ZD2; // water level at downstream baffle const ZDB = ZD2 + this.result.resultElement.values.h; if ((0, internal_modules_7.isLowerThan)(this.prms.Z2.v, ZDB)) { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.WARNING_PAR_NOT_SUBMERGED); m.extraVar.DH = ZDB - this.prms.Z2.v; this.result.resultElement.addMessage(m); } // expose fall for Verificateur this.result.resultElement.values.DH = Math.max(0, ZDB - this.prms.Z2.v); } return this.result; } /** * Checks that at least one of ZR, ZD is given; if both are given, checks that * each one corresponds to the expected value calculated from the other one; * returned message id undefined if everything is OK * @param ZR ZR1 or ZR2 * @param ZD ZD1 or ZD2 */ checkZrZd(ZR, ZD) { let message; let expectedZR; let expectedZD; if (ZR.v === undefined && ZD.v === undefined) { message = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_AT_LEAST_ONE_OF_THOSE_MUST_BE_DEFINED); message.extraVar.variables = [ZR.symbol, ZD.symbol]; } else { // calculate missing value let zrDef = true; let zdDef = true; if (ZR.v === undefined) { zrDef = false; expectedZR = this.parCalc.CalcZRFromZD(ZD.V); /* ZR.v = expectedZR; ZR.singleValue = round(expectedZR, 3); */ } if (ZD.v === undefined) { zdDef = false; expectedZD = this.parCalc.CalcZDFromZR(ZR.V); /* ZD.v = expectedZD; ZD.singleValue = round(expectedZD, 3); */ } // if both values were defined, check that they match if (zrDef && zdDef) { expectedZR = this.parCalc.CalcZRFromZD(ZD.V); expectedZD = this.parCalc.CalcZDFromZR(ZR.V); if (!(0, internal_modules_7.isEqual)(ZR.v, expectedZR, 1E-3)) { message = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_PAR_ZR_ZD_MISMATCH); message.extraVar.var_ZR = ZR.symbol; message.extraVar.var_ZD = ZD.symbol; message.extraVar.expectedZR = expectedZR; message.extraVar.expectedZD = expectedZD; } } } return { message, expectedZR, expectedZD }; } CalcNb(expectedZD1, expectedZD2) { // if parameters ZD1 and ZD2 were not given, use expected values calculated by checkZrZd let realZD1 = this.prms.ZD1.v; if (realZD1 === undefined) { realZD1 = expectedZD1; } let realZD2 = this.prms.ZD2.v; if (realZD2 === undefined) { realZD2 = expectedZD2; } const rLs = (realZD1 - realZD2) * Math.sqrt(1 + this.prms.S.v * this.prms.S.v) / this.prms.S.v; const nb = Math.floor((rLs + 0.01) / this.parCalc.P); switch (this.parType) { case internal_modules_6.ParType.PLANE: case internal_modules_6.ParType.FATOU: return nb + 1; case internal_modules_6.ParType.SUPERACTIVE: case internal_modules_6.ParType.CHEVRON: return nb; } } Equation(sVarCalc) { let v; switch (sVarCalc) { case "Q": v = this.parCalc.CalcQFromHa(); break; case "Z1": v = this.parCalc.ZD1 + this.parCalc.CalcHa(); break; default: throw new Error("Par.Equation() : invalid variable name " + sVarCalc); } return new internal_modules_3.Result(v, this); } setParametersCalculability() { this.prms.Q.calculability = internal_modules_2.ParamCalculability.EQUATION; this.prms.Z1.calculability = internal_modules_2.ParamCalculability.EQUATION; this.prms.Z2.calculability = internal_modules_2.ParamCalculability.FREE; this.prms.S.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.P.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.Nb.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.ZR1.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.ZD1.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.ZR2.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.ZD2.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.L.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.a.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.N.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.M.calculability = internal_modules_2.ParamCalculability.FIXED; } exposeResults() { this._resultsFamilies = { h: undefined, ha: undefined, V: undefined }; } } exports.ParSimulation = ParSimulation; //# sourceMappingURL=par_simulation.js.map