UNPKG

jalhyd

Version:

JaLHyd, a Javascript Library for Hydraulics

176 lines 8.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Bief = 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"); const internal_modules_8 = require("../internal_modules"); const internal_modules_9 = require("../internal_modules"); const internal_modules_10 = require("../internal_modules"); const internal_modules_11 = require("../internal_modules"); class Bief extends internal_modules_11.SectionNub { constructor(s, bp, dbg = false) { super(bp, dbg); this.setCalculatorType(internal_modules_1.CalculatorType.Bief); this.setSection(s); this._props.addObserver(this); this.regime = internal_modules_7.BiefRegime.Fluvial; this._defaultCalculatedParam = bp.Z1; } get prms() { return this._prms; } setSection(s) { super.setSection(s); this.setParametersCalculability(); // to override acSection's tuning if (this.section !== undefined) { // If from Section is not linkable here this.section.prms.If.visible = false; this.section.prms.Y.visible = false; } } set regime(regime) { this.setPropValue("regime", regime); } Calc(sVarCalc, rInit) { // reinit local CourbeRemous with same section and same parameters const rp = new internal_modules_10.CourbeRemousParams(this.prms.Z1.v, this.prms.Z2.v, this.prms.ZF1.v, this.prms.ZF2.v, this.prms.Long.v, this.prms.Dx.v); const serialisedSection = this.section.serialise(); const sectionCopy = internal_modules_4.Session.getInstance().unserialiseSingleNub(serialisedSection, false).nub; this.courbeRemous = new internal_modules_9.CourbeRemous(sectionCopy, rp, internal_modules_8.MethodeResolution.Trapezes); // set values for hidden parameters this.prms.setYamontYavalFromElevations(); this.courbeRemous.prms.setYamontYavalFromElevations(); this.courbeRemous.setIfFromElevations(); // init .v for every parameter this.courbeRemous.section.copySingleValuesToSandboxValues(); this.courbeRemous.copySingleValuesToSandboxValues(); // if a section parameter is variating, copySingleValuesToSandboxValues() just set it // to undefined, because in general case the iterator is called after; here, re-set // the section copy parameters to the current section values for (const p of this.section.parameterIterator) { if (p.visible) { // do not affect hidden generated parameters (If) this.courbeRemous.section.getParameter(p.symbol).v = p.v; } } if (this.calculatedParam === this.prms.Z1 && this.getPropValue("regime") === internal_modules_7.BiefRegime.Torrentiel) { throw new Error("Bief.Equation() : cannot calculate Z1 in Torrential regime"); } if (this.calculatedParam === this.prms.Z2 && this.getPropValue("regime") === internal_modules_7.BiefRegime.Fluvial) { throw new Error("Bief.Equation() : cannot calculate Z2 in Fluvial regime"); } // regular calculation return super.Calc(sVarCalc, rInit); } Equation(sVarCalc) { let v; const xValues = new internal_modules_3.ParamValues(); const l = this.prms.Long.v; const dx = this.prms.Dx.v; xValues.setValues(0, l, dx); // in Dichotomie mode, update sandbox value of calculated param if (!this.calculatedParam.isAnalytical()) { // we're calculating Ks or Q, in section this.courbeRemous.section.getParameter(this.calculatedParam.symbol).v = this.calculatedParam.v; } switch (sVarCalc) { case "Z1": this.courbeRemous.section.CalcSection("Yc"); const ligneFlu = this.courbeRemous.calculFluvial(xValues); if (ligneFlu !== undefined && ligneFlu.trY !== undefined && ligneFlu.trY[0] !== undefined) { v = ligneFlu.trY[0] + this.prms.ZF1.v; } else { const res = new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_BIEF_Z1_CALC_FAILED), this); res.log.insertLog(ligneFlu.log); return res; } break; case "Z2": this.courbeRemous.section.CalcSection("Yc"); const ligneTor = this.courbeRemous.calculTorrentiel(xValues); if (ligneTor !== undefined && ligneTor.trY !== undefined && ligneTor.trY[l] !== undefined) { v = ligneTor.trY[l] + this.prms.ZF2.v; } else { const res = new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_BIEF_Z2_CALC_FAILED), this); res.log.insertLog(ligneTor.log); return res; } break; default: throw new Error("Bief.Equation() : invalid variable name " + sVarCalc); } return new internal_modules_6.Result(v, this); } // interface Observer update(sender, data) { if (data.action === "propertyChange") { switch (data.name) { case "regime": if (data.value === internal_modules_7.BiefRegime.Fluvial) { this.prms.Z1.calculability = internal_modules_2.ParamCalculability.EQUATION; if (this.calculatedParam === undefined || this.calculatedParam === this.prms.Z2) { this.prms.Z1.setCalculated(); } this.prms.Z2.calculability = internal_modules_2.ParamCalculability.FREE; } if (data.value === internal_modules_7.BiefRegime.Torrentiel) { this.prms.Z2.calculability = internal_modules_2.ParamCalculability.EQUATION; if (this.calculatedParam === undefined || this.calculatedParam === this.prms.Z1) { this.prms.Z2.setCalculated(); } this.prms.Z1.calculability = internal_modules_2.ParamCalculability.FREE; } break; } } } setParametersCalculability() { this.prms.Long.calculability = internal_modules_2.ParamCalculability.FREE; this.prms.Dx.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.Yamont.calculability = internal_modules_2.ParamCalculability.FIXED; this.prms.Yaval.calculability = internal_modules_2.ParamCalculability.FIXED; // do not set Z1 and Z2 here to avoid both being calculable at the same time this.prms.ZF1.calculability = internal_modules_2.ParamCalculability.FREE; this.prms.ZF2.calculability = internal_modules_2.ParamCalculability.FREE; // section params if (this.section) { this.section.prms.Ks.calculability = internal_modules_2.ParamCalculability.DICHO; this.section.prms.Q.calculability = internal_modules_2.ParamCalculability.DICHO; this.section.prms.If.calculability = internal_modules_2.ParamCalculability.FREE; this.section.prms.YB.calculability = internal_modules_2.ParamCalculability.FREE; this.section.prms.Y.calculability = internal_modules_2.ParamCalculability.FREE; this.section.prms.LargeurBerge.calculability = internal_modules_2.ParamCalculability.FREE; // parameters depending on section type const D = this.section.getParameter("D"); if (D) { D.calculability = internal_modules_2.ParamCalculability.FREE; } const k = this.section.getParameter("k"); if (k) { k.calculability = internal_modules_2.ParamCalculability.FREE; } const fruit = this.section.getParameter("Fruit"); if (fruit) { fruit.calculability = internal_modules_2.ParamCalculability.FREE; } const largeurFond = this.section.getParameter("LargeurFond"); if (largeurFond) { largeurFond.calculability = internal_modules_2.ParamCalculability.FREE; } } } } exports.Bief = Bief; //# sourceMappingURL=bief.js.map