macrorugo.spec.ts 6.76 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.1003***
8
*** INPUT ***
9
10
ks: 0.010000,
D: 0.500000,
11
k = 0.700000
12
13
14
15
16
Cd0: 1.100300,
S: 0.050000,
B: 1.000000,
h: 0.600000,
C: 0.130000,
17
RESULTS:
18
19
20
21
22
23
24
25
26
27
28
29
find_Q_nat(1.052827)=0.600769
Q=0.692366  fVal=0.000000
ZF2: 12.200000,
Vdeb: 1.153943,
Vg: 1.804601,
Fr: 0.743826,
PV: 566.009124,
flowcond: emergent,
Vmax: 2.673506,
V_technique: 1.991299,
q_technique: 0.561860,
Strickler: 7.254351,
30
31
 */

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

50
const macroRugoExtraResultEmergentCd1: { [key: string]: number | MacroRugoFlowType } = {
51
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
52
    ZF2: 12.200000,
53
54
55
56
57
58
    Vdeb: 1.153943,
    Vg: 1.804601,
    Fr: 0.743826,
    PV: 566.009124,
    Vmax: 2.673506,
    Strickler: 7.254351
59
60
61
};

/*
62
** Emergent conditions Cd=2.592***
63
64
65
*** INPUT ***
ks: 0.010000,
D: 0.500000,
66
k = 0.700000
67
Cd0: 2.592000,
68
69
70
71
S: 0.050000,
B: 1.000000,
h: 0.600000,
C: 0.130000,
72
RESULTS:
73
74
find_Q_nat(0.675214)=0.321449
Q=0.482344  fVal=0.000000
75
ZF2: 12.200000,
76
77
78
79
Vdeb: 0.803907,
Vg: 1.257195,
Fr: 0.518194,
PV: 394.316317,
80
flowcond: emergent,
81
Vmax: 2.166970,
82
83
V_technique: 1.991299,
q_technique: 0.561860,
84
Strickler: 5.053822
85
86
 */

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

94
const macroRugoExtraResultEmergentCd2: { [key: string]: number | MacroRugoFlowType } = {
95
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
96
    ZF2: 12.200000,
97
98
99
100
101
102
    Vdeb: 0.803907,
    Vg: 1.257195,
    Fr: 0.518194,
    PV: 394.316317,
    Vmax: 2.166970,
    Strickler: 5.053822
103
104
105
};

/*
106
** Submerged conditions  Cd=1.1003***
107
108
109
*** INPUT ***
ks: 0.010000,
D: 0.500000,
110
k = 0.700000
111
Cd0: 1.100300,
112
113
114
115
S: 0.050000,
B: 1.000000,
h: 0.800000,
C: 0.130000,
116
RESULTS:
117
118
find_Q_nat(1.403770)=0.143414
Q=1.289038  fVal=0.000000
119
ZF2: 12.200000,
120
121
122
123
Vdeb: 1.611298,
Vg: 2.519839,
Fr: 0.899484,
PV: 790.341606,
124
125
flowcond: immerge,
q_technique: 0.940450,
126
Strickler: 8.361756
127
128
 */

129
function macroRugoInstanceSubmerged(): MacroRugo {
130
    const nub: MacroRugo = macroRugoInstanceEmergentCd1();
Dorchies David's avatar
Dorchies David committed
131
    nub.prms.Y.singleValue = 0.8;
132
    nub.prms.Q.singleValue = 1.289038;
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
    ZF2: 12.200000,
139
140
141
    Vdeb: 1.611298,
    PV: 790.341606,
    Strickler: 8.361756
142
143
144
};

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

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

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

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

216
217
describe("Class MacroRugo: ", () => {

218
219
    testMacroRugoConfig("EmergentCd1", 1.052827, 0.600769, macroRugoExtraResultEmergentCd1);
    testMacroRugoConfig("EmergentCd2", 0.675214, 0.321449, macroRugoExtraResultEmergentCd2);
220
221
222
223
224
225
226
    // 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);
    //     });
    // });
227
    testMacroRugoConfig("Submerged", 1.403770, 0.143414, macroRugoExtraResultSubmerged);
Dorchies David's avatar
Dorchies David committed
228
229

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

            nubMR.prms.Y.setValues(0.7, 1.2, 0.1);
235
            const aQ: number[] = [0.688476, 0.824387, 1.166239, 1.475853, 1.850393, 2.288123];
Dorchies David's avatar
Dorchies David committed
236
237
238
239

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