diff --git a/spec/iterator/param_equation.spec.ts b/spec/iterator/param_equation.spec.ts index 8a182a9636946794aa700b61b9d9ff939b66c605..40660ada8280255a156208939a42079e52c3da92 100644 --- a/spec/iterator/param_equation.spec.ts +++ b/spec/iterator/param_equation.spec.ts @@ -10,7 +10,8 @@ import { ConduiteDistribParams, ConduiteDistrib } from "../../src/cond_distri"; import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; import { ParallelStructure } from "../../src/structure/parallel_structure"; import { Structure } from "../../src/structure/structure"; -import { CreateStructure, StructureType, LoiDebit } from "../../src/structure/factory_structure"; +import { CreateStructure } from "../../src/structure/factory_structure"; +import { StructureType, LoiDebit } from "../../src/structure/structure_props"; import { IParamDefinitionIterator } from "../../src/param/params-equation"; function checkParams(pdi: IParamDefinitionIterator, symbols: string[], values: number[]) { diff --git a/spec/structure/parallel_structure.spec.ts b/spec/structure/parallel_structure.spec.ts index 1f2d7d9b9ccbbd7204fe4e28ee0774d245b85bb1..78f1ca3edfe8a8443f4a7ebc9288c8fa7910d15a 100644 --- a/spec/structure/parallel_structure.spec.ts +++ b/spec/structure/parallel_structure.spec.ts @@ -7,7 +7,8 @@ // import { describe, expect, it, xdescribe, xit } from "../mock_jasmine"; import { ParamCalculability } from "../../src/param/param-definition"; -import { CreateStructure, loiAdmissibles, LoiDebit, StructureType } from "../../src/structure/factory_structure"; +import { CreateStructure } from "../../src/structure/factory_structure"; +import { LoiDebit, StructureType, loiAdmissibles } from "../../src/structure/structure_props"; import { ParallelStructure } from "../../src/structure/parallel_structure"; import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; import { Structure } from "../../src/structure/structure"; diff --git a/spec/structure/structure_kivi.spec.ts b/spec/structure/structure_kivi.spec.ts index 1db9a2b5335eb3dca76b5eb6a1d369e64eed6bd9..1286b02b87ea3183cbb4ea328586eccb8d205414 100644 --- a/spec/structure/structure_kivi.spec.ts +++ b/spec/structure/structure_kivi.spec.ts @@ -7,7 +7,8 @@ // import { describe, expect, it, xdescribe, xit } from "../mock_jasmine"; import { StructureFlowMode, StructureFlowRegime, MessageCode } from "../../src"; -import { CreateStructure, LoiDebit, StructureType } from "../../src/structure/factory_structure"; +import { CreateStructure } from "../../src/structure/factory_structure"; +import { LoiDebit, StructureType } from "../../src/structure/structure_props"; import { StructureKivi } from "../../src/structure/structure_kivi"; import { StructureKiviParams } from "../../src/structure/structure_kivi_params"; import { testStructure } from "./structure_test"; diff --git a/src/index.ts b/src/index.ts index cf56f425510c0ddd8984ad984715844b48d6712b..8d0ea14996d5a09e4f99b346a447901c6aeaa3a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,4 +36,5 @@ export * from "./structure/parallel_structure_params"; export * from "./structure/structure"; export * from "./structure/structure_params"; export * from "./structure/factory_structure"; +export * from "./structure/structure_props"; export * from "./jalhyd_object"; diff --git a/src/nub_factory.ts b/src/nub_factory.ts index 69ac91a6e1c0edb04f078f9a42a9813ccc277b18..2301efbb517ff5b4c9398b2e37954370e238685d 100644 --- a/src/nub_factory.ts +++ b/src/nub_factory.ts @@ -14,7 +14,8 @@ import { RegimeUniforme } from "./regime_uniforme"; import { CourbeRemousParams, MethodeResolution, CourbeRemous } from "./remous"; import { PabDimensionParams, PabDimension } from "./pab/pab_dimension"; import { PabPuissance, PabPuissanceParams } from "./pab/pab_puissance"; -import { CreateStructure, StructureType, LoiDebit } from "./structure/factory_structure"; +import { CreateStructure } from "./structure/factory_structure"; +import { StructureType, LoiDebit } from "./structure/structure_props"; import { Structure } from "./structure/structure"; import { ParallelStructure } from "./structure/parallel_structure"; import { ParallelStructureParams } from "./structure/parallel_structure_params"; diff --git a/src/structure/factory_structure.ts b/src/structure/factory_structure.ts index 787daa1f7999c71e0143ca7aea8ba98c11a47d0e..abda575bea35b86a4986a4b28f3ef1e73465997f 100644 --- a/src/structure/factory_structure.ts +++ b/src/structure/factory_structure.ts @@ -8,40 +8,7 @@ import { StructureKiviParams } from "./structure_kivi_params"; import { StructureOrificeFree } from "./structure_orifice_free"; import { StructureOrificeSubmerged } from "./structure_orifice_submerged"; import { StructureWeirFree } from "./structure_weir_free"; - -export enum StructureType { - SeuilRectangulaire, VanneRectangulaire - // 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 - Cem88v, - // loi de débit Cunge 1980 - Cunge80, - // loi de débit pour vanne dénoyée - OrificeFree, - // loi de débit pour vanne noyée - OrificeSubmerged, - // loi de débit pour seuil dénoyé - WeirFree, - // Loi Kindsvater-Carter et Villemonte - KIVI -} - -export const loiAdmissibles: { [key: string]: LoiDebit[] } = { - SeuilRectangulaire: [ - LoiDebit.Cem88d, LoiDebit.Cem88v, LoiDebit.Cunge80, LoiDebit.WeirFree, - LoiDebit.KIVI - ], - VanneRectangulaire: [ - LoiDebit.Cem88d, LoiDebit.Cem88v, LoiDebit.Cunge80, LoiDebit.OrificeFree, - LoiDebit.OrificeSubmerged - ] -}; +import { StructureType, LoiDebit, StructureProperties } from "./structure_props"; export function CreateStructure(structureType: StructureType, loiDebit: LoiDebit, dbg: boolean = false): Structure { const rectStructPrms: RectangularStructureParams = new RectangularStructureParams( @@ -57,14 +24,14 @@ export function CreateStructure(structureType: StructureType, loiDebit: LoiDebit case StructureType.VanneRectangulaire: rectStructPrms.W.v = 0.5; rectStructPrms.Cd.v = 0.6; // Cd pour une vanne rectangulaire - if (!(loiAdmissibles.VanneRectangulaire.includes(loiDebit))) { + if (!(StructureProperties.isCompatibleValues(StructureType.VanneRectangulaire, loiDebit))) { throw new Error( `la loi de débit ${LoiDebit[loiDebit]} n'est pas admissible pour les vannes rectangulaires` ); } break; case StructureType.SeuilRectangulaire: - if (!loiAdmissibles.SeuilRectangulaire.includes(loiDebit)) { + if (!(StructureProperties.isCompatibleValues(StructureType.SeuilRectangulaire, loiDebit))) { throw new Error( `la loi de débit ${LoiDebit[loiDebit]} n'est pas admissible pour les seuils rectangulaires` ); @@ -96,6 +63,7 @@ export function CreateStructure(structureType: StructureType, loiDebit: LoiDebit case LoiDebit.WeirFree: return new StructureWeirFree(rectStructPrms, dbg); + case LoiDebit.KIVI: const structKiviPrm: StructureKiviParams = new StructureKiviParams( 8.516, // Q @@ -107,8 +75,8 @@ export function CreateStructure(structureType: StructureType, loiDebit: LoiDebit 0.001, // béta 100); // ZRAM : cote Radier Amont return new StructureKivi(structKiviPrm, dbg); + default: throw new Error(`type de LoiDebit ${LoiDebit[loiDebit]} non pris en charge`); - } } diff --git a/src/structure/structure_props.ts b/src/structure/structure_props.ts new file mode 100644 index 0000000000000000000000000000000000000000..7c7d63a4b41962f54cd52afee7203785cadc1ac5 --- /dev/null +++ b/src/structure/structure_props.ts @@ -0,0 +1,63 @@ +export enum StructureType { + SeuilRectangulaire, VanneRectangulaire + // 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 + Cem88v, + // loi de débit Cunge 1980 + Cunge80, + // loi de débit pour vanne dénoyée + OrificeFree, + // loi de débit pour vanne noyée + OrificeSubmerged, + // loi de débit pour seuil dénoyé + WeirFree, + // Loi Kindsvater-Carter et Villemonte + KIVI +} + +export const loiAdmissibles: { [key: string]: LoiDebit[] } = { + SeuilRectangulaire: [ + LoiDebit.Cem88d, LoiDebit.Cem88v, LoiDebit.Cunge80, LoiDebit.WeirFree, + LoiDebit.KIVI + ], + VanneRectangulaire: [ + LoiDebit.Cem88d, LoiDebit.Cem88v, LoiDebit.Cunge80, LoiDebit.OrificeFree, + LoiDebit.OrificeSubmerged + ] +}; + +export class StructureProperties { + /** + * @return true si les valeurs de StructureType et LoiDebit sont compatibles + */ + public static isCompatibleValues(struct: StructureType, loi: LoiDebit): boolean { + return loiAdmissibles[StructureType[struct]].includes(loi); + } + + /** + * @return la 1ère valeur de StructureType compatible avec la loi de débit + */ + public static findCompatibleStructure(loi: LoiDebit): StructureType { + for (const st in loiAdmissibles) { + const lds: LoiDebit[] = loiAdmissibles[st]; + for (const ld of lds) + if (ld === loi) + return (<any>StructureType)[st]; + } + return undefined; + } + + /** + * @return la 1ère valeur de LoiDebit compatible avec le type de structure + */ + public static findCompatibleLoiDebit(struct: StructureType): LoiDebit { + const sst: string = StructureType[struct]; + return loiAdmissibles[sst][0]; + } +} \ No newline at end of file