jalhyd
Version:
JaLHyd, a Javascript Library for Hydraulics
683 lines • 24.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.acSection = void 0;
const internal_modules_1 = require("../../internal_modules");
const internal_modules_2 = require("../../internal_modules");
const internal_modules_3 = require("../../internal_modules");
const internal_modules_4 = require("../../internal_modules");
const internal_modules_5 = require("../../internal_modules");
const internal_modules_6 = require("../../internal_modules");
const internal_modules_7 = require("../../internal_modules");
const internal_modules_8 = require("../../internal_modules");
const internal_modules_9 = require("../../internal_modules");
const internal_modules_10 = require("../../internal_modules");
const internal_modules_11 = require("../../internal_modules");
/**
* Gestion commune pour les différents types de section.
* Comprend les formules pour la section rectangulaire pour gérer les débordements
*/
// tslint:disable-next-line:class-name
class acSection extends internal_modules_2.Nub {
/**
* Construction de la classe.
* Calcul des hauteurs normale et critique
*/
constructor(prms, dbg = false) {
super(prms, dbg);
/**
* true si la section est fermée (on considère alors qu'il existe une fente de Preissmann)
*/
this.bSnFermee = false;
this.arCalcGeo = {}; /// Données ne dépendant pas de la cote de l'eau
/**
* Tableau contenant les données dépendantes du tirant d'eau this->rY.
*
* Les clés du tableau peuvent être :
* - S : la surface hydraulique
* - P : le périmètre hydraulique
* - R : le rayon hydraulique
* - B : la largeur au miroir
* - J : la perte de charge
* - Fr : le nombre de Froude
* - dP : la dérivée de P par rapport Y
* - dR : la dérivée de R par rapport Y
* - dB : la dérivée de B par rapport Y
*/
this.arCalc = {};
// tslint:disable-next-line:variable-name
this.Calc_old = {}; /// Mémorisation des données hydrauliques pour calcul intermédiaire
this.setCalculatorType(internal_modules_1.CalculatorType.Section);
this._newtonDbg = dbg;
this._intlType = "Section";
}
get prms() {
return this._prms;
}
get HautCritique() {
return this._hautCritique;
}
static get availableSectionTypes() {
return acSection._availableSectionTypes;
}
get nodeType() {
return this._props.getPropValue("nodeType");
}
set nodeType(nt) {
this._props.setPropValue("nodeType", nt);
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Section ones
*/
get calculatedParam() {
if (this.parent) {
return this.parent.calculatedParam;
}
return undefined;
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Section ones
*/
set calculatedParam(p) {
if (this.parent) {
this.parent.calculatedParam = p;
}
}
clone() {
return Object.create(this);
}
/**
* Efface toutes les données calculées pour forcer le recalcul
* @param bGeo Réinitialise les données de géométrie aussi
*/
Reset(bGeo = true) {
this.debug("reset(" + bGeo + ")");
this.arCalc = {};
if (bGeo) {
this.arCalcGeo = {};
this.bSnFermee = false;
}
}
debug(m) {
super.debug(this.calcIndent() + m);
}
/**
* The parent is the Nub that holds the parameter to calculate;
* ask it to perform calculation and copy its result to local
* result, to facilitate values reading by targetting modules
* (used by triggerChainCalculation)
*/
CalcSerie(rInit) {
this.currentResultElement = this.parent.CalcSerie(rInit);
return this.result;
}
/**
* 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
*/
CalcSection(sDonnee, rY) {
this.debug(`Calc(${sDonnee},${rY})`);
this._indentCalc = -1;
this.Reset(true);
return this.calcFromY(sDonnee, rY);
}
/**
* Proxy to parent SectionNub, to compute non-hydraulic variables
* @param sVarCalc
* @param rInit
*/
Calc(sVarCalc, rInit) {
return this.parent.Calc(sVarCalc, rInit);
}
Equation(sVarCalc) {
throw new Error("acSection.Equation() : cannot be called");
}
setParametersCalculability() {
this.prms.Ks.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.Q.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.If.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.YB.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.Y.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.LargeurBerge.calculability = internal_modules_3.ParamCalculability.DICHO;
}
/**
* calcul des données à la section dépendant de Y
*/
calcFromY(sDonnee, rY) {
this._indentCalc++;
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 || (this.prms.Y.isDefined && rY !== this.prms.Y.v))) {
this.prms.Y.v = rY;
// On efface toutes les données dépendantes de Y pour forcer le calcul
this.Reset(false);
}
let res;
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
const rJ = this.calcFromY("J");
if (rJ.ok) {
this.arCalc[sDonnee] = this.prms.If.v - rJ.vCalc;
res = new internal_modules_6.Result(this.arCalc[sDonnee]);
}
else {
res = rJ;
}
break;
default:
const methode = "Calc_" + sDonnee;
/* !!!!!
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
!!!!!
*/
res = this[methode]();
if (res.ok) {
this.arCalc[sDonnee] = res.vCalc;
}
break;
}
this.debug("calcFromY(" + sDonnee + ") resultat -> " + this.arCalc[sDonnee]);
}
else {
this.debug("calcFromY(" + sDonnee + ") cache= " + this.arCalc[sDonnee]);
res = new internal_modules_6.Result(this.arCalc[sDonnee]);
}
this._indentCalc--;
this.debug("this.Y=" + this.prms.Y.toString());
// return this.arCalc[sDonnee];
return res;
}
/**
* Calcul des données uniquement dépendantes de la géométrie de la section
* @param sDonnee Clé de la donnée à calculer (voir this->arCalcGeo)
* @return la donnée calculée
*/
CalcGeo(sDonnee) {
this._indentCalc++;
this.debug("in CalcGeo(" + sDonnee + ") old " + sDonnee + "=" + this.arCalcGeo[sDonnee]);
this.debug("this.Y=" + this.prms.Y.toString());
// Si la largeur aux berges n'a pas encore été calculée, on commence par ça
if (sDonnee !== "B" && this.arCalcGeo.B === undefined) {
this.CalcGeo("B");
}
let res;
if (this.arCalcGeo[sDonnee] === undefined) {
// La donnée a besoin d'être calculée
this.Swap(true); // On mémorise les données hydrauliques en cours
this.Reset(false);
this.prms.Y.v = this.prms.YB.v;
switch (sDonnee) {
case "B": // Largeur aux berges
// this.arCalcGeo[sDonnee] = this.Calc_B();
res = this.Calc_B();
if (res.ok) {
this.arCalcGeo[sDonnee] = res.vCalc;
if (this.arCalcGeo[sDonnee] < this.prms.YB.v / 100) {
// Section fermée
this.bSnFermee = true;
// On propose une fente de Preissmann
// égale à 1/100 de la hauteur des berges
this.arCalcGeo[sDonnee] = this.prms.YB.v / 100;
}
this.prms.LargeurBerge.v = this.arCalcGeo[sDonnee];
}
break;
default:
const methode = "Calc_" + sDonnee;
// this.arCalcGeo[sDonnee] = this[methode]();
res = this[methode]();
if (res.ok) {
this.arCalcGeo[sDonnee] = res.vCalc;
}
break;
}
this.Swap(false); // On restitue les données hydrauliques en cours
this.debug("CalcGeo(" + sDonnee + ") resultat -> " + this.arCalcGeo[sDonnee]);
}
else {
this.debug("CalcGeo(" + sDonnee + ") cache= " + this.arCalcGeo[sDonnee]);
res = new internal_modules_6.Result(this.arCalcGeo[sDonnee]);
}
// this.debug('this.Y=' + this.prms.Y.toString());
this._indentCalc--;
// return this.arCalcGeo[sDonnee];
return res;
}
Calc_dS() {
return this.calcFromY("B"); // largeur au miroir
}
/**
* Calcul de la surface hydraulique en cas de débordement
* @param Y hauteur d'eau au delà de la berge
*/
Calc_S_Debordement(Y) {
this.debug("section->CalcS(rY=" + Y + ") LargeurBerge=" + this.CalcGeo("B"));
// return Y * this.CalcGeo("B");
const rB = this.CalcGeo("B");
if (!rB.ok) {
return rB;
}
return new internal_modules_6.Result(Y * rB.vCalc);
}
/**
* Calcul du périmètre hydraulique en cas de débordement
* @param Y hauteur d'eau au dela de la berge
*/
Calc_P_Debordement(Y) {
return new internal_modules_6.Result(2 * Y);
}
/**
* Calcul de dérivée du périmètre hydraulique par rapport au tirant d'eau en cas de débordement
* @return la dérivée du périmètre hydraulique par rapport au tirant d'eau en cas de débordement
*/
Calc_dP_Debordement() {
return new internal_modules_6.Result(2);
}
/**
* Calcul de la largeur au miroir en cas de débordement
* @return La largeur au miroir en cas de débordement
*/
Calc_B_Debordement() {
// return this.prms.LargeurBerge.v;
return new internal_modules_6.Result(this.prms.LargeurBerge.v);
}
/**
* Calcul de dérivée de la largeur au miroir par rapport au tirant d'eau en cas de débordement
* @return la dérivée de la largeur au miroir par rapport au tirant d'eau en cas de débordement
*/
Calc_dB_Debordement() {
return new internal_modules_6.Result(0);
}
/**
* Calcul de la distance du centre de gravité de la section à la surface libre
* multiplié par la surface hydraulique
* @return S x Yg
*/
Calc_SYg() {
// return Math.pow(this.prms.Y.v, 2) * this.CalcGeo("B") / 2;
const rGeoB = this.CalcGeo("B");
if (!rGeoB.ok) {
return rGeoB;
}
// return Math.pow(this.prms.Y.v, 2) * this.CalcGeo("B") / 2;
const v = Math.pow(this.prms.Y.v, 2) * rGeoB.vCalc / 2;
return new internal_modules_6.Result(v);
}
/**
* Calcul de la dérivée distance du centre de gravité de la section à la surface libre
* multiplié par la surface hydraulique
* @return S x Yg
*/
Calc_dSYg() {
const rGeoB = this.CalcGeo("B");
if (!rGeoB.ok) {
return rGeoB;
}
// return this.prms.Y.v * this.CalcGeo("B");
const v = this.prms.Y.v * rGeoB.vCalc;
return new internal_modules_6.Result(v);
}
/**
* Calcul de l'angle Alpha entre la surface libre et le fond pour les sections circulaires.
* @return Angle Alpha pour une section circulaire, 0 sinon.
*/
Calc_Alpha() {
return new internal_modules_6.Result(0);
}
/**
* Calcul de la dérivée de l'angle Alpha entre la surface libre et le fond pour les sections circulaires.
* @return Dérivée de l'angle Alpha pour une section circulaire, 0 sinon.
*/
Calc_dAlpha() {
return new internal_modules_6.Result(0);
}
/**
* Mémorise les données hydrauliques en cours ou les restitue
* @param bMem true pour mémorisation, false pour restitution
*/
Swap(bMem) {
if (bMem) {
this.debug("save Y=" + this.prms.Y.toString());
this.Y_old = this.prms.Y.v;
this.Calc_old = this.arCalc;
}
else {
this.debug("restore Y=" + this.Y_old);
this.prms.Y.v = this.Y_old;
this.arCalc = this.Calc_old;
this.Calc_old = {};
}
}
calcIndent() {
let res = "";
for (let i = 0; i < this._indentCalc; i++) {
res += " ";
}
return res;
}
/**
* Calcul de la dérivée surface hydraulique en cas de débordement
* @return La dérivée de la surface hydraulique en cas de débordement
*/
Calc_dS_Debordement() {
return this.CalcGeo("B");
}
/**
* Calcul du rayon hydraulique.
* @return Le rayon hydraulique
*/
Calc_R() {
const rP = this.calcFromY("P");
if (!rP.ok) {
return rP;
}
if (rP.vCalc === 0) {
return new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_PERIMETRE_NUL));
}
const rS = this.calcFromY("S");
if (!rS.ok) {
return rS;
}
return new internal_modules_6.Result(rS.vCalc / rP.vCalc);
}
/**
* Calcul de dérivée du rayon hydraulique par rapport au tirant d'eau.
* @return dR
*/
Calc_dR() {
const rP = this.calcFromY("P");
if (!rP.ok) {
return rP;
}
// if (P !== 0)
if (rP.vCalc === 0) {
return new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_PERIMETRE_NUL));
}
const rB = this.calcFromY("B");
if (!rB.ok) {
return rB;
}
const rS = this.calcFromY("S");
if (!rS.ok) {
return rS;
}
const rDP = this.calcFromY("dP");
if (!rDP.ok) {
return rDP;
}
const v = ((rB.vCalc * rP.vCalc - rS.vCalc * rDP.vCalc) / Math.pow(rP.vCalc, 2));
return new internal_modules_6.Result(v);
// return 0;
}
/**
* Calcul de la perte de charge par la formule de Manning-Strickler.
* @return La perte de charge
*/
Calc_J() {
const rR = this.calcFromY("R");
if (!rR.ok) {
return rR;
}
if (rR.vCalc === 0) {
return new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_RAYON_NUL));
}
const rV = 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 internal_modules_6.Result(v);
}
/**
* Calcul du nombre de Froude.
* @return Le nombre de Froude
*/
Calc_Fr() {
const rS = this.calcFromY("S");
if (!rS.ok) {
return rS;
}
if (rS.vCalc === 0) {
return new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_SURFACE_NULLE));
}
const rB = this.calcFromY("B");
if (!rB.ok) {
return rB;
}
const v = this.prms.Q.v / rS.vCalc * Math.sqrt(rB.vCalc / rS.vCalc / internal_modules_11.ParamsSection.G);
return new internal_modules_6.Result(v);
}
/**
* Calcul de dy/dx
*/
Calc_dYdX(Y) {
// L'appel à calcFromY("J') avec Y en paramètre réinitialise toutes les données
// dépendantes de la ligne d'eau
const rJ = this.calcFromY("J", Y);
if (!rJ.ok) {
return rJ;
}
const rFR = this.calcFromY("Fr", Y);
if (!rFR.ok) {
return rFR;
}
const v = -(this.prms.If.v - rJ.vCalc / (1 - Math.pow(rFR.vCalc, 2)));
return new internal_modules_6.Result(v);
}
/**
* Calcul de la vitesse moyenne.
* @return Vitesse moyenne
*/
Calc_V() {
const rS = this.calcFromY("S");
if (!rS.ok) {
return rS;
}
if (rS.vCalc === 0) {
return new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_SURFACE_NULLE));
}
const v = this.prms.Q.v / rS.vCalc;
return new internal_modules_6.Result(v);
}
/**
* Calcul de la charge spécifique.
* @return Charge spécifique
*/
Calc_Hs() {
const rV = this.calcFromY("V");
if (!rV.ok) {
return rV;
}
const v = this.prms.Y.v + Math.pow(rV.vCalc, 2) / (2 * internal_modules_11.ParamsSection.G);
return new internal_modules_6.Result(v);
}
/**
* Calcul de la charge spécifique critique.
* @return Charge spécifique critique
*/
Calc_Hsc() {
let res;
this.Swap(true); // On mémorise les données hydrauliques en cours
// On calcule la charge avec la hauteur critique
const rYC = this.CalcGeo("Yc");
if (!rYC.ok) {
res = rYC;
}
else {
res = this.calcFromY("Hs", rYC.vCalc);
}
// On restitue les données initiales
this.Swap(false);
// return Hsc;
return res;
}
/**
* Calcul du tirant d'eau critique.
* @return tirant d'eau critique
*/
Calc_Yc(init = this.prms.YB.v) {
const maxIter = internal_modules_4.SessionSettings.maxIterations;
const hautCritique = new internal_modules_9.cHautCritique(this, maxIter, this.newtonDbg);
this._hautCritique = hautCritique.Newton(init);
if (!this._hautCritique.ok) {
const m = new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE);
this._hautCritique = new internal_modules_6.Result(m);
}
return this._hautCritique;
}
/**
* Calcul du tirant d'eau normal.
* @return tirant d'eau normal
*/
Calc_Yn() {
if (this.prms.If.v <= 0) {
const m = new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_PENTE_NEG_NULLE_HNORMALE_INF);
// this.oLog.add(m);
// return undefined;
return new internal_modules_6.Result(m);
}
const rYC = this.CalcGeo("Yc");
if (!rYC.ok) {
return rYC;
}
const maxIter = internal_modules_4.SessionSettings.maxIterations;
const oHautNormale = new internal_modules_10.cHautNormale(this, maxIter, this._newtonDbg);
// let res = oHautNormale.Newton(this.CalcGeo("Yc"));
let rYN = oHautNormale.Newton(rYC.vCalc);
// if (res === undefined || !oHautNormale.hasConverged()) {
if (!rYN.ok) {
const m = new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE);
// this.oLog.add(m);
rYN = new internal_modules_6.Result(m);
}
return rYN;
}
/**
* Calcul du tirant d'eau correspondant.
* @return tirant d'eau correpondant
*/
Calc_Ycor() {
const rGeoYC = this.CalcGeo("Yc");
if (!rGeoYC.ok) {
return rGeoYC;
}
let nInit;
if (this.prms.Y.v < rGeoYC.vCalc) {
nInit = rGeoYC.vCalc * 2;
}
else {
nInit = rGeoYC.vCalc / 2;
}
const maxIter = internal_modules_4.SessionSettings.maxIterations;
const oHautCorrespondante = new internal_modules_8.cHautCorrespondante(this, maxIter, this._newtonDbg);
let rYF = oHautCorrespondante.Newton(nInit);
if (!rYF.ok) {
const m = new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCOR);
rYF = new internal_modules_6.Result(m);
}
return rYF;
}
/**
* Calcul du tirant d'eau conjugué.
* @return tirant d'eau conjugué
*/
Calc_Ycon() {
let res;
this.Swap(true);
const maxIter = internal_modules_4.SessionSettings.maxIterations;
const oHautConj = new internal_modules_7.cHautConjuguee(this, maxIter, this._newtonDbg);
const rFR = this.calcFromY("Fr");
if (!rFR.ok) {
res = rFR;
}
else {
let Y0;
// Choisir une valeur initiale du bon côté de la courbe
Y0 = this.calcFromY("Ycor");
if (!Y0.ok) {
res = Y0;
}
else {
// let Ycon = oHautConj.Newton(Y0);
// tslint:disable-next-line:variable-name
const Ycon = oHautConj.Newton(Y0.vCalc);
// if (Ycon === undefined || !oHautConj.hasConverged()) {
if (!Ycon.ok) {
const m = new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG);
// this.oLog.add(m);
res = new internal_modules_6.Result(m);
}
else {
res = Ycon;
}
}
}
this.Swap(false);
return res;
}
/**
* Calcul de la contrainte de cisaillement.
* @return contrainte de cisaillement
*/
Calc_Tau0() {
const rR = this.calcFromY("R");
if (!rR.ok) {
return rR;
}
const rJ = this.calcFromY("J");
if (!rJ.ok) {
return rJ;
}
return new internal_modules_6.Result(1000 * internal_modules_11.ParamsSection.G * rR.vCalc * rJ.vCalc);
}
/**
* Calcul de l'impulsion hydraulique.
* @return Impulsion hydraulique
*/
Calc_Imp() {
const rV = this.calcFromY("V");
if (!rV.ok) {
return rV;
}
const rSYG = this.calcFromY("SYg");
if (!rSYG.ok) {
return rSYG;
}
const v = 1000 * (this.prms.Q.v * rV.vCalc + internal_modules_11.ParamsSection.G * rSYG.vCalc);
return new internal_modules_6.Result(v);
}
// interface IProperties
hasProperty(key) {
return key === "nodeType";
}
}
exports.acSection = acSection;
acSection._availableSectionTypes = [
{
id: "SectionCercle",
value: internal_modules_1.SectionType.SectionCercle
},
{
id: "SectionRectangle",
value: internal_modules_1.SectionType.SectionRectangle
},
{
id: "SectionTrapeze",
value: internal_modules_1.SectionType.SectionTrapeze
},
{
id: "SectionPuissance",
value: internal_modules_1.SectionType.SectionPuissance
}
];
//# sourceMappingURL=section_type.js.map