macrorugo.spec.ts 6.36 KB
Newer Older
1
2
3
4
5
6
7
8
/**
 * IMPORTANT !
 * Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
 * Pour exécuter ce code dans le débugger.
 * Faire de même avec le fichier test_func.ts
 */
// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";

9
import { ParamCalculability, ParamValueMode } from "../../src/index";
10
import { MacroRugo, MacroRugoFlowType, MacrorugoParams } from "../../src/macrorugo/macrorugo";
11
import { checkResult } from "../test_func";
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
*** 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 {
35
36
37
38
39
40
    return new MacroRugo(
        new MacrorugoParams(
            12.5,   // ZF1
            6,      // L
            1,      // B
            0.05,   // If
41
            0.493722,    // Q
42
43
            0.6,    // h
            0.01,   // Ks
44
            0.13,   // C
45
            0.5,    // D
46
            0.7,    // k
47
48
49
50
51
            1.5     // Cd0
        )
    );
}

52
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
79
80
81
82
83
84
85
const macroRugoExtraResultEmergentCd15: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
    Fr: 0.530417,
    PV: 242.170537,
    Q_GuideTech: 0.561860,
    V_GuideTech: 1.991299,
    Vdeb: 0.822870,
    Vmax: 1.799472,
    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
86
87
    nub.prms.Cd0.singleValue = 2;
    nub.prms.Q.singleValue = 0.376808;
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    return nub;
}

const macroRugoExtraResultEmergentCd2: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
    Fr: 0.404814,
    PV: 184.824088,
    Q_GuideTech: 0.414154,
    V_GuideTech: 1.592932,
    Vdeb: 0.628013,
    Vmax: 1.536115,
    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
 */

121
function macroRugoInstanceSubmerged(): MacroRugo {
122
    const nub: MacroRugo = macroRugoInstanceEmergentCd15();
Dorchies David's avatar
Dorchies David committed
123
124
    nub.prms.Y.singleValue = 0.8;
    nub.prms.Q.singleValue = 0.908068;
125
126
127
    return nub;
}

128
129
130
131
132
133
134
135
136
137
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
138
    let nub: MacroRugo;
139
140
    switch (sInstance) {
        case "EmergentCd15": {
Dorchies David's avatar
Dorchies David committed
141
142
            nub = macroRugoInstanceEmergentCd15();
            break;
143
144
        }
        case "EmergentCd2": {
Dorchies David's avatar
Dorchies David committed
145
146
            nub = macroRugoInstanceEmergentCd2();
            break;
147
148
        }
        case "Submerged": {
Dorchies David's avatar
Dorchies David committed
149
150
            nub = macroRugoInstanceSubmerged();
            break;
151
152
153
154
155
        }
        default: {
            throw new Error("Instance name error");
        }
    }
Dorchies David's avatar
Dorchies David committed
156
157
158
159
    for (const p of nub.parameterIterator) {
        p.v = p.singleValue;
    }
    return nub;
160
161
162
163
164
}

function testMacroRugo(sInstance: string, varTest: string, valRef: number) {
        it(`Calc(${varTest}) should be ${valRef}`, () => {
            const nub = MacroRugoFactory(sInstance);
165
            nub.prms.Q.v = nub.Calc("Q").vCalc;
166
167
168
            const p = nub.getParameter(varTest);
            p.v = undefined;
            p.valueMode = ParamValueMode.CALCUL;
169
170
            const r = nub.Calc(varTest, 0.1);
            checkResult(r, valRef);
171
172
173
        });
}

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

199
200
201
202
describe("Class MacroRugo: ", () => {

    testMacroRugoConfig("EmergentCd15", 0.901710, 0.379574, macroRugoExtraResultEmergentCd15);
    testMacroRugoConfig("EmergentCd2", 0.768677, 0.418044, macroRugoExtraResultEmergentCd2);
203
204
205
206
207
208
209
    // 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);
    //     });
    // });
210
    testMacroRugoConfig("Submerged", 1.202280, 0.145051, macroRugoExtraResultSubmerged);
Dorchies David's avatar
Dorchies David committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

    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);
            }
        });
    });
228
});