diff --git a/src/dichotomie.ts b/src/dichotomie.ts index 93c6676aecd1c5af0224dab85c608fc0c5bd5b67..55e4b48a2740ff685d6bd1ff703c68ce5adb3ef1 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -245,7 +245,12 @@ export class Dichotomie extends Debug { } let intMax: Interval = new Interval(min, max); - intMax.checkValue(rInit); + try { + intMax.checkValue(rInit); + } + catch (m) { + return { ok: false, "res": m }; + } // initialisation de l'intervalle de recherche let intSearch: SearchInterval = new SearchInterval(this, rInit - step / 2, rInit + step / 2, step); diff --git a/src/regime_uniforme.ts b/src/regime_uniforme.ts index 5582c5e6366611fc27e0aee48c263695078593c9..d1bd51e9734161f8c967e26736195968ec980e6f 100644 --- a/src/regime_uniforme.ts +++ b/src/regime_uniforme.ts @@ -24,34 +24,40 @@ export class RegimeUniforme extends Nub { * Calcul du débit en régime uniforme. * @return Débit en régime uniforme */ - Calc_Qn(): number { + Calc_Qn(): Result { this.Sn.Reset(true); if (this.Sn.prms.If.v <= 0) - return 0; + return new Result(0); // this.debug("RU: Calc_Qn : "); // this.debug(this.Sn.prms); - return this.Sn.prms.Ks.v * Math.pow(this.Sn.Calc("R", this.Sn.prms.Y.v), 2 / 3) * this.Sn.Calc("S", this.Sn.prms.Y.v) * Math.sqrt(this.Sn.prms.If.v); + // return this.Sn.prms.Ks.v * Math.pow(this.Sn.Calc("R", this.Sn.prms.Y.v), 2 / 3) * this.Sn.Calc("S", this.Sn.prms.Y.v) * Math.sqrt(this.Sn.prms.If.v); + + const rR: Result = this.Sn.Calc("R", this.Sn.prms.Y.v); + if (!rR) + return rR; + + const rS: Result = this.Sn.Calc("S", this.Sn.prms.Y.v) + if (!rS) + return rS; + + const v = this.Sn.prms.Ks.v * Math.pow(rR.vCalc, 2 / 3) * rS.vCalc * Math.sqrt(this.Sn.prms.If.v); + return new Result(v); } Equation(sVarCalc: string): Result { this.debug("RU: Equation(" + sVarCalc + ")") - let v: number; switch (sVarCalc) { case 'Y': - v = this.Sn.Calc("Yn"); - break; + return this.Sn.Calc("Yn"); case 'Q': - v = this.Calc_Qn(); - break; + return this.Calc_Qn(); default: throw "RegimeUniforme.Equation() : invalid variable name " + sVarCalc; } - - return new Result(v); } }