Skip to content
Snippets Groups Projects
Commit 24e027dd authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #198 - Solveur: stop calculation if Nub chain is variated

parent 3e381cd4
No related branches found
No related tags found
No related merge requests found
......@@ -326,4 +326,15 @@ describe("solveur multi-modules", () => {
});
it("test 12: bug jalhyd#198", () => {
// tslint:disable-next-line:max-line-length
const sess = `{"header":{"source":"jalhyd","format_version":"1.3","created":"2020-02-19T15:58:34.204Z"},"settings":{"precision":1e-7,"maxIterations":100,"displayPrecision":3},"documentation":"","session":[{"uid":"dHczZm","props":{"calcType":"PabDimensions"},"meta":{"title":"PAB : dimensions"},"children":[],"parameters":[{"symbol":"L","mode":"MINMAX","min":1,"max":4,"step":0.15,"extensionStrategy":0},{"symbol":"W","mode":"SINGLE","value":0.6397826086956476},{"symbol":"Y","mode":"SINGLE","value":0.5},{"symbol":"V","mode":"CALCUL"}]},{"uid":"NWtydz","props":{"calcType":"PabPuissance"},"meta":{"title":"PAB : puissance"},"children":[],"parameters":[{"symbol":"DH","mode":"SINGLE","value":0.3},{"symbol":"Q","mode":"SINGLE","value":0.1},{"symbol":"V","mode":"LINK","targetNub":"dHczZm","targetParam":"V"},{"symbol":"PV","mode":"CALCUL"}]},{"uid":"Ympkdj","props":{"calcType":"Solveur","nubToCalculate":"NWtydz","searchedParameter":"dHczZm/W"},"meta":{"title":"Solveur"},"children":[],"parameters":[{"symbol":"Xinit","mode":"SINGLE","value":1},{"symbol":"Ytarget","mode":"SINGLE","value":230}]}]}`;
Session.getInstance().clear();
Session.getInstance().unserialise(sess);
const s = Session.getInstance().findNubByUid("Ympkdj") as Solveur;
const res = s.CalcSerie();
expect(res.vCalc).toBeUndefined();
expect(res.log.messages.length).toBe(1);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_SOLVEUR_NO_VARIATED_PARAMS_ALLOWED);
});
});
......@@ -7,6 +7,7 @@ import { Observer } from "../util/observer";
import { Result } from "../util/result";
import { ResultElement } from "../util/resultelement";
import { SolveurParams } from "./solveur_params";
import { Message, MessageCode } from "../util/message";
export class Solveur extends Nub implements Observer {
......@@ -128,6 +129,19 @@ export class Solveur extends Nub implements Observer {
this.properties.setPropValue("searchedParameter", sp);
}
/**
* Looks for potential errors before calling Nub.Calc()
*/
public Calc(sVarCalc?: string, rInit?: number): Result {
const r: Result = new Result(new ResultElement());
if (this.nubToCalculate.resultHasMultipleValues()) {
r.resultElement.addMessage(new Message(MessageCode.ERROR_SOLVEUR_NO_VARIATED_PARAMS_ALLOWED));
this.currentResult = r;
return this.result;
}
return super.Calc(sVarCalc, rInit);
}
public CalcSerie(rInit?: number): Result {
// affect initial value of X for Dichotomie search
this.prms.X.singleValue = this.prms.Xinit.currentValue;
......
......@@ -166,6 +166,9 @@ export enum MessageCode {
/** Aucune ligne d'eau ne peut être calculée (aucun tirant d'eau à l'amont ni nà l'aval) */
ERROR_REMOUS_NO_WATER_LINE,
/** Solveur : interdiction de faire varier des paramètres dans le Nub calculé */
ERROR_SOLVEUR_NO_VARIATED_PARAMS_ALLOWED,
/**
* internationalisation : langue non prise en charge
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment