diff --git a/spec/macrorugo/macrorugo.spec.ts b/spec/macrorugo/macrorugo.spec.ts index 74cb6b1c82e1d9d77ce30c687eddb0451d11af32..5d79f246075e53ebcf56635144282218d16adfd3 100644 --- a/spec/macrorugo/macrorugo.spec.ts +++ b/spec/macrorugo/macrorugo.spec.ts @@ -1,4 +1,4 @@ -import { ParamCalculability, ParamValueMode, Session } from "../../src/index"; +import { MessageCode, ParamCalculability, ParamValueMode, Session } from "../../src/index"; import { MacroRugo, MacroRugoFlowType } from "../../src/macrorugo/macrorugo"; import { MacrorugoParams } from "../../src/macrorugo/macrorugo_params"; import { checkResult } from "../test_func"; @@ -242,4 +242,50 @@ describe("Class MacroRugo: ", () => { } }); }); + + describe("ramp width tolerance should be 1cm", () => { + it("", () => { + const prms = new MacrorugoParams( + 12.5, // ZF1 + 6, // L + 2.2, // B + 0.05, // If + 0.1, // Q + 0.6, // h + 0.01, // Ks + 0.13, // C + 0.4, // D + 0.6, // k + 1 // Cd0 + ); + const mr = new MacroRugo(prms); + mr.calculatedParam = mr.prms.Q; + + // ramp not wide enough : warning on tolerance (min width=1.109 m) + + prms.B.singleValue = 1.099; + let res = mr.CalcSerie(); + expect(res.log.messages.length).toEqual(1); + expect(res.log.messages[0].code).toEqual(MessageCode.WARNING_RAMP_WIDTH_LOWER_THAN_PATTERN_WIDTH); + + // ramp just wide enough for one block pattern : no warning (min width=1.109 m) + + prms.B.singleValue = 1.1; + res = mr.CalcSerie(); + expect(res.log.messages.length).toEqual(0); + + // ramp wide enough : warning on tolerance (B=2.2, closest rounded value=2.219, B-rounded > 0.01) + + prms.B.singleValue = 2.2; + res = mr.CalcSerie(); + expect(res.log.messages.length).toEqual(1); + expect(res.log.messages[0].code).toEqual(MessageCode.WARNING_RAMP_WIDTH_NOT_MULTIPLE_OF_HALF_PATTERN_WIDTH); + + // ramp wide enough : no warning (B=2.21, closest rounded value=2.219, B-rounded < 0.01) + + prms.B.singleValue = 2.21; + res = mr.CalcSerie(); + expect(res.log.messages.length).toEqual(0); + }); + }); }); diff --git a/spec/macrorugo/macrorugo_compound.spec.ts b/spec/macrorugo/macrorugo_compound.spec.ts index be2e09c8f6dd3b811316aea450de0453f1ee7f86..bc81d33cb2f1ac6490ff32059c8b53939629c890 100644 --- a/spec/macrorugo/macrorugo_compound.spec.ts +++ b/spec/macrorugo/macrorugo_compound.spec.ts @@ -1,5 +1,6 @@ import { CalculatorType } from "../../src/compute-node"; import { Session } from "../../src/index"; +import { MacrorugoCompoundParams, MessageCode } from "../../src/internal_modules"; import { MacroRugo } from "../../src/macrorugo/macrorugo"; import { MacrorugoCompound } from "../../src/macrorugo/macrorugo_compound"; import { MacrorugoParams } from "../../src/macrorugo/macrorugo_params"; @@ -47,7 +48,7 @@ describe("MacroRugoCompound: ", () => { const mr = getMacroRugoRef(); mr.prms.L.singleValue = mrc.children[0].prms.L.v; mr.CalcSerie(); - compareTwoResults(mrc.children[0].result, mr.result, 3, [ "ZF2" ]); + compareTwoResults(mrc.children[0].result, mr.result, 3, ["ZF2"]); }); it("variating Z1, children Y should not always be 0.6", () => { const mrc = Session.getInstance().createNub( @@ -58,7 +59,7 @@ describe("MacroRugoCompound: ", () => { mrc.prms.Z1.setValues(10, 15, 5); mrc.CalcSerie(); const childYs = mrc.children[0].prms.Y.getInferredValuesList(); - expect(childYs).toEqual([ 0, 2.5 ]); + expect(childYs).toEqual([0, 2.5]); }); }); describe("Default inclined but flat apron", () => { @@ -134,8 +135,72 @@ describe("MacroRugoCompound: ", () => { }); it(`Apron #${i} should return same result as Macrorugo`, () => { const mr = getMacroRugoRef(i); - compareTwoResults(mrc2.children[i].result, mr.result, 3, [ "ZF2" ]); + compareTwoResults(mrc2.children[i].result, mr.result, 3, ["ZF2"]); }); } }); + + describe("Ramp width tolerance", () => { + it("tolerance should be 1cm", () => { + const MRCprms = new MacrorugoCompoundParams( + 13.1, // Z1 + 12.5, // ZRL + 12.5, // ZRR + 60, // B + 3, // DH + 0.05, // If + 0.01, // RF (Ks) + 0.13, // C (concentration de bloc) + 0.4, // D (diamètre de bloc) + 0.4, // H (hauteur de bloc) + 1 // Cd0 + ); + const mrc = new MacrorugoCompound(MRCprms); + + const MRprms = new MacrorugoParams( // B 1 + 12.5, // ZF1 + 6, // L + 1, // B + 0.05, // If + 1.57, // Q + 0.6, // Y + 0.01, // Ks + 0.13, // C + 0.4, // D + 0.4, // H + 1 // Cd0 + ); + mrc.addChild(new MacroRugo(MRprms)); + + // ramp not wide enough : warning on tolerance (min width=1.109 m) + + MRprms.B.singleValue = 1.099; + mrc.CalcSerie(); + let res = mrc.children[0].result; // warnings are in the child nub + expect(res.log.messages.length).toEqual(1); + expect(res.log.messages[0].code).toEqual(MessageCode.WARNING_RAMP_WIDTH_LOWER_THAN_PATTERN_WIDTH); + + // ramp just wide enough for one block pattern : no warning (min width=1.109 m) + + MRprms.B.singleValue = 1.1; + mrc.CalcSerie(); + res = mrc.children[0].result; + expect(res.log.messages.length).toEqual(0); + + // ramp wide enough : warning on tolerance (B=2.2, closest rounded value=2.219, B-rounded > 0.01) + + MRprms.B.singleValue = 2.2; + mrc.CalcSerie(); + res = mrc.children[0].result; + expect(res.log.messages.length).toEqual(1); + expect(res.log.messages[0].code).toEqual(MessageCode.WARNING_RAMP_WIDTH_NOT_MULTIPLE_OF_HALF_PATTERN_WIDTH); + + // ramp wide enough : no warning (B=2.21, closest rounded value=2.219, B-rounded < 0.01) + + MRprms.B.singleValue = 2.21; + mrc.CalcSerie(); + res = mrc.children[0].result; + expect(res.log.messages.length).toEqual(0); + }); + }); }); diff --git a/src/macrorugo/concentration_blocs_params.ts b/src/macrorugo/concentration_blocs_params.ts index 8c35f597c5402d85778be79ddce215eafe86b4b5..0003e56779bb90c2bb34a07a450cb87a704b3e2f 100644 --- a/src/macrorugo/concentration_blocs_params.ts +++ b/src/macrorugo/concentration_blocs_params.ts @@ -18,10 +18,10 @@ export class ConcentrationBlocsParams extends ParamsEquation { constructor(rC: number, rN: number, rL: number, rD: number, nullParams: boolean = false) { super(); - this._C = new ParamDefinition(this, "C", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), undefined, rC, undefined, undefined, nullParams); + this._C = new ParamDefinition(this, "C", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), undefined, rC, ParamFamily.BLOCKCONCENTRATION, undefined, nullParams); this._N = new ParamDefinition(this, "N", ParamDomainValue.POS, undefined, rN, undefined, undefined, nullParams); this._L = new ParamDefinition(this, "L", ParamDomainValue.POS, "m", rL, ParamFamily.WIDTHS, undefined, nullParams); - this._D = new ParamDefinition(this, "D", new ParamDomain(ParamDomainValue.INTERVAL, 0, 2), "m", rD, undefined, undefined, nullParams); + this._D = new ParamDefinition(this, "D", new ParamDomain(ParamDomainValue.INTERVAL, 0, 2), "m", rD, ParamFamily.DIAMETERS, undefined, nullParams); this.addParamDefinition(this._C); this.addParamDefinition(this._N); diff --git a/src/macrorugo/macrorugo.ts b/src/macrorugo/macrorugo.ts index db2cd017f3a232dcb056c4d2e430443870552730..1015d3ad1620dfd57b20a5c508a47e933ecdf703 100644 --- a/src/macrorugo/macrorugo.ts +++ b/src/macrorugo/macrorugo.ts @@ -105,11 +105,12 @@ export class MacroRugo extends FishPass { ) ) { const ax: number = this.prms.PBD.v / Math.sqrt(this.prms.C.v); - if (this.prms.B.v < ax - 0.001) { // B < ax, with a little tolerance + const tol = 0.01; // tolérance avant avertissement (1 cm) + if (this.prms.B.v < ax - tol) { // B < ax, with a little tolerance const m = new Message(MessageCode.WARNING_RAMP_WIDTH_LOWER_THAN_PATTERN_WIDTH); m.extraVar.pattern = ax; r.resultElement.log.add(m); - } else if (this.prms.B.v % (ax / 2) > 0.001 && this.prms.B.v % (ax / 2) < ax / 2 - 0.001) { + } else if (this.prms.B.v % (ax / 2) > tol && this.prms.B.v % (ax / 2) < ax / 2 - tol) { const m = new Message(MessageCode.WARNING_RAMP_WIDTH_NOT_MULTIPLE_OF_HALF_PATTERN_WIDTH); m.extraVar.halfPattern = ax / 2; m.extraVar.lower = Math.floor(this.prms.B.v / ax * 2) * (ax / 2); diff --git a/src/macrorugo/macrorugo_compound.ts b/src/macrorugo/macrorugo_compound.ts index 7744680b562b074a761868af23e028458c7b00b2..a9cdad1e5f0787e65183403294c63cc5708bd77f 100644 --- a/src/macrorugo/macrorugo_compound.ts +++ b/src/macrorugo/macrorugo_compound.ts @@ -99,11 +99,12 @@ export class MacrorugoCompound extends MacroRugo implements Observer { this.result.resultElement.values.LIncl = (this.prms.ZRL.v - this.prms.ZRR.v) / this.prms.BR.v; // La largeur de la rampe inclinée est-elle adéquate par rapport à la largeur de motif ax ? const ax: number = this.prms.PBD.v / Math.sqrt(this.prms.C.v); - if (this.prms.BR.v - ax < -0.001) { // BR < ax, with a little tolerance + const tol = 0.01; // tolérance avant avertissement (1 cm) + if (this.prms.BR.v - ax < -tol) { // BR < ax, with a little tolerance const m = new Message(MessageCode.WARNING_RAMP_WIDTH_LOWER_THAN_PATTERN_WIDTH); m.extraVar.pattern = ax; this._result.resultElement.log.add(m); - } else if (this.prms.BR.v % (ax / 2) > 0.001 && this.prms.BR.v % (ax / 2) < ax / 2 - 0.001) { + } else if (this.prms.BR.v % (ax / 2) > tol && this.prms.BR.v % (ax / 2) < ax / 2 - tol) { const m = new Message(MessageCode.WARNING_RAMP_WIDTH_NOT_MULTIPLE_OF_HALF_PATTERN_WIDTH); m.extraVar.halfPattern = ax / 2; m.extraVar.lower = Math.floor(this.prms.BR.v / ax * 2) * (ax / 2); diff --git a/src/macrorugo/macrorugo_params.ts b/src/macrorugo/macrorugo_params.ts index 859dbc19248258979510ca0451cf1646dde09edd..d36b2f9915d5671c0a9d3e36f4f683a1771818a8 100644 --- a/src/macrorugo/macrorugo_params.ts +++ b/src/macrorugo/macrorugo_params.ts @@ -77,10 +77,10 @@ export class MacrorugoParams extends ParamsEquation { this._Ks = new ParamDefinition(this, "Ks", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "m", rRF, ParamFamily.STRICKLERS, undefined, nullParams); this.addParamDefinition(this._Ks); - this._C = new ParamDefinition(this, "C", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "", rCB, undefined, undefined, nullParams); + this._C = new ParamDefinition(this, "C", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "", rCB, ParamFamily.BLOCKCONCENTRATION, undefined, nullParams); this.addParamDefinition(this._C); - this._PBD = new ParamDefinition(this, "PBD", new ParamDomain(ParamDomainValue.INTERVAL, 0, 2), "m", rPBD, undefined, undefined, nullParams); + this._PBD = new ParamDefinition(this, "PBD", new ParamDomain(ParamDomainValue.INTERVAL, 0, 2), "m", rPBD, ParamFamily.DIAMETERS, undefined, nullParams); this.addParamDefinition(this._PBD); this._PBH = new ParamDefinition(this, "PBH", ParamDomainValue.POS, "m", rPBH, ParamFamily.HEIGHTS, undefined, nullParams); diff --git a/src/open-channel/remous.ts b/src/open-channel/remous.ts index 2e2f15a8031fce2e5c5087d6706383ae3df67570..7eab9c0c23ed1d8b7e9691b29f30874fd70dd649 100644 --- a/src/open-channel/remous.ts +++ b/src/open-channel/remous.ts @@ -757,7 +757,7 @@ export class CourbeRemous extends SectionNub { } // let k2 = this.Calc_dYdX(Y + Dx / 2 * k1); - const rDXDY2: Result = this.Calc_dYdX(Y + rDx / 2 * k1); + const rDXDY2: Result = this.Calc_dYdX(Math.max(Y + rDx / 2 * k1, 0)); if (!rDXDY2.ok) { return rDXDY2; } @@ -768,7 +768,7 @@ export class CourbeRemous extends SectionNub { } // let k3 = this.Calc_dYdX(Y + Dx / 2 * k2); - const rDXDY3: Result = this.Calc_dYdX(Y + rDx / 2 * k2); + const rDXDY3: Result = this.Calc_dYdX(Math.max(Y + rDx / 2 * k2, 0)); if (!rDXDY3.ok) { return rDXDY3; } @@ -779,14 +779,14 @@ export class CourbeRemous extends SectionNub { } // let k4 = this.Calc_dYdX(Y + Dx * k3); - const rDXDY4: Result = this.Calc_dYdX(Y + rDx * k3); + const rDXDY4: Result = this.Calc_dYdX(Math.max(Y + rDx * k3, 0)); if (!rDXDY4.ok) { return rDXDY4; } const k4 = rDXDY4.vCalc; // tslint:disable-next-line:variable-name - const Yout = Y + rDx / 6 * (k1 + 2 * (k2 + k3) + k4); + const Yout = Math.max(Y + rDx / 6 * (k1 + 2 * (k2 + k3) + k4), 0); // if ($this ->rDx > 0 xor !($Yout < $this ->oSect ->rHautCritique)) { return false; } if (XOR(rDx > 0, !(Yout < hc))) { diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index b476c28e9fd31a57095e91d4689c0320e5ac8c84..42e706c9de50cb3f57487038a2add8b15cdf9feb 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -42,7 +42,8 @@ export enum ParamFamily { FLOWS, // débit DIAMETERS, SPEEDS, // vitesses, seulement des résultats - STRICKLERS + STRICKLERS, + BLOCKCONCENTRATION // concentrations de blocs } /**