import { 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"; /* *** Emergent conditions Cd=1.1*** *** INPUT *** ks = 0.010000 D = 0.500000 k = 0.700000 Cd0 = 1.100000 S = 0.050000 B = 1.000000 h = 0.600000 C = 0.130000 RESULTS: find_Q_nat(1.052971)=0.600890 Q=0.692437 fVal=0.000000 cote_bas = 12.200000 Vdeb = 1.154061 Vg: 1.804786, Fr = 0.743902 P = 566.066964 flowcond = emergent Vmax = 2.673954 V_technique = 1.991299 q_technique = 0.561860 Strickler = 7.255093 */ function macroRugoInstanceEmergentCd11(): MacroRugo { return new MacroRugo( new MacrorugoParams( 12.5, // ZF1 6, // L 1, // B 0.05, // If 0.692437, // Q 0.6, // h 0.01, // Ks 0.13, // C 0.5, // D 0.7, // k 1.1 // Cd0 ) ); } const macroRugoExtraResultEmergentCd11: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT, ZF2: 12.200000, Vdeb: 1.154061, Vg: 1.804786, Fr: 0.743902, PV: 566.066964, Vmax: 2.673954, Strickler: 7.255093 }; /* ** Emergent conditions Cd=2.6*** *** INPUT *** ks: 0.010000, D: 0.500000, k = 0.700000 Cd0: 2.600000, S: 0.050000, B: 1.000000, h: 0.600000, C: 0.130000, RESULTS: find_Q_nat(0.674174)=0.320793 Q=0.481698 fVal=0.000000 ZF2: 12.200000, Vdeb: 0.802831, Vg: 1.255512, Fr: 0.517500, PV: 393.788411, flowcond: emergent, Vmax: 2.163235, V_technique: 1.991299, q_technique: 0.561860, Strickler: 5.047056 */ function macroRugoInstanceEmergentCd26(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd11(); nub.prms.Cd0.singleValue = 2.6; nub.prms.Q.singleValue = 0.481698; return nub; } const macroRugoExtraResultEmergentCd26: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT, ZF2: 12.200000, Vdeb: 0.802831, Vg: 1.255512, Fr: 0.517500, PV: 393.788411, Vmax: 2.163235, Strickler: 5.047056 }; /* *** Submerged conditions Cd=1.1*** *** INPUT *** ks: 0.010000, D: 0.500000, k = 0.700000 Cd0: 1.100000, S: 0.050000, B: 1.000000, h: 0.800000, C: 0.130000, RESULTS: find_Q_nat(1.403961)=0.143445 Q=1.289205 fVal=0.000000 ZF2: 12.200000, Vdeb: 1.611506, Vg: 2.520165, Fr: 0.899600, PV: 790.443862, flowcond: immerge, q_technique: 0.940450, Strickler: 8.362838 */ function macroRugoInstanceSubmerged(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd11(); nub.prms.Y.singleValue = 0.8; nub.prms.Q.singleValue = 1.289205; return nub; } const macroRugoExtraResultSubmerged: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED, ZF2: 12.200000, Vdeb: 1.611506, Vg: 2.520165, Fr: 0.899600, PV: 790.443862, Strickler: 8.362838 }; function MacroRugoFactory(sInstance: string): MacroRugo { let nub: MacroRugo; switch (sInstance) { case "EmergentCd11": { nub = macroRugoInstanceEmergentCd11(); break; } case "EmergentCd26": { nub = macroRugoInstanceEmergentCd26(); break; } case "Submerged": { nub = macroRugoInstanceSubmerged(); break; } default: { throw new Error("Instance name error"); } } for (const p of nub.parameterIterator) { p.v = p.singleValue; } return nub; } function testMacroRugo(sInstance: string, varTest: string, valRef: number) { it(`Calc(${varTest}) should be ${valRef}`, () => { const nub = MacroRugoFactory(sInstance); nub.prms.Q.v = nub.Calc("Q").vCalc; const p = nub.getParameter(varTest); p.v = undefined; p.valueMode = ParamValueMode.CALCUL; const r = nub.Calc(varTest, 0.1); checkResult(r, valRef); }); } function testMacroRugoConfig(sInstance: string, Q0: number, fVal0: number, mrExtraRes: { [key: string]: number }) { describe(`Condition ${sInstance}`, () => { it(`resolveQ(${Q0}) should be ${fVal0}`, () => { const nubit = MacroRugoFactory(sInstance); nubit.prms.Q.v = Q0; // tslint:disable-next-line:no-string-literal nubit["setFlowType"](); // tslint:disable-next-line:no-string-literal expect(nubit["resolveQ"]()).toBeCloseTo(fVal0, 5); }); const nub = MacroRugoFactory(sInstance); for (const prm of nub.prms) { if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) { testMacroRugo(sInstance, prm.symbol, prm.v); } } for (const sExtraRes in mrExtraRes) { if (mrExtraRes.hasOwnProperty(sExtraRes)) { it(`${sExtraRes} should be ${mrExtraRes[sExtraRes]}`, () => { expect(MacroRugoFactory(sInstance).Calc("Q").values[sExtraRes]) .toBeCloseTo(mrExtraRes[sExtraRes], 3); }); } } }); } function macroRugoInstanceJalHyd85(): MacroRugo { const nubMR = macroRugoInstanceEmergentCd11(); nubMR.prms.C.singleValue = 0.2; nubMR.prms.PBH.singleValue = 0.8; nubMR.calculatedParam = nubMR.prms.Q; return nubMR; } describe("Class MacroRugo: ", () => { testMacroRugoConfig("EmergentCd11", 1.052971, 0.600890, macroRugoExtraResultEmergentCd11); testMacroRugoConfig("EmergentCd26", 0.674174, 0.320793, macroRugoExtraResultEmergentCd26); // Le test passe en debug mais pas sous Jasmine !?? // describe(`Condition Submerged` , () => { // it(`resolveAlpha_t(0.07) should be 0.074752`, () => { // // tslint:disable-next-line:no-string-literal // expect(macroRugoInstanceSubmerged()["resolveAlpha_t"](0.07)).toBeCloseTo(0.074752, 5); // }); // }); testMacroRugoConfig("Submerged", 1.403961, 0.143445, macroRugoExtraResultSubmerged); describe("JalHyd #85", () => { it("CalcSerie Q should return the good result :)", () => { const nubMR = macroRugoInstanceJalHyd85(); const nubMR2 = macroRugoInstanceJalHyd85(); nubMR.prms.Y.setValues(0.7, 1.2, 0.1); const aQ: number[] = [0.6885501, 0.8244762, 1.1663925, 1.4760379, 1.8506109, 2.2883764]; nubMR.CalcSerie(); for (let i = 0; i < aQ.length; i++) { expect(nubMR.result.resultElements[i].vCalc).toBeCloseTo(aQ[i], 4); nubMR2.prms.Y.setValue(0.7 + i * 0.1); expect(nubMR2.CalcSerie().vCalc).toBeCloseTo(aQ[i], 4); } }); }); });