diff --git a/spec/section_param_trapez.spec_fluvial.spec.ts b/spec/section_param_trapez.spec_fluvial.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d0d6a9a106b887e76ca4322e517cd11d0b4fdee9 --- /dev/null +++ b/spec/section_param_trapez.spec_fluvial.spec.ts @@ -0,0 +1,116 @@ +/// <reference path="../node_modules/@types/jasmine/index.d.ts" /> + +import { Result } from "../src/base"; +import { nub, precDigits, precDist } from "./nubtest"; +import { cSnTrapez } from "../src/section/section_trapez"; +import { cParamsCanal } from "../src/section/section_type"; + +let paramCnl: cParamsCanal; +let sect: cSnTrapez; + +describe('Section paramétrée trapèze : ', () => { + beforeEach(() => { + paramCnl = new cParamsCanal(40, // Ks=Strickler + 1.2, // Q=Débit + 0.001, // If=pente du fond + precDist, // précision + 1 // YB= hauteur de berge + // YCL=Condition limite en cote à l'amont ou à l'aval + ); + + sect = new cSnTrapez(undefined, paramCnl, + 2.5, // largeur de fond + 0.56 // fruit + ); + // tirant d'eau + sect.v.Y = 0.8; + }); + + describe('fluvial :', () => { + // charge spécifique + it('Hs should equal to 0.813', () => { + expect(sect.Calc_Hs()).toBeCloseTo(0.813, precDigits); + }); + + // charge critique + it('Hsc should equal to 0.413', () => { + expect(sect.Calc_Hsc()).toBeCloseTo(0.413, precDigits); + }); + + // largeur au miroir + it('B should equal to 3.396', () => { + expect(sect.Calc_B()).toBeCloseTo(3.396, precDigits); + }); + + // périmètre mouillé + it('P should equal to 4.334', () => { + expect(sect.Calc_P()).toBeCloseTo(4.334, precDigits); + }); + + // surface mouillée + it('S should equal to 2.358', () => { + expect(sect.Calc_S()).toBeCloseTo(2.358, precDigits); + }); + + // rayon hydraulique + it('R should equal to 0.544', () => { + expect(sect.Calc_R()).toBeCloseTo(0.544, precDigits); + }); + + // vitesse moyenne + it('V should equal to 0.509', () => { + expect(sect.Calc_V()).toBeCloseTo(0.509, precDigits); + }); + + // nombre de Froude + it('Fr should equal to 0.195', () => { + expect(sect.Calc_Fr()).toBeCloseTo(0.195, precDigits); + }); + + // tirant d'eau critique + it('Yc should equal to 0.28', () => { + expect(sect.Calc_Yc()).toBeCloseTo(0.28, precDigits); + }); + + // tirant d'eau normal + it('Yn should equal to 0.587', () => { + expect(sect.Calc_Yn()).toBeCloseTo(0.587, precDigits); + }); + + // tirant d'eau fluvial + it('Yf should equal to 0.8', () => { + expect(sect.Calc_Yf()).toBeCloseTo(0.8, precDigits); + }); + + // tirant d'eau torrentiel + it('Yt should equal to 0.127', () => { + expect(sect.Calc_Yt()).toBeCloseTo(0.127, precDigits); + }); + + // tirant d'eau conjugué + it('Yco should equal to 0.061', () => { + expect(sect.Calc_Yco()).toBeCloseTo(0.061, precDigits); + }); + + // perte de charge + it('J should equal to 0.00036', () => { + paramCnl.v.Prec = 0.00001; + expect(sect.Calc_J()).toBeCloseTo(0.00036, precDigits); + }); + + // Variation linéaire de l'énergie spécifique + it('I-J should equal to 0.001', () => { + expect(sect.Calc('I-J')).toBeCloseTo(0.001, precDigits); + }); + + // impulsion hydraulique + it('Imp should equal to 9396.158', () => { + expect(sect.Calc_Imp()).toBeCloseTo(9396.158, precDigits); + }); + + // force tractrice (contrainte de cisaillement) + it('Tau0 should equal to 1.944', () => { + expect(sect.Calc_Tau0()).toBeCloseTo(1.944, precDigits); + }); + }); +}); diff --git a/src/section/hauteur.ts b/src/section/hauteur.ts index a3ebbc060a3565680ac7783c501a3b4a7c852f55..5ae8046752970523b5dffacd07bce34fc74fea2f 100644 --- a/src/section/hauteur.ts +++ b/src/section/hauteur.ts @@ -14,8 +14,8 @@ export class cHautCritique extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(Sn: acSection, oP: cParamsCanal) { - super(oP); + constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) { + super(oP, dbg); this.Sn = Sn; this.oP = oP; @@ -64,8 +64,8 @@ export class cHautNormale extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(Sn: acSection, oP: cParamsCanal) { - super(oP); + constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) { + super(oP, dbg); this.Sn = Sn; this.Q = oP.v.Q; this.Ks = oP.v.Ks; @@ -106,8 +106,8 @@ export class cHautCorrespondante extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(Sn: acSection, oP: cParamsCanal) { - super(oP); + constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) { + super(oP, dbg); this.Y = Sn.v.Y; this.rS2 = Math.pow(Sn.Calc('S'), -2); this.Sn = Sn; @@ -160,8 +160,8 @@ export class cHautConjuguee extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(oSn: acSection, oP: cParamsCanal) { - super(oP); + constructor(oSn: acSection, oP: cParamsCanal, dbg: boolean = false) { + super(oP, dbg); this.Y = oSn.v.Y; this.rQ2 = Math.pow(oP.v.Q, 2); this.Sn = oSn; diff --git a/src/section/newton.ts b/src/section/newton.ts index f09889d0af00cba670251f22da9aebeeabae41d9..592beb944802773c6759d6f2d1808eee2d9d8cb4 100644 --- a/src/section/newton.ts +++ b/src/section/newton.ts @@ -1,7 +1,8 @@ +import { Debug } from "../base" import { cParamsCanal } from "./section_type" import { cLog } from "./log"; -export abstract class acNewton { +export abstract class acNewton extends Debug { protected rTol: number; protected Dx: number; private iCpt = 0; @@ -15,7 +16,8 @@ export abstract class acNewton { * Constructeur de la classe * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(oP: cParamsCanal) { + constructor(oP: cParamsCanal, dbg: boolean = false) { + super(dbg); this.rTol = oP.v.Prec; this.Dx = oP.v.Prec / 10; } @@ -56,13 +58,18 @@ export abstract class acNewton { } public Newton(rX) { + this.debug('in Newton(rX=' + rX + ')'); this.iCpt++; + this.debug('Newton : calcul de Fn...') var rFn = this.CalcFn(rX); + this.debug('Newton : Fn -> ' + rFn) if (this.FuzzyEqual(rFn) || this.iCpt >= this.iCptMax) { return rX; } else { + this.debug('Newton : calcul de rDer...') var rDer = this.CalcDer(rX); + this.debug('Newton : rDer -> ' + rDer) //~ echo(' - f\' = '.rDer); if (rDer != 0) { if (this.XOR(rFn < 0, this.rFnPrec < 0)) { diff --git a/src/section/section_type.ts b/src/section/section_type.ts index fcb296e3ddcf008a89de810e8d915e06b1e2fdf6..c80356b0cd21ff9a2aa09ac46184630faaf682fa 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -139,29 +139,41 @@ export abstract class acSection extends Debug { * @param bRecalc Pour forcer le recalcul de la donnée * @return la donnée calculée */ - Calc(sDonnee, rY: number = undefined) { - this.debug("in Calc(" + sDonnee + ', rY=' + rY + ')'); + Calc(sDonnee: string, rY: number = undefined) { + this.debug('in Calc(' + sDonnee + ', rY=' + rY + ') old ' + sDonnee + '=' + this.arCalc[sDonnee]); if (rY != undefined && rY != this.v.Y) { this.v.Y = rY; // On efface toutes les données dépendantes de Y pour forcer le calcul this.Reset(false); } - // | or || ??? if (this.arCalc[sDonnee] == undefined) { // La donnée a besoin d'être calculée switch (sDonnee) { case 'I-J': // Variation linéaire de l'énergie spécifique (I-J) en m/m this.arCalc[sDonnee] = this.oP.v.If - this.Calc('J'); break; + case 'Yn': // Hauteur normale return this.Calc_Yn(); + default: var methode = 'Calc_' + sDonnee; - this.arCalc[sDonnee] = this[methode](); + + /* !!!!! + si on réunit les 2 lignes suivantes ( this.arCalc[sDonnee] = this[methode](); ), + il arrive que this.arCalc[sDonnee] soit affecté à undefined alors que this[methode]() renvoie + une valeur bien définie + !!!!! + */ + let res = this[methode](); + this.arCalc[sDonnee] = res; + break; } + this.debug('Calc(' + sDonnee + ') resultat -> ' + this.arCalc[sDonnee]); } - this.debug('Calc(' + sDonnee + ')=' + this.arCalc[sDonnee]); + else + this.debug('Calc(' + sDonnee + ') cache=' + this.arCalc[sDonnee]); return this.arCalc[sDonnee]; } @@ -172,7 +184,7 @@ export abstract class acSection extends Debug { * @return la donnée calculée */ CalcGeo(sDonnee) { - this.debug("in CalcGeo(" + sDonnee + ')'); + this.debug("in CalcGeo(" + sDonnee + ') old ' + sDonnee + '=' + this.arCalcGeo[sDonnee]); if (sDonnee != 'B' && !this.arCalcGeo['B']) { // Si la largeur aux berges n'a pas encore été calculée, on commence par ça this.CalcGeo('B'); @@ -202,8 +214,11 @@ export abstract class acSection extends Debug { } //~ spip_log('CalcGeo('.sDCalcGeonnee.',rY='.this->oP->rYB.')='.this->arCalcGeo[sDonnee],'hydraulic.'._LOG_DEBUG); this.Swap(false); // On restitue les données hydrauliques en cours + this.debug('CalcGeo(' + sDonnee + ') resultat -> ' + this.arCalcGeo[sDonnee]); } - this.debug('CalcGeo(' + sDonnee + ')=' + this.arCalcGeo[sDonnee]); + // this.debug('CalcGeo(' + sDonnee + ')=' + this.arCalcGeo[sDonnee]); + else + this.debug('CalcGeo(' + sDonnee + ') cache=' + this.arCalcGeo[sDonnee]); return this.arCalcGeo[sDonnee]; } @@ -491,7 +506,7 @@ export abstract class acSection extends Debug { return this.v.Y; } else { - var oHautCorrespondante = new cHautCorrespondante(this, this.oP); + var oHautCorrespondante = new cHautCorrespondante(this, this.oP, this.DBG); return oHautCorrespondante.Newton(this.Calc('Yc') * 2); } } @@ -505,7 +520,7 @@ export abstract class acSection extends Debug { return this.v.Y; } else { - var oHautCorrespondante = new cHautCorrespondante(this, this.oP); + var oHautCorrespondante = new cHautCorrespondante(this, this.oP, this.DBG); return oHautCorrespondante.Newton(this.CalcGeo('Yc') / 2); } } @@ -515,6 +530,7 @@ export abstract class acSection extends Debug { * @return tirant d'eau conjugué */ Calc_Yco() { + this.Swap(true); var oHautConj = new cHautConjuguee(this, this.oP); // Choisir une valeur initiale du bon côté de la courbe if (this.Calc('Fr') < 1) { @@ -525,10 +541,9 @@ export abstract class acSection extends Debug { // Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial Y0 = this.Calc('Yf'); } - /* if(!Yco = oHautConj->Newton(Y0) || !oHautConj.HasConverged()) { - //this->oLog->Add(_T('hydraulic:h_conjuguee').' : '._T('hydraulic:newton_non_convergence'),true); - } - return Yco;*/ // c quoi Yco ? + let Yco = oHautConj.Newton(Y0); + this.Swap(false); + return Yco; } /**