From 50ca78fcb988b4b1ebee14b0e252da5352312ce2 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Wed, 14 Mar 2018 16:31:26 +0100 Subject: [PATCH] =?UTF-8?q?ouvrages=20:=20-=20enum=20StructureType=20renom?= =?UTF-8?q?m=C3=A9=20en=20LoiDebit=20-=20ajout=20enum=20StructureType=20po?= =?UTF-8?q?ur=20les=20types=20d'ouvrage=20(seuil=20rectangulaire,=20vanne?= =?UTF-8?q?=20circulaire,=20...)=20-=20modif=20de=20la=20factory=20d'ouvra?= =?UTF-8?q?ges=20-=20modif=20des=20tests=20unitaires=20en=20cons=C3=A9quen?= =?UTF-8?q?ce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/structure/parallel_structure.spec.ts | 21 ++++--- src/structure/factory_structure.ts | 73 ++++++++++++++++++----- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/spec/structure/parallel_structure.spec.ts b/spec/structure/parallel_structure.spec.ts index 3e8b6fd1..f5f0ca22 100644 --- a/spec/structure/parallel_structure.spec.ts +++ b/spec/structure/parallel_structure.spec.ts @@ -4,10 +4,10 @@ * Pour exécuter ce code dans le débugger. * Faire de même avec le fichier test_func.ts */ -// import { describe, expect, it, xdescribe } from "../mock_jasmine"; +// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine"; import { ParamCalculability, ParamDefinition, ParamsEquation } from "../../src/param"; -import { CreateStructure, StructureType } from "../../src/structure/factory_structure"; +import { CreateStructure, LoiDebit, StructureType } from "../../src/structure/factory_structure"; import { ParallelStructure } from "../../src/structure/parallel_structure"; import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; import { Structure } from "../../src/structure/structure"; @@ -48,7 +48,7 @@ function itParallelStructure(sVarCalc: string, rVcalc: number, Q?: number) { const res: Result = pstruct.Calc(sVarCalc); checkResult(res, rVcalc); if (Q !== undefined) { - for (let i = 1 ; i < res.nbResults ; i++) { + for (let i = 1; i < res.nbResults; i++) { checkResult(res.extractResult(i), Q); } } @@ -65,17 +65,22 @@ const ps2: ParallelStructure = new ParallelStructure( ); // Ajout d'une structure de chaque type dans ParallelStructure -for (const i of EnumEx.getValues(StructureType)) { - ps2.addStructure(CreateStructure(i)); -} +for (const s of EnumEx.getValues(StructureType)) + for (const i of EnumEx.getValues(LoiDebit)) { + try { + ps2.addStructure(CreateStructure(s, i)); + } + catch (e) { + } + } ps2.prms.Q.v = ps2.Calc("Q").vCalc; // tslint:disable-next-line:prefer-for-of describe("Class ParallelStructure: ", () => { - for (let i = 0 ; i < ps2.structures.length ; i++) { + for (let i = 0; i < ps2.structures.length; i++) { const st: Structure = ps2.structures[i]; - describe(`this.structures[${i}]: Structure${StructureType[i]}: `, () => { + describe(`this.structures[${i}]: Structure${LoiDebit[i]}: `, () => { // tslint:disable-next-line:forin for (const prm of st.prms) { if (prm.calculability === ParamCalculability.DICHO && diff --git a/src/structure/factory_structure.ts b/src/structure/factory_structure.ts index 3d6d4065..d5fe52f4 100644 --- a/src/structure/factory_structure.ts +++ b/src/structure/factory_structure.ts @@ -8,6 +8,12 @@ import { StructureOrificeSubmerged } from "./structure_orifice_submerged"; import { StructureWeirFree } from "./structure_weir_free"; export enum StructureType { + VanneRectangulaire, SeuilRectangulaire, + // VanneCirculaire, + // VanneTrapezoidale, SeuilTrapezoidal +} + +export enum LoiDebit { // loi de débit Déversoir / Orifice Cemagref 1988 Cem88d, // loi de débit Déversoir / Vanne de fond Cemagref 1988 @@ -22,28 +28,63 @@ export enum StructureType { WeirFree } -export function CreateStructure(structureType: StructureType): Structure { - const structPrms: RectangularStructureParams = new RectangularStructureParams( - 0, // Q - 100, // ZDV - 102, // Z1 - 101.5, // Z2 - 2, // L - 0.6, // Cd - 0.5 // W - ); +const loiAdmissibles: { [key: string]: LoiDebit[] } = { + "VanneRectangulaire": [LoiDebit.Cem88d, LoiDebit.Cem88v, LoiDebit.WeirFree, LoiDebit.Cunge80], + "SeuilRectangulaire": [LoiDebit.Cem88d, LoiDebit.Cem88v, LoiDebit.Cunge80, LoiDebit.OrificeFree, LoiDebit.OrificeSubmerged] +} + +export function CreateStructure(structureType: StructureType, loiDebit: LoiDebit): Structure { switch (structureType) { - case StructureType.Cem88d: + case StructureType.VanneRectangulaire: + var structPrms: RectangularStructureParams = new RectangularStructureParams( + 0, // Q + 100, // ZDV + 102, // Z1 + 101.5, // Z2 + 2, // L + 0.6, // Cd + 0.5 // W + ); + if (!(loiDebit in loiAdmissibles["VanneRectangulaire"])) { + throw new Error(`la loi de débit ${LoiDebit[loiDebit]} n'est pas admissible pour les vannes rectangulaires`); + } + break; + + case StructureType.SeuilRectangulaire: + structPrms = new RectangularStructureParams( + 0, // Q + 100, // ZDV + 102, // Z1 + 101.5, // Z2 + 2, // L + 0.6 // Cd + ); + if (!(loiDebit in loiAdmissibles["SeuilRectangulaire"])) { + throw new Error(`la loi de débit ${LoiDebit[loiDebit]} n'est pas admissible pour les seuils rectangulaires`); + } + break; + + default: + throw new Error(`type de structure ${StructureType[structureType]} non pris en charge`); + } + + switch (loiDebit) { + case LoiDebit.Cem88d: return new StructureCem88d(structPrms); - case StructureType.Cem88v: + + case LoiDebit.Cem88v: return new StructureCem88v(structPrms); - case StructureType.Cunge80: + + case LoiDebit.Cunge80: return new StructureCunge80(structPrms); - case StructureType.OrificeFree: + + case LoiDebit.OrificeFree: return new StructureOrificeFree(structPrms); - case StructureType.OrificeSubmerged: + + case LoiDebit.OrificeSubmerged: return new StructureOrificeSubmerged(structPrms); - case StructureType.WeirFree: + + case LoiDebit.WeirFree: const st: StructureWeirFree = new StructureWeirFree(structPrms); st.prms.Cd.v = 0.4; return st; -- GitLab