Commit 24781a50 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Fix #163 - ParallelStructure results when calc fails

parent cd29abf3
import { ParallelStructure, ParallelStructureParams, Session } from "../../src/index";
import { StructureOrificeFree } from "../../src/structure/structure_orifice_free";
import { StructureOrificeFreeParams } from "../../src/structure/structure_orifice_free_params";
describe("ParallelStructures, jalhyd#163, calculated variables present in the results − ", () => {
it("when Z1 is high enough and Zco calc succeeds, 10 variables should be present", () => {
// tslint:disable-next-line:max-line-length
const sess = `{"header":{"source":"jalhyd","format_version":"1.3","created":"2019-10-29T14:06:53.775Z"},"settings":{"precision":0.0001,"maxIterations":100,"displayPrecision":3},"documentation":"","session":[{"uid":"c292bn","props":{"calcType":"ParallelStructure"},"meta":{"title":"Ouvrages 1"},"children":[{"uid":"bGxmYT","props":{"calcType":"Structure","structureType":"Orifice","loiDebit":"OrificeFree"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":0.1},{"symbol":"CdO","mode":"SINGLE","value":0.7},{"symbol":"Zco","mode":"CALCUL"}]}],"parameters":[{"symbol":"Q","mode":"SINGLE","value":0.5},{"symbol":"Z1","mode":"SINGLE","value":105},{"symbol":"Z2","mode":"SINGLE","value":100}]}]}`;
Session.getInstance().clear();
Session.getInstance().unserialise(sess);
const nub = Session.getInstance().findNubByUid("c292bn");
nub.CalcSerie();
const vN = nub.result.resultElement.values;
const vS = nub.getChildren()[0].result.resultElement.values;
const vSK = Object.keys(vS);
vSK.sort();
const vNK = Object.keys(vN);
vNK.sort();
expect(vNK.length).toBe(1);
expect(vNK).toEqual([ "Zco" ]);
expect(vSK.length).toBe(5);
expect(vSK).toEqual(
[ "ENUM_StructureFlowMode", "ENUM_StructureFlowRegime", "ENUM_StructureJetType", "Q", "Zco" ]
);
});
it("when Z1 is too low and Zco calc fails, 10 variables should be present", () => {
// tslint:disable-next-line:max-line-length
const sess = `{"header":{"source":"jalhyd","format_version":"1.3","created":"2019-10-29T14:06:53.775Z"},"settings":{"precision":0.0001,"maxIterations":100,"displayPrecision":3},"documentation":"","session":[{"uid":"c292bn","props":{"calcType":"ParallelStructure"},"meta":{"title":"Ouvrages 1"},"children":[{"uid":"bGxmYT","props":{"calcType":"Structure","structureType":"Orifice","loiDebit":"OrificeFree"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":0.1},{"symbol":"CdO","mode":"SINGLE","value":0.7},{"symbol":"Zco","mode":"CALCUL"}]}],"parameters":[{"symbol":"Q","mode":"SINGLE","value":0.5},{"symbol":"Z1","mode":"SINGLE","value":90},{"symbol":"Z2","mode":"SINGLE","value":100}]}]}`;
Session.getInstance().clear();
Session.getInstance().unserialise(sess);
const nub = Session.getInstance().findNubByUid("c292bn");
nub.CalcSerie();
const vN = nub.result.resultElement.values;
const vS = nub.getChildren()[0].result.resultElement.values;
const vSK = Object.keys(vS);
vSK.sort();
const vNK = Object.keys(vN);
vNK.sort();
expect(vNK.length).toBe(1);
expect(vNK).toEqual([ "Zco" ]);
expect(vSK.length).toBe(5);
expect(vSK).toEqual(
[ "ENUM_StructureFlowMode", "ENUM_StructureFlowRegime", "ENUM_StructureJetType", "Q", "Zco" ]
);
});
});
import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
import { StructureFlowMode, StructureFlowRegime, StructureJetType } from "../../src/structure/structure";
import { checkResult } from "../test_func";
import { CreateStructTest, StructureTest } from "./structure_test";
......@@ -43,7 +43,8 @@ describe("Class Structure: ", () => {
describe("Calc()", () => {
const flagsNull = {
ENUM_StructureFlowMode: StructureFlowMode.NULL,
ENUM_StructureFlowRegime: StructureFlowRegime.NULL
ENUM_StructureFlowRegime: StructureFlowRegime.NULL,
ENUM_StructureJetType: StructureJetType.SO
};
it("Z1=Z2 => Q=0", () => {
structTest.prms.Z2.v = structTest.prms.Z1.v;
......
......@@ -127,14 +127,13 @@ export class ParallelStructure extends Nub {
// Pour les caractéristiques des ouvrages
const structureIndex = this.getIndexForChild(sVarCalc.uid);
const r = this.CalcStructPrm(structureIndex, sVarCalc.symbol, rInit);
if (r.ok) {
this.result.symbol = r.symbol;
this.result.vCalc = r.vCalc;
// merge logs
this.result.log.addLog(r.log);
} else {
this.currentResult = r;
}
// whether r is .ok() or not, just copy vCalc and logs to avoid
// this._result being polluted by structure.flagsNull
this.result.symbol = r.symbol;
this.result.vCalc = r.vCalc;
// merge logs
this.result.log.addLog(r.log);
this.result.globalLog.addLog(r.globalLog);
}
return this.result;
......
......@@ -210,8 +210,11 @@ export abstract class Structure extends Nub {
this.prms.update_h1h2();
// Gestion du débit nul
const flagsNull = { ENUM_StructureFlowMode: StructureFlowMode.NULL,
ENUM_StructureFlowRegime: StructureFlowRegime.NULL };
const flagsNull = {
ENUM_StructureFlowMode: StructureFlowMode.NULL,
ENUM_StructureFlowRegime: StructureFlowRegime.NULL,
ENUM_StructureJetType: StructureJetType.SO
};
if (sVarCalc === "Q") {
if (this.prms.h1.v <= 0 || Math.abs(this.prms.h1.v - this.prms.h2.v) < 1E-20 || this.W <= 1E-20) {
return new Result(0, this, flagsNull);
......
Markdown is supported
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