Commit 1a2aab3e authored by Grand Francois's avatar Grand Francois
Browse files

refactor: Dichotomie: add flag saying a dichotomy is currently running

refs #302
Showing with 15 additions and 0 deletions
+15 -0
...@@ -37,6 +37,11 @@ export class Dichotomie extends Debug { ...@@ -37,6 +37,11 @@ export class Dichotomie extends Debug {
private _func: () => number; private _func: () => number;
/**
* si > 0, un calcul dichotomique est en cours
*/
private static _inDicho: number = 0;
/** /**
* Construction de la classe. * Construction de la classe.
* @param nub Noeud de calcul contenant la méthode de calcul Equation * @param nub Noeud de calcul contenant la méthode de calcul Equation
...@@ -68,6 +73,10 @@ export class Dichotomie extends Debug { ...@@ -68,6 +73,10 @@ export class Dichotomie extends Debug {
this._startIntervalMaxSteps = n; this._startIntervalMaxSteps = n;
} }
public static get inDico(): boolean {
return Dichotomie._inDicho > 0;
}
public CalculX(x: number): number { public CalculX(x: number): number {
this.vX = x; this.vX = x;
return this.Calcul(); return this.Calcul();
...@@ -80,6 +89,8 @@ export class Dichotomie extends Debug { ...@@ -80,6 +89,8 @@ export class Dichotomie extends Debug {
* @param rInit valeur initiale approximative de x * @param rInit valeur initiale approximative de x
*/ */
public Dichotomie(rTarget: number, rTol: number, rInit: number): Result { public Dichotomie(rTarget: number, rTol: number, rInit: number): Result {
Dichotomie._inDicho++;
this._target = rTarget; this._target = rTarget;
// console.log("-----"); // console.log("-----");
// for (let x = 0; x <= 1; x += 0.1) // for (let x = 0; x <= 1; x += 0.1)
...@@ -109,20 +120,24 @@ export class Dichotomie extends Debug { ...@@ -109,20 +120,24 @@ export class Dichotomie extends Debug {
this.debug( this.debug(
`${this.analyticalSymbol}(${this.sVarCalc}=${s.value}) = ${rTarget}` `${this.analyticalSymbol}(${this.sVarCalc}=${s.value}) = ${rTarget}`
); );
Dichotomie._inDicho--;
return new Result(s.value); return new Result(s.value);
} else { } else {
this.debug( this.debug(
"Non convergence" "Non convergence"
); );
Dichotomie._inDicho--;
return new Result(new Message(MessageCode.ERROR_DICHO_CONVERGE, { return new Result(new Message(MessageCode.ERROR_DICHO_CONVERGE, {
lastApproximation: s.value lastApproximation: s.value
}), this.nub); }), this.nub);
} }
} else { } else {
Dichotomie._inDicho--;
return new Result(r.res); return new Result(r.res);
} }
} catch (e) { } catch (e) {
// un appel à Calcul() a généré une erreur // un appel à Calcul() a généré une erreur
Dichotomie._inDicho--;
return this.nub.result; return this.nub.result;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment