section_nub.ts 6.64 KiB
import { Nub } from "../nub";
import { acSection } from "./section_type";
import { Result } from "../util/result";
import { ParamDefinition, ParamCalculability } from "../param/param-definition";
import { ParamDomain, ParamDomainValue } from "../param/param-domain";
import { ParamValueMode } from "../param/param-values";
import { ResultElement } from "../util/resultelement";
/**
 * Nub sur les sections paramétrées
export class SectionParametree extends Nub {
    private _section: acSection;
    private _sectionVars: { [key: string]: ParamDefinition };
    constructor(sect: acSection, dbg: boolean = false) {
        super(sect.prms, dbg);
        this._section = sect;
        this.initSectionVars();
    private initSectionVars() {
        this._sectionVars = {};
        this.initSectionVar("Hs");
        this.initSectionVar("Hsc");
        this.initSectionVar("B");
        this.initSectionVar("P");
        this.initSectionVar("S");
        this.initSectionVar("R");
        this.initSectionVar("V");
        this.initSectionVar("Fr");
        this.initSectionVar("Yc");
        this.initSectionVar("Yn");
        this.initSectionVar("Yf");
        this.initSectionVar("Yt");
        this.initSectionVar("Yco");
        this.initSectionVar("J");
        this.initSectionVar("Imp");
        this.initSectionVar("Tau0");
        this.initSectionVar("I-J");
    private initSectionVar(symbol: string) {
        this._sectionVars[symbol] = this.createSectionVar(symbol);
    private createSectionVar(symbol: string): ParamDefinition {
        switch (symbol) {
            case "Hs":
            case "Hsc":
            case "B":
            case "P":
            case "S":
            case "R":
            case "V":
            case "Fr":
            case "Yc":
            case "Yn":
            case "Yf":
            case "Yt":
            case "Yco":
            case "J":
            case "Imp":
            case "Tau0":
                var dom = new ParamDomain(ParamDomainValue.POS_NULL);
                break;
            case "I-J":
                var dom = new ParamDomain(ParamDomainValue.ANY);
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
break; default: throw new Error(`SectionParametree.createSectionVar() : symbole ${symbol} non pris en charge`); } const res = new ParamDefinition(symbol, dom); res.calculability = ParamCalculability.EQUATION; return res; } public get section(): acSection { return this._section; } public getParameter(name: string): ParamDefinition { let res = super.getParameter(name); if (res === undefined) { // pas trouvé -> il s'agit peut être d'une variable dans le genre Hs, B, P, ... res = this._sectionVars[name]; if (!res) throw new Error(`SectionParametree.getParameter() : nom de paramètre ${name} incorrect`); } return res; } public getFirstAnalyticalParameter(): ParamDefinition { let res = super.getFirstAnalyticalParameter(); if (res) return res; for (const k in this._sectionVars) { const p = this._sectionVars[k]; if (p.isAnalytical) return p; } return undefined; } /** * paramétrage de la calculabilité des paramètres */ protected setParametersCalculability() { } Equation(sVarCalc: string): Result { switch (sVarCalc) { case "Hs": case "Hsc": case "B": case "P": case "S": case "R": case "V": case "Fr": case "Yc": case "Yn": case "Yf": case "Yt": case "Yco": case "J": case "Imp": case "Tau0": case "I-J": return this._section.Calc(sVarCalc, this.getParameter("Y").v); default: throw new Error(`SectionParam.Equation() : calcul sur ${sVarCalc} non implémenté`); }
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
} private hasVariatedParameter(): boolean { for (const p of this.parameterIterator) { switch (p.valueMode) { case ParamValueMode.LISTE: case ParamValueMode.MINMAX: return true; } } return false; } private addExtraResultFromVar(varCalc: string, Y: number, re: ResultElement) { const r: Result = this._section.Calc(varCalc, Y); if (r.ok) re.addExtraResult(varCalc, r.vCalc); else re.log.addLog(r.log); } public CalcSerie(rPrec: number = 0.001, rInit?: number, sDonnee?: string): Result { //paramètre à varier ? if (this.hasVariatedParameter()) return super.CalcSerie(rPrec, rInit, sDonnee); // sinon, on stocke toutes les valeurs des variables à calcul dans les résultats supplémentaires const Y = this.getParameter("Y").v; // tirant d'eau original (doit être fourni à acSection.Calc() sous peine d'être modifié par les appels successifs car c'est en même temps un paramètre et une variable temporaire) const result = new Result(); const re = new ResultElement(); result.addResultElement(re); // charge spécifique this.addExtraResultFromVar("Hs", Y, re); // charge critique this.addExtraResultFromVar("Hsc", Y, re); // largeur au miroir this.addExtraResultFromVar("B", Y, re); // périmètre hydraulique this.addExtraResultFromVar("P", Y, re); // surface hydraulique this.addExtraResultFromVar("S", Y, re); // rayon hydraulique this.addExtraResultFromVar("R", Y, re); // vitesse moyenne this.addExtraResultFromVar("V", Y, re); // nombre de Froude this.addExtraResultFromVar("Fr", Y, re); // tirant d'eau critique this.addExtraResultFromVar("Yc", Y, re); // tirant d'eau normal this.addExtraResultFromVar("Yn", Y, re); // tirant d'eau fluvial this.addExtraResultFromVar("Yf", Y, re); // tirant d'eau torrentiel this.addExtraResultFromVar("Yt", Y, re);
211212213214215216217218219220221222223224225226227228229
// tirant d'eau conjugué this.addExtraResultFromVar("Yco", Y, re); // perte de charge this.addExtraResultFromVar("J", Y, re); // Variation linéaire de l'énergie spécifique this.addExtraResultFromVar("I-J", Y, re); // impulsion hydraulique this.addExtraResultFromVar("Imp", Y, re); // contrainte de cisaillement this.addExtraResultFromVar("Tau0", Y, re); return result; } }