structure.ts 11.86 KiB
import { ChildNub } from "../child_nub";
import { CalculatorType } from "../compute-node";
import { ParamCalculability, ParamDefinition, ParamFamily } from "../param/param-definition";
import { Props } from "../props";
import { Message, MessageCode } from "../util/message";
import { Result } from "../util/result";
import { StructureParams } from "./structure_params";
import { LoiDebit } from "./structure_props";
/**
 * Flow mode: weir or orifice flow
export enum StructureFlowMode {
    /** Weir flow */
    WEIR,
    /** Orifice flow */
    ORIFICE,
    /** Zéro flow */
    NULL
/**
 * Flow regime: free flow, partially submerged or submerged
export enum StructureFlowRegime {
    /** Free flow (unsubmerged) */
    FREE,
    /** Partially submerged flow */
    PARTIAL,
    /** Submerged flow */
    SUBMERGED,
    /** Zéro flow */
    NULL
/** Type de jet : Sans objet (orifice), plongeant, de surface */
export enum StructureJetType {
    /** Plongeant */
    PLONGEANT,
    /** De surface */
    SURFACE,
    /** Sans objet (orifice) */
/**
 * classe de calcul sur la conduite distributrice
export abstract class Structure extends ChildNub {
    /**
     * Test générique si VarCalc="Q" pour l'utilisation de Equation
    public static CheckEquation(sVarCalc: string) {
        if (sVarCalc !== "Q") { throw new Error("Structure.Equation() : invalid parameter name " + sVarCalc); }
    /** Constante utile : Racine de 2g */
    protected static readonly R2G: number = Math.sqrt(2 * 9.81);
    /** Peut-on calculer ZDV ? */
    protected _isZDVcalculable: boolean;
    protected _loiDebit: LoiDebit;
    constructor(prms: StructureParams, dbg: boolean = false) {
        super(prms, dbg);
        this._calcType = CalculatorType.Structure;
        this._isZDVcalculable = true;
        // Q is always the only calculated variable; setting another parameter
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
// of a Structure to CALC mode makes it the calculated variable of the // *parent* ParallelStructures this.calculatedParam = this.prms.Q; } /** Returns Props object (observable set of key-values) associated to this Nub */ public get properties(): Props { // completes props with calcType and loiDebit if not already set this._props.setPropValue("calcType", this.calcType); if (this._props.getPropValue("loiDebit") === undefined) { this._props.setPropValue("loiDebit", this._loiDebit); } return this._props; } // setter is not inherited from Nub if getter is redefined :/ public set properties(props: Props) { super.setProperties(props); } public get isZDVcalculable(): boolean { return this._isZDVcalculable; } /** * paramètres castés au bon type */ public get prms(): StructureParams { return this._prms as StructureParams; } public get W(): number { if (this.prms.W.visible) { return this.prms.W.v; } else { return Infinity; } } public get loiDebit(): LoiDebit { return this._loiDebit; } /** * Returns the nth visible parameter (used in nghyd/PabTable) */ public getNthVisibleParam(n: number): ParamDefinition { let i = 0; for (const p of this.parameterIterator) { if (p.visible) { if (n === i) { return p; } i++; } } return undefined; } /** * Calcul d'une équation quelle que soit l'inconnue à calculer. * Gestion du débit nul et de l'inversion de débit * @param sVarCalc nom de la variable à calculer * @param rInit valeur initiale de la variable à calculer dans le cas de la dichotomie */ public Calc(sVarCalc: string, rInit?: number): Result { // Gestion de l'exception de calcul de W sur les seuils if (rInit === undefined) { rInit = this.getParameter(sVarCalc).v; }
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
if (sVarCalc === "W" && rInit === Infinity) { throw new Error("Structure:Calc : Calcul de W impossible sur un seuil"); } // Gestion de l'erreur de calcul de ZDV quand il n'est pas calculable if (sVarCalc === "ZDV" && !this.isZDVcalculable) { return new Result( new Message(MessageCode.ERROR_STRUCTURE_ZDV_PAS_CALCULABLE) ); } this.prms.update_h1h2(); // Gestion du débit nul const flagsNull = { ENUM_StructureFlowMode: StructureFlowMode.NULL, ENUM_StructureFlowRegime: StructureFlowRegime.NULL, ENUM_StructureJetType: StructureJetType.SO }; if (sVarCalc === "Q") { if (this.prms.h1.v <= 1E-20 || Math.abs(this.prms.h1.v - this.prms.h2.v) < 1E-20 || this.W <= 1E-20) { this.currentResult = new Result(0, this, flagsNull); return this._result; } } else if (this.prms.Q.v === 0) { // Débit nul <=> tirant d'eau amont = tirant d'eau aval ou tout autre paramètre nul switch (sVarCalc) { case "Z1": this.currentResult = new Result(this.prms.Z2.v, this, flagsNull); return this._result; case "Z2": this.currentResult = new Result(this.prms.Z1.v, this, flagsNull); return this._result; default: // Est-ce toujours vrai ? Nécessitera peut-être d'étendre la méthode this.currentResult = new Result(0, this, flagsNull); return this._result; } } else if (this.W === 0 && sVarCalc === "Z1") { // Si la vanne est fermée la cote amont est infinie this.currentResult = new Result(Infinity, this, flagsNull); return this._result; } // Gestion du cas d'écoulement impossible Z1 > Z2 et Q <= 0 if (!(sVarCalc === "Q" || sVarCalc === "Z1" || sVarCalc === "Z2")) { if ( (this.prms.Z1.v >= this.prms.Z2.v && this.prms.Q.v <= 0) || (this.prms.Z1.v <= this.prms.Z2.v && this.prms.Q.v >= 0) ) { // On ferme l'ouvrage et on renvoie un code d'erreur let rPrm: number; switch (sVarCalc) { case "ZDV": rPrm = Math.max(this.prms.Z1.v, this.prms.Z2.v); break; default: rPrm = 0; } let res: Result; if (this.prms.Z1.v === this.prms.Z2.v && this.prms.Q.v !== 0) { res = new Result(new Message(MessageCode.ERROR_STRUCTURE_Z_EGAUX_Q_NON_NUL), this); } else { res = new Result(new Message(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE), this, flagsNull); } res.vCalc = rPrm; this.currentResult = res; // "Les cotes et le débit ne sont pas cohérents => fermeture de l'ouvrage return res; }
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
} // Gestion de l'inversion de débit : on inverse l'amont et l'aval pour le calcul if (sVarCalc !== "Q" && this.prms.Q.v < 0) { [this.prms.Z1.v, this.prms.Z2.v] = [this.prms.Z2.v, this.prms.Z1.v]; // Swap ES6 fashion const res: Result = super.Calc(sVarCalc, rInit); [this.prms.Z1.v, this.prms.Z2.v] = [this.prms.Z2.v, this.prms.Z1.v]; // Swap ES6 fashion this.currentResult = res; return res; } // Calcul normal hors débit nul return super.Calc(sVarCalc, rInit); } /** * Equation preprocessing * @return true if inverted discharge */ public Equation(sVarCalc: string): Result { Structure.CheckEquation(sVarCalc); let res: Result; let bInverted: boolean = false; if (this.prms.Z1.v < this.prms.Z2.v) { [this.prms.Z1.v, this.prms.Z2.v] = [this.prms.Z2.v, this.prms.Z1.v]; // Swap ES6 fashion bInverted = true; } this.prms.update_h1h2(); res = this.CalcQ(); if (bInverted) { if (sVarCalc === "Q") { res.vCalc = -res.vCalc; } [this.prms.Z1.v, this.prms.Z2.v] = [this.prms.Z2.v, this.prms.Z1.v]; // Swap ES6 fashion } return res; } /** * Function to implement for the stage discharge equation of hydraulic structure */ protected abstract CalcQ(): Result; protected getResultData() { return { ENUM_StructureFlowMode: this.getFlowMode(), ENUM_StructureFlowRegime: this.getFlowRegime(), ENUM_StructureJetType: this.getJetType() }; } /** * paramétrage de la calculabilité des paramètres */ protected setParametersCalculability() { this.prms.Q.calculability = ParamCalculability.EQUATION; this.prms.ZDV.calculability = ParamCalculability.DICHO; this.prms.Z1.calculability = ParamCalculability.DICHO; this.prms.Z2.calculability = ParamCalculability.DICHO; this.prms.h1.calculability = ParamCalculability.DICHO; this.prms.h2.calculability = ParamCalculability.DICHO; this.prms.W.calculability = ParamCalculability.FIXED; } /** * Give the flow mode : weir or orifice flow */ protected getFlowMode(): StructureFlowMode { if (this.prms.h1.v > this.W) { this.debug("Structure.getFlowMode(h1=" + this.prms.h1.v + ",W=" + this.W + ")=ORIFICE");
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
return StructureFlowMode.ORIFICE; } else { this.debug("Structure.getFlowMode(h1=" + this.prms.h1.v + ",W=" + this.W + ")=WEIR"); return StructureFlowMode.WEIR; } } /** * Give the flow regime for a rectangular section : free, partially submerged or submerged flow */ protected getFlowRegime(): StructureFlowRegime { // Weir have only two flow regimes: free and submerged flow // Orifice have three flow regimes: free, partially submerged and (totally) submerged if (this.prms.h2.v <= 2 / 3 * this.prms.h1.v) { // free flow for both weirs and orifices this.debug( "Structure.getFlowRegime(h1=" + this.prms.h1.v + ",h2=" + this.prms.h2.v + ",W=" + this.W + ")=FREE"); return StructureFlowRegime.FREE; } else if (this.prms.h1.v > this.W && this.prms.h2.v < (2 * this.prms.h1.v + this.W) / 3) { // Partially submerged only for orifices this.debug( "Structure.getFlowRegime(h1=" + this.prms.h1.v + ",h2=" + this.prms.h2.v + ",W=" + this.W + ")=PARTIAL"); return StructureFlowRegime.PARTIAL; } else { // (Totally) submerged for both weirs and orifices this.debug( "Structure.getFlowRegime(h1=" + this.prms.h1.v + ",h2=" + this.prms.h2.v + ",W=" + this.W + ")=SUBMERGED"); return StructureFlowRegime.SUBMERGED; } } /** * Give the Jet Type for weir flow * Cf. Baudoin J.M., Burgun V., Chanseau M., Larinier M., Ovidio M., Sremski W., Steinbach P. et Voegtle B., 2014. * Evaluer le franchissement des obstacles par les poissons. Principes et méthodes. Onema. 200 pages */ protected getJetType(): StructureJetType { if (this.getFlowMode() === StructureFlowMode.WEIR) { if (Math.abs(this.prms.h1.v - this.prms.h2.v) < 0.5 * this.prms.h1.v) { return StructureJetType.SURFACE; } else { return StructureJetType.PLONGEANT; } } else { return StructureJetType.SO; } } protected exposeResults() { this._resultsFamilies = { Q: ParamFamily.FLOWS }; } }