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.1003*** *** INPUT *** ks: 0.010000, D: 0.500000, k = 0.700000 Cd0: 1.100300, S: 0.050000, B: 1.000000, h: 0.600000, C: 0.130000, RESULTS: find_Q_nat(1.052827)=0.600769 Q=0.692366 fVal=0.000000 ZF2: 12.200000, Vdeb: 1.153943, Vg: 1.804601, Fr: 0.743826, PV: 566.009124, flowcond: emergent, Vmax: 2.673506, V_technique: 1.991299, q_technique: 0.561860, Strickler: 7.254351, */ function macroRugoInstanceEmergentCd1(): MacroRugo { return new MacroRugo( new MacrorugoParams( 12.5, // ZF1 6, // L 1, // B 0.05, // If 0.692366, // Q 0.6, // h 0.01, // Ks 0.13, // C 0.5, // D 0.7, // k 1 // Cd0 ) ); } const macroRugoExtraResultEmergentCd1: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT, ZF2: 12.200000, Vdeb: 1.153943, Vg: 1.804601, Fr: 0.743826, PV: 566.009124, Vmax: 2.673506, Strickler: 7.254351 }; /* ** Emergent conditions Cd=2.592*** *** INPUT *** ks: 0.010000, D: 0.500000, k = 0.700000 Cd0: 2.592000, S: 0.050000, B: 1.000000, h: 0.600000, C: 0.130000, RESULTS: find_Q_nat(0.675214)=0.321449 Q=0.482344 fVal=0.000000 ZF2: 12.200000, Vdeb: 0.803907, Vg: 1.257195, Fr: 0.518194, PV: 394.316317, flowcond: emergent, Vmax: 2.166970, V_technique: 1.991299, q_technique: 0.561860, Strickler: 5.053822 */ function macroRugoInstanceEmergentCd2(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd1(); nub.prms.Cd0.singleValue = 2; nub.prms.Q.singleValue = 0.481698; return nub; } const macroRugoExtraResultEmergentCd2: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT, ZF2: 12.200000, Vdeb: 0.803907, Vg: 1.257195, Fr: 0.518194, PV: 394.316317, Vmax: 2.166970, Strickler: 5.053822 }; /* ** Submerged conditions Cd=1.1003*** *** INPUT *** ks: 0.010000, D: 0.500000, k = 0.700000 Cd0: 1.100300, S: 0.050000, B: 1.000000, h: 0.800000, C: 0.130000, RESULTS: find_Q_nat(1.403770)=0.143414 Q=1.289038 fVal=0.000000 ZF2: 12.200000, Vdeb: 1.611298, Vg: 2.519839, Fr: 0.899484, PV: 790.341606, flowcond: immerge, q_technique: 0.940450, Strickler: 8.361756 */ function macroRugoInstanceSubmerged(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd1(); nub.prms.Y.singleValue = 0.8; nub.prms.Q.singleValue = 1.289038; return nub; } const macroRugoExtraResultSubmerged: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED, ZF2: 12.200000, Vdeb: 1.611298, PV: 790.341606, Strickler: 8.361756 }; function MacroRugoFactory(sInstance: string): MacroRugo { let nub: MacroRugo; switch (sInstance) { case "EmergentCd1": { nub = macroRugoInstanceEmergentCd1(); break; } case "EmergentCd2": { nub = macroRugoInstanceEmergentCd2(); 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 = macroRugoInstanceEmergentCd1(); nubMR.prms.C.singleValue = 0.2; nubMR.prms.PBH.singleValue = 0.8; nubMR.calculatedParam = nubMR.prms.Q; return nubMR; } describe("Class MacroRugo: ", () => { testMacroRugoConfig("EmergentCd1", 1.052827, 0.600769, macroRugoExtraResultEmergentCd1); testMacroRugoConfig("EmergentCd2", 0.675214, 0.321449, macroRugoExtraResultEmergentCd2); // 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.403770, 0.143414, 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.688476, 0.824387, 1.166239, 1.475853, 1.850393, 2.288123]; 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); } }); }); });