remous_rect_euler_penteforte.spec.ts 21 KB
Newer Older
1
import { MethodeResolution } from "../../src/remous/methode-resolution";
2
3
4
5
import { CourbeRemous } from "../../src/remous/remous";
import { CourbeRemousParams } from "../../src/remous/remous_params";
import { cSnRectang } from "../../src/section/section_rectang";
import { ParamsSectionRectang } from "../../src/section/section_rectang_params";
6
import { SessionSettings } from "../../src/session_settings";
7
8
import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
9
import { precDist } from "../test_config";
10
import { compareExtraResult, compareLog, extraResultLength } from "../test_func";
11

12
13
14
15
16
17
18
/*
   Certaines valeurs de ligne d'eau torrentielle étaient auparavant remplacées par une valeur fluviale
   pour la représentation graphique du ressaut (mais fausse car torrentielle).
   Idem pour la réciproque fluvial/torrentiel.
   Le code ne faisant plus ça, les valeurs de validation ont été remplacée par les bonnes.
 */

19
20
21
22
23
24
25
/*
  De nombreux tests ont été désactivés suite au changement de format des résultats de calcul de remous.
  Avant : un Result contenant un ResultElement par variable (valeurs stockées dans un résultat complémentaire)
  Après : un Result contenant un ResultElement par valeur de x avec des résultats complémentaires pour chaque variable
  Ces tests sont annotés par "désactivé suite au changement de format de résultat"
*/

26
27
describe("Class Remous / section rectangulaire :", () => {
    describe("méthode Euler explicite :", () => {
28
        // désactivé suite au changement de format de résultat
29
        it("forte pente, ressaut avant l'amont", () => {
30
            const prms = new ParamsSectionRectang(undefined, // tirant d'eau
31
32
33
34
                2.5, // largeur de fond
                40, //  Ks=Strickler
                2, // Q=Débit
                0.05, // If=pente du fond
35
                1, // YB=hauteur de berge
36
            );
37
            SessionSettings.precision = precDist;
38

39
            const sect = new cSnRectang(prms);
40

41
            const prem = new CourbeRemousParams(105.15, 106, 105, 100,
42
43
                100,  // Long= Longueur du bief
                5,  // Dx=Pas d'espace
44
45
            );

46
            const rem = new CourbeRemous(sect, prem, MethodeResolution.EulerExplicite);
47

48
            const res = rem.calculRemous(undefined);
49
50
51

            // données de validation : version Typescript (Oct 2017) méthode des trapèzes

52
            const f: any = {
Mathias Chouet's avatar
Mathias Chouet committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
                0: 0.9767500000000044,
                5: 1.2360000000000044,
                10: 1.4910000000000045,
                15: 1.7437500000000046,
                20: 1.9955000000000045,
                25: 2.2465000000000046,
                30: 2.497500000000005,
                35: 2.7485000000000053,
                40: 2.9985000000000053,
                45: 3.2485000000000053,
                50: 3.4985000000000053,
                55: 3.7485000000000053,
                60: 3.9985000000000053,
                65: 4.248500000000004,
                70: 4.498750000000004,
                75: 4.749000000000003,
                80: 4.999250000000003,
                85: 5.249500000000002,
                90: 5.4997500000000015,
                95: 5.750000000000001,
                100: 6
            };
75
76
77
78
            // màj pour jalhyd#146 : ajout de la cote de fond aux valeurs attendues
            for (const fk of Object.keys(f)) {
                f[fk] = f[fk] + rem.getCoteFond(Number(fk));
            }
79
            // compareObject("Yfluvial", res.getValue("flu"), f, 0.03);
80
            compareExtraResult("Yfluvial", res, "flu", f, 0.03);
81

82
            const t = {};
83
            // compareObject("Ytorrentiel", res.getValue("tor"), t, 0.03);
84
            compareExtraResult("Ytorrentiel", res, "tor", t, 0.03);
85

86
            // const x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100];
87
            // compareArray("abscisses", res.getValue("trX"), x);
88

89
            const expLog = new cLog();
90

91
            let m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE);
92
            m.extraVar.Yc = 0.403;
93
94
            expLog.add(m);

95
            m = new Message(MessageCode.INFO_REMOUS_H_NORMALE);
96
            m.extraVar.Yn = 0.253;
97
98
            expLog.add(m);

99
100
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL));
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL));
101

102
            m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS);
103
104
            m.extraVar.sens = "amont";
            m.extraVar.x = 0;
105
106
            expLog.add(m);

107
            compareLog(res.globalLog, expLog);
108
109
        });

110
        // désactivé suite au changement de format de résultat
111
        it("forte pente, ressaut après l'aval", () => {
112
            // TODO algo à reprendre
113
            const prms = new ParamsSectionRectang(undefined, // tirant d'eau
114
115
116
117
                2.5, // largeur de fond
                40, //  Ks=Strickler
                2, // Q=Débit
                0.05, // If=pente du fond
118
                1, // YB=hauteur de berge
119
            );
120
            SessionSettings.precision = precDist;
121

122
            const sect = new cSnRectang(prms);
123

124
            const prem = new CourbeRemousParams(105.15, 100.45, 105, 100,
125
126
                100,  // Long= Longueur du bief
                5,  // Dx=Pas d'espace
127
128
            );

129
            const rem = new CourbeRemous(sect, prem, MethodeResolution.EulerExplicite);
130

131
            const res = rem.calculRemous(undefined);
132
133
134

            // données de validation : version Typescript (Oct 2017) méthode des trapèzes

135
            const f = {};
136
            // compareObject("Yfluvial", res.getValue("flu"), f, 0.03);
137
            compareExtraResult("Yfluvial", res, "flu", f, 0.03);
138

139
            const t: any = {
Mathias Chouet's avatar
Mathias Chouet committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
                0: 0.15,
                5: 0.20725000000000002,
                10: 0.23500000000000001,
                15: 0.24675000000000002,
                20: 0.251,
                25: 0.25225,
                30: 0.25249999999999995,
                35: 0.2527499999999999,
                40: 0.2529999999999999,
                45: 0.2527499999999999,
                50: 0.2529999999999999,
                55: 0.2527499999999999,
                60: 0.2529999999999999,
                65: 0.2527499999999999,
                70: 0.2529999999999999,
                75: 0.2527499999999999,
                80: 0.2529999999999999,
                85: 0.2527499999999999,
                90: 0.2529999999999999,
                95: 0.2527499999999999,
                100: 0.253
            }; // dernière valeur modifiée pour la raison en tête de fichier
162
163
164
165
            // màj pour jalhyd#146 : ajout de la cote de fond aux valeurs attendues
            for (const tk of Object.keys(t)) {
                t[tk] = t[tk] + rem.getCoteFond(Number(tk));
            }
166
            // compareObject("Ytorrentiel", res.getValue("tor"), t, 0.03);
167
            compareExtraResult("Ytorrentiel", res, "tor", t, 0.03);
168

169
            // const x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100];
170
            // compareArray("abscisses", res.getValue("trX"), x);
171

172
            const expLog = new cLog();
173

174
            let m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE);
175
            m.extraVar.Yc = 0.403;
176
177
            expLog.add(m);

178
            m = new Message(MessageCode.INFO_REMOUS_H_NORMALE);
179
            m.extraVar.Yn = 0.253;
180
181
            expLog.add(m);

182
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL));
183

184
            m = new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE);
185
            m.extraVar.x = 95;
186
187
            expLog.add(m);

188
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL));
189

190
            m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS);
191
192
            m.extraVar.sens = "aval";
            m.extraVar.x = 100;
193
194
            expLog.add(m);

195
            compareLog(res.globalLog, expLog);
196
197
        });

Mathias Chouet's avatar
Mathias Chouet committed
198
199
200
        xit("forte pente, ressaut (plusieurs points) à l'intérieur du bief", () => {
        // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique)

201
            const prms = new ParamsSectionRectang(undefined, // tirant d'eau
202
203
204
205
                2.5, // largeur de fond
                40, //  Ks=Strickler
                2, // Q=Débit
                0.05, // If=pente du fond
206
                1, // YB=hauteur de berge
207
            );
208
            SessionSettings.precision = precDist;
209

210
            const sect = new cSnRectang(prms);
211

212
            const prem = new CourbeRemousParams(100.425, 101, 100.275, 100,
213
214
                5.5,  // Long= Longueur du bief
                0.25,  // Dx=Pas d'espace
215
216
            );

217
            const rem = new CourbeRemous(sect, prem, MethodeResolution.EulerExplicite);
218

219
            const res = rem.calculRemous(undefined);
220
221
222

            // données de validation : version Typescript (Oct 2017) méthode des trapèzes

223
224
225
226
227
228
229
            // let f = { "0": 0.15, "1": 0.7560000000000007, "2": 0.8120000000000005, "3": 0.8670000000000002,
            // "4": 0.9205000000000001, "5": 0.9735, "5.5": 1, "5.25": 0.98675, "4.75": 0.96025,
            // "4.5": 0.9470000000000001, "4.25": 0.9337500000000001, "3.75": 0.9072500000000001,
            // "3.5": 0.8940000000000001, "3.25": 0.8807500000000001, "2.75": 0.8532500000000003,
            // "2.5": 0.8395000000000004, "2.25": 0.8257500000000004, "1.75": 0.7982500000000006,
            // "1.5": 0.7845000000000006, "1.25": 0.7702500000000007, "0.75": 0.7417500000000007,
            // "0.5": 0.7275000000000007, "0.25": 0.7132500000000007 };
230
            const f: any = {
Mathias Chouet's avatar
Mathias Chouet committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
                0: 0.698,
                1: 0.7560000000000007,
                2: 0.8120000000000005,
                3: 0.8670000000000002,
                4: 0.9205000000000001,
                5: 0.9735,
                5.5: 1,
                5.25: 0.98675,
                4.75: 0.96025,
                4.5: 0.9470000000000001,
                4.25: 0.9337500000000001,
                3.75: 0.9072500000000001,
                3.5: 0.8940000000000001,
                3.25: 0.8807500000000001,
                2.75: 0.8532500000000003,
                2.5: 0.8395000000000004,
                2.25: 0.8257500000000004,
                1.75: 0.7982500000000006,
                1.5: 0.7845000000000006,
                1.25: 0.7702500000000007,
                0.75: 0.7417500000000007,
                0.5: 0.7275000000000007,
                0.25: 0.7132500000000007
            }; // première valeur modifiée pour la raison en tête de fichier
255
256
257
258
            // màj pour jalhyd#146 : ajout de la cote de fond aux valeurs attendues
            for (const fk of Object.keys(f)) {
                f[fk] = f[fk] + rem.getCoteFond(Number(fk));
            }
259
            // compareObject("Yfluvial", res.getValue("flu"), f, 0.03);
260
            compareExtraResult("Yfluvial", res, "flu", f, 0.03);
261

Mathias Chouet's avatar
Mathias Chouet committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
            const t = {
                0: 0.15,
                1: 0.161,
                2: 0.17200000000000001,
                3: 0.18100000000000002,
                0.25: 0.15275,
                0.5: 0.1555,
                0.75: 0.15825,
                1.25: 0.16375,
                1.5: 0.1665,
                1.75: 0.16925,
                2.25: 0.17425000000000002,
                2.5: 0.17650000000000002,
                2.75: 0.17875000000000002,
                3.25: 0.18325000000000002,
                3.5: 0.18550000000000003,
                3.75: 0.9072500000000001
            };
280
            // compareObject("Ytorrentiel", res.getValue("tor"), t, 0.03);
281
            compareExtraResult("Ytorrentiel", res, "tor", t, 0.03);
282

Mathias Chouet's avatar
Mathias Chouet committed
283
            // tslint:disable-next-line:max-line-length
284
            // const x = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5];
285
            // compareArray("abscisses", res.getValue("trX"), x);
286

287
            const expLog = new cLog();
288

289
            let m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE);
290
            m.extraVar.Yc = 0.403;
291
292
            expLog.add(m);

293
            m = new Message(MessageCode.INFO_REMOUS_H_NORMALE);
294
            m.extraVar.Yn = 0.253;
295
296
            expLog.add(m);

297
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL));
298

299
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL));
300

301
            m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO);
302
303
            m.extraVar.xmin = 0;
            m.extraVar.xmax = 3.75;
304
305
            expLog.add(m);

306
            compareLog(res.globalLog, expLog);
307
308
        });

309
        // désactivé suite au changement de format de résultat
310
        it("forte pente, pas de ressaut, Yaval < Yc, Yamont < Yn", () => {
311
            const prms = new ParamsSectionRectang(undefined, // tirant d'eau
312
313
314
315
                2.5, // largeur de fond
                40, //  Ks=Strickler
                2, // Q=Débit
                0.05, // If=pente du fond
316
                1, // YB=hauteur de berge
317
            );
318
            SessionSettings.precision = precDist;
319

320
            const sect = new cSnRectang(prms);
321

322
            const prem = new CourbeRemousParams(101.6, 100.3, 101.5, 100,
323
324
                30,  // Long= Longueur du bief
                1,  // Dx=Pas d'espace
325
326
            );

327
            const rem = new CourbeRemous(sect, prem, MethodeResolution.EulerExplicite);
328

329
            const res = rem.calculRemous(undefined);
330
331
332

            // données de validation : version Typescript (Oct 2017) méthode trapèzes

333
            expect(extraResultLength(res, "flu") === 0).toBeTruthy(
334
335
                "la ligne d'eau fluviale ne devrait comporter aucune valeur");

336
            const t: any = {
337
338
339
340
341
342
343
                0: 0.1, 1: 0.11425000000000002, 2: 0.12750000000000003, 3: 0.14025000000000004,
                4: 0.15200000000000005, 5: 0.16325000000000006, 6: 0.17350000000000007, 7: 0.18325000000000008,
                8: 0.1920000000000001, 9: 0.1997500000000001, 10: 0.2070000000000001, 11: 0.2137500000000001,
                12: 0.2195000000000001, 13: 0.22475000000000012, 14: 0.22900000000000012, 15: 0.23275000000000012,
                16: 0.23600000000000013, 17: 0.23875000000000013, 18: 0.24100000000000013, 19: 0.24325000000000013,
                20: 0.24500000000000013, 21: 0.24625000000000014, 22: 0.24750000000000014, 23: 0.2485000000000001,
                24: 0.2492500000000001, 25: 0.2502500000000001, 26: 0.25050000000000006, 27: 0.25075000000000003,
344
345
                28: 0.251, 29: 0.25125, 30: 0.25149999999999995
            };
346
347
348
349
            // màj pour jalhyd#146 : ajout de la cote de fond aux valeurs attendues
            for (const tk of Object.keys(t)) {
                t[tk] = t[tk] + rem.getCoteFond(Number(tk));
            }
350
            // compareObject("Ytorrentiel", res.getValue("tor"), t, 0.01);
351
            compareExtraResult("Ytorrentiel", res, "tor", t, 0.01);
352

353
354
            // const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
            //     19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
355
            // compareArray("abscisses", res.getValue("trX"), x);
356
357

            const expLog = new cLog();
358

359
            let m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE);
360
            m.extraVar.Yc = 0.403;
361
362
            expLog.add(m);

363
            m = new Message(MessageCode.INFO_REMOUS_H_NORMALE);
364
            m.extraVar.Yn = 0.253;
365
366
            expLog.add(m);

Mathias Chouet's avatar
Mathias Chouet committed
367
            expLog.add(new Message(MessageCode.WARNING_REMOUS_PAS_CALCUL_DEPUIS_AVAL));
368

369
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL));
370

371
            compareLog(res.globalLog, expLog);
372
373
        });

374
375
        // désactivé suite au changement de format de résultat
        xit("forte pente, pas de ressaut, Yaval < Yc, Yn < Yamont < Yc", () => {
376
            const prms = new ParamsSectionRectang(undefined, // tirant d'eau
377
378
379
380
                2.5, // largeur de fond
                40, //  Ks=Strickler
                2, // Q=Débit
                0.05, // If=pente du fond
381
                1, // YB=hauteur de berge
382
            );
383
            SessionSettings.precision = precDist;
384

385
            const sect = new cSnRectang(prms);
386

387
            const prem = new CourbeRemousParams(100.85, 100.3, 100.5, 100,
388
389
                10,  // Long= Longueur du bief
                0.1,  // Dx=Pas d'espace
390
391
            );

392
            const rem = new CourbeRemous(sect, prem, MethodeResolution.EulerExplicite);
393

394
            const res = rem.calculRemous(undefined);
395
396
397

            // données de validation : version PHP (Oct 2017) méthode trapèzes

398
            expect(extraResultLength(res, "flu") === 0)
Mathias Chouet's avatar
Mathias Chouet committed
399
                .toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur");
400

Mathias Chouet's avatar
Mathias Chouet committed
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
            const t = {
                0.000: 0.35,
                0.100: 0.345,
                0.200: 0.34,
                0.300: 0.336,
                0.400: 0.332,
                0.500: 0.329,
                0.600: 0.326,
                0.700: 0.323,
                0.800: 0.32,
                0.900: 0.318,
                1.000: 0.316,
                1.100: 0.313,
                1.200: 0.311,
                1.300: 0.309,
                1.400: 0.308,
                1.500: 0.306,
                1.600: 0.305,
                1.700: 0.303,
                1.800: 0.302,
                1.900: 0.3,
                2.000: 0.298,
                2.100: 0.297,
                2.200: 0.295,
                2.300: 0.294,
                2.400: 0.293,
                2.500: 0.292,
                2.600: 0.291,
                2.700: 0.291,
                2.800: 0.29,
                2.900: 0.289,
                3.000: 0.288,
                3.100: 0.287,
                3.200: 0.287,
                3.300: 0.286,
                3.400: 0.285,
                3.500: 0.284,
                3.600: 0.283,
                3.700: 0.283,
                3.800: 0.282,
                3.900: 0.281,
                4.000: 0.28,
                4.100: 0.28,
                4.200: 0.279,
                4.300: 0.278,
                4.400: 0.277,
                4.500: 0.276,
                4.600: 0.276,
                4.700: 0.275,
                4.800: 0.274,
                4.900: 0.273,
                5.000: 0.272,
                5.100: 0.272,
                5.200: 0.271,
                5.300: 0.27,
                5.400: 0.269,
                5.500: 0.269,
                5.600: 0.269,
                5.700: 0.269,
                5.800: 0.269,
                5.900: 0.269,
                6.000: 0.269,
                6.100: 0.269,
                6.200: 0.269,
                6.300: 0.269,
                6.400: 0.269,
                6.500: 0.269,
                6.600: 0.269,
                6.700: 0.269,
                6.800: 0.269,
                6.900: 0.269,
                7.000: 0.269,
                7.100: 0.269,
                7.200: 0.269,
                7.300: 0.269,
                7.400: 0.269,
                7.500: 0.269,
                7.600: 0.269,
                7.700: 0.269,
                7.800: 0.269,
                7.900: 0.269,
                8.000: 0.269,
                8.100: 0.269,
                8.200: 0.269,
                8.300: 0.269,
                8.400: 0.269,
                8.500: 0.269,
                8.600: 0.269,
                8.700: 0.269,
                8.800: 0.269,
                8.900: 0.269,
                9.000: 0.269,
                9.100: 0.269,
                9.200: 0.269,
                9.300: 0.269,
                9.400: 0.269,
                9.500: 0.269,
                9.600: 0.269,
                9.700: 0.269,
                9.800: 0.269,
                9.900: 0.269,
                10.000: 0.269
            };
504
            // compareObject("Ytorrentiel", res.getValue("tor"), t, 0.03);
505
            compareExtraResult("Ytorrentiel", res, "tor", t, 0.03);
506

Mathias Chouet's avatar
Mathias Chouet committed
507
            // tslint:disable-next-line:max-line-length
508
            // const x = [0.000, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000, 1.100, 1.200, 1.300, 1.400, 1.500, 1.600, 1.700, 1.800, 1.900, 2.000, 2.100, 2.200, 2.300, 2.400, 2.500, 2.600, 2.700, 2.800, 2.900, 3.000, 3.100, 3.200, 3.300, 3.400, 3.500, 3.600, 3.700, 3.800, 3.900, 4.000, 4.100, 4.200, 4.300, 4.400, 4.500, 4.600, 4.700, 4.800, 4.900, 5.000, 5.100, 5.200, 5.300, 5.400, 5.500, 5.600, 5.700, 5.800, 5.900, 6.000, 6.100, 6.200, 6.300, 6.400, 6.500, 6.600, 6.700, 6.800, 6.900, 7.000, 7.100, 7.200, 7.300, 7.400, 7.500, 7.600, 7.700, 7.800, 7.900, 8.000, 8.100, 8.200, 8.300, 8.400, 8.500, 8.600, 8.700, 8.800, 8.900, 9.000, 9.100, 9.200, 9.300, 9.400, 9.500, 9.600, 9.700, 9.800, 9.900, 10.000];
509
            // compareArray("abscisses", res.getValue("trX"), x);
510

511
            const expLog = new cLog();
512

513
            let m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE);
514
            m.extraVar.Yc = 0.403;
515
516
            expLog.add(m);

517
            m = new Message(MessageCode.INFO_REMOUS_H_NORMALE);
518
            m.extraVar.Yn = 0.253;
519
520
            expLog.add(m);

Mathias Chouet's avatar
Mathias Chouet committed
521
            expLog.add(new Message(MessageCode.WARNING_REMOUS_PAS_CALCUL_DEPUIS_AVAL));
522

523
            expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL));
524

525
            compareLog(res.globalLog, expLog);
526
527
528
        });
    });
});