Commit 97d1c720 authored by Dorchies David's avatar Dorchies David
Browse files

fix(PreBarrage): Nan in cloison calculation

Fix #276
parent 967b26ab
import { Session } from "../../src/index";
import { checkResultConsistency } from "../test_func";
describe("PreBarrage", () => {
describe("jalhyd#276", () => {
it("1-CalcSerie() should return consistent result with no NaN or Infinity", () => {
// tslint:disable-next-line:max-line-length
const sessionJson = `{"header":{"source":"jalhyd","format_version":"1.3","created":"2020-09-24T14:38:57.568Z"},"settings":{"precision":1e-7,"maxIterations":100,"displayPrecision":3},"documentation":"","session":[{"uid":"b2kxNm","props":{"calcType":"PreBarrage"},"meta":{"title":"Prébarrages"},"children":[{"uid":"Zjczdz","props":{"calcType":"PbBassin"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":13.8},{"symbol":"ZF","mode":"SINGLE","value":95}]},{"uid":"dWJrZX","props":{"calcType":"PbBassin"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":15.4},{"symbol":"ZF","mode":"SINGLE","value":94.7}]},{"uid":"dzMxN2","props":{"calcType":"PbBassin"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":16.2},{"symbol":"ZF","mode":"SINGLE","value":94.7}]},{"uid":"ZXZua2","props":{"calcType":"PbBassin"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":17.5},{"symbol":"ZF","mode":"SINGLE","value":94.4}]},{"uid":"YmR5aD","props":{"calcType":"PbBassin"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":32.1},{"symbol":"ZF","mode":"SINGLE","value":94.25}]},{"uid":"bDN2OW","props":{"calcType":"PbBassin"},"children":[],"parameters":[{"symbol":"S","mode":"SINGLE","value":35},{"symbol":"ZF","mode":"SINGLE","value":94.1}]},{"uid":"MWxycH","props":{"calcType":"PbCloison","upstreamBasin":"","downstreamBasin":"Zjczdz"},"children":[{"uid":"MmZ2aG","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.3},{"symbol":"L","mode":"SINGLE","value":0.4},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"eW9jZH","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":96.25},{"symbol":"L","mode":"SINGLE","value":4.4},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"c3Zpb2","props":{"calcType":"PbCloison","upstreamBasin":"","downstreamBasin":"dWJrZX"},"children":[{"uid":"bTQ2cG","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":96},{"symbol":"L","mode":"SINGLE","value":1},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"N24zM2","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":96.25},{"symbol":"L","mode":"SINGLE","value":5},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"MG4wNG","props":{"calcType":"PbCloison","upstreamBasin":"","downstreamBasin":"YmR5aD"},"children":[{"uid":"azV4dj","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":96.25},{"symbol":"L","mode":"SINGLE","value":3.5},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"YjJra2","props":{"calcType":"PbCloison","upstreamBasin":"","downstreamBasin":"bDN2OW"},"children":[{"uid":"aDd4Y3","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":96.25},{"symbol":"L","mode":"SINGLE","value":3.6},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"enE4cn","props":{"calcType":"PbCloison","upstreamBasin":"Zjczdz","downstreamBasin":"dzMxN2"},"children":[{"uid":"ZHczZ2","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95},{"symbol":"L","mode":"SINGLE","value":0.4},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"aXRjZ3","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":96.25},{"symbol":"L","mode":"SINGLE","value":5.2},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"NXNoNG","props":{"calcType":"PbCloison","upstreamBasin":"dWJrZX","downstreamBasin":"dzMxN2"},"children":[{"uid":"eXFqeH","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.85},{"symbol":"L","mode":"SINGLE","value":4.38},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"bGhodG","props":{"calcType":"PbCloison","upstreamBasin":"dWJrZX","downstreamBasin":"ZXZua2"},"children":[{"uid":"b3Z3OD","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.85},{"symbol":"L","mode":"SINGLE","value":3},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"MDZ3aH","props":{"calcType":"PbCloison","upstreamBasin":"dWJrZX","downstreamBasin":"YmR5aD"},"children":[{"uid":"NTBzZm","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.5},{"symbol":"L","mode":"SINGLE","value":1},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"b3pjZX","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.75},{"symbol":"L","mode":"SINGLE","value":3},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"emZ2bX","props":{"calcType":"PbCloison","upstreamBasin":"dzMxN2","downstreamBasin":"ZXZua2"},"children":[{"uid":"cGllNj","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":94.7},{"symbol":"L","mode":"SINGLE","value":0.4},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"aWFseW","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.65},{"symbol":"L","mode":"SINGLE","value":5.74},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"bG1ucj","props":{"calcType":"PbCloison","upstreamBasin":"ZXZua2","downstreamBasin":"YmR5aD"},"children":[{"uid":"MDJsaD","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":94.4},{"symbol":"L","mode":"SINGLE","value":0.4},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"ZzY2bT","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.35},{"symbol":"L","mode":"SINGLE","value":6},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"dGNnZz","props":{"calcType":"PbCloison","upstreamBasin":"YmR5aD","downstreamBasin":"bDN2OW"},"children":[{"uid":"dnNqeX","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":94.25},{"symbol":"L","mode":"SINGLE","value":0.7},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"ODFkZ2","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":95.05},{"symbol":"L","mode":"SINGLE","value":9.5},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]},{"uid":"amprcm","props":{"calcType":"PbCloison","upstreamBasin":"bDN2OW","downstreamBasin":""},"children":[{"uid":"OG02MT","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":94.1},{"symbol":"L","mode":"SINGLE","value":0.95},{"symbol":"CdCunge","mode":"SINGLE","value":1}]},{"uid":"MHVxZn","props":{"calcType":"Structure","loiDebit":"WeirCunge80","structureType":"SeuilRectangulaire"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":94.75},{"symbol":"L","mode":"SINGLE","value":10.2},{"symbol":"CdCunge","mode":"SINGLE","value":1}]}],"parameters":[]}],"parameters":[{"symbol":"Q","mode":"SINGLE","value":221},{"symbol":"Z1","mode":"CALCUL"},{"symbol":"Z2","mode":"SINGLE","value":94.45}]}]}`;
Session.getInstance().unserialise(sessionJson);
const nub = Session.getInstance().findNubByUid("b2kxNm");
// nub.DBG = true;
nub.CalcSerie();
checkResultConsistency(nub);
});
});
});
......@@ -488,7 +488,12 @@ export class PreBarrage extends Nub {
for (const c of cloisons) {
let Z1: number;
if(c.prms.Q.v >= 1E-6) {
Z1 = c.Calc("Z1").vCalc;
const r = c.Calc("Z1")
if(r.ok) {
Z1 = r.vCalc;
} else {
Z1 = c.prms.Z2.v;
}
zStat.moy += Z1;
n++;
this.debug(`CalcZ1Cloisons: n°${n} Z1=${Z1} Q=${c.prms.Q.v} Z2=${c.prms.Z2.v}`);
......
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