macrorugo.spec.ts 6.82 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
*** Emergent conditions Cd=1.1***
*** INPUT ***
9
10
11
ks = 0.010000
D = 0.500000
k = 0.700000
12
Cd0 = 1.100000
13
14
15
16
17
S = 0.050000
B = 1.000000
h = 0.600000
C = 0.130000
RESULTS:
18
19
find_Q_nat(1.052971)=0.600890
Q=0.692437  fVal=0.000000
20
cote_bas = 12.200000
21
22
23
24
Vdeb = 1.154061
Vg: 1.804786,
Fr = 0.743902
P = 566.066964
25
flowcond = emergent
26
Vmax = 2.722572
27
28
V_technique = 1.991299
q_technique = 0.561860
29
Strickler = 7.255093
30
31
 */

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

50
const macroRugoExtraResultEmergentCd11: { [key: string]: number | MacroRugoFlowType } = {
51
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
52
53
54
55
56
57
58
    ZF2: 12.200000,
    Vdeb: 1.154061,
    Vg: 1.804786,
    Fr: 0.743902,
    PV: 566.066964,
    Vmax: 2.722572,
    Strickler: 7.255093
59
60
61
};

/*
62
63
64
65
** Emergent conditions Cd=2.6***
*** INPUT ***
ks: 0.010000,
D: 0.500000,
66
k = 0.700000
67
68
69
70
71
Cd0: 2.600000,
S: 0.050000,
B: 1.000000,
h: 0.600000,
C: 0.130000,
72
RESULTS:
73
74
75
76
77
78
79
80
81
82
83
84
find_Q_nat(0.674174)=0.320793
Q=0.481698  fVal=0.000000
ZF2: 12.200000,
Vdeb: 0.802831,
Vg: 1.255512,
Fr: 0.517500,
PV: 393.788411,
flowcond: emergent,
Vmax: 2.047863,
V_technique: 1.991299,
q_technique: 0.561860,
Strickler: 5.047056
85
86
 */

87
88
89
90
function macroRugoInstanceEmergentCd26(): MacroRugo {
    const nub: MacroRugo = macroRugoInstanceEmergentCd11();
    nub.prms.Cd0.singleValue = 2.6;
    nub.prms.Q.singleValue = 0.481698;
91
92
93
    return nub;
}

94
const macroRugoExtraResultEmergentCd26: { [key: string]: number | MacroRugoFlowType } = {
95
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
96
97
98
99
100
101
102
    ZF2: 12.200000,
    Vdeb: 0.802831,
    Vg: 1.255512,
    Fr: 0.517500,
    PV: 393.788411,
    Vmax: 2.047863,
    Strickler: 5.047056
103
104
105
};

/*
106
107
108
109
*** Submerged conditions  Cd=1.1***
*** INPUT ***
ks: 0.010000,
D: 0.500000,
110
k = 0.700000
111
112
113
114
115
Cd0: 1.100000,
S: 0.050000,
B: 1.000000,
h: 0.800000,
C: 0.130000,
116
RESULTS:
117
118
119
120
121
122
123
124
125
126
find_Q_nat(1.403961)=0.143445
Q=1.289205  fVal=0.000000
ZF2: 12.200000,
Vdeb: 1.611506,
Vg: 2.520165,
Fr: 0.899600,
PV: 790.443862,
flowcond: immerge,
q_technique: 0.940450,
Strickler: 8.362838
127
128
 */

129
function macroRugoInstanceSubmerged(): MacroRugo {
130
    const nub: MacroRugo = macroRugoInstanceEmergentCd11();
Dorchies David's avatar
Dorchies David committed
131
    nub.prms.Y.singleValue = 0.8;
132
    nub.prms.Q.singleValue = 1.289205;
133
134
135
    return nub;
}

Mathias Chouet's avatar
Mathias Chouet committed
136
const macroRugoExtraResultSubmerged: { [key: string]: number | MacroRugoFlowType } = {
137
    ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED,
138
139
140
141
142
143
    ZF2: 12.200000,
    Vdeb: 1.611506,
    Vg: 2.520165,
    Fr: 0.899600,
    PV: 790.443862,
    Strickler: 8.362838
144
145
146
};

function MacroRugoFactory(sInstance: string): MacroRugo {
Dorchies David's avatar
Dorchies David committed
147
    let nub: MacroRugo;
148
    switch (sInstance) {
149
150
        case "EmergentCd11": {
            nub = macroRugoInstanceEmergentCd11();
Dorchies David's avatar
Dorchies David committed
151
            break;
152
        }
153
154
        case "EmergentCd26": {
            nub = macroRugoInstanceEmergentCd26();
Dorchies David's avatar
Dorchies David committed
155
            break;
156
157
        }
        case "Submerged": {
Dorchies David's avatar
Dorchies David committed
158
159
            nub = macroRugoInstanceSubmerged();
            break;
160
161
162
163
164
        }
        default: {
            throw new Error("Instance name error");
        }
    }
Dorchies David's avatar
Dorchies David committed
165
166
167
168
    for (const p of nub.parameterIterator) {
        p.v = p.singleValue;
    }
    return nub;
169
170
171
}

function testMacroRugo(sInstance: string, varTest: string, valRef: number) {
Mathias Chouet's avatar
Mathias Chouet committed
172
173
174
175
176
177
178
179
180
    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);
    });
181
182
}

183
function testMacroRugoConfig(sInstance: string, Q0: number, fVal0: number, mrExtraRes: { [key: string]: number }) {
Mathias Chouet's avatar
Mathias Chouet committed
184
    describe(`Condition ${sInstance}`, () => {
185
186
        it(`resolveQ(${Q0}) should be ${fVal0}`, () => {
            const nubit = MacroRugoFactory(sInstance);
Dorchies David's avatar
Dorchies David committed
187
            nubit.prms.Q.v = Q0;
188
            // tslint:disable-next-line:no-string-literal
189
            nubit["setFlowType"]();
190
            // tslint:disable-next-line:no-string-literal
Dorchies David's avatar
Dorchies David committed
191
            expect(nubit["resolveQ"]()).toBeCloseTo(fVal0, 5);
192
        });
193
        const nub = MacroRugoFactory(sInstance);
194
195
        for (const prm of nub.prms) {
            if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) {
196
197
198
199
200
201
                testMacroRugo(sInstance, prm.symbol, prm.v);
            }
        }
        for (const sExtraRes in mrExtraRes) {
            if (mrExtraRes.hasOwnProperty(sExtraRes)) {
                it(`${sExtraRes} should be ${mrExtraRes[sExtraRes]}`, () => {
202
                    expect(MacroRugoFactory(sInstance).Calc("Q").values[sExtraRes])
203
                        .toBeCloseTo(mrExtraRes[sExtraRes], 3);
204
                });
205
            }
206
        }
207
    });
208
}
209

Dorchies David's avatar
Dorchies David committed
210
function macroRugoInstanceJalHyd85(): MacroRugo {
211
    const nubMR = macroRugoInstanceEmergentCd11();
Dorchies David's avatar
Dorchies David committed
212
213
214
215
216
217
    nubMR.prms.C.singleValue = 0.2;
    nubMR.prms.PBH.singleValue = 0.8;
    nubMR.calculatedParam = nubMR.prms.Q;
    return nubMR;
}

218
219
describe("Class MacroRugo: ", () => {

220
221
    testMacroRugoConfig("EmergentCd11", 1.052971, 0.600890, macroRugoExtraResultEmergentCd11);
    testMacroRugoConfig("EmergentCd26", 0.674174, 0.320793, macroRugoExtraResultEmergentCd26);
222
223
224
225
226
227
228
    // 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);
    //     });
    // });
229
    testMacroRugoConfig("Submerged", 1.403961, 0.143445, macroRugoExtraResultSubmerged);
Dorchies David's avatar
Dorchies David committed
230
231

    describe("JalHyd #85", () => {
232
        it("CalcSerie Q should return the good result :)", () => {
Dorchies David's avatar
Dorchies David committed
233
234
            const nubMR = macroRugoInstanceJalHyd85();
            const nubMR2 = macroRugoInstanceJalHyd85();
Dorchies David's avatar
Dorchies David committed
235
236

            nubMR.prms.Y.setValues(0.7, 1.2, 0.1);
237
            const aQ: number[] = [0.6885501, 0.8244762, 1.1663925, 1.4760379, 1.8506109, 2.2883764];
Dorchies David's avatar
Dorchies David committed
238
239
240
241

            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
242
243
                nubMR2.prms.Y.setValue(0.7 + i * 0.1);
                expect(nubMR2.CalcSerie().vCalc).toBeCloseTo(aQ[i], 4);
Dorchies David's avatar
Dorchies David committed
244
245
246
            }
        });
    });
247
});