From 1a2aab3e258ccdc0230c4bf229465c6596e923a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Mon, 17 Apr 2023 10:00:07 +0200 Subject: [PATCH] refactor: Dichotomie: add flag saying a dichotomy is currently running refs #302 --- src/dichotomie.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/dichotomie.ts b/src/dichotomie.ts index 115d1f6b..e748417c 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -37,6 +37,11 @@ export class Dichotomie extends Debug { private _func: () => number; + /** + * si > 0, un calcul dichotomique est en cours + */ + private static _inDicho: number = 0; + /** * Construction de la classe. * @param nub Noeud de calcul contenant la méthode de calcul Equation @@ -68,6 +73,10 @@ export class Dichotomie extends Debug { this._startIntervalMaxSteps = n; } + public static get inDico(): boolean { + return Dichotomie._inDicho > 0; + } + public CalculX(x: number): number { this.vX = x; return this.Calcul(); @@ -80,6 +89,8 @@ export class Dichotomie extends Debug { * @param rInit valeur initiale approximative de x */ public Dichotomie(rTarget: number, rTol: number, rInit: number): Result { + Dichotomie._inDicho++; + this._target = rTarget; // console.log("-----"); // for (let x = 0; x <= 1; x += 0.1) @@ -109,20 +120,24 @@ export class Dichotomie extends Debug { this.debug( `${this.analyticalSymbol}(${this.sVarCalc}=${s.value}) = ${rTarget}` ); + Dichotomie._inDicho--; return new Result(s.value); } else { this.debug( "Non convergence" ); + Dichotomie._inDicho--; return new Result(new Message(MessageCode.ERROR_DICHO_CONVERGE, { lastApproximation: s.value }), this.nub); } } else { + Dichotomie._inDicho--; return new Result(r.res); } } catch (e) { // un appel à Calcul() a généré une erreur + Dichotomie._inDicho--; return this.nub.result; } } -- GitLab