From f50d3f45ce5fe7f08f89ad60ee4a4e528b7caa79 Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Tue, 18 Jun 2019 16:32:58 +0200 Subject: [PATCH] Closes #100 Debug calcul DH --- spec/pab/cloisons.spec.ts | 58 +++++++++++------------------- src/pab/cloisons.ts | 10 +++++- src/structure/factory_structure.ts | 5 +++ 3 files changed, 34 insertions(+), 39 deletions(-) mode change 100644 => 100755 spec/pab/cloisons.spec.ts mode change 100644 => 100755 src/structure/factory_structure.ts diff --git a/spec/pab/cloisons.spec.ts b/spec/pab/cloisons.spec.ts old mode 100644 new mode 100755 index 98a67f2e..c665e535 --- a/spec/pab/cloisons.spec.ts +++ b/spec/pab/cloisons.spec.ts @@ -29,44 +29,34 @@ function getEmptyCloisonsTest(): Cloisons { function getCloisonsTest(): Cloisons { const cloisons: Cloisons = getEmptyCloisonsTest(); - - const fente: StructureWeirSubmergedLarinier = new StructureWeirSubmergedLarinier( - new RectangularStructureParams( - 0, - 101, - 102, - 101.5, - 0.2, - 0.65 - ) - ); - - cloisons.addChild(fente); + cloisons.addChild(CreateStructure(LoiDebit.CloisonsWeirSubmergedLarinier)); + cloisons.calculatedParam = cloisons.prms.Q; + cloisons.structures[0].prms.h1.singleValue = 1; return cloisons; } describe("Class Cloisons: ", () => { - beforeAll( () => { - const c2: Cloisons = new Cloisons( - new CloisonsParams( - 0, // Débit total (m3/s) - 102, // Cote de l'eau amont (m) - 10, // Longueur des bassins (m) - 1, // Largeur des bassins (m) - 1, // Profondeur moyenne (m) - 0.5 // Hauteur de chute (m) - ), - false // debug - ); - }); - describe("Calc(Q) Fente noyée (Larinier 1992)", () => { - + let c: Cloisons; + beforeEach( () => { + c = getCloisonsTest(); + }); it("vCalc should return 0.407", () => { - expect(getCloisonsTest().Calc("Q").vCalc).toBeCloseTo(0.407, 3); + expect(c.CalcSerie().vCalc).toBeCloseTo(0.407, 3); }); it("extraResults.PV should return 199.7", () => { - expect(getCloisonsTest().Calc("Q").extraResults.PV).toBeCloseTo(199.7, 1); + expect(c.CalcSerie().extraResults.PV).toBeCloseTo(199.7, 1); + }); + it("ZRMB should be 100.5", () => { + c.CalcSerie(); + expect(c.prms.ZRMB.v).toBeCloseTo(100.5, 3); + }); + it("Calc(DH) should return 0.5", () => { + c.calculatedParam = c.prms.Q; + c.prms.Q.singleValue = c.CalcSerie().vCalc; + c.calculatedParam = c.prms.DH; + c.calculatedParam.singleValue = 100; + expect(c.CalcSerie().vCalc).toBeCloseTo(0.5, 3); }); }); @@ -74,14 +64,6 @@ describe("Class Cloisons: ", () => { testParallelStructures(CreateParalleleStructureTest(getEmptyCloisonsTest())); }); - describe("Calcul de ZRMB", () => { - it("ZRMB should be 100.5", () => { - const c3 = CreateParalleleStructureTest(getEmptyCloisonsTest()).ps as Cloisons; - c3.Calc("Q"); - expect(c3.prms.ZRMB.v).toBeCloseTo(100.5, 3); - }); - }); - describe("Exemple Formation Cassiopée 2018-09", () => { it("Calc(Z1) Exemple Formation Cassiopée 2018-09", () => { // Modèle de cloison diff --git a/src/pab/cloisons.ts b/src/pab/cloisons.ts index 8c3d8fe4..9e1f30a0 100644 --- a/src/pab/cloisons.ts +++ b/src/pab/cloisons.ts @@ -41,10 +41,15 @@ export class Cloisons extends ParallelStructure { let sVC: string = sVarCalc; if (sVarCalc === "DH") { sVC = "Z2"; + rInit = this.prms.Z1.v - this.prms.DH.v; } this.updatePrms(); const r: Result = super.Calc(sVC, rInit); + if (!r.ok) { // Error during calculation + return r; + } + // Transformation Z2 => DH if (sVarCalc === "DH") { r.vCalc = this.prms.Z1.v - r.vCalc; @@ -96,7 +101,10 @@ export class Cloisons extends ParallelStructure { } private updatePrms() { - this.prms.Z2.v = this.prms.Z1.v - this.prms.DH.v; + if (this.calculatedParam !== this.prms.DH) { + // Z2 is the variable to find if DH is the calculated param + this.prms.Z2.v = this.prms.Z1.v - this.prms.DH.v; + } this.prms.ZRAM.v = this.prms.Z1.v - this.prms.PB.v; this.prms.ZRMB.v = this.prms.Z1.v - this.prms.PB.v - this.prms.DH.v; for (const structure of this.structures) { diff --git a/src/structure/factory_structure.ts b/src/structure/factory_structure.ts old mode 100644 new mode 100755 index fa05ef8a..35867fbe --- a/src/structure/factory_structure.ts +++ b/src/structure/factory_structure.ts @@ -87,6 +87,11 @@ export function CreateStructure(loiDebit: LoiDebit, parentNub?: ParallelStructur case LoiDebit.WeirSubmergedLarinier: case LoiDebit.CloisonsWeirSubmergedLarinier: ret = new StructureWeirSubmergedLarinier(rectStructPrms, dbg); + const prms = ret.prms as RectangularStructureParams; + prms.L.singleValue = 0.2; + prms.Cd.singleValue = 0.65; + prms.ZDV.singleValue = 101; + prms.h1.singleValue = 1; break; case LoiDebit.KIVI: -- GitLab