Commit b98cb52e authored by Grand Francois's avatar Grand Francois
Browse files

- ajout des tests sur section paramétrée trapèze en régime fluvial

- classes de calcul de hauteur, classe Newton : ajout flag de debug
- acSection : complété ecriture de Calc_Yco(), correction cas bizarre d'undefined dans Calc()
Showing with 161 additions and 23 deletions
+161 -23
/// <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);
});
});
});
...@@ -14,8 +14,8 @@ export class cHautCritique extends acNewton { ...@@ -14,8 +14,8 @@ export class cHautCritique extends acNewton {
* @param oSn Section sur laquelle on fait le calcul * @param oSn Section sur laquelle on fait le calcul
* @param oP Paramètres supplémentaires (Débit, précision...) * @param oP Paramètres supplémentaires (Débit, précision...)
*/ */
constructor(Sn: acSection, oP: cParamsCanal) { constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) {
super(oP); super(oP, dbg);
this.Sn = Sn; this.Sn = Sn;
this.oP = oP; this.oP = oP;
...@@ -64,8 +64,8 @@ export class cHautNormale extends acNewton { ...@@ -64,8 +64,8 @@ export class cHautNormale extends acNewton {
* @param oSn Section sur laquelle on fait le calcul * @param oSn Section sur laquelle on fait le calcul
* @param oP Paramètres supplémentaires (Débit, précision...) * @param oP Paramètres supplémentaires (Débit, précision...)
*/ */
constructor(Sn: acSection, oP: cParamsCanal) { constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) {
super(oP); super(oP, dbg);
this.Sn = Sn; this.Sn = Sn;
this.Q = oP.v.Q; this.Q = oP.v.Q;
this.Ks = oP.v.Ks; this.Ks = oP.v.Ks;
...@@ -106,8 +106,8 @@ export class cHautCorrespondante extends acNewton { ...@@ -106,8 +106,8 @@ export class cHautCorrespondante extends acNewton {
* @param oSn Section sur laquelle on fait le calcul * @param oSn Section sur laquelle on fait le calcul
* @param oP Paramètres supplémentaires (Débit, précision...) * @param oP Paramètres supplémentaires (Débit, précision...)
*/ */
constructor(Sn: acSection, oP: cParamsCanal) { constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) {
super(oP); super(oP, dbg);
this.Y = Sn.v.Y; this.Y = Sn.v.Y;
this.rS2 = Math.pow(Sn.Calc('S'), -2); this.rS2 = Math.pow(Sn.Calc('S'), -2);
this.Sn = Sn; this.Sn = Sn;
...@@ -160,8 +160,8 @@ export class cHautConjuguee extends acNewton { ...@@ -160,8 +160,8 @@ export class cHautConjuguee extends acNewton {
* @param oSn Section sur laquelle on fait le calcul * @param oSn Section sur laquelle on fait le calcul
* @param oP Paramètres supplémentaires (Débit, précision...) * @param oP Paramètres supplémentaires (Débit, précision...)
*/ */
constructor(oSn: acSection, oP: cParamsCanal) { constructor(oSn: acSection, oP: cParamsCanal, dbg: boolean = false) {
super(oP); super(oP, dbg);
this.Y = oSn.v.Y; this.Y = oSn.v.Y;
this.rQ2 = Math.pow(oP.v.Q, 2); this.rQ2 = Math.pow(oP.v.Q, 2);
this.Sn = oSn; this.Sn = oSn;
......
import { Debug } from "../base"
import { cParamsCanal } from "./section_type" import { cParamsCanal } from "./section_type"
import { cLog } from "./log"; import { cLog } from "./log";
export abstract class acNewton { export abstract class acNewton extends Debug {
protected rTol: number; protected rTol: number;
protected Dx: number; protected Dx: number;
private iCpt = 0; private iCpt = 0;
...@@ -15,7 +16,8 @@ export abstract class acNewton { ...@@ -15,7 +16,8 @@ export abstract class acNewton {
* Constructeur de la classe * Constructeur de la classe
* @param oP Paramètres supplémentaires (Débit, précision...) * @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.rTol = oP.v.Prec;
this.Dx = oP.v.Prec / 10; this.Dx = oP.v.Prec / 10;
} }
...@@ -56,13 +58,18 @@ export abstract class acNewton { ...@@ -56,13 +58,18 @@ export abstract class acNewton {
} }
public Newton(rX) { public Newton(rX) {
this.debug('in Newton(rX=' + rX + ')');
this.iCpt++; this.iCpt++;
this.debug('Newton : calcul de Fn...')
var rFn = this.CalcFn(rX); var rFn = this.CalcFn(rX);
this.debug('Newton : Fn -> ' + rFn)
if (this.FuzzyEqual(rFn) || this.iCpt >= this.iCptMax) { if (this.FuzzyEqual(rFn) || this.iCpt >= this.iCptMax) {
return rX; return rX;
} }
else { else {
this.debug('Newton : calcul de rDer...')
var rDer = this.CalcDer(rX); var rDer = this.CalcDer(rX);
this.debug('Newton : rDer -> ' + rDer)
//~ echo(' - f\' = '.rDer); //~ echo(' - f\' = '.rDer);
if (rDer != 0) { if (rDer != 0) {
if (this.XOR(rFn < 0, this.rFnPrec < 0)) { if (this.XOR(rFn < 0, this.rFnPrec < 0)) {
......
...@@ -139,29 +139,41 @@ export abstract class acSection extends Debug { ...@@ -139,29 +139,41 @@ export abstract class acSection extends Debug {
* @param bRecalc Pour forcer le recalcul de la donnée * @param bRecalc Pour forcer le recalcul de la donnée
* @return la donnée calculée * @return la donnée calculée
*/ */
Calc(sDonnee, rY: number = undefined) { Calc(sDonnee: string, rY: number = undefined) {
this.debug("in Calc(" + sDonnee + ', rY=' + rY + ')'); this.debug('in Calc(' + sDonnee + ', rY=' + rY + ') old ' + sDonnee + '=' + this.arCalc[sDonnee]);
if (rY != undefined && rY != this.v.Y) { if (rY != undefined && rY != this.v.Y) {
this.v.Y = rY; this.v.Y = rY;
// On efface toutes les données dépendantes de Y pour forcer le calcul // On efface toutes les données dépendantes de Y pour forcer le calcul
this.Reset(false); this.Reset(false);
} }
// | or || ???
if (this.arCalc[sDonnee] == undefined) { if (this.arCalc[sDonnee] == undefined) {
// La donnée a besoin d'être calculée // La donnée a besoin d'être calculée
switch (sDonnee) { switch (sDonnee) {
case 'I-J': // Variation linéaire de l'énergie spécifique (I-J) en m/m 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'); this.arCalc[sDonnee] = this.oP.v.If - this.Calc('J');
break; break;
case 'Yn': // Hauteur normale case 'Yn': // Hauteur normale
return this.Calc_Yn(); return this.Calc_Yn();
default: default:
var methode = 'Calc_' + sDonnee; 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]; return this.arCalc[sDonnee];
} }
...@@ -172,7 +184,7 @@ export abstract class acSection extends Debug { ...@@ -172,7 +184,7 @@ export abstract class acSection extends Debug {
* @return la donnée calculée * @return la donnée calculée
*/ */
CalcGeo(sDonnee) { CalcGeo(sDonnee) {
this.debug("in CalcGeo(" + sDonnee + ')'); this.debug("in CalcGeo(" + sDonnee + ') old ' + sDonnee + '=' + this.arCalcGeo[sDonnee]);
if (sDonnee != 'B' && !this.arCalcGeo['B']) { if (sDonnee != 'B' && !this.arCalcGeo['B']) {
// Si la largeur aux berges n'a pas encore été calculée, on commence par ça // Si la largeur aux berges n'a pas encore été calculée, on commence par ça
this.CalcGeo('B'); this.CalcGeo('B');
...@@ -202,8 +214,11 @@ export abstract class acSection extends Debug { ...@@ -202,8 +214,11 @@ export abstract class acSection extends Debug {
} }
//~ spip_log('CalcGeo('.sDCalcGeonnee.',rY='.this->oP->rYB.')='.this->arCalcGeo[sDonnee],'hydraulic.'._LOG_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.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]; return this.arCalcGeo[sDonnee];
} }
...@@ -491,7 +506,7 @@ export abstract class acSection extends Debug { ...@@ -491,7 +506,7 @@ export abstract class acSection extends Debug {
return this.v.Y; return this.v.Y;
} }
else { else {
var oHautCorrespondante = new cHautCorrespondante(this, this.oP); var oHautCorrespondante = new cHautCorrespondante(this, this.oP, this.DBG);
return oHautCorrespondante.Newton(this.Calc('Yc') * 2); return oHautCorrespondante.Newton(this.Calc('Yc') * 2);
} }
} }
...@@ -505,7 +520,7 @@ export abstract class acSection extends Debug { ...@@ -505,7 +520,7 @@ export abstract class acSection extends Debug {
return this.v.Y; return this.v.Y;
} }
else { else {
var oHautCorrespondante = new cHautCorrespondante(this, this.oP); var oHautCorrespondante = new cHautCorrespondante(this, this.oP, this.DBG);
return oHautCorrespondante.Newton(this.CalcGeo('Yc') / 2); return oHautCorrespondante.Newton(this.CalcGeo('Yc') / 2);
} }
} }
...@@ -515,6 +530,7 @@ export abstract class acSection extends Debug { ...@@ -515,6 +530,7 @@ export abstract class acSection extends Debug {
* @return tirant d'eau conjugué * @return tirant d'eau conjugué
*/ */
Calc_Yco() { Calc_Yco() {
this.Swap(true);
var oHautConj = new cHautConjuguee(this, this.oP); var oHautConj = new cHautConjuguee(this, this.oP);
// Choisir une valeur initiale du bon côté de la courbe // Choisir une valeur initiale du bon côté de la courbe
if (this.Calc('Fr') < 1) { if (this.Calc('Fr') < 1) {
...@@ -525,10 +541,9 @@ export abstract class acSection extends Debug { ...@@ -525,10 +541,9 @@ export abstract class acSection extends Debug {
// Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial // Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial
Y0 = this.Calc('Yf'); Y0 = this.Calc('Yf');
} }
/* if(!Yco = oHautConj->Newton(Y0) || !oHautConj.HasConverged()) { let Yco = oHautConj.Newton(Y0);
//this->oLog->Add(_T('hydraulic:h_conjuguee').' : '._T('hydraulic:newton_non_convergence'),true); this.Swap(false);
} return Yco;
return Yco;*/ // c quoi Yco ?
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment