Newer
Older
Dorchies David
committed
import { round, XOR } from "./base";

Grand Francois
committed
import { Dichotomie } from "./dichotomie";
import { Nub } from "./nub";
import { ParamsEquation } from "./param/params-equation";
import { ParamDefinition, ParamCalculability } from "./param/param-definition";
import { ParamDomainValue } from "./param/param-domain";
Dorchies David
committed
import { acSection, ParamsSection } from "./section/section_type";
import { cLog } from "./util/log";
Dorchies David
committed
import { Message, MessageCode } from "./util/message";
import { Result } from "./util/result";
import { ResultElement } from "./util/resultelement";
import { ParamValueIterator, ParamValues, BaseParam } from ".";

Grand Francois
committed
export enum MethodeResolution {
Dorchies David
committed
Trapezes, EulerExplicite, RungeKutta4

Grand Francois
committed
}
/**
* paramètres pour les courbes de remous
*/
export class CourbeRemousParams extends ParamsEquation {
Dorchies David
committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* section associée
*/
private _section: acSection;
/**
* Débit amont
*/
// private _Qamont: ParamDefinition;
/**
* Tirant imposé à l'amont
*/
private _Yamont: ParamDefinition;
/**
* Tirant imposé à l'aval
*/
private _Yaval: ParamDefinition;
/**
* Longueur du bief
*/
private _Long: ParamDefinition;
/**
* Pas de discrétisation de l'espace (positif en partant de l'aval, négatif en partant de l'amont)
*/
private _Dx: ParamDefinition;
/**
* Méthode de résolution de l'équation différentielle
*/
private _methodeResolution: MethodeResolution;
constructor(s: acSection, rYamont: number, rYAval: number, rLong: number, rDx: number, meth: MethodeResolution) {
super();
this._section = s;
this._Yamont = new ParamDefinition("Yamont", ParamDomainValue.POS, rYamont);
this._Yaval = new ParamDefinition("Yaval", ParamDomainValue.POS, rYAval);
this._Long = new ParamDefinition("Long", ParamDomainValue.POS, rLong);
this._Dx = new ParamDefinition("Dx", ParamDomainValue.POS, rDx);
Dorchies David
committed
this._methodeResolution = meth;
this.addParamDefinition(this._Yamont);
this.addParamDefinition(this._Yaval);
this.addParamDefinition(this._Long);
this.addParamDefinition(this._Dx);
this.addParamDefinitions(this._section.prms);
this.DefineCalculability(); // Pour ne pas remettre en undefined les prms de _section
Dorchies David
committed
}
get Sn() {
return this._section;
}
get Yamont() {
return this._Yamont;
}
get Yaval() {
return this._Yaval;
}
get Long() {
return this._Long;
}
get Dx(): ParamDefinition {
return this._Dx;
}
get methodeResolution() {
return this._methodeResolution;
}

Grand Francois
committed
}
/**
* Calcul d'une courbe de remous
*/
Dorchies David
committed
// tslint:disable-next-line:max-classes-per-file

Grand Francois
committed
export class CourbeRemous extends Nub {
Dorchies David
committed
[key: string]: any; // pour pouvoir faire this['methode]();
private _debugDicho: boolean = false;
private Dx: number;
Dorchies David
committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* Journal de calcul
*/
// private _log: cLog;
private prmSect: ParamsSection;
constructor(crp: CourbeRemousParams, dbg: boolean = false) {
super(crp, dbg);
// this._log = crp.Sn.log;
this.prmSect = crp.Sn.prms;
this.Sn.Calc("Yc");
}
/**
* @param val_a_cal nom de la variable à calculer
*/
public calculRemous(val_a_cal: string):
// {
// "flu": { [key: number]: number; },
// "tor": { [key: number]: number; },
// "trX": string[],
// "tRes": { [key: number]: number }
// }
Result {
const res = new Result();
// let Yc: number = this.Sn.Calc("Yc");
const rYC = this.Sn.Calc("Yc");
if (!rYC.ok) {
res.addLog(rYC.log);
return res;
}
const Yc: number = rYC.vCalc;
const rB: Result = this.Sn.Calc("B", this.Sn.prms.YB.v);
if (!rB.ok) {
res.addLog(rB.log);
return res;
}
let m: Message = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE);
// m.extraVar["B"] = this.Sn.Calc("B", this.Sn.prms.YB.v);
m.extraVar.B = rB.vCalc;
// this._log.add(m);
res.addMessage(m);
m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE);
m.extraVar.Yc = Yc;
// this._log.add(m);
res.addMessage(m);
const rYN = this.Sn.Calc("Yn");
if (!rYN.ok) {
res.addLog(rYN.log);
return res;
}
const Yn = rYN.vCalc;
m = new Message(MessageCode.INFO_REMOUS_H_NORMALE);
m.extraVar.Yn = Yn;
// this._log.add(m);
res.addMessage(m);
// this.debug("largeur berge " + this.Sn.Calc("B"));
// const rB2: Result = this.Sn.Calc("B")
// this.debug("largeur berge " + rB2.vCalc);
// this.debug("hauteur critique " + Yc);
// this.Sn.HautNormale = this.Sn.Calc("Yn");
// this.debug("hauteur normale " + this.Sn.HautNormale);
// this.debug("hauteur normale " + Yn);
// Calcul des courbes de remous

Grand Francois
committed
const xValues = new ParamValues();
xValues.setValues(0, this.prms.Long.v, this.prms.Dx.v)

Grand Francois
committed
Dorchies David
committed
// let crbFlu: { [key: number]: number; } = this.calculFluvial();

Grand Francois
committed
const rCourbeFlu: ResultElement = this.calculFluvial(xValues);
Dorchies David
committed
// if (!rCourbeFlu.ok) {
res.addLog(rCourbeFlu.log);
// return res;
// }
// let crbTor: { [key: number]: number; } = this.calculTorrentiel();

Grand Francois
committed
const rCourbeTor: ResultElement = this.calculTorrentiel(xValues);
Dorchies David
committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// if (!rCourbeTor.ok) {
res.addLog(rCourbeTor.log);
// return res;
// }
let crbFlu = rCourbeFlu.getExtraResult("trY");
if (crbFlu === undefined) {
crbFlu = {};
}
let crbTor = rCourbeTor.getExtraResult("trY");
if (crbTor === undefined) {
crbTor = {};
}
// this.debug("HautCritique ", this.Sn.HautCritique);
this.debug("flu ");
// this.logObject(crbFlu);
this.debug(JSON.stringify(crbFlu));
this.debug("tor");
// this.logObject(crbTor);
this.debug(JSON.stringify(crbTor));
// tslint:disable-next-line:forin
for (const xflu in crbFlu) {
const yflu = crbFlu[xflu];
// this.debug("imp x " + xflu + " flu " + this.Sn.Calc('Imp', yflu));
}
// tslint:disable-next-line:forin
for (const xtor in crbTor) {
const ytor = crbTor[xtor];
// this.debug("imp x " + xtor + " tor " + this.Sn.Calc('Imp', ytor));
}
// Détection du ressaut hydraulique
const nFlu: number = this.size(crbFlu);
const nTor: number = this.size(crbTor);
if (nFlu !== 0 && nTor !== 0) {
const firstYFlu = crbFlu[0];
const lastYTor = this.last(crbTor);
// this.debug("end flu " + firstYFlu);
// this.debug("end tor " + lastYTor);
// this.debug("nFlu " + nFlu);
// this.debug("nTor " + nTor);
// this.debug("Imp flu " + this.Sn.Calc('Imp', firstYFlu));
// this.debug("Imp tor " + this.Sn.Calc('Imp', lastYTor));
let crbComplete: any;
let crbPartielle: any;
let iSens: number;
let sSens: string;
if (nFlu > nTor || (nFlu === nTor && Yn < Yc)) {
// La courbe fluviale va jusqu'au bout
crbComplete = crbFlu; // courbe calculée sur tout le bief
crbPartielle = crbTor; // courbe calculée sur une partie seulement du bief
iSens = 1; // On cherche l'aval du ressaut
sSens = "amont";
this.debug("complete=flu, partielle=tor");
// this.debug("complete(flu)");
// this.debug(crbComplete);
// this.debug("partielle(tor)");
// this.debug(crbPartielle);
} else {
// La courbe torrentielle va jusqu'au bout
crbComplete = crbTor;
crbPartielle = crbFlu;
iSens = -1; // On cherche l'amont du ressaut
sSens = "aval";
this.debug("complete=tor, partielle=flu");
// this.debug("complete(tor)");
// this.debug(crbComplete);
// this.debug("partielle(flu)");
// this.debug(crbPartielle);
}
// Parcours des sections de la ligne d'eau la plus courte
const trX: string[] = Object.keys(crbPartielle);
if (iSens === -1) {// tri dans l'ordre croissant { {
trX.sort((a, b) => {
if (+a > +b) { return 1; }
if (+a < +b) { return -1; }
return 0;
});
} else { // tri dans l'ordre décroissant { {
trX.sort((a, b) => {
if (+a > +b) { return -1; }
if (+a < +b) { return 1; }
return 0;
});
}
const trXr = trX.slice(0); // copie
trXr.reverse();
// this.debug("trX");
// this.debug(trX);
let bRessaut = false;

Grand Francois
committed
const Dx = xValues.step;
Dorchies David
committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
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
for (let irX = 0; irX < trX.length; irX++) {
const rX: number = +trX[irX];
// this.debug("irX=" + irX);
// this.debug("rX=" + rX);
// this.debug("partielle[" + rX + "]=" + crbPartielle[rX]);
// Calcul de l'abscisse de la section dans l'autre régime
const rYCO = this.Sn.Calc("Yco", crbPartielle[rX]); // Y conjugué
if (!rYCO.ok) {
res.addLog(rYCO.log);
return res;
}
const Yco = rYCO.vCalc;
// this.debug("rX=" + rX + " Yco(Ypartiel=" + crbPartielle[rX] + ")=" + Yco);
const rLongRst = 5 * Math.abs(crbPartielle[rX] - Yco); // Longueur du ressaut
// this.debug("longueur ressaut=" + rLongRst);
let xRst = rX + Math.round(iSens * rLongRst / Dx) * Dx; // Abscisse où comparer Yconj et Y
// this.debug("xRst=" + xRst);
// let rxRst = rX + iSens * rLongRst; // Abscisse réelle du ressaut
// this.debug("xRst reel=" + (rX + iSens * rLongRst));
xRst = round(xRst, this.prmSect.iPrec.v);
// this.debug("xRst (arr)=" + xRst);
const impYpartielle = this.Sn.Calc("Imp", crbPartielle[rX]);
// this.debug("imp(Ypartiel[rX=" + rX + "]=" + crbPartielle[rX] + ")=" + impYpartielle);
if (!impYpartielle.ok) {
res.addLog(impYpartielle.log);
return res;
}
if (crbComplete[xRst] !== undefined) {
// Hauteur décalée de la longueur du ressaut (il faut gérer la pente du fond)
const Ydec: number = crbComplete[xRst] + rLongRst * this.prmSect.If.v * iSens;
// this.debug("Ydec=" + Ydec);
const impYcomplete = this.Sn.Calc("Imp", crbComplete[xRst]);
// this.debug("imp(Ycomplet[xRst=" + xRst + "]=" + crbComplete[xRst] + ")=" + impYcomplete);
if (!impYcomplete.ok) {
res.addLog(impYcomplete.log);
return res;
}
if (impYpartielle.vCalc > impYcomplete.vCalc) {
this.debug(
"Ressaut hydraulique détecté entre les abscisses " +
Math.min(rX, xRst) + " et " + Math.max(rX, xRst));
m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO);
m.extraVar.xmin = Math.min(rX, xRst);
m.extraVar.xmax = Math.max(rX, xRst);
// this._log.add(m);
res.addMessage(m);
// this.debug("rX=" + rX + " xRst=" + xRst);
// Modification de la ligne d'eau complète
for (const pi of trXr) {
const rXCC: number = +pi;
// this.debug("rXCC=" + rXCC);
if (iSens * (rXCC - rX) <= 0) {
delete crbComplete[rXCC];
this.debug(
"Modification de la ligne d'eau complète : suppression de la valeur à rXCC=" +
rXCC + ", rX=" + rX + ", iSens*(rXCC-rX)=" + (iSens * (rXCC - rX))
);
}
}
// Modification de la ligne d'eau partielle
for (const xcn of trX) {
const rXCN = +xcn;
// this.debug("rXCN=" + rXCN);
if (iSens * (rXCN - xRst) >= 0) {
this.debug(
"Modification de la ligne d'eau partielle : suppression de la valeur à rX=" + rXCN
);
delete crbPartielle[rXCN];
}
}
bRessaut = true;
break;
}
}
}
if (!bRessaut) {
// Le ressaut est en dehors du canal
m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS);
m.extraVar.sens = sSens;
m.extraVar.x = +this.last(trX);
// this._log.add(m);
res.addMessage(m);
this.debug("Ressaut hydraulique détecté à l'" + sSens + " de l'abscisse " + this.last(trX));
if (iSens === 1) {
crbTor = {};
} else {
crbFlu = {};
}
crbPartielle = {}; // pour le log uniquement, à virer
}
this.debug("complete (" + (iSens === 1 ? "flu" : "tor") + ") modifiée");
// this.logObject(crbComplete);
this.debug(JSON.stringify(crbComplete));
this.debug("partielle (" + (iSens === 1 ? "tor" : "flu") + ") modifiée");
// this.logObject(crbPartielle);
this.debug(JSON.stringify(crbPartielle));
}
// Définition des abscisses
let trX: number[] = [];
if (nFlu !== 0) {
trX = Object.keys(crbFlu).map((k) => +k);
}
if (nTor !== 0) {
const kTor = Object.keys(crbTor).map(k => +k);
trX = trX.concat(kTor);
}
// this.debug("trX=" + trX);
trX.sort((a, b) => {
if (a > b) { return 1; }
if (a < b) { return -1; }
return 0;
});
// this.debug("trX tri=" + trX);
trX = trX.filter((elem, index, array) => {
if (index > 0) {
return elem !== array[index - 1];
}
return true;
});
// this.debug("trX unique=" + trX);
this.debug("abscisses ");
this.logArray(trX);
// Calcul de la variable à calculer
const tRes: { [key: number]: number } = {};
if (val_a_cal !== undefined && (nFlu !== 0 || nTor !== 0)) {
for (const rX of trX) {
let rY: number;
const hasFlu: boolean = crbFlu[rX] !== undefined;
const hasTor: boolean = crbTor[rX] !== undefined;
if (hasFlu && !hasTor) {
rY = crbFlu[rX];
}
if (hasTor) {
if (!hasFlu || (hasFlu && crbFlu[rX] === crbTor[rX])) {
rY = crbTor[rX];
}
}
if (rY !== undefined) {
// tRes[+rX] = this.Sn.Calc(val_a_cal, rY);
const rVar = this.Sn.Calc(val_a_cal, rY);
if (!rVar.ok) {
res.addLog(rVar.log);
return res;
}
tRes[rX] = rVar.vCalc;
this.debug("X=" + rX + " Calc(" + val_a_cal + ", Y=" + rY + ")=" + tRes[rX]);
}
}
this.debug("extra param " + val_a_cal);
this.logObject(tRes);
}
const hasRes = Object.keys(tRes).length > 0;
for (const x of trX) {
let ligneDeau;
if (crbFlu[x] === undefined) {
ligneDeau = crbTor[x];
} else if (crbTor[x] === undefined) {
ligneDeau = crbFlu[x];
} else {
ligneDeau = Math.max(crbFlu[x], crbTor[x]);
}
const re = new ResultElement(ligneDeau);
if (crbFlu[x]) {
re.addExtraResult("flu", crbFlu[x]);
}
if (crbTor[x]) {
re.addExtraResult("tor", crbTor[x]);
}
if (hasRes && tRes[x]) {
re.addExtraResult("tRes", tRes[x]);
}
res.addResultElement(re);
}
Dorchies David
committed
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
return res;
}
public Calc(sVarCalc: string, rInit?: number, rPrec: number = 0.001): Result {
if (sVarCalc === "Hs") {
return this.Equation(sVarCalc);
}
throw new Error("CourbeRemous.Calc() : parameter " + sVarCalc + " not allowed");
}
public Equation(sVarCalc: string): Result {
if (sVarCalc === "Hs") {
// Equation de l'intégration par la méthode des trapèzes
this.Sn.Reset(); // pour forcer le calcul avec la nouvelle valeur de prmSect.Y
// let res: number = this.Sn.Calc('Hs') - this.Sn.Calc('J') / 2 * this.Dx;
const rHS = this.Sn.Calc("Hs");
if (!rHS.ok) {
return rHS;
}
const rJ = this.Sn.Calc("J");
if (!rJ.ok) {
return rJ;
}
const res: number = rHS.vCalc - rJ.vCalc / 2 * this.Dx;
return new Result(res);
}
throw new Error("CourbeRemous.Equation() : parameter " + sVarCalc + " not allowed");
}
private get Sn(): acSection {
return this.prms.Sn;
}
private get prms(): CourbeRemousParams {
return this._prms as CourbeRemousParams;
}
protected setParametersCalculability() {
this.prms.map.Y.calculability = ParamCalculability.DICHO;
this.prms.Long.calculability = ParamCalculability.FREE;
this.prms.map.Dx.calculability = ParamCalculability.FREE;
this.prms.map.Yamont.calculability = ParamCalculability.FREE;
this.prms.map.Yaval.calculability = ParamCalculability.FREE;
}
/**
* calcul de la ligne fluviale depuis l'aval (si possible)
*/
private calculFluvial(xValues: ParamValues): ResultElement {
if (!this.Sn.HautCritique.ok) {
return new ResultElement(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
let res: ResultElement;
// Calcul depuis l'aval
if (this.Sn.HautCritique.vCalc <= this.prms.Yaval.v) {
// this._log.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL));
this.debug(
`Condition limite aval (${this.prms.Yaval.v}) >= ` +
`Hauteur critique (${this.Sn.HautCritique}) : calcul de la partie fluviale à partir de l'aval`);
this.Dx = this.prms.Dx.v;
xValues.initIterator(true);
res = this.calcul(this.prms.Yaval.v, xValues);
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
res.insertMessage(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL));
} else {
this.debug(
"Condition limite aval (" + this.prms.Yaval.v +
") < Hauteur critique (" + this.Sn.HautCritique +
") : pas de calcul possible depuis l'aval");
// this._log.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL));
res = new ResultElement();
res.addMessage(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL));
}
return res;
}
/**
* calcul de la ligne torrentielle depuis l'amont (si possible)
*/
private calculTorrentiel(xValues: ParamValues): ResultElement {
if (!this.Sn.HautCritique.ok) {
return new ResultElement(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
let res: ResultElement;
// Calcul depuis l'amont
if (this.Sn.HautCritique.vCalc >= this.prms.Yamont.v) {
// this._log.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL));
this.debug(
"Condition limite amont (" + this.prms.Yamont.v +
") <= Hauteur critique (" + this.Sn.HautCritique +
") : calcul de la partie torrentielle à partir de l'amont");
this.Dx = -this.prms.Dx.v;
xValues.initIterator(false);
res = this.calcul(this.prms.Yamont.v, xValues);
res.insertMessage(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL));
} else {
// this._log.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT));
this.debug(
"Condition limite amont (" + this.prms.Yamont.v +
") > Hauteur critique (" + this.Sn.HautCritique +
") : pas de calcul possible depuis l'amont");
res = new ResultElement();
res.addMessage(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT));
}
return res;
}
Dorchies David
committed
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/**
* Calcul de dy/dx (utilisé par Euler explicite et Runge-Kutta 4)
* @param Y Tirant d'eau initial
*/
private Calc_dYdX(Y: number): Result {
// L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau
// return - (this.prmSect.If.v - this.Sn.Calc('J', Y)) / (1 - Math.pow(this.Sn.Calc('Fr', Y), 2));
const rJ = this.Sn.Calc("J", Y);
if (!rJ.ok) {
return rJ;
}
const rFR = this.Sn.Calc("Fr", Y);
if (!rFR.ok) {
return rFR;
}
const v = - (this.prmSect.If.v - rJ.vCalc) / (1 - Math.pow(rFR.vCalc, 2));
return new Result(v);
}
/**
* Calcul du point suivant de la courbe de remous par la méthode Euler explicite.
* @param Y Tirant d'eau initial
* @return Tirant d'eau
*/
private Calc_Y_EulerExplicite(Y: number): Result {
if (!this.Sn.HautCritique.ok) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
// L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau
const rDXDY = this.Calc_dYdX(Y);
if (!rDXDY.ok) {
return rDXDY;
}
// let Y2 = Y + this.Dx * this.Calc_dYdX(Y);
const Y2 = Y + this.Dx * rDXDY.vCalc;
return new Result(Y2);
}
/**
* Calcul du point suivant de la courbe de remous par la méthode RK4.
* @param Y Tirant d'eau initial
* @return Tirant d'eau
*/
private Calc_Y_RK4(Y: number): Result {
if (!this.Sn.HautCritique.ok) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
// L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau
const rDx = this.Dx;
// let k1 = this.Calc_dYdX(Y);
const rDXDY: Result = this.Calc_dYdX(Y);
if (!rDXDY.ok) {
return rDXDY;
}
const k1 = rDXDY.vCalc;
const hc = this.Sn.HautCritique.vCalc;
if (XOR(rDx > 0, !(Y + rDx / 2 * k1 < hc))) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
// let k2 = this.Calc_dYdX(Y + Dx / 2 * k1);
const rDXDY2: Result = this.Calc_dYdX(Y + rDx / 2 * k1);
if (!rDXDY2.ok) {
return rDXDY2;
}
const k2 = rDXDY2.vCalc;
if (XOR(rDx > 0, !(Y + rDx / 2 * k2 < hc))) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
// let k3 = this.Calc_dYdX(Y + Dx / 2 * k2);
const rDXDY3: Result = this.Calc_dYdX(Y + rDx / 2 * k2);
if (!rDXDY3.ok) {
return rDXDY3;
}
const k3 = rDXDY3.vCalc;
if (XOR(rDx > 0, !(Y + rDx / 2 * k3 < hc))) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
// let k4 = this.Calc_dYdX(Y + Dx * k3);
const rDXDY4: Result = this.Calc_dYdX(Y + rDx * k3);
if (!rDXDY4.ok) {
return rDXDY4;
}
const k4 = rDXDY4.vCalc;
const Yout = Y + rDx / 6 * (k1 + 2 * (k2 + k3) + k4);
// if ($this ->rDx > 0 xor !($Yout < $this ->oSect ->rHautCritique)) { return false; }
if (XOR(rDx > 0, !(Yout < hc))) {
const res = new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
return new Result(Yout);
}
/**
* Calcul du point suivant de la courbe de remous par la méthode de l'intégration par trapèze
* @param Y Tirant d'eau initial
* @return Tirant d'eau
*/
private Calc_Y_Trapez(Y: number): Result {
if (!this.Sn.HautCritique.ok) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
}
const dicho = new Dichotomie(this, "Y", this._debugDicho, "Hs");
// Calcul de H + J * \Delta x / 2
// let Trapez_Fn = this.Sn.Calc('Hs', Y) + this.Sn.Calc('J', Y) / 2 * this.Dx
const rHS: Result = this.Sn.Calc("Hs", Y);
if (!rHS.ok) {
return rHS;
}
const rJ: Result = this.Sn.Calc("J", Y);
if (!rJ.ok) {
return rJ;
}
let trapezFn = rHS.vCalc + rJ.vCalc / 2 * this.Dx;
// H est la charge totale. On se place dans le référentiel ou Zf de la section à calculer = 0
trapezFn -= this.Dx * this.prmSect.If.v;
const r: Result = dicho.Dichotomie(trapezFn, this.prmSect.Prec.v, Y);
if (!r.ok) {
return r;
}
// return new Result(Y2);
return r;
}
/**
* Calcul du point suivant d'une courbe de remous
* @param Y Tirant d'eau initial
* @return Tirant d'eau
*/
private Calc_Y(Y: number): Result {
// let funcCalcY = 'Calc_Y_' + Resolution;
// return this[funcCalcY](Y);
let res: Result;
Dorchies David
committed
switch (this.prms.methodeResolution) {
case MethodeResolution.Trapezes:
res = this.Calc_Y_Trapez(Y);
break;
Dorchies David
committed
case MethodeResolution.RungeKutta4:
res = this.Calc_Y_RK4(Y);
break;
Dorchies David
committed
case MethodeResolution.EulerExplicite:
res = this.Calc_Y_EulerExplicite(Y);
break;
default:
throw new Error("CourbeRemous.Calc_Y() : type de méthode de résolution " +
MethodeResolution[this.prms.methodeResolution] + " non pris en charge");
}
Dorchies David
committed
if (!res.ok || XOR(this.Dx > 0, !(res.vCalc < this.Sn.HautCritique.vCalc))) {
return new Result(new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE));
Dorchies David
committed
}
return res;
Dorchies David
committed
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
}
private size(o: {}): number {
let res: number = 0;
for (const i in o) {
res++;
}
return res;
}
private last(o: any): any {
let res: any;
for (const i in o) {
res = o[i];
}
return res;
}
/**
* Calcul d'une courbe de remous en fluvial ou torrentiel
* @param YCL Condition limite amont (torrentiel) ou aval (fluvial)
*/
private calcul(YCL: number, varParam: ParamValues): ResultElement {
Dorchies David
committed
const trY: { [key: number]: number; } = {};
const res = new ResultElement();
let lastY = YCL;
trY[round(varParam.next, this.prmSect.iPrec.v)] = lastY;
Dorchies David
committed
// Boucle de calcul de la courbe de remous
while (varParam.hasNext) {
const x = varParam.next;
Dorchies David
committed
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
// this.debug("lastY " + lastY);
const rY: Result = this.Calc_Y(lastY);
// this.debug("calcul : x " + x + " y " + rY.vCalc);
// this.debug("trY ");
// this.logObject(trY);
// this.debug("end trY " + this.last(trY));
// this.debug("Yn " + this.Sn.HautNormale);
if (rY.ok) {
// on vérifie qu'on ne traverse pas la hauteur normale (à la précision de calcul près)
const prec: number = this.prms.map.Prec.v;
const b1: boolean = lastY - this.Sn.HautNormale > prec;
const b2: boolean = rY.vCalc - this.Sn.HautNormale > prec;
if (XOR(b1, b2)) {
this.debug(
"La pente de la ligne d'eau est trop forte à l'abscisse "
+ x + " m (Il faudrait réduire le pas de discrétisation)"
);
const m: Message = new Message(MessageCode.ERROR_REMOUS_PENTE_FORTE);
m.extraVar.x = x;
// this._log.add(m);
res.addMessage(m);
}
trY[round(x, this.prmSect.iPrec.v)] = rY.vCalc;
} else {
const m = new Message(MessageCode.WARNING_REMOUS_ARRET_CRITIQUE);
m.extraVar.x = x;
// this._log.add(m);
res.addMessage(m);
this.debug("Arrêt du calcul : Hauteur critique atteinte à l'abscisse " + x + " m");
break;
}
lastY = rY.vCalc;
}
// return trY;
res.addExtraResult("trY", trY);
return res;
}
private logArray(a: any[]) {
let s = "[";
let first = true;
for (const e of a) {
if (!first) {
s += ",";
}
s += String(e);
first = false;
}
s += "]";
this.debug(s);
}
private logObject(o: { [key: number]: number }) {
if (o === undefined) {
this.debug("<undefined>");
} else {
const ks: string[] = Object.keys(o);
ks.sort((a, b) => {
if (+a > +b) { return 1; }
if (+a < +b) { return -1; }
return 0;
});
for (const k of ks) {
this.debug("[" + (+k).toFixed(3) + "]=" + o[+k]);
}
}
}