Commit 68e57ae1 authored by Grand Francois's avatar Grand Francois
Browse files

acSection : méthode Calc() renommée en calcFromY(), création d'une méthode...

acSection : méthode Calc() renommée en calcFromY(), création d'une méthode Calc() avec la même signature pour faire un Reset() systématique au 1er appel
closes #42
Showing with 58 additions and 96 deletions
+58 -96
......@@ -25,7 +25,6 @@ export class RegimeUniforme extends Nub {
* @return Débit en régime uniforme
*/
Calc_Qn(): Result {
this.Sn.Reset(true);
if (this.Sn.prms.If.v <= 0)
return new Result(0);
......
......@@ -130,11 +130,10 @@ export class cSnCirc extends acSection {
this.debug("circ.Calc_B() : PAS débordement");
if (this.prms.D.isDefined && this.prms.Y.isDefined) {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
// let res = this.prms.D.v * Math.sin(this.Calc("Alpha"));
let res = this.prms.D.v * Math.sin(rAlpha.vCalc);
this.debug("circ.Calc_B() : res=" + res);
return new Result(res);
......@@ -167,11 +166,10 @@ export class cSnCirc extends acSection {
return new Result(v);
}
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
// return this.prms.D.v * this.Calc("Alpha");
const v = this.prms.D.v * rAlpha.vCalc;
return new Result(v);
}
......@@ -195,7 +193,7 @@ export class cSnCirc extends acSection {
return new Result(v);
}
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
......@@ -214,11 +212,10 @@ export class cSnCirc extends acSection {
if (!this.bSnFermee && this.isDebordement())
return super.Calc_dP_Debordement();
const rDAlpha: Result = this.Calc("dAlpha");
const rDAlpha: Result = this.calcFromY("dAlpha");
if (!rDAlpha.ok)
return rDAlpha;
// return this.prms.D.v * this.Calc("dAlpha");
const v = this.prms.D.v * rDAlpha.vCalc;
return new Result(v);
}
......@@ -231,15 +228,14 @@ export class cSnCirc extends acSection {
if (this.isDebordement())
return super.Calc_dB_Debordement();
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
const rDAlpha: Result = this.Calc("dAlpha");
const rDAlpha: Result = this.calcFromY("dAlpha");
if (!rDAlpha.ok)
return rDAlpha;
// return this.prms.D.v * this.Calc("dAlpha") * Math.cos(this.Calc("Alpha"));
const v = this.prms.D.v * rDAlpha.vCalc * Math.cos(rAlpha.vCalc);
return new Result(v);
}
......@@ -250,9 +246,7 @@ export class cSnCirc extends acSection {
* @return S x Yg
*/
protected Calc_SYg(): Result {
// let alpha = this.Calc("Alpha");
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
......@@ -269,14 +263,11 @@ export class cSnCirc extends acSection {
* @return S x Yg
*/
protected Calc_dSYg(): Result {
// let alpha = this.Calc("Alpha");
// let dAlpha = this.Calc("dAlpha");
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
const rDAlpha: Result = this.Calc("dAlpha");
const rDAlpha: Result = this.calcFromY("dAlpha");
if (!rDAlpha.ok)
return rDAlpha;
......
......@@ -59,11 +59,10 @@ export class cSnPuiss extends acSection {
if (this.prms.Y.v >= this.prms.YB.v)
return new Result(this.prms.LargeurBerge.v);
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
// return this.Calc("Alpha") * Math.pow(this.prms.Y.v, this.prms.k.v);
const v = rAlpha.vCalc * Math.pow(this.prms.Y.v, this.prms.k.v);
return new Result(v);
}
......@@ -73,12 +72,11 @@ export class cSnPuiss extends acSection {
* @return B
*/
protected Calc_P(): Result {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
var n = 100; /// Le nombre de partie pour le calcul de l'intégrale
// var Lambda2 = Math.pow(this.Calc("Alpha"), 2);
var Lambda2 = Math.pow(rAlpha.vCalc, 2);
var P = 0; /// Le périmètre à calculer
var Previous = 0;
......@@ -96,7 +94,7 @@ export class cSnPuiss extends acSection {
* @return S
*/
protected Calc_S(): Result {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
......@@ -110,12 +108,11 @@ export class cSnPuiss extends acSection {
* @return dP
*/
protected Calc_dP(): Result {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
let k = this.prms.k.v;
// return 2 * Math.sqrt(1 + Math.pow(k * this.Calc("Alpha") / 2, 2) * Math.pow(this.prms.Y.v, 2 * (k - 1)));
const v = 2 * Math.sqrt(1 + Math.pow(k * rAlpha.vCalc / 2, 2) * Math.pow(this.prms.Y.v, 2 * (k - 1)));
return new Result(v);
}
......@@ -125,12 +122,11 @@ export class cSnPuiss extends acSection {
* @return dB
*/
protected Calc_dB(): Result {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
let k = this.prms.k.v;
// return this.Calc("Alpha") * k * Math.pow(this.prms.Y.v, k - 1);
const v = rAlpha.vCalc * k * Math.pow(this.prms.Y.v, k - 1);
return new Result(v);
}
......@@ -141,12 +137,11 @@ export class cSnPuiss extends acSection {
* @return S x Yg
*/
protected Calc_SYg(): Result {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
let k = this.prms.k.v;
// return this.Calc("Alpha") * Math.pow(this.prms.Y.v, k + 2) / ((k + 1) * (k + 2));
const v = rAlpha.vCalc * Math.pow(this.prms.Y.v, k + 2) / ((k + 1) * (k + 2));
return new Result(v);
}
......@@ -157,17 +152,16 @@ export class cSnPuiss extends acSection {
* @return S x Yg
*/
protected Calc_dSYg(): Result {
const rAlpha: Result = this.Calc("Alpha");
const rAlpha: Result = this.calcFromY("Alpha");
if (!rAlpha.ok)
return rAlpha;
const rDAlpha: Result = this.Calc("dAlpha");
const rDAlpha: Result = this.calcFromY("dAlpha");
if (!rDAlpha.ok)
return rDAlpha;
let k = this.prms.k.v;
let Y = this.prms.Y.v;
// let SYg = this.Calc("dAlpha") * Math.pow(Y, k + 2) + this.Calc("Alpha") * Math.pow(Y, k + 1) * (k + 2);
let SYg = rDAlpha.vCalc * Math.pow(Y, k + 2) + rAlpha.vCalc * Math.pow(Y, k + 1) * (k + 2);
const v = SYg / ((k + 1) * (k + 2));
return new Result(v);
......
......@@ -57,9 +57,7 @@ export class cSnRectang extends acSection {
* @return tirant d'eau conjugué
*/
protected CalcYco(): Result {
// return this.prms.Y.v * (Math.sqrt(1 + 8 * Math.pow(this.Calc("Fr"), 2)) - 1) / 2;
const rFR: Result = this.Calc("Fr");
const rFR: Result = this.calcFromY("Fr");
if (!rFR.ok)
return rFR;
......
......@@ -155,7 +155,7 @@ export abstract class acSection extends ComputeNode {
*/
private _newtonDbg: boolean;
private _indentCalc: number = -1;
private _indentCalc: number;
/**
* Construction de la classe.
......@@ -244,13 +244,23 @@ export abstract class acSection extends ComputeNode {
/**
* Calcul des données à la section
* effectue un reset du cache des résultats
* @param sDonnee Clé de la donnée à calculer (voir this->arCalc)
* @param rY valeur de Y à utiliser
* @return la donnée calculée
*/
public Calc(sDonnee: string, rY: number = undefined): Result {
this._indentCalc = -1;
this.Reset(true);
return this.calcFromY(sDonnee, rY);
}
/**
* calcul des données à la section dépendant de Y
*/
protected calcFromY(sDonnee: string, rY: number = undefined): Result {
this._indentCalc++;
this.debug("in Calc(" + sDonnee + ", rY=" + rY + ") old " + sDonnee + "=" + this.arCalc[sDonnee]);
this.debug("in calcFromY(" + sDonnee + ", rY=" + rY + ") old " + sDonnee + "=" + this.arCalc[sDonnee]);
this.debug("this.Y=" + this.prms.Y.toString());
if (rY != undefined && (!this.prms.Y.isDefined || rY != this.prms.Y.v)) {
......@@ -262,8 +272,7 @@ export abstract class acSection extends ComputeNode {
// 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.prms.If.v - this.Calc("J");
var rJ: Result = this.Calc("J");
var rJ: Result = this.calcFromY("J");
if (rJ.ok) {
this.arCalc[sDonnee] = this.prms.If.v - rJ.vCalc;
var res = new Result(this.arCalc[sDonnee]);
......@@ -286,10 +295,10 @@ export abstract class acSection extends ComputeNode {
this.arCalc[sDonnee] = res.vCalc;
break;
}
this.debug("Calc(" + sDonnee + ") resultat -> " + this.arCalc[sDonnee]);
this.debug("calcFromY(" + sDonnee + ") resultat -> " + this.arCalc[sDonnee]);
}
else {
this.debug("Calc(" + sDonnee + ") cache= " + this.arCalc[sDonnee]);
this.debug("calcFromY(" + sDonnee + ") cache= " + this.arCalc[sDonnee]);
res = new Result(this.arCalc[sDonnee]);
}
this._indentCalc--;
......@@ -367,7 +376,7 @@ export abstract class acSection extends ComputeNode {
protected Calc_dS(): Result {
return this.Calc("B"); // largeur au miroir
return this.calcFromY("B"); // largeur au miroir
}
/**
......@@ -425,23 +434,18 @@ export abstract class acSection extends ComputeNode {
* @return Le rayon hydraulique
*/
private Calc_R(): Result {
// let P = this.Calc("P");
let rP: Result = this.Calc("P");
let rP: Result = this.calcFromY("P");
if (!rP.ok)
return rP;
// if (P != 0)
if (rP.vCalc == 0)
return new Result(new Message(MessageCode.ERROR_SECTION_PERIMETRE_NUL));
// return this.Calc("S") / P;
let rS = this.Calc("S");
let rS = this.calcFromY("S");
if (!rS.ok)
return rS;
return new Result(rS.vCalc / rP.vCalc);
// return Infinity;
}
/**
......@@ -449,8 +453,7 @@ export abstract class acSection extends ComputeNode {
* @return dR
*/
private Calc_dR(): Result {
// let P = this.Calc("P");
const rP: Result = this.Calc("P");
const rP: Result = this.calcFromY("P");
if (!rP.ok)
return rP;
......@@ -459,16 +462,15 @@ export abstract class acSection extends ComputeNode {
if (rP.vCalc == 0)
return new Result(new Message(MessageCode.ERROR_SECTION_PERIMETRE_NUL));
//return ((this.Calc("B") * P - this.Calc("S") * this.Calc("dP")) / Math.pow(P, 2));
const rB: Result = this.Calc("B");
const rB: Result = this.calcFromY("B");
if (!rB.ok)
return rB;
const rS: Result = this.Calc("S");
const rS: Result = this.calcFromY("S");
if (!rS.ok)
return rS;
const rDP: Result = this.Calc("dP");
const rDP: Result = this.calcFromY("dP");
if (!rDP.ok)
return rDP;
......@@ -513,23 +515,19 @@ export abstract class acSection extends ComputeNode {
* @return La perte de charge
*/
private Calc_J(): Result {
// let R = this.Calc("R");
let rR: Result = this.Calc("R");
let rR: Result = this.calcFromY("R");
if (!rR.ok)
return rR;
// if (R != 0)
if (rR.vCalc == 0)
return new Result(new Message(MessageCode.ERROR_SECTION_RAYON_NUL));
// return Math.pow(this.Calc("V") / this.prms.Ks.v, 2) / Math.pow(R, 4 / 3);
const rV: Result = this.Calc("V");
const rV: Result = this.calcFromY("V");
if (!rV.ok)
return rV;
const v = Math.pow(rV.vCalc / this.prms.Ks.v, 2) / Math.pow(rR.vCalc, 4 / 3);
return new Result(v);
// return Infinity;
}
/**
......@@ -537,39 +535,33 @@ export abstract class acSection extends ComputeNode {
* @return Le nombre de Froude
*/
private Calc_Fr(): Result {
// let S = this.Calc("S");
const rS: Result = this.Calc("S");
const rS: Result = this.calcFromY("S");
if (!rS.ok)
return rS;
// if (S != 0)
if (rS.vCalc == 0)
return new Result(new Message(MessageCode.ERROR_SECTION_SURFACE_NULLE));
const rB: Result = this.Calc("B");
const rB: Result = this.calcFromY("B");
if (!rB.ok)
return rB;
// return this.prms.Q.v / S * Math.sqrt(this.Calc("B") / S / cParamsCanal.G);
const v = this.prms.Q.v / rS.vCalc * Math.sqrt(rB.vCalc / rS.vCalc / cParamsCanal.G);
return new Result(v);
// return Infinity;
}
/**
* Calcul de dy/dx
*/
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
// L'appel à calcFromY("J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau
// return - (this.prms.If.v - this.Calc("J", Y) / (1 - Math.pow(this.Calc("Fr", Y), 2)));
const rJ: Result = this.Calc("J", Y);
const rJ: Result = this.calcFromY("J", Y);
if (!rJ.ok)
return rJ;
const rFR: Result = this.Calc("Fr", Y);
const rFR: Result = this.calcFromY("Fr", Y);
if (!rFR.ok)
return rFR;
......@@ -582,20 +574,15 @@ export abstract class acSection extends ComputeNode {
* @return Vitesse moyenne
*/
private Calc_V(): Result {
// let S = this.Calc("S");
let rS: Result = this.Calc("S");
let rS: Result = this.calcFromY("S");
if (!rS.ok)
return rS;
// if (S != 0)
if (rS.vCalc == 0)
return new Result(new Message(MessageCode.ERROR_SECTION_SURFACE_NULLE));
// return this.prms.Q.v / S;
const v = this.prms.Q.v / rS.vCalc;
return new Result(v);
// return Infinity;
}
/**
......@@ -603,9 +590,7 @@ export abstract class acSection extends ComputeNode {
* @return Charge spécifique
*/
private Calc_Hs(): Result {
// return this.prms.Y.v + Math.pow(this.Calc("V"), 2) / (2 * cParamsCanal.G);
let rV: Result = this.Calc("V");
let rV: Result = this.calcFromY("V");
if (!rV.ok)
return rV;
......@@ -623,12 +608,11 @@ export abstract class acSection extends ComputeNode {
this.Swap(true); // On mémorise les données hydrauliques en cours
// On calcule la charge avec la hauteur critique
// var Hsc = this.Calc("Hs", this.CalcGeo("Yc"));
const rYC: Result = this.CalcGeo("Yc");
if (!rYC.ok)
res = rYC;
else
res = this.Calc("Hs", rYC.vCalc);
res = this.calcFromY("Hs", rYC.vCalc);
// On restitue les données initiales
this.Swap(false);
......@@ -699,10 +683,9 @@ export abstract class acSection extends ComputeNode {
const oHautCorrespondante = new cHautCorrespondante(this, this._newtonMaxIter, this._newtonDbg);
const rYC: Result = this.Calc("Yc");
const rYC: Result = this.calcFromY("Yc");
if (!rYC.ok)
return rYC;
// let res = oHautCorrespondante.Newton(this.Calc("Yc") * 2);
let rYF = oHautCorrespondante.Newton(rYC.vCalc * 2);
// if (res == undefined || !oHautCorrespondante.hasConverged()) {
......@@ -752,19 +735,18 @@ export abstract class acSection extends ComputeNode {
const oHautConj = new cHautConjuguee(this, this._newtonMaxIter, this._newtonDbg);
const rFR: Result = this.Calc("Fr");
const rFR: Result = this.calcFromY("Fr");
if (!rFR.ok)
res = rFR;
else {
// Choisir une valeur initiale du bon côté de la courbe
// if (this.Calc("Fr") < 1) {
if (rFR.vCalc < 1) {
// Ecoulement fluvial, on cherche la conjuguée à partir du tirant d'eau torrentiel
var Y0: Result = this.Calc("Yt");
var Y0: Result = this.calcFromY("Yt");
}
else {
// Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial
Y0 = this.Calc("Yf");
Y0 = this.calcFromY("Yf");
}
if (!Y0.ok)
res = Y0;
......@@ -792,15 +774,14 @@ export abstract class acSection extends ComputeNode {
* @return contrainte de cisaillement
*/
private Calc_Tau0(): Result {
const rR: Result = this.Calc("R");
const rR: Result = this.calcFromY("R");
if (!rR.ok)
return rR;
const rJ: Result = this.Calc("J");
const rJ: Result = this.calcFromY("J");
if (!rJ.ok)
return rJ;
// return 1000 * cParamsCanal.G * this.Calc("R") * this.Calc("J");
return new Result(1000 * cParamsCanal.G * rR.vCalc * rJ.vCalc);
}
......@@ -841,15 +822,14 @@ export abstract class acSection extends ComputeNode {
* @return Impulsion hydraulique
*/
private Calc_Imp(): Result {
const rV: Result = this.Calc("V");
const rV: Result = this.calcFromY("V");
if (!rV.ok)
return rV;
const rSYG: Result = this.Calc("SYg");
const rSYG: Result = this.calcFromY("SYg");
if (!rSYG.ok)
return rSYG;
// return 1000 * (this.prms.Q.v * this.Calc("V") + cParamsCanal.G * this.Calc("SYg"));
const v = 1000 * (this.prms.Q.v * rV.vCalc + cParamsCanal.G * rSYG.vCalc);
return new Result(v);
}
......
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