macrorugo.spec.ts 6.75 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
/*
*** Emergent conditions Cd=1.5***
8
9
10
11
12
13
14
15
16
17
18
ks = 0.010000
D = 0.500000
k = 0.700000
Cd0 = 1.500000
S = 0.050000
B = 1.000000
h = 0.600000
C = 0.130000
RESULTS:
find_Q_nat(0.901710)=0.679969
Q=0.493729  fVal=0.000000
19
cote_bas = 12.200000
20
21
22
Vdeb = 0.822881
Fr = 0.530425
P = 242.174003
23
flowcond = emergent
24
Vmax = 1.799502
25
26
V_technique = 1.991299
q_technique = 0.561860
27
Strickler = 5.173107
28
29
30
 */

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

48
49
const macroRugoExtraResultEmergentCd15: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
50
51
52
53
    Fr: 0.530425,
    PV: 242.174003,
    Vdeb: 0.822881,
    Vmax: 1.799502,
54
    Strickler: 5.173107,
55
56
57
58
59
    ZF2: 12.2
};

/*
*** Emergent conditions Cd=2***
60
61
62
63
64
65
66
67
68
69
70
ks = 0.010000
D = 0.500000
k = 0.700000
Cd0 = 2.000000
S = 0.050000
B = 1.000000
h = 0.600000
C = 0.130000
RESULTS:
find_Q_nat(0.768677)=0.653110
Q=0.376811  fVal=0.000000
71
cote_bas = 12.200000
72
73
74
Vdeb = 0.628018
Fr = 0.404817
P = 184.825731
75
flowcond = emergent
76
Vmax = 1.536129
77
78
V_technique = 1.592932
q_technique = 0.414154
79
Strickler = 3.948084
80
81
82
83
 */

function macroRugoInstanceEmergentCd2(): MacroRugo {
    const nub: MacroRugo = macroRugoInstanceEmergentCd15();
Dorchies David's avatar
Dorchies David committed
84
    nub.prms.Cd0.singleValue = 2;
85
    nub.prms.Q.singleValue = 0.376811;
86
87
88
89
90
    return nub;
}

const macroRugoExtraResultEmergentCd2: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
91
    Fr: 0.404817,
92
    PV: 184.825731,
93
94
    Vdeb: 0.628018,
    Vmax: 1.536129,
95
    Strickler: 3.948084,
96
97
98
99
100
    ZF2: 12.2
};

/*
*** Submerged conditions ***
101
102
103
104
105
106
107
108
109
110
111
ks = 0.010000
D = 0.500000
k = 0.700000
Cd0 = 1.500000
S = 0.050000
B = 1.000000
h = 0.800000
C = 0.130000
RESULTS:
find_Q_nat(1.202280)=0.112522
Q=1.112263  fVal=0.000000
112
cote_bas = 12.200000
113
114
115
Vdeb = 1.390328
Fr = 0.776130
P = 545.564782
116
117
flowcond = immerge
q_technique = 0.940450
118
Strickler = 7.215044
119
120
 */

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

128
129
const macroRugoExtraResultSubmerged: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED,
130
131
132
133
    Fr: 0.776130,
    PV: 545.564782,
    Vdeb: 1.390328,
    Strickler: 7.215044,
134
135
136
137
    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
180
181
            nubit["bSubmerged"] = (nubit.prms.Y.v / nubit.prms.PBH.v > MacroRugo["limitSubmerg"]);
            // tslint:disable-next-line:no-string-literal
Dorchies David's avatar
Dorchies David committed
182
            expect(nubit["resolveQ"]()).toBeCloseTo(fVal0, 5);
183
        });
184
        const nub = MacroRugoFactory(sInstance);
185
186
        for (const prm of nub.prms) {
            if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) {
187
188
189
190
191
192
                testMacroRugo(sInstance, prm.symbol, prm.v);
            }
        }
        for (const sExtraRes in mrExtraRes) {
            if (mrExtraRes.hasOwnProperty(sExtraRes)) {
                it(`${sExtraRes} should be ${mrExtraRes[sExtraRes]}`, () => {
193
                    expect(MacroRugoFactory(sInstance).Calc("Q").values[sExtraRes])
194
195
                    .toBeCloseTo(mrExtraRes[sExtraRes], 5);
                });
196
            }
197
        }
198
    });
199
}
200

Dorchies David's avatar
Dorchies David committed
201
202
203
204
205
206
207
208
function macroRugoInstanceJalHyd85(): MacroRugo {
    const nubMR = macroRugoInstanceEmergentCd15();
    nubMR.prms.C.singleValue = 0.2;
    nubMR.prms.PBH.singleValue = 0.8;
    nubMR.calculatedParam = nubMR.prms.Q;
    return nubMR;
}

209
210
describe("Class MacroRugo: ", () => {

211
212
    testMacroRugoConfig("EmergentCd15", 0.901710, 0.679969, macroRugoExtraResultEmergentCd15);
    testMacroRugoConfig("EmergentCd2", 0.768677, 0.653110, macroRugoExtraResultEmergentCd2);
213
214
215
216
217
218
219
    // 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);
    //     });
    // });
220
    testMacroRugoConfig("Submerged", 1.202280, 0.112522, macroRugoExtraResultSubmerged);
Dorchies David's avatar
Dorchies David committed
221
222

    describe("JalHyd #85", () => {
223
        it("CalcSerie Q should return the good result :)", () => {
Dorchies David's avatar
Dorchies David committed
224
225
            const nubMR = macroRugoInstanceJalHyd85();
            const nubMR2 = macroRugoInstanceJalHyd85();
Dorchies David's avatar
Dorchies David committed
226
227

            nubMR.prms.Y.setValues(0.7, 1.2, 0.1);
228
            const aQ: number[] = [ 0.484255, 0.578363, 1.004229, 1.280269, 1.618937, 2.018687 ];
Dorchies David's avatar
Dorchies David committed
229
230
231
232

            nubMR.CalcSerie();
            for (let i = 0; i < aQ.length; i++) {
                expect(nubMR.result.resultElements[i].vCalc).toBeCloseTo(aQ[i], 4);
Dorchies David's avatar
Dorchies David committed
233
234
                nubMR2.prms.Y.setValue(0.7 + i * 0.1);
                expect(nubMR2.CalcSerie().vCalc).toBeCloseTo(aQ[i], 4);
Dorchies David's avatar
Dorchies David committed
235
236
237
            }
        });
    });
238
});