diff --git a/spec/structure/functions.ts b/spec/structure/functions.ts index 8b9ec809f9c7fcfba9d32a46b63baccb88f76643..324a5a63a198294221702a4ea931cdcbb41a42c4 100644 --- a/spec/structure/functions.ts +++ b/spec/structure/functions.ts @@ -65,7 +65,8 @@ export function testStructure( ).toThrow(new Error("Structure:Calc : Calcul de W impossible sur un seuil")); }); } else { - const ref: number = prm.currentValue; + const ref: number = prm.v; + prm.v = prm.v + 100; const res: Result = st.Calc(prm.symbol); if (bNotZDV) { // Les lois CEM88D et CUNGE80 ne font pas intervenir ZDV dans le calcul d'un orifice noyé diff --git a/spec/structure/parallel_structure.spec.ts b/spec/structure/parallel_structure.spec.ts index 8a01b1d2014e232fa97f1147a6ae49803962326f..053820c6bf5d7068e7f86c1b9df4bd6301f0f5d8 100644 --- a/spec/structure/parallel_structure.spec.ts +++ b/spec/structure/parallel_structure.spec.ts @@ -10,6 +10,7 @@ import { MessageCode } from "../../src/index"; import { CreateStructure } from "../../src/structure/factory_structure"; import { ParallelStructure } from "../../src/structure/parallel_structure"; import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; +import { StructureKivi, StructureKiviParams } from "../../src/structure/structure_kivi"; import { loiAdmissiblesOuvrages, StructureType } from "../../src/structure/structure_props"; import { EnumEx } from "../../src/util/enum"; import { Result } from "../../src/util/result"; @@ -19,46 +20,21 @@ import { testParallelStructures } from "./functions"; import { structTest } from "./structure_test"; function createEnv() { - const pstruct = new ParallelStructure( + const ps = new ParallelStructure( new ParallelStructureParams(30, 30, 15), // Q = 30, Z1 = 30, Z2 = 15 false // debug ); /* * Tests avec deux structures test identiques */ - pstruct.addChild(structTest); - pstruct.addChild(structTest); - return pstruct; + ps.addChild(structTest); + ps.addChild(structTest); + return ps; } let pstruct: ParallelStructure; -describe("Class ParallelStructure: ", () => { - describe("Calc()", () => { - beforeEach(() => { - pstruct = createEnv(); - }); - it("should return 1 result", () => { - const p1 = createEnv(); - const res: Result = p1.Calc("Q"); - expect(p1.Calc("Q").nbResultElements).toEqual(1); - }); - itParallelStructure(null, "Q", 30, 15); - itParallelStructure(null, "Z1", 30, 15); - itParallelStructure(null, "Z2", 15, 15); - itParallelStructure(0, "ZDV", 0, 15); - itParallelStructure(1, "ZDV", 0, 15); - it("shoud return an error Q too high", () => { - pstruct.prms.Q.v = 14; - const res: Result = pstruct.Calc({ - uid: pstruct.structures[1].uid, - symbol: "ZDV" - }); - expect(res.code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE); - }); - }); -}); -function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc: string) : any { +function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc: string): any { if (structIndex !== null) { return { uid: pstructLoc.structures[structIndex].uid, @@ -75,7 +51,7 @@ function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc * @param rVcalc Valeur de référence à retrouver * @param Q Débit de chacune des structures (pour structures identiques uniquement) */ -function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: number, Q?: number) { +function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: number, Q?: number) { it(`${sVarCalc} should be ${rVcalc}`, () => { const VC1: any = getVarCalc(pstruct, structIndex, sVarCalc); checkResult(pstruct.Calc(VC1), rVcalc); @@ -105,25 +81,70 @@ function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: numb } } -/* - * Tests avec toutes les équations et toutes les variables (cf. jalhyd#38) - */ - -const ps2: ParallelStructure = new ParallelStructure( - new ParallelStructureParams(0, 102, 101.5), // Q = 0, Z1 = 102, Z2 = 101.5 - false // debug -); - describe("Class ParallelStructure: ", () => { - // Ajout d'une structure de chaque type dans ParallelStructure - const iLoiDebits: number[] = []; - const iStTypes: number[] = []; - for (const s of EnumEx.getValues(StructureType)) { - for (const la of loiAdmissiblesOuvrages[StructureType[s]]) { - ps2.addChild(CreateStructure(la, ps2, false)); - iLoiDebits.push(la); - iStTypes.push(s); + describe("Calc()", () => { + beforeEach(() => { + pstruct = createEnv(); + }); + it("should return 1 result", () => { + const p1 = createEnv(); + const res: Result = p1.Calc("Q"); + expect(p1.Calc("Q").nbResultElements).toEqual(1); + }); + itParallelStructure(null, "Q", 30, 15); + itParallelStructure(null, "Z1", 30, 15); + itParallelStructure(null, "Z2", 15, 15); + itParallelStructure(0, "ZDV", 0, 15); + itParallelStructure(1, "ZDV", 0, 15); + it("shoud return an error Q too high", () => { + pstruct.prms.Q.v = 14; + const res: Result = pstruct.Calc({ + uid: pstruct.structures[1].uid, + symbol: "ZDV" + }); + expect(res.code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE); + }); + + /* + * Tests avec toutes les équations et toutes les variables (cf. jalhyd#38) + */ + const ps2: ParallelStructure = new ParallelStructure( + new ParallelStructureParams(0, 102, 101.5), // Q = 0, Z1 = 102, Z2 = 101.5 + false // debug + ); + // Ajout d'une structure de chaque type dans ParallelStructure + const iLoiDebits: number[] = []; + const iStTypes: number[] = []; + for (const s of EnumEx.getValues(StructureType)) { + for (const la of loiAdmissiblesOuvrages[StructureType[s]]) { + ps2.addChild(CreateStructure(la, ps2, false)); + iLoiDebits.push(la); + iStTypes.push(s); + } } - } - testParallelStructures(ps2, iLoiDebits); + testParallelStructures(ps2, iLoiDebits); + }); + + describe("#94 Lois d'ouvrage: Erreur de calcul de ZDV", () => { + it(`Calc(ZDV) should return 101.57`, () => { + const ps3: ParallelStructure = new ParallelStructure( + new ParallelStructureParams(0.5, 102, 101.5), // Q = 0.5, Z1 = 102, Z2 = 101.5 + false // debug + ); + const structTestKivi3: StructureKivi = new StructureKivi( + new StructureKiviParams( + 0, 0, 0, 0, // Q, ZDV, Z1, Z2 + 1, // L + 0.4, // alpha + 0.001, // béta + 95.7 // ZRAM : cote Radier Amont + ), + false + ); + ps3.addChild(structTestKivi3); + expect(ps3.Calc(getVarCalc(ps3, 0, "ZDV")).vCalc).toBeCloseTo(101.57, 2); + }); + }); }); + + diff --git a/spec/structure/structure_kivi.spec.ts b/spec/structure/structure_kivi.spec.ts index 8c9bc5d5503f58ced56956b43378a3e67ac027e1..e2ccf53f565fa8b9c41f01fd659521c4a0d86347 100644 --- a/spec/structure/structure_kivi.spec.ts +++ b/spec/structure/structure_kivi.spec.ts @@ -51,4 +51,20 @@ describe("Class StructureKivi: ", () => { ).toBe(MessageCode.WARNING_STRUCTUREKIVI_HP_TROP_ELEVE); }); }); + describe("Test calcul ZDV (#94)", () => { + const kiviParams2: StructureKiviParams = new StructureKiviParams( + 0.5, // Q + 0, // ZDV + 102, // Z1 + 101.5, // Z2 + 1, // L + 0.4, // alpha + 0.001, // béta + 95.7 // ZRAM : cote Radier Amont + ); + const structTestKivi2: StructureKivi = new StructureKivi(kiviParams2, false); + it(`Calc(ZDV) should return 101.57`, () => { + expect(structTestKivi2.Calc("ZDV").vCalc).toBeCloseTo(101.57, 2); + }); + }); }); diff --git a/spec/test_func.ts b/spec/test_func.ts index 3fea98947ee6783e1f9d06a11297bf03c78f48bd..6ba21c51776761291540cf3e69bc3a828d9cda7b 100644 --- a/spec/test_func.ts +++ b/spec/test_func.ts @@ -189,9 +189,9 @@ export function compareLog(logTest: cLog, logValid: cLog) { } } -export function checkResult(val1: Result, val2: number, prec?: number) { - expect(val1.ok).toBeTruthy((!val1.ok) ? "Result: ERROR code=" + MessageCode[val1.code] : ""); - if (val1.ok) { +export function checkResult(result: Result, valRef: number, prec?: number) { + expect(result.ok).toBeTruthy((!result.ok) ? "Result: ERROR code=" + MessageCode[result.code] : ""); + if (result.ok) { /* * on demande une précision de vérification inférieure à la précision de calcul * pour ne pas échouer sur un arrondi sur le dernier chiffre @@ -204,7 +204,7 @@ export function checkResult(val1: Result, val2: number, prec?: number) { prec = Math.max(0, precDigits - 1); } - expect(val1.vCalc).toBeCloseTo(val2, prec); + expect(result.vCalc).toBeCloseTo(valRef, prec); } } diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts index 4b1d89243bfb67353b52cfd7f4a17b220491184f..3ba3dbcdc543381d8d68be46ae1e0ccbfaa279aa 100644 --- a/src/structure/parallel_structure.ts +++ b/src/structure/parallel_structure.ts @@ -191,6 +191,7 @@ export class ParallelStructure extends Nub { this.structures[index].prms.Q.v = this.prms.Q.v - this.CalcQ(index).vCalc; // Calcul du paramètre de la structure en calcul + this.updateStructuresH1H2(); return this.structures[index].Calc(symbol, rInit); } diff --git a/src/structure/structure.ts b/src/structure/structure.ts index 123d0490d8b9cf906af2cc109b43fa505c421cf9..27b49cc712a92815e9bb5152a211f7256808d208 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -205,8 +205,8 @@ export abstract class Structure extends Nub { // Gestion du cas d'écoulement impossible Z1 > Z2 et Q <= 0 if (!(sVarCalc === "Q" || sVarCalc === "Z1" || sVarCalc === "Z2")) { if ( - (this.prms.Z1.v > this.prms.Z2.v && this.prms.Q.v <= 0) || - (this.prms.Z1.v < this.prms.Z2.v && this.prms.Q.v >= 0) + (this.prms.Z1.v >= this.prms.Z2.v && this.prms.Q.v <= 0) || + (this.prms.Z1.v <= this.prms.Z2.v && this.prms.Q.v >= 0) ) { // On ferme l'ouvrage et on renvoie un code d'erreur let rPrm: number; @@ -217,7 +217,12 @@ export abstract class Structure extends Nub { default: rPrm = 0; } - const res: Result = new Result(new Message(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE), this, flagsNull); + let res: Result; + if (this.prms.Z1.v === this.prms.Z2.v && this.prms.Q.v !== 0) { + res = new Result(new Message(MessageCode.ERROR_STRUCTURE_Z_EGAUX_Q_NON_NUL), this); + } else { + res = new Result(new Message(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE), this, flagsNull); + } res.vCalc = rPrm; // "Les cotes et le débit ne sont pas cohérents => fermeture de l'ouvrage diff --git a/src/util/message.ts b/src/util/message.ts index 8cdaa78ec234e7667ba8ce00801e1c5cf0541c54..0fa570d1bd690810f2caff3f19966471043a31f5 100644 --- a/src/util/message.ts +++ b/src/util/message.ts @@ -241,6 +241,11 @@ export enum MessageCode { */ ERROR_STRUCTURE_Q_TROP_ELEVE, + /** + * Les cotes amont aval sont égales et le débit n'est pas nul + */ + ERROR_STRUCTURE_Z_EGAUX_Q_NON_NUL, + /** * StructureKivi : La pelle du seuil doit mesurer au moins 0,1 m. Le coefficient béta est forcé à 0. */