Commit 84f9664d authored by Dorchies David's avatar Dorchies David
Browse files

#94 Correction de bug sur transmission cote amont/aval des ouvrages depuis la...

#94 Correction de bug sur transmission cote amont/aval des ouvrages depuis la structure parallèle. Ajout d'une erreur si les cotes sont égales et le débit non nul.
Showing with 107 additions and 58 deletions
+107 -58
...@@ -65,7 +65,8 @@ export function testStructure( ...@@ -65,7 +65,8 @@ export function testStructure(
).toThrow(new Error("Structure:Calc : Calcul de W impossible sur un seuil")); ).toThrow(new Error("Structure:Calc : Calcul de W impossible sur un seuil"));
}); });
} else { } else {
const ref: number = prm.currentValue; const ref: number = prm.v;
prm.v = prm.v + 100;
const res: Result = st.Calc(prm.symbol); const res: Result = st.Calc(prm.symbol);
if (bNotZDV) { if (bNotZDV) {
// Les lois CEM88D et CUNGE80 ne font pas intervenir ZDV dans le calcul d'un orifice noyé // Les lois CEM88D et CUNGE80 ne font pas intervenir ZDV dans le calcul d'un orifice noyé
......
...@@ -10,6 +10,7 @@ import { MessageCode } from "../../src/index"; ...@@ -10,6 +10,7 @@ import { MessageCode } from "../../src/index";
import { CreateStructure } from "../../src/structure/factory_structure"; import { CreateStructure } from "../../src/structure/factory_structure";
import { ParallelStructure } from "../../src/structure/parallel_structure"; import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; 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 { loiAdmissiblesOuvrages, StructureType } from "../../src/structure/structure_props";
import { EnumEx } from "../../src/util/enum"; import { EnumEx } from "../../src/util/enum";
import { Result } from "../../src/util/result"; import { Result } from "../../src/util/result";
...@@ -19,46 +20,21 @@ import { testParallelStructures } from "./functions"; ...@@ -19,46 +20,21 @@ import { testParallelStructures } from "./functions";
import { structTest } from "./structure_test"; import { structTest } from "./structure_test";
function createEnv() { function createEnv() {
const pstruct = new ParallelStructure( const ps = new ParallelStructure(
new ParallelStructureParams(30, 30, 15), // Q = 30, Z1 = 30, Z2 = 15 new ParallelStructureParams(30, 30, 15), // Q = 30, Z1 = 30, Z2 = 15
false // debug false // debug
); );
/* /*
* Tests avec deux structures test identiques * Tests avec deux structures test identiques
*/ */
pstruct.addChild(structTest); ps.addChild(structTest);
pstruct.addChild(structTest); ps.addChild(structTest);
return pstruct; return ps;
} }
let pstruct: ParallelStructure; let pstruct: ParallelStructure;
describe("Class ParallelStructure: ", () => { function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc: string): any {
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 {
if (structIndex !== null) { if (structIndex !== null) {
return { return {
uid: pstructLoc.structures[structIndex].uid, uid: pstructLoc.structures[structIndex].uid,
...@@ -75,7 +51,7 @@ function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc ...@@ -75,7 +51,7 @@ function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc
* @param rVcalc Valeur de référence à retrouver * @param rVcalc Valeur de référence à retrouver
* @param Q Débit de chacune des structures (pour structures identiques uniquement) * @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}`, () => { it(`${sVarCalc} should be ${rVcalc}`, () => {
const VC1: any = getVarCalc(pstruct, structIndex, sVarCalc); const VC1: any = getVarCalc(pstruct, structIndex, sVarCalc);
checkResult(pstruct.Calc(VC1), rVcalc); checkResult(pstruct.Calc(VC1), rVcalc);
...@@ -105,25 +81,70 @@ function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: numb ...@@ -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: ", () => { describe("Class ParallelStructure: ", () => {
// Ajout d'une structure de chaque type dans ParallelStructure describe("Calc()", () => {
const iLoiDebits: number[] = []; beforeEach(() => {
const iStTypes: number[] = []; pstruct = createEnv();
for (const s of EnumEx.getValues(StructureType)) { });
for (const la of loiAdmissiblesOuvrages[StructureType[s]]) { it("should return 1 result", () => {
ps2.addChild(CreateStructure(la, ps2, false)); const p1 = createEnv();
iLoiDebits.push(la); const res: Result = p1.Calc("Q");
iStTypes.push(s); 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);
});
});
}); });
...@@ -51,4 +51,20 @@ describe("Class StructureKivi: ", () => { ...@@ -51,4 +51,20 @@ describe("Class StructureKivi: ", () => {
).toBe(MessageCode.WARNING_STRUCTUREKIVI_HP_TROP_ELEVE); ).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);
});
});
}); });
...@@ -189,9 +189,9 @@ export function compareLog(logTest: cLog, logValid: cLog) { ...@@ -189,9 +189,9 @@ export function compareLog(logTest: cLog, logValid: cLog) {
} }
} }
export function checkResult(val1: Result, val2: number, prec?: number) { export function checkResult(result: Result, valRef: number, prec?: number) {
expect(val1.ok).toBeTruthy((!val1.ok) ? "Result: ERROR code=" + MessageCode[val1.code] : ""); expect(result.ok).toBeTruthy((!result.ok) ? "Result: ERROR code=" + MessageCode[result.code] : "");
if (val1.ok) { if (result.ok) {
/* /*
* on demande une précision de vérification inférieure à la précision de calcul * 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 * pour ne pas échouer sur un arrondi sur le dernier chiffre
...@@ -204,7 +204,7 @@ export function checkResult(val1: Result, val2: number, prec?: number) { ...@@ -204,7 +204,7 @@ export function checkResult(val1: Result, val2: number, prec?: number) {
prec = Math.max(0, precDigits - 1); prec = Math.max(0, precDigits - 1);
} }
expect(val1.vCalc).toBeCloseTo(val2, prec); expect(result.vCalc).toBeCloseTo(valRef, prec);
} }
} }
......
...@@ -191,6 +191,7 @@ export class ParallelStructure extends Nub { ...@@ -191,6 +191,7 @@ export class ParallelStructure extends Nub {
this.structures[index].prms.Q.v = this.prms.Q.v - this.CalcQ(index).vCalc; this.structures[index].prms.Q.v = this.prms.Q.v - this.CalcQ(index).vCalc;
// Calcul du paramètre de la structure en calcul // Calcul du paramètre de la structure en calcul
this.updateStructuresH1H2();
return this.structures[index].Calc(symbol, rInit); return this.structures[index].Calc(symbol, rInit);
} }
......
...@@ -205,8 +205,8 @@ export abstract class Structure extends Nub { ...@@ -205,8 +205,8 @@ export abstract class Structure extends Nub {
// Gestion du cas d'écoulement impossible Z1 > Z2 et Q <= 0 // Gestion du cas d'écoulement impossible Z1 > Z2 et Q <= 0
if (!(sVarCalc === "Q" || sVarCalc === "Z1" || sVarCalc === "Z2")) { if (!(sVarCalc === "Q" || sVarCalc === "Z1" || sVarCalc === "Z2")) {
if ( 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 // On ferme l'ouvrage et on renvoie un code d'erreur
let rPrm: number; let rPrm: number;
...@@ -217,7 +217,12 @@ export abstract class Structure extends Nub { ...@@ -217,7 +217,12 @@ export abstract class Structure extends Nub {
default: default:
rPrm = 0; 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; res.vCalc = rPrm;
// "Les cotes et le débit ne sont pas cohérents => fermeture de l'ouvrage // "Les cotes et le débit ne sont pas cohérents => fermeture de l'ouvrage
......
...@@ -241,6 +241,11 @@ export enum MessageCode { ...@@ -241,6 +241,11 @@ export enum MessageCode {
*/ */
ERROR_STRUCTURE_Q_TROP_ELEVE, 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. * StructureKivi : La pelle du seuil doit mesurer au moins 0,1 m. Le coefficient béta est forcé à 0.
*/ */
......
Supports Markdown
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