diff --git a/spec/pipe_flow/lechaptcalmon.spec.ts b/spec/pipe_flow/lechaptcalmon.spec.ts index a354e7cbd4b020123a150bea12b5085706299621..7dd97ca93aae0ee2cc53b4fabd395e572fd4e27a 100644 --- a/spec/pipe_flow/lechaptcalmon.spec.ts +++ b/spec/pipe_flow/lechaptcalmon.spec.ts @@ -1,66 +1,48 @@ +import { ParamCalculability } from "../../src/param/param-definition"; import { LechaptCalmon } from "../../src/pipe_flow/lechaptcalmon"; import { LechaptCalmonParams } from "../../src/pipe_flow/lechaptcalmon_params"; -import { checkResult } from "../test_func"; - -let lechapt: LechaptCalmon; -let prms: LechaptCalmonParams; +import { SessionSettings } from "../../src/session_settings"; + +function getLechapt(): LechaptCalmon { + const l = new LechaptCalmon( + new LechaptCalmonParams( + 0.3, // débit + 0.5, // diamètre + 0.1, /// perte de charge + 20, // longueur du toyo + 1.863, // paramètre L du matériau + 2, // paramètre M du matériau + 5.33, // paramètre N du matériau + 1 // Ks + ) + ); + l.calculatedParam = l.prms.J; + l.prms.J.singleValue = l.CalcSerie().vCalc; + return l; +} + +let lechapt: LechaptCalmon = getLechapt(); describe("Class LechaptCalmon : ", () => { - describe("Calc() : ", () => { - it("Q should be 2.917", () => { - prms = new LechaptCalmonParams(undefined, // débit - 1.2, // diamètre - 0.6, /// perte de charge - 100, // longueur du toyo - 1.863, // paramètre L du matériau - 2, // paramètre M du matériau - 5.33// paramètre N du matériau - ); - lechapt = new LechaptCalmon(prms); - - checkResult(lechapt.Calc("Q", 0), 2.917); - }); - - it("D should be 1.213", () => { - prms = new LechaptCalmonParams(3, // débit - undefined, // diamètre - 0.6, /// perte de charge - 100, // longueur du toyo - 1.863, // paramètre L du matériau - 2, // paramètre M du matériau - 5.33// paramètre N du matériau - ); - lechapt = new LechaptCalmon(prms); - - checkResult(lechapt.Calc("D", 0), 1.213); - }); - - it("J should be 0.634", () => { - prms = new LechaptCalmonParams(3, // débit - 1.2, // diamètre - undefined, /// perte de charge - 100, // longueur du toyo - 1.863, // paramètre L du matériau - 2, // paramètre M du matériau - 5.33// paramètre N du matériau - ); - lechapt = new LechaptCalmon(prms); - - checkResult(lechapt.Calc("J", 0), 0.634); - }); - - it("Lg should be 94.565", () => { - prms = new LechaptCalmonParams(3, // débit - 1.2, // diamètre - 0.6, /// perte de charge - undefined, // longueur du toyo - 1.863, // paramètre L du matériau - 2, // paramètre M du matériau - 5.33// paramètre N du matériau - ); - lechapt = new LechaptCalmon(prms); - - checkResult(lechapt.Calc("Lg", 0), 94.565); - }); + beforeEach(() => { + lechapt = getLechapt(); }); + for (const p of lechapt.parameterIterator) { + if ([ParamCalculability.EQUATION, ParamCalculability.DICHO].includes(p.calculability) && p.visible) { + it(`Calc(${p.symbol}) should return ${p.currentValue}`, () => { + lechapt.calculatedParam = lechapt.getParameter(p.symbol); + const ref: number = p.currentValue; + const V: number = lechapt.result.values.V; + const Jl: number = lechapt.result.values.Jl; + const Kl: number = lechapt.result.values.Kl; + const fD: number = lechapt.result.values.fD; + lechapt.calculatedParam.singleValue = lechapt.calculatedParam.singleValue / 2; + expect(lechapt.CalcSerie().vCalc).toBeCloseTo(ref, 2); + expect(lechapt.result.values.V).toBeCloseTo(V, 3); + expect(lechapt.result.values.Jl).toBeCloseTo(Jl, 3); + expect(lechapt.result.values.Kl).toBeCloseTo(Kl, 3); + expect(lechapt.result.values.fD).toBeCloseTo(fD, 3); + }); + } + } }); diff --git a/src/pipe_flow/lechaptcalmon.ts b/src/pipe_flow/lechaptcalmon.ts index 5181f3c5c6fc493b44a985d2a3c22a458673e061..9dc511f30e189d917a4980d055ebfa3fe3818a34 100644 --- a/src/pipe_flow/lechaptcalmon.ts +++ b/src/pipe_flow/lechaptcalmon.ts @@ -86,35 +86,29 @@ export class LechaptCalmon extends Nub implements Observer { return this._prms as LechaptCalmonParams; } + public Calc(sVarCalc: string, rInit?: number): Result { + const r = super.Calc(sVarCalc, rInit); + const V2 = Math.pow(r.values.V, 2); + r.values.Kl = 19.62 * r.values.Jl / V2; + r.values.fD = this.prms.J.V / this.prms.Lg.V / V2 * 19.62 * this.prms.D.V; + return r; + } + public Equation(sVarCalc: string): Result { - let v: number; - - switch (sVarCalc) { - case "Q": - v = Math.pow((((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) / this.prms.L.v) - * (1000 / this.prms.Lg.v)), 1 / this.prms.M.v); - break; - - case "D": - v = Math.pow((((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / this.prms.J.v) - * (this.prms.Lg.v / 1000)), 1 / this.prms.N.v); - break; - - case "J": - v = ((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / Math.pow(this.prms.D.v, this.prms.N.v)) - * (this.prms.Lg.v / 1000); - break; - - case "Lg": - v = ((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) - / (this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v))) * 1000; - break; - - default: - throw new Error("LechaptCalmon.Equation() : invalid variable name " + sVarCalc); + + if (sVarCalc !== "J") { + throw new Error("LechaptCalmon.Equation() : invalid variable name " + sVarCalc); } - return new Result(v, this); + const r: Result = new Result(0, this); + + r.values.V = this.prms.Q.v / (Math.PI * Math.pow(this.prms.D.v / 2, 2)); + r.values.Jl = this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v) + / Math.pow(this.prms.D.v, this.prms.N.v) * (this.prms.Lg.v / 1000); + + r.vCalc = r.values.Jl + this.prms.Ks.v / 19.62 * Math.pow(r.values.V, 2); + + return r; } public setMaterial(material: LCMaterial) { @@ -133,10 +127,11 @@ export class LechaptCalmon extends Nub implements Observer { * paramétrage de la calculabilité des paramètres */ protected setParametersCalculability() { - this.prms.Q.calculability = ParamCalculability.EQUATION; - this.prms.D.calculability = ParamCalculability.EQUATION; + this.prms.Q.calculability = ParamCalculability.DICHO; + this.prms.D.calculability = ParamCalculability.DICHO; this.prms.J.calculability = ParamCalculability.EQUATION; - this.prms.Lg.calculability = ParamCalculability.EQUATION; + this.prms.Lg.calculability = ParamCalculability.DICHO; + this.prms.Ks.calculability = ParamCalculability.DICHO; this.prms.L.calculability = ParamCalculability.FIXED; this.prms.M.calculability = ParamCalculability.FIXED; this.prms.N.calculability = ParamCalculability.FIXED; diff --git a/src/pipe_flow/lechaptcalmon_params.ts b/src/pipe_flow/lechaptcalmon_params.ts index dbe8ebd447eb0e29764637d1ca86a54293081d98..7b5db0318dea03f4c7209369880b05b95032a768 100644 --- a/src/pipe_flow/lechaptcalmon_params.ts +++ b/src/pipe_flow/lechaptcalmon_params.ts @@ -27,13 +27,16 @@ export class LechaptCalmonParams extends ParamsEquation { /** Paramètre de rugosité N */ private _N: ParamDefinition; - constructor(rQ: number, rD: number, rJ: number, rLg: number, rL: number, rM: number, rN: number) { + /** Perte de charge singulière Ks */ + private _Ks: ParamDefinition; + + constructor(rQ: number, rD: number, rJ: number, rLg: number, rL: number, rM: number, rN: number, rKs: number) { super(); - this._Q = new ParamDefinition(this, "Q", ParamDomainValue.POS, "m³/s", rQ, ParamFamily.FLOWS); + this._Q = new ParamDefinition(this, "Q", ParamDomainValue.POS_NULL, "m³/s", rQ, ParamFamily.FLOWS); this._D = new ParamDefinition( this, "D", new ParamDomain(ParamDomainValue.INTERVAL, 0, 20), "m", rD, ParamFamily.DIAMETERS ); - this._J = new ParamDefinition(this, "J", ParamDomainValue.POS, "m", rJ); + this._J = new ParamDefinition(this, "J", ParamDomainValue.POS_NULL, "m", rJ); this._Lg = new ParamDefinition(this, "Lg", ParamDomainValue.POS, "m", rLg, ParamFamily.LENGTHS); this._L = new ParamDefinition(this, "L", new ParamDomain(ParamDomainValue.INTERVAL, 0.8, 2), undefined, rL, undefined, false); @@ -41,6 +44,7 @@ export class LechaptCalmonParams extends ParamsEquation { undefined, false); this._N = new ParamDefinition(this, "N", new ParamDomain(ParamDomainValue.INTERVAL, 4.5, 5.5), undefined, rN, undefined, false); + this._Ks = new ParamDefinition(this, "Ks", ParamDomainValue.POS_NULL, undefined, rKs); this.addParamDefinition(this._Q); this.addParamDefinition(this._D); @@ -49,6 +53,7 @@ export class LechaptCalmonParams extends ParamsEquation { this.addParamDefinition(this._L); this.addParamDefinition(this._M); this.addParamDefinition(this._N); + this.addParamDefinition(this._Ks); } get Q() { @@ -78,4 +83,8 @@ export class LechaptCalmonParams extends ParamsEquation { get N() { return this._N; } + + get Ks() { + return this._Ks; + } } diff --git a/src/session.ts b/src/session.ts index aae284cb409567b4207a8cd7125a99920e02a11a..a3fe3a2c8130ff698cb6f6644788056c9fb230a2 100644 --- a/src/session.ts +++ b/src/session.ts @@ -375,7 +375,8 @@ export class Session { 100, // longueur du toyo 1.863, // paramètre L du matériau 2, // paramètre M du matériau - 5.33// paramètre N du matériau + 5.33, // paramètre N du matériau + 0 // Ks Perte de charge singulière ); nub = new LechaptCalmon(prms, dbg); break;