diff --git a/spec/structure/structure.spec.ts b/spec/structure/structure.spec.ts index ea18f087e1db333237e2b1354c31dd2c18f4f051..bf02f0577222a9e54a4ef67f143002df18341b78 100644 --- a/spec/structure/structure.spec.ts +++ b/spec/structure/structure.spec.ts @@ -18,7 +18,6 @@ class StructureTest extends Structure { constructor(prms: StructureTestParams, dbg: boolean = false) { super(prms, dbg); - this.setParametersCalculability(); } Equation(sVarCalc: string): Result { diff --git a/spec/structure/structure_cem88d.spec.ts b/spec/structure/structure_cem88d.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..defd90c8e22990961f466a68459d91dcda6c3223 --- /dev/null +++ b/spec/structure/structure_cem88d.spec.ts @@ -0,0 +1,22 @@ +/// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> + +import { StructureCem88d, RectangularStructureParams } from "../../src/structure/structure_cem88d"; +import { Result } from "../../src/base"; +import { precDigits } from "../nubtest"; + +let structPrm: RectangularStructureParams = new RectangularStructureParams(1, undefined, 1, 2, 0.6, 0); +let structTest: StructureCem88d = new StructureCem88d(structPrm, false); + +let resultTesth1FnW: number[] = [Infinity, 3.603062, 1.560872, 1.323331, 1.154102, 1.073632, 1.047438, 1.035118, 1.027086, 1.021649, 1.021305]; + +describe('Class StructureCem88d: ', () => { + describe('Calcul h1 avec W croissant: ', () => { + for(let iW = 0; iW <= 10; iW++ ) { + structTest.prms.W.v = iW / 10 ; + it('h1(W='+structTest.prms.W.v+') should be '+resultTesth1FnW[iW], () => { + console.log('h1(W='+structTest.prms.W.v+') should be '+resultTesth1FnW[iW]); + expect(structTest.Calc('h1').vCalc).toBeCloseTo(resultTesth1FnW[iW],precDigits); + }); + } + }); +}); diff --git a/src/structure/rectangular_structure.ts b/src/structure/rectangular_structure.ts new file mode 100644 index 0000000000000000000000000000000000000000..5766a8c4725d7035fc7606a5a926af4785220c8b --- /dev/null +++ b/src/structure/rectangular_structure.ts @@ -0,0 +1,46 @@ +/** + * @file structure/rectangular_structure.ts Equation for weir and orifice (high sill elevation) from Cemagref 1988 + */ +import { ComputeNodeType, ParamDefinition, ParamDomainValue, ParamCalculability, ParamsEquation } from "../param"; +import { StructureParams, Structure } from "./structure"; + +export class RectangularStructureParams extends StructureParams { + /** Width of the gate or length of the sill (m) */ + L: ParamDefinition; + + /** Discharge coefficient */ + Cd: ParamDefinition + + constructor(rQ: number, rh1: number, rh2: number, rL: number, rCd: number, rW: number = Infinity) { + super(rQ, rh1, rh2, rW); + this.L = new ParamDefinition(ComputeNodeType.CondDistri, 'L', ParamDomainValue.POS, rL); + this.addParamDefinition(this.L); + this.Cd = new ParamDefinition(ComputeNodeType.CondDistri, 'Cd', ParamDomainValue.POS, rCd); + this.addParamDefinition(this.Cd); + } + +} + +export abstract class RectangularStructure extends Structure { + + constructor(prms: RectangularStructureParams, dbg: boolean = false) { + super(prms, dbg); + } + + /** + * paramètres castés au bon type + */ + get prms(): RectangularStructureParams { + return <RectangularStructureParams>this._prms; + } + + /** + * paramétrage de la calculabilité des paramètres + */ + protected setParametersCalculability() { + super.setParametersCalculability(); + this.prms.L.calculability = ParamCalculability.DICHO; + this.prms.Cd.calculability = ParamCalculability.DICHO; + } + +} diff --git a/src/structure/structure.ts b/src/structure/structure.ts index 9b41135c610b4bc797b5303e4df62b6bc5fc8fbd..2b3937e1ffe098e97fe3eb32870630a65e4372c2 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -27,9 +27,13 @@ export abstract class StructureParams extends ParamsEquation { constructor(rQ: number, rh1: number, rh2: number, rW: number = Infinity ) { super(); this.Q = new ParamDefinition(ComputeNodeType.CondDistri, 'Q', ParamDomainValue.POS_NULL, rQ); + this.addParamDefinition(this.Q); this.h1 = new ParamDefinition(ComputeNodeType.CondDistri, 'h1', ParamDomainValue.POS_NULL, rh1); + this.addParamDefinition(this.h1); this.h2 = new ParamDefinition(ComputeNodeType.CondDistri, 'h2', ParamDomainValue.POS_NULL, rh2); + this.addParamDefinition(this.h2); this.W = new ParamDefinition(ComputeNodeType.CondDistri, 'W', ParamDomainValue.POS_NULL, rW); + this.addParamDefinition(this.W); } } @@ -62,6 +66,10 @@ export enum StructureFlowRegime { * classe de calcul sur la conduite distributrice */ export abstract class Structure extends Nub { + + /** Constante utile : Racine de 2g */ + protected static readonly R2G: number = Math.sqrt(2*9.81); + constructor(prms: StructureParams, dbg: boolean = false) { super(prms, dbg); } @@ -138,6 +146,8 @@ export abstract class Structure extends Nub { default : return new Result(0); // Est-ce toujours vrai ? Nécessitera peut-être d'étendre la méthode } + } else if(this.prms.W.v == 0 && sVarCalc == "h1") { + return new Result(Infinity); // Si la vanne est fermée la cote amont est infinie } // Gestion de l'inversion de débit : on inverse l'amont et l'aval pour le calcul @@ -153,4 +163,11 @@ export abstract class Structure extends Nub { } + /** + * Test générique si VarCalc="Q" pour l'utilisation de Equation + */ + CheckEquation(sVarCalc: string) { + if(sVarCalc!="Q") throw 'Structure.Equation() : invalid parameter name ' + sVarCalc; + } + } \ No newline at end of file diff --git a/src/structure/structure_cem88d.ts b/src/structure/structure_cem88d.ts new file mode 100644 index 0000000000000000000000000000000000000000..324c7fac86b5da5fb467f96df03d53747b066924 --- /dev/null +++ b/src/structure/structure_cem88d.ts @@ -0,0 +1,39 @@ +/** + * @file structure/structure_cem88d.ts Equation for weir and orifice (high sill elevation) from Cemagref 1988 + */ +import { RectangularStructureParams, RectangularStructure } from "./rectangular_structure"; +import { StructureFlowMode, StructureFlowRegime, Structure } from "./structure" +import { Result } from "../base" + +export { RectangularStructureParams }; + +export class StructureCem88d extends RectangularStructure { + Equation(sVarCalc: string): Result { + this.CheckEquation(sVarCalc); + let v : number; + let cd : number = this.prms.Cd.v * this.prms.L.v * Structure.R2G; + let b1 : number = Math.sqrt(this.prms.h1.v); + let b2 : number = Math.sqrt(this.prms.h2.v); + let cd1 : number = cd * 2.5981; + switch(this.getFlowMode()) { + case StructureFlowMode.WEIR: + switch(this.getFlowRegime()) { + case StructureFlowRegime.FREE: + v = cd * this.prms.h1.v * b1; + case StructureFlowRegime.SUBMERGED: + v = cd1 * this.prms.h1.v * b2; + } + case StructureFlowMode.ORIFICE: + let b3 : number = this.prms.h1.v - this.prms.W.v; + switch(this.getFlowRegime()) { + case StructureFlowRegime.FREE: + v = cd * (this.prms.h1.v * b1 -b3); + case StructureFlowRegime.PARTIAL: + v = cd1 * b2 * this.prms.h2.v - cd * b3; + case StructureFlowRegime.SUBMERGED: + v = cd1 * b2 * this.prms.W.v; + } + } + return new Result(v); + } +}