UNPKG

jalhyd

Version:

JaLHyd, a Javascript Library for Hydraulics

164 lines 7.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SPP = exports.SPPOperation = 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"); var SPPOperation; (function (SPPOperation) { SPPOperation[SPPOperation["SUM"] = 0] = "SUM"; SPPOperation[SPPOperation["PRODUCT"] = 1] = "PRODUCT"; // Produit })(SPPOperation = exports.SPPOperation || (exports.SPPOperation = {})); /** * Somme et produit de puissances * Y = Σ ou π (a1.x1^p1, … an.xn^pn) */ class SPP extends internal_modules_2.Nub { constructor(prms, dbg = false) { super(prms, dbg); this.setCalculatorType(internal_modules_1.CalculatorType.SPP); this._defaultCalculatedParam = prms.Y; this.resetDefaultCalculatedParam(); this.operation = SPPOperation.SUM; } /** paramètres castés au bon type */ get prms() { return this._prms; } get operation() { return this.getPropValue("sppOperation"); } set operation(o) { this.setPropValue("sppOperation", o); } /** * @param sVarCalc Nom du paramètre à calculer : "Y", ou * { uid: "abcdef", symbol: "X" } avec "abcdef" l'UID du module YAXN et "X" son paramètre * @param rInit Valeur initiale */ Calc(sVarCalc, rInit) { // if Calc() is called outside of CalcSerie(), _result might not be initialized if (!this.result) { this.initNewResultElement(); } switch (sVarCalc) { case "Y": this.currentResultElement = super.Calc(sVarCalc, rInit); if (this.result.ok) { this.getParameter(sVarCalc).v = this.result.resultElement.vCalc; } break; default: if (typeof sVarCalc === "string") { throw new Error("SPP.Calc() : unknow parameter to calculate " + sVarCalc); } let vPartielle; // 1. calcul de la somme / du produit des modules YAXN, sauf celui qui est en calcul; // 2. soustraction / division de Y par le résultat de 1. if (this.operation === SPPOperation.SUM) { vPartielle = 0; for (const c of this._children) { if (c.uid !== sVarCalc.uid) { const cRes = c.Calc("Y"); if (cRes.ok) { vPartielle += cRes.vCalc; } else { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_SOMETHING_FAILED_IN_CHILD); m.extraVar.number = String(c.findPositionInParent() + 1); // String to avoid decimals this.result.log.add(m); this.result.log.addLog(cRes.log); return this.result; } } } vPartielle = this.prms.Y.v - vPartielle; } else if (this.operation === SPPOperation.PRODUCT) { vPartielle = 1; for (const c of this._children) { if (c.uid !== sVarCalc.uid) { const cRes = c.Calc("Y"); if (cRes.ok) { vPartielle *= cRes.vCalc; } else { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_SOMETHING_FAILED_IN_CHILD); m.extraVar.number = String(c.findPositionInParent() + 1); // String to avoid decimals this.result.log.add(m); this.result.log.addLog(cRes.log); return this.result; } } } if (vPartielle === 0) { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_DIVISION_BY_ZERO); m.extraVar.symbol = "vPartielle"; this.result.resultElement.addMessage(m); return this.result; } vPartielle = this.prms.Y.v / vPartielle; } // 3. injection de vPartielle dans le Y du module YAXN en calcul const yaxnEnCalcul = this.getChildren()[this.getIndexForChild(sVarCalc.uid)]; yaxnEnCalcul.prms.Y.v = vPartielle; const r = yaxnEnCalcul.Calc(sVarCalc.symbol, rInit); // sVarCalc.symbol should always be "X" // "copy" result this.result.symbol = r.symbol; this.result.vCalc = r.vCalc; this.result.log.addLog(r.log); this.result.globalLog.addLog(r.globalLog); } return this.result; } Equation(sVarCalc) { let v; switch (sVarCalc) { case "Y": if (this.operation === SPPOperation.SUM) { v = 0; for (const c of this._children) { const cRes = c.Calc("Y"); if (cRes.ok) { v += cRes.vCalc; } else { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_SOMETHING_FAILED_IN_CHILD); m.extraVar.number = String(c.findPositionInParent() + 1); // String to avoid decimals this.result.log.add(m); this.result.log.addLog(cRes.log); return this.result; } } } else if (this.operation === SPPOperation.PRODUCT) { v = 1; for (const c of this._children) { const cRes = c.Calc("Y"); if (cRes.ok) { v *= cRes.vCalc; } else { const m = new internal_modules_4.Message(internal_modules_4.MessageCode.ERROR_SOMETHING_FAILED_IN_CHILD); m.extraVar.number = String(c.findPositionInParent() + 1); // String to avoid decimals this.result.log.add(m); this.result.log.addLog(cRes.log); return this.result; } } } break; default: throw new Error("YAXN.Equation() : invalid variable name " + sVarCalc); } return new internal_modules_5.Result(v, this); } /** paramétrage de la calculabilité des paramètres */ setParametersCalculability() { this.prms.Y.calculability = internal_modules_3.ParamCalculability.EQUATION; } } exports.SPP = SPP; //# sourceMappingURL=spp.js.map