diff --git a/spec/open-channel/regime_uniforme/regime_uniforme_rect.spec.ts b/spec/open-channel/regime_uniforme/regime_uniforme_rect.spec.ts index bdbf1b66823458b35a98e9bec95ff7d7cf4c089b..4204d3419eb34264958bbbc5640567f35174563e 100644 --- a/spec/open-channel/regime_uniforme/regime_uniforme_rect.spec.ts +++ b/spec/open-channel/regime_uniforme/regime_uniforme_rect.spec.ts @@ -5,75 +5,42 @@ import { SessionSettings } from "../../../src/session_settings"; import { MessageCode } from "../../../src/util/message"; import { precDist } from "../../test_config"; import { checkResult } from "../../test_func"; +import { acSection } from "../../../src/open-channel/section/section_type"; + +function generateRectangularSection(): cSnRectang { + const prms = new ParamsSectionRectang( + 0.8, // tirant d'eau + 2.5, // largeur de fond + 40, // Ks=Strickler + 1.5676680, // Q=Débit + 0.001, // If=pente du fond + 1, // YB=hauteur de berge + ); + return new cSnRectang(prms, false); +} + +function generateRegimeUniforme(sect: acSection): RegimeUniforme { + return new RegimeUniforme(sect, false); +} + +let ruRect1 = generateRegimeUniforme(generateRectangularSection()); describe("Class RegimeUniforme / section rectangulaire :", () => { describe("pas de débordement : ", () => { - /** - * test de la largeur de fond (= largeur de berge pour le rectangulaire) - */ - it("LargeurBerge should be 2.5", () => { - const prms = new ParamsSectionRectang(0.8, // tirant d'eau - undefined, // largeur de fond - 40, // Ks=Strickler - 1.568, // Q=Débit - 0.001, // If=pente du fond - 1, // YB=hauteur de berge - ); - SessionSettings.precision = precDist; - const sect = new cSnRectang(prms, false); - const ru = new RegimeUniforme(sect, false); - - checkResult(ru.Calc("LargeurBerge", 0), 2.5); - }); - - it("Strickler should be 30.619", () => { - const prms = new ParamsSectionRectang(0.8, // tirant d'eau - 2.5, // largeur de fond - undefined, // Ks=Strickler - 1.2, // Q=Débit - 0.001, // If=pente du fond - 1, // YB=hauteur de berge - ); - SessionSettings.precision = precDist; - - const sect = new cSnRectang(prms); - const ru = new RegimeUniforme(sect); - - checkResult(ru.Calc("Ks", 1e-8), 30.619); - }); - - it("If should be 0.001", () => { - const prms = new ParamsSectionRectang(0.8, // tirant d'eau - 2.5, // largeur de fond - 40, // Ks=Strickler - 1.568, // Q=Débit - undefined, // If=pente du fond - 1, // YB=hauteur de berge - ); - SessionSettings.precision = precDist; - - const sect = new cSnRectang(prms); - const ru = new RegimeUniforme(sect, false); - - // nom variable à calculer, valeur de Ks - checkResult(ru.Calc("If", 0.001), 0.001); - }); - - it("Q should be 1.568", () => { - const prms = new ParamsSectionRectang(0.8, // tirant d'eau - 2.5, // largeur de fond - 40, // Ks=Strickler - undefined, // Q=Débit - 0.001, // If=pente du fond - 1, // YB=hauteur de berge - ); - SessionSettings.precision = precDist; - - const sect = new cSnRectang(prms); - const ru = new RegimeUniforme(sect); - - checkResult(ru.Calc("Q", 0), 1.568); - }); + beforeEach(() => { + ruRect1 = generateRegimeUniforme(generateRectangularSection()); + SessionSettings.precision = 1E-7; + }) + for (const p of ruRect1.calculableParameters) { + it(`${p.symbol} should be ${p.singleValue}`, () => { + const ref: number = p.singleValue; + p.singleValue = undefined; + p.initValue = 1e-8; + ruRect1.calculatedParam = p; + checkResult(ruRect1.CalcSerie(), ref); + expect(ruRect1.result.values.V).toBeCloseTo(0.784, 3); + }); + } it("Q should be 0.731", () => { const prms = new ParamsSectionRectang(1.1, // tirant d'eau diff --git a/src/open-channel/regime_uniforme.ts b/src/open-channel/regime_uniforme.ts index 3a6d330b5ab1e3c0d087498e5cf062735a848ba5..857622bc5c2bbae2f635a41dde37db48f453f226 100644 --- a/src/open-channel/regime_uniforme.ts +++ b/src/open-channel/regime_uniforme.ts @@ -43,10 +43,6 @@ export class RegimeUniforme extends SectionNub { throw new Error("RegimeUniforme.Equation() : invalid variable name " + sVarCalc); } - // Vitesse moyenne - const V = this.section.CalcSection("V", this.section.prms.Y.v); - r.resultElement.values.V = V.vCalc; - return r; } @@ -58,6 +54,11 @@ export class RegimeUniforme extends SectionNub { */ public Calc(sVarCalc?: string, rInit?: number): Result { const r = super.Calc(sVarCalc, rInit); + + // Vitesse moyenne + const V = this.section.CalcSection("V", this.section.prms.Y.v); + r.resultElement.values.V = V.vCalc; + // Est-ce que ça déborde ? if (this.section.prms.Y.v > this.section.prms.YB.v) { r.resultElement.log.add(new Message(MessageCode.WARNING_SECTION_OVERFLOW)); @@ -73,11 +74,12 @@ export class RegimeUniforme extends SectionNub { } // tslint:disable-next-line:no-empty - protected setParametersCalculability() {} + protected setParametersCalculability() { } protected adjustChildParameters(): void { this.section.prms.Q.calculability = ParamCalculability.EQUATION; this.section.prms.Y.calculability = ParamCalculability.EQUATION; + this.section.prms.YB.calculability = ParamCalculability.FREE; } protected exposeResults() {