macrorugo.spec.ts 6.16 KB
Newer Older
1
import { ParamCalculability, ParamValueMode, Session } from "../../src/index";
2
3
import { MacroRugo, MacroRugoFlowType } from "../../src/macrorugo/macrorugo";
import { MacrorugoParams } from "../../src/macrorugo/macrorugo_params";
4
import { checkResult } from "../test_func";
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
*** Emergent conditions Cd=1.5***
ks=0.010000
D=0.500000
k=0.700000
Cd0=1.500000
S=0.050000
B=1.000000
h=0.600000
C=0.130000
Q=0.493722  fVal=0.000000
cote_bas = 12.200000
Vdeb = 0.822870
Fr = 0.530417
P = 242.170537
flowcond = emergent
Vmax = 1.799472
V_technique = 1.991299
q_technique = 0.561860
 */

function macroRugoInstanceEmergentCd15(): MacroRugo {
28
29
30
31
32
33
    return new MacroRugo(
        new MacrorugoParams(
            12.5,   // ZF1
            6,      // L
            1,      // B
            0.05,   // If
34
            0.493722,    // Q
35
36
            0.6,    // h
            0.01,   // Ks
37
            0.13,   // C
38
            0.5,    // D
39
            0.7,    // k
40
41
42
43
44
            1.5     // Cd0
        )
    );
}

45
46
const macroRugoExtraResultEmergentCd15: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
47
48
    Fr: 0.530425,
    PV: 242.174003,
49
50
    Q_GuideTech: 0.561860,
    V_GuideTech: 1.991299,
51
52
    Vdeb: 0.822881,
    Vmax: 1.799502,
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    ZF2: 12.2
};

/*
*** Emergent conditions Cd=2***
ks=0.010000
D=0.500000
k=0.700000
Cd0=2.000000
S=0.050000
B=1.000000
h=0.600000
C=0.130000
Q=0.376808  fVal=0.000000
cote_bas = 12.200000
Vdeb = 0.628013
Fr = 0.404814
P = 184.824088
flowcond = emergent
Vmax = 1.536115
V_technique = 1.592932
q_technique = 0.414154
 */

function macroRugoInstanceEmergentCd2(): MacroRugo {
    const nub: MacroRugo = macroRugoInstanceEmergentCd15();
Dorchies David's avatar
Dorchies David committed
79
80
    nub.prms.Cd0.singleValue = 2;
    nub.prms.Q.singleValue = 0.376808;
81
82
83
84
85
    return nub;
}

const macroRugoExtraResultEmergentCd2: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
86
87
    Fr: 0.404817,
    PV: 184.825734,
88
89
    Q_GuideTech: 0.414154,
    V_GuideTech: 1.592932,
90
91
    Vdeb: 0.628018,
    Vmax: 1.536129,
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    ZF2: 12.2
};

/*
*** Submerged conditions ***
ks=0.010000
D=0.500000
k=0.700000
Cd0=1.500000
S=0.050000
B=1.000000
h=0.800000
C=0.130000
Q=0.908068  fVal=0.000000
cote_bas = 12.200000
Vdeb = 1.135085
Fr = 0.633645
P = 445.407266
flowcond = immerge
q_technique = 0.940450
 */

114
function macroRugoInstanceSubmerged(): MacroRugo {
115
    const nub: MacroRugo = macroRugoInstanceEmergentCd15();
Dorchies David's avatar
Dorchies David committed
116
117
    nub.prms.Y.singleValue = 0.8;
    nub.prms.Q.singleValue = 0.908068;
118
119
120
    return nub;
}

121
122
123
124
125
126
127
128
129
130
const macroRugoExtraResultSubmerged: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED,
    Fr: 0.633645,
    PV: 445.407266,
    Q_GuideTech: 0.940450,
    Vdeb: 1.135085,
    ZF2: 12.2
};

function MacroRugoFactory(sInstance: string): MacroRugo {
Dorchies David's avatar
Dorchies David committed
131
    let nub: MacroRugo;
132
133
    switch (sInstance) {
        case "EmergentCd15": {
Dorchies David's avatar
Dorchies David committed
134
135
            nub = macroRugoInstanceEmergentCd15();
            break;
136
137
        }
        case "EmergentCd2": {
Dorchies David's avatar
Dorchies David committed
138
139
            nub = macroRugoInstanceEmergentCd2();
            break;
140
141
        }
        case "Submerged": {
Dorchies David's avatar
Dorchies David committed
142
143
            nub = macroRugoInstanceSubmerged();
            break;
144
145
146
147
148
        }
        default: {
            throw new Error("Instance name error");
        }
    }
Dorchies David's avatar
Dorchies David committed
149
150
151
152
    for (const p of nub.parameterIterator) {
        p.v = p.singleValue;
    }
    return nub;
153
154
155
156
157
}

function testMacroRugo(sInstance: string, varTest: string, valRef: number) {
        it(`Calc(${varTest}) should be ${valRef}`, () => {
            const nub = MacroRugoFactory(sInstance);
158
            nub.prms.Q.v = nub.Calc("Q").vCalc;
159
160
161
            const p = nub.getParameter(varTest);
            p.v = undefined;
            p.valueMode = ParamValueMode.CALCUL;
162
163
            const r = nub.Calc(varTest, 0.1);
            checkResult(r, valRef);
164
165
166
        });
}

167
function testMacroRugoConfig(sInstance: string, Q0: number, fVal0: number, mrExtraRes: { [key: string]: number }) {
168
    describe(`Condition ${sInstance}` , () => {
169
170
        it(`resolveQ(${Q0}) should be ${fVal0}`, () => {
            const nubit = MacroRugoFactory(sInstance);
Dorchies David's avatar
Dorchies David committed
171
            nubit.prms.Q.v = Q0;
172
            // tslint:disable-next-line:no-string-literal
Dorchies David's avatar
Dorchies David committed
173
            expect(nubit["resolveQ"]()).toBeCloseTo(fVal0, 5);
174
        });
175
        const nub = MacroRugoFactory(sInstance);
176
177
        for (const prm of nub.prms) {
            if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) {
178
179
180
181
182
183
                testMacroRugo(sInstance, prm.symbol, prm.v);
            }
        }
        for (const sExtraRes in mrExtraRes) {
            if (mrExtraRes.hasOwnProperty(sExtraRes)) {
                it(`${sExtraRes} should be ${mrExtraRes[sExtraRes]}`, () => {
184
                    expect(MacroRugoFactory(sInstance).Calc("Q").values[sExtraRes])
185
186
                    .toBeCloseTo(mrExtraRes[sExtraRes], 5);
                });
187
            }
188
        }
189
    });
190
}
191

192
193
describe("Class MacroRugo: ", () => {

194
195
    testMacroRugoConfig("EmergentCd15", 0.901710, 0.379539, macroRugoExtraResultEmergentCd15);
    testMacroRugoConfig("EmergentCd2", 0.768677, 0.418029, macroRugoExtraResultEmergentCd2);
196
197
198
199
200
201
202
    // 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);
    //     });
    // });
203
    testMacroRugoConfig("Submerged", 1.202280, 0.145051, macroRugoExtraResultSubmerged);
Dorchies David's avatar
Dorchies David committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

    describe("JalHyd #85", () => {
        it("CalcSerie Q should return the goog result :)", () => {
            const nubMR = macroRugoInstanceEmergentCd2();
            nubMR.prms.C.singleValue = 0.2;
            nubMR.prms.PBH.singleValue = 0.8;
            nubMR.calculatedParam = nubMR.prms.Q;

            nubMR.prms.Y.setValues(0.7, 1.2, 0.1);
            const aQ: number[] = [ 0.363679, 0.433841, 0.595482, 0.768310, 0.991123, 1.441876 ];

            nubMR.CalcSerie();
            for (let i = 0; i < aQ.length; i++) {
                expect(nubMR.result.resultElements[i].vCalc).toBeCloseTo(aQ[i], 4);
            }
        });
    });
221
});