diff --git a/spec/fuzzing.spec.ts b/spec/fuzzing.spec.ts index c264390629b89d77ec0e084797dc8aa2f5d8f58b..20bf5dd0f2cfbd0ff015112593781d361f849407 100644 --- a/spec/fuzzing.spec.ts +++ b/spec/fuzzing.spec.ts @@ -1,4 +1,5 @@ import { CalculatorType } from "../src/compute-node"; +import { MacrorugoCompound } from "../src/macrorugo/macrorugo_compound"; import { Nub } from "../src/nub"; import { CloisonAval } from "../src/pab/cloison_aval"; import { Pab } from "../src/pab/pab"; @@ -110,6 +111,10 @@ function setPab(pab: Pab, nClMax = 30, nStMax = 3) { addRandomStructures(pab.downWall, nStMax); } +function setMacrorugoCompound(n: MacrorugoCompound) { + n.properties.setPropValue("InclinedApron", Math.random() > 0.5); +} + function CreateTestNub(iCalType: number): Nub { const n = Session.getInstance().createNub( new Props({ calcType: iCalType }) @@ -129,6 +134,9 @@ function CreateTestNub(iCalType: number): Nub { if (iCalType === CalculatorType.Pab) { setPab(n as Pab, fuzzyCfg.Pab.poolMax, fuzzyCfg.Pab.structureMax); } + if (iCalType === CalculatorType.MacroRugoCompound) { + setMacrorugoCompound(n as MacrorugoCompound); + } for (const p of n.parameterIterator) { if (p.visible) { randomizeParameter(p); diff --git a/spec/macrorugo/macrorugo_compound.spec.ts b/spec/macrorugo/macrorugo_compound.spec.ts index a96da3862626689a373ca9fcebcf0b0c11c76632..90883d3638c0dd108e601a6937167a2c0a012c2d 100644 --- a/spec/macrorugo/macrorugo_compound.spec.ts +++ b/spec/macrorugo/macrorugo_compound.spec.ts @@ -4,6 +4,8 @@ import { MacrorugoCompound } from "../../src/macrorugo/macrorugo_compound"; import { Props } from "../../src/props"; import { Session } from "../../src/session"; +let B: number; + describe("MacroRugoCompound", () => { describe("Default 1 apron", () => { it("should return same result as Macrorugo", () => { @@ -14,8 +16,28 @@ describe("MacroRugoCompound", () => { const mr = Session.getInstance().createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo; mr.prms.Q.setCalculated(); expect(mrc.CalcSerie().vCalc).toBeCloseTo(mr.CalcSerie().vCalc, 3); - console.debug(mrc.result.vCalc); - console.debug(mr.result.vCalc); }); }); + describe("Default inclined but flat apron", () => { + beforeAll(() => { + B = 2; + }); + beforeEach(() => { + B++; + }); + for (let i = 2; i < 6; i++) { + it(`B = ${i} should return same result as Macrorugo`, () => { + const mrc = Session.getInstance().createNub( + new Props({ calcType: CalculatorType.MacroRugoCompound }) + ) as MacrorugoCompound; + mrc.properties.setPropValue("InclinedApron", true); + mrc.prms.B.singleValue = 4; + const mr = Session.getInstance() + .createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo; + mr.prms.Q.setCalculated(); + expect(mrc.CalcSerie().vCalc).toBeCloseTo(mr.CalcSerie().vCalc * mrc.prms.B.currentValue, 3); + }); + } + }); + }); diff --git a/src/macrorugo/macrorugo.ts b/src/macrorugo/macrorugo.ts index 2f1bb744be7f26d1ce36ebd779c7489a7ac91133..1adc516b0486cc9972da5b3cbab4c0ee7f64d94f 100644 --- a/src/macrorugo/macrorugo.ts +++ b/src/macrorugo/macrorugo.ts @@ -66,6 +66,8 @@ export class MacroRugo extends Nub { this.getParameter(sVarCalc).valueMode = ParamValueMode.CALCUL; const r: Result = super.Calc(sVarCalc, rInit); + this.getParameter(sVarCalc).valueMode = originalValueMode; + // Ajout des résultats complémentaires // Cote de fond aval r.resultElement.values.ZF2 = this.prms.ZF1.v - this.prms.If.v * this.prms.L.v; @@ -115,9 +117,6 @@ export class MacroRugo extends Nub { Math.pow(this.prms.If.v, cV[2]) * Math.sqrt(MacroRugo.g * this.prms.PBD.v); } - // mode d'origine du paramètre; voir le haut de la fonction - this.getParameter(sVarCalc).valueMode = originalValueMode; - return r; } @@ -125,8 +124,13 @@ export class MacroRugo extends Nub { this.Q = this.prms.Q.v; const q0 = Math.sqrt(2 * MacroRugo.g * this.prms.If.v * this.prms.PBD.v * ( 1 - (this.sigma * this.prms.C.v)) / (this.prms.Cd0.v * this.prms.C.v)) * this.prms.Y.v * this.prms.B.v; - const dicho = new Dichotomie(this, "Q", false, this.resolveQ); - const r: Result = dicho.Dichotomie(0, this.prms.Pr.v, q0); + let r: Result; + if (q0 > 0) { + const dicho = new Dichotomie(this, "Q", false, this.resolveQ); + r = dicho.Dichotomie(0, this.prms.Pr.v, q0); + } else { + r = new Result(0); + } this.prms.Q.v = this.Q; return r; diff --git a/src/macrorugo/macrorugo_compound.ts b/src/macrorugo/macrorugo_compound.ts index 204ad8d27e3dd7027494abdc383b2f8878197a64..718e9ecbd055777bad531ae19a125e753606c909 100644 --- a/src/macrorugo/macrorugo_compound.ts +++ b/src/macrorugo/macrorugo_compound.ts @@ -29,6 +29,9 @@ export class MacrorugoCompound extends MacroRugo { if (sVarCalc !== "Q") { throw new Error("MacrorugoCompound.Calc() : invalid parameter " + sVarCalc); } + if (this.properties.getPropValue("InclinedApron")) { + this.generateInclinedFishway(); + } this.copyPrmsToChildren(); this.currentResult = this.Equation(sVarCalc); return this._result; @@ -84,7 +87,7 @@ export class MacrorugoCompound extends MacroRugo { } // Calculate Length and depth from other parameters child.prms.L.v = this.prms.DH.v / this.prms.If.v; - child.prms.Y.v = this.prms.Z1.v - child.prms.ZF1.v; + child.prms.Y.v = Math.max(this.prms.Z1.v - child.prms.ZF1.v, 0); } } @@ -101,27 +104,28 @@ export class MacrorugoCompound extends MacroRugo { // Taille d'une cellule de calcul const ax: number = this.prms.PBD.v / Math.sqrt(this.prms.C.v); // Nombre entier de cellules et reste - const ncells: number = Math.floor(this.prms.B.v / ax); - const xRest: number = this.prms.B.v % ax; + const nCells: number = Math.floor(this.prms.BR.v / ax); + const xRest: number = this.prms.BR.v % ax; const xCenters: number[] = []; - let iStart: number; - // Calcul du centre de la première cellule + let lastBorder: number = 0; + // Position du centre de la première cellule if (xRest > ax / 2) { // Ajout d'une cellule à gauche - xCenters.push(xRest / 2); - iStart = 0; + xCenters.push(xRest / 4); } else { - // Décalage de la première cellule - xCenters.push((ax + xRest) / 2); - iStart = 1; + xCenters.push((ax + xRest / 2) / 2); } - // Ajout des cellules centrales - for (let i = iStart; i < ncells; i++) { - xCenters.push(xCenters[xCenters.length - 1] + ax); + lastBorder = xCenters[0] * 2; + // Ajout des cellules centrales décalées de ax + for (let i = 0; i < nCells; i++) { + xCenters.push(lastBorder + ax / 2); + lastBorder += ax; } if (xRest > ax / 2) { // Ajout de la cellule supplémentaire à droite - xCenters.push(this.prms.B.v - xRest / 2); + xCenters.push(this.prms.B.v - xRest / 4); + } else { + xCenters[xCenters.length - 1] = this.prms.BR.v - (ax + xRest / 2) / 2; } // Génération des radiers @@ -129,11 +133,14 @@ export class MacrorugoCompound extends MacroRugo { while (this.children.length > 0) { this.deleteChild(0); } - // Ajout des radiers et calcul de la cote amont + // Ajout des radiers et calcul de leur cote amont et de leur largeur + lastBorder = 0; for (const xCenter of xCenters) { this.addDefaultChild(); this.children[this.children.length - 1].prms.ZF1.v = - this.prms.ZRL.v + xCenter / this.prms.B.v * (this.prms.ZRR.v - this.prms.ZRL.v); + this.prms.ZRL.v + xCenter / this.prms.BR.v * (this.prms.ZRR.v - this.prms.ZRL.v); + this.children[this.children.length - 1].prms.B.v = (xCenter - lastBorder) * 2; + lastBorder += this.children[this.children.length - 1].prms.B.v; } } } diff --git a/src/macrorugo/macrorugo_compound_params.ts b/src/macrorugo/macrorugo_compound_params.ts index db437758a3d472ad2cd8919c7950e27561959858..93e55e4917b56b3ad922b15802a22e7a47902f47 100644 --- a/src/macrorugo/macrorugo_compound_params.ts +++ b/src/macrorugo/macrorugo_compound_params.ts @@ -1,5 +1,5 @@ import { ParamDefinition, ParamFamily } from "../param/param-definition"; -import { ParamDomainValue } from "../param/param-domain"; +import { ParamDomain, ParamDomainValue } from "../param/param-domain"; import { MacrorugoParams } from "./macrorugo"; export class MacrorugoCompoundParams extends MacrorugoParams { @@ -16,11 +16,16 @@ export class MacrorugoCompoundParams extends MacrorugoParams { /** Inclined apron: Right bank apron elevation (m) */ private _ZRR: ParamDefinition; + /** Inclined apron: Apron total width (m) */ + private _BR: ParamDefinition; + /** * * @param rZ1 Cote de l'eau amont (m) + * @param rZRL Cote de radier gauche (m) (Radier incliné seulement) + * @param rZRR Cote de radier droit (m) (Radier incliné seulement) + * @param rB Largeur (m) (Radier incliné seulement) * @param rDH Chute (m) - * @param rB Largeur (m) * @param rIf Pente (m/m) * @param rY Tirant d'eau (m) * @param rRF Rugosité de fond (m) @@ -33,6 +38,7 @@ export class MacrorugoCompoundParams extends MacrorugoParams { rZ1: number, rZRL: number, rZRR: number, + rB: number, rDH: number, rIf: number, rRF: number, @@ -41,18 +47,23 @@ export class MacrorugoCompoundParams extends MacrorugoParams { rPBH: number, rCd0: number ) { - super((rZRL + rZRR) / 2, rDH / rIf, 1, rIf, 1, 1, rRF, rCB, rPBD, rPBH, rCd0); + super((rZRL + rZRR) / 2, 1, rDH / rIf, rIf, 1, 1, rRF, rCB, rPBD, rPBH, rCd0); - this._Z1 = new ParamDefinition(this, "Z1", ParamDomainValue.POS, "m", rZ1, ParamFamily.ELEVATIONS); + this._Z1 = new ParamDefinition(this, "Z1", ParamDomainValue.ANY, "m", rZ1, ParamFamily.ELEVATIONS); this.addParamDefinition(this._Z1); - this._ZRL = new ParamDefinition(this, "ZRL", ParamDomainValue.POS, "m", rZRL, ParamFamily.ELEVATIONS); + this._ZRL = new ParamDefinition(this, "ZRL", ParamDomainValue.ANY, "m", rZRL, ParamFamily.ELEVATIONS); this.addParamDefinition(this.ZRL); - this._ZRR = new ParamDefinition(this, "ZRR", ParamDomainValue.POS, "m", rZRR, ParamFamily.ELEVATIONS); + this._ZRR = new ParamDefinition(this, "ZRR", ParamDomainValue.ANY, "m", rZRR, ParamFamily.ELEVATIONS); this.addParamDefinition(this._ZRR); - this._DH = new ParamDefinition(this, "DH", ParamDomainValue.POS, "m", rDH, ParamFamily.ELEVATIONS); + this._BR = new ParamDefinition(this, "BR", + new ParamDomain(ParamDomainValue.INTERVAL, 0, 100), "m", rB, ParamFamily.WIDTHS); + this.addParamDefinition(this._BR); + + this._DH = new ParamDefinition(this, "DH", + new ParamDomain(ParamDomainValue.INTERVAL, 0, 100), "m", rDH, ParamFamily.ELEVATIONS); this.addParamDefinition(this._DH); // Width, water depth, and Bottom elevation are defined in Macrorugo children @@ -60,6 +71,7 @@ export class MacrorugoCompoundParams extends MacrorugoParams { this.ZF1.visible = false; this.Y.visible = false; this.Q.visible = false; + } public get Z1(): ParamDefinition { @@ -74,6 +86,10 @@ export class MacrorugoCompoundParams extends MacrorugoParams { return this._ZRR; } + public get BR(): ParamDefinition { + return this._BR; + } + public get DH(): ParamDefinition { return this._DH; } diff --git a/src/macrorugo/macrorugo_params.ts b/src/macrorugo/macrorugo_params.ts index 71f48818ef91106e2d6d976776fce4e44f6a5a8d..123d120c1c4d3d384280baac1430ce54e31a3513 100644 --- a/src/macrorugo/macrorugo_params.ts +++ b/src/macrorugo/macrorugo_params.ts @@ -1,5 +1,5 @@ import { ParamDefinition, ParamFamily } from "../param/param-definition"; -import { ParamDomainValue } from "../param/param-domain"; +import { ParamDomain, ParamDomainValue } from "../param/param-domain"; import { ParamsEquation } from "../param/params-equation"; export class MacrorugoParams extends ParamsEquation { @@ -65,22 +65,23 @@ export class MacrorugoParams extends ParamsEquation { this._B = new ParamDefinition(this, "B", ParamDomainValue.POS, "m", rB, ParamFamily.WIDTHS); this.addParamDefinition(this._B); - this._If = new ParamDefinition(this, "If", ParamDomainValue.POS, "m/m", rIf, ParamFamily.SLOPES); + this._If = new ParamDefinition(this, "If", + new ParamDomain(ParamDomainValue.INTERVAL, 0, 0.5), "m/m", rIf, ParamFamily.SLOPES); this.addParamDefinition(this._If); this._Q = new ParamDefinition(this, "Q", ParamDomainValue.POS, "m³/s", rQ, ParamFamily.FLOWS); this.addParamDefinition(this._Q); - this._Y = new ParamDefinition(this, "Y", ParamDomainValue.POS, "m", rY, ParamFamily.HEIGHTS); + this._Y = new ParamDefinition(this, "Y", ParamDomainValue.POS_NULL, "m", rY, ParamFamily.HEIGHTS); this.addParamDefinition(this._Y); - this._Ks = new ParamDefinition(this, "Ks", ParamDomainValue.POS_NULL, "m", rRF); + this._Ks = new ParamDefinition(this, "Ks", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "m", rRF); this.addParamDefinition(this._Ks); - this._C = new ParamDefinition(this, "C", ParamDomainValue.POS, "m", rCB); + this._C = new ParamDefinition(this, "C", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "-", rCB); this.addParamDefinition(this._C); - this._PBD = new ParamDefinition(this, "PBD", ParamDomainValue.POS, "m", rPBD); + this._PBD = new ParamDefinition(this, "PBD", new ParamDomain(ParamDomainValue.INTERVAL, 0, 2), "m", rPBD); this.addParamDefinition(this._PBD); this._PBH = new ParamDefinition(this, "PBH", ParamDomainValue.POS, "m", rPBH, ParamFamily.HEIGHTS); diff --git a/src/session.ts b/src/session.ts index f973e1f7418f47480e76770d3f2050897481e346..68f7c096c224f4eaa1295cd8de8bbaf9ca12faf8 100644 --- a/src/session.ts +++ b/src/session.ts @@ -418,6 +418,7 @@ export class Session { 13.1, // Z1 12.5, // ZRL 12.5, // ZRR + 4, // B 3, // DH 0.05, // If 0.01, // Ks