diff --git a/spec/structure/parallel_structure.spec.ts b/spec/structure/parallel_structure.spec.ts index 3e8b6fd12499908e1b6c753a2d9b86795daf0580..f5f0ca22b3b80bb876a8c8bf82168805098b8135 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 3d6d40659e26439aab8f55b8008441a3823423c9..d5fe52f42eff286c6168e3e3e7dae331fcde6ea3 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;