macrorugo.spec.ts 6.76 KiB
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.***
*** INPUT ***
ks: 0.010000,
D: 0.500000,
k = 0.600000
Cd0: 1.000000,
S: 0.050000,
B: 1.000000,
h: 0.400000,
C: 0.130000,
RESULTS:
find_Q_nat(0.736243)=0.625925
Q=0.485873  fVal=0.000000
ZF2: 12.200000,
Vdeb: 1.214683,
Vg: 1.899590,
Fr: 0.958949,
PV: 595.801953,
flowcond: emergent,
Vmax: 1.953423,
V_technique: 1.748990,
q_technique: 0.312101,
Strickler: 10.006248
function macroRugoInstanceEmergentCd1(): MacroRugo {
    return new MacroRugo(
        new MacrorugoParams(
            12.5,   // ZF1
            6,      // L
            1,      // B
            0.05,   // If
            0.485873,    // Q
            0.4,    // h
            0.01,   // Ks
            0.13,   // C
            0.5,    // D
            0.6,    // k
            1     // Cd0
const macroRugoExtraResultEmergentCd1: { [key: string]: number | MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
    ZF2: 12.200000,
    Vdeb: 1.214683,
    Vg: 1.899590,
    Fr: 0.958949,
    PV: 595.801953,
    Vmax: 1.953423,
    Strickler: 10.006248
*** Emergent conditions Cd=2***
*** INPUT ***
ks: 0.010000,
D: 0.500000,
k = 0.600000
Cd0: 2.000000,
S: 0.050000,
B: 1.000000,
h: 0.400000,
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
C: 0.130000, RESULTS: find_Q_nat(0.512451)=0.610003 Q=0.268450 fVal=0.000000 ZF2: 12.200000, Vdeb: 0.671125, Vg: 1.049543, Fr: 0.529829, PV: 329.186776, flowcond: emergent, Vmax: 1.580263, V_technique: 1.427752, q_technique: 0.266857, Strickler: 5.528556 */ function macroRugoInstanceEmergentCd2(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd1(); nub.prms.Cd0.singleValue = 2; nub.prms.Q.singleValue = 0.268450; return nub; } const macroRugoExtraResultEmergentCd2: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT, ZF2: 12.200000, Vdeb: 0.671125, Vg: 1.049543, Fr: 0.529829, PV: 329.186776, Vmax: 1.580263, Strickler: 5.528556 }; /* *** Submerged conditions Cd=1*** *** INPUT *** ks: 0.010000, D: 0.500000, k = 0.600000 Cd0: 1.000000, S: 0.050000, B: 1.000000, h: 0.800000, C: 0.130000, RESULTS: find_Q_nat(1.472487)=0.092897 Q=1.546804 fVal=0.000000 ZF2: 12.200000, Vdeb: 1.933505, Vg: 3.023725, Fr: 1.079351, PV: 948.384279, flowcond: immerge, q_technique: 1.060933, Strickler: 10.033836, */ function macroRugoInstanceSubmerged(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd1(); nub.prms.Y.singleValue = 0.8; nub.prms.Q.singleValue = 1.546804; return nub; } const macroRugoExtraResultSubmerged: { [key: string]: number | MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED, ZF2: 12.200000, Vdeb: 1.933505, PV: 948.384279,
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
Strickler: 10.033836 }; 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(Math.abs(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;
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
nubMR.prms.PBH.singleValue = 0.8; nubMR.calculatedParam = nubMR.prms.Q; return nubMR; } xdescribe("Class MacroRugo: ", () => { testMacroRugoConfig("EmergentCd1", 0.736243, 0.625925, macroRugoExtraResultEmergentCd1); testMacroRugoConfig("EmergentCd2", 0.512451, 0.610003, 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.472487, 0.092897, 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.656297, 0.778636, 1.211155, 1.523789, 1.902439, 2.345380]; 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); } }); }); });