macrorugo.spec.ts 5.47 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";
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
86
87
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
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();
    nub.prms.Cd0.v = 2;
    nub.prms.Q.v = 0.376808;
    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();
123
    nub.prms.Y.v = 0.8;
124
    nub.prms.Q.v = 0.908068;
125
126
127
    return nub;
}

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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 {
    switch (sInstance) {
        case "EmergentCd15": {
            return macroRugoInstanceEmergentCd15();
        }
        case "EmergentCd2": {
            return macroRugoInstanceEmergentCd2();
        }
        case "Submerged": {
            return macroRugoInstanceSubmerged();
        }
        default: {
            throw new Error("Instance name error");
        }
    }
}

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

165
function testMacroRugoConfig(sInstance: string, Q0: number, fVal0: number, mrExtraRes: { [key: string]: number }) {
166
    describe(`Condition ${sInstance}` , () => {
167
168
        it(`resolveQ(${Q0}) should be ${fVal0}`, () => {
            const nubit = MacroRugoFactory(sInstance);
169
            // tslint:disable-next-line:no-string-literal
170
            expect(nubit["resolveQ"](Q0)).toBeCloseTo(fVal0, 5);
171
        });
172
        const nub = MacroRugoFactory(sInstance);
173
174
        for (const prm of nub.prms) {
            if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) {
175
176
177
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]}`, () => {
                    expect(MacroRugoFactory(sInstance).Calc("Q").extraResults[sExtraRes])
                    .toBeCloseTo(mrExtraRes[sExtraRes], 5);
                });
184
            }
185
        }
186
    });
187
}
188

189
190
191
192
describe("Class MacroRugo: ", () => {

    testMacroRugoConfig("EmergentCd15", 0.901710, 0.379574, macroRugoExtraResultEmergentCd15);
    testMacroRugoConfig("EmergentCd2", 0.768677, 0.418044, macroRugoExtraResultEmergentCd2);
193
194
195
196
197
198
199
    // 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);
    //     });
    // });
200
    testMacroRugoConfig("Submerged", 1.202280, 0.145051, macroRugoExtraResultSubmerged);
201
});