section_parametree.ts 8.85 KiB
import { CalculatorType } from "../compute-node";
import { ParamCalculability, ParamDefinition, ParamFamily } from "../param/param-definition";
import { ParamDomain, ParamDomainValue } from "../param/param-domain";
import { ParamValueMode } from "../param/param-value-mode";
import { ParamValues } from "../param/param-values";
import { ParamsEquation } from "../param/params-equation";
import { Result } from "../util/result";
import { ResultElement } from "../util/resultelement";
import { SectionNub } from "./section_nub";
import { acSection } from "./section_type";
// dummy ParamsEquation for code consistency
export class SectionParams extends ParamsEquation {}
/**
 * Nub sur les sections paramétrées
// tslint:disable-next-line:max-classes-per-file
export class SectionParametree extends SectionNub {
    constructor(s: acSection, dbg: boolean = false) {
        super(new SectionParams(), dbg);
        this._calcType = CalculatorType.SectionParametree;
        this.setSection(s);
        this.initSectionVars();
        // no calculated parameter
        this._defaultCalculatedParam = undefined;
    public getFirstAnalyticalParameter(): ParamDefinition {
        const res = super.getFirstAnalyticalParameter();
        if (res) {
            return res;
        // tslint:disable-next-line:forin
        for (const k in this._sectionVars) {
            const p = this._sectionVars[k];
            if (p.isAnalytical) {
                return p;
        return undefined;
    public 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.CalcSection(sVarCalc, this.getParameter("Y").v);
            default:
                throw new Error(`SectionParam.Equation() : calcul sur ${sVarCalc} non implémenté`);
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
public CalcSerie(rInit?: number, sDonnee?: string): Result { this.triggerChainCalculation(); let variatedParam: ParamDefinition; let variatedValues: ParamValues; for (const p of this.parameterIterator) { // checks which values are variating, if any switch (p.valueMode) { case ParamValueMode.SINGLE: case ParamValueMode.CALCUL: break; case ParamValueMode.LISTE: case ParamValueMode.MINMAX: variatedParam = this.setVariatedValues(p, variatedParam); break; case ParamValueMode.LINK: if ( p.isReferenceDefined() && p.referencedValue.hasMultipleValues() ) { variatedParam = this.setVariatedValues(p, variatedParam); } break; default: // tslint:disable-next-line:max-line-length throw new Error(`CalcSerie() : valeur de ParamValueMode ${ParamValueMode[p.valueMode]} non prise en charge`); } } if (variatedParam === undefined) { this.Calc(); // résultat dans this._result } else { // extract variated values from variated Parameter // (in LINK mode, proxies to target data) variatedValues = variatedParam.paramValues; const res = new Result(undefined, this); variatedValues.initValuesIterator(false); while (variatedValues.hasNext) { variatedValues.next(); this.Calc(); // résultat dans this._result if (this._result.ok) { res.addResultElement(this._result.resultElement); res.addLog(this._result.log); } res.globalLog.addLog(this._result.globalLog); } this._result = res; } this.notifyResultUpdated(); return this._result; } /** * Aucune variable à calculer plus que les autres, on stocke toutes les * valeurs des variables à calcul dans les résultats complémentaires */ public Calc(): Result { // 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)
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
const Y = this.getParameter("Y").v; this._result = new Result(undefined, this); const re = new ResultElement(); this._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); // 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 this._result; } // tslint:disable-next-line:no-empty protected setParametersCalculability(): void {} // tslint:disable-next-line:no-empty protected adjustChildParameters(): void {} protected setExtraResultsFamilies() { this._extraResultsFamilies = { B: ParamFamily.WIDTHS, Yc: ParamFamily.HEIGHTS,
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
Yn: ParamFamily.HEIGHTS, Yf: ParamFamily.HEIGHTS, Yt: ParamFamily.HEIGHTS, Yco: ParamFamily.HEIGHTS }; } private initSectionVars() { 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 { let dom; 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": dom = new ParamDomain(ParamDomainValue.POS_NULL); break; case "I-J": dom = new ParamDomain(ParamDomainValue.ANY); break; default: throw new Error(`SectionParametree.createSectionVar() : symbole ${symbol} non pris en charge`); } const pe = new SectionParams(this); const res = new ParamDefinition(pe, symbol, dom); res.calculability = ParamCalculability.EQUATION; return res; } /** * Calculates varCalc from Y, and sets the result as an * extraResult of the given ResultElement
281282283284285286287288289290291
*/ private addExtraResultFromVar(varCalc: string, Y: number, re: ResultElement) { const r: Result = this.section.CalcSection(varCalc, Y); if (r.ok) { re.addExtraResult(varCalc, r.vCalc); } else { re.log.addLog(r.log); } } }