Forked from HYCAR-Hydro / airGR
Source project has a limited visibility.
structure.ts 7.59 KiB
import { Nub } from "../nub";
import { ParamCalculability } from "../param/param-definition";
import { Message, MessageCode } from "../util/message";
import { Result } from "../util/result";
import { StructureParams } from "./structure_params";
export { StructureParams };
/**
 * 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,
/**
 * classe de calcul sur la conduite distributrice
export abstract class Structure extends Nub {
    /**
     * 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;
    constructor(prms: StructureParams, dbg: boolean = false) {
        super(prms, dbg);
        this._isZDVcalculable = true;
    get isZDVcalculable(): boolean {
        return this._isZDVcalculable;
    /**
     * paramètres castés au bon type
    get prms(): StructureParams {
        return this._prms as StructureParams;
    /**
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
* Calcul d'une équation quelque 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 * @param rPrec précision de calcul */ public Calc(sVarCalc: string, rInit?: number, rPrec: number = 0.001): Result { // Gestion de l'exception de calcul de W sur les seuils if (rInit === undefined) { rInit = this.getParameter(sVarCalc).v; } 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) ); } // Mise à jour de h1 et h2 this.prms.update_h1h2(); // Gestion du débit nul const flagsNull = { Mode: StructureFlowMode.NULL, Regime: StructureFlowRegime.NULL }; if (sVarCalc === "Q") { if (this.prms.h1.v === this.prms.h2.v || this.prms.W.v <= 0) { return new Result(0, flagsNull); } } 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": return new Result(this.prms.h2.v, flagsNull); case "Z2": return new Result(this.prms.h1.v, flagsNull); default: // Est-ce toujours vrai ? Nécessitera peut-être d'étendre la méthode return new Result(0, flagsNull); } } else if (this.prms.W.v === 0 && sVarCalc === "Z1") { return new Result(Infinity, flagsNull); // Si la vanne est fermée la cote amont est infinie } // 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 = Infinity; default: rPrm = 0; } // TODO Ajouter un message d'erreur // "Les cotes et le débit ne sont pas cohérents => fermeture de l'ouvrage return new Result(rPrm, flagsNull); } } // Gestion de l'inversion de débit : on inverse l'amont et l'aval pour le calcul if ((sVarCalc === "Q" && (this.prms.h1.v < this.prms.h2.v)) || (sVarCalc !== "Q" && this.prms.Q.v < 0)) { [this.prms.h1.v, this.prms.h2.v] = [this.prms.h2.v, this.prms.h1.v]; // Swap ES6 fashion const res: Result = super.Calc(sVarCalc, rInit, rPrec); [this.prms.h1.v, this.prms.h2.v] = [this.prms.h2.v, this.prms.h1.v]; // Swap ES6 fashion
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
return res; } // Calcul normal hors débit nul et inversion de débit return super.Calc(sVarCalc, rInit, rPrec); } protected getResultData() { return { Mode: this.getFlowMode(), Regime: this.getFlowRegime(), }; } /** * 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.FREE; this.prms.Z2.calculability = ParamCalculability.FREE; this.prms.h1.calculability = ParamCalculability.FREE; this.prms.h2.calculability = ParamCalculability.FREE; this.prms.W.calculability = ParamCalculability.DICHO; } /** * Give the flow mode : weir or orifice flow */ protected getFlowMode(): StructureFlowMode { if (this.prms.h1.v > this.prms.W.v) { this.debug("Structure.getFlowMode(h1=" + this.prms.h1.v + ",W=" + this.prms.W.v + ")=ORIFICE"); return StructureFlowMode.ORIFICE; } else { this.debug("Structure.getFlowMode(h1=" + this.prms.h1.v + ",W=" + this.prms.W.v + ")=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.prms.W.v + ")=FREE"); return StructureFlowRegime.FREE; } else if (this.prms.h1.v > this.prms.W.v && this.prms.h2.v < (2 * this.prms.h1.v + this.prms.W.v) / 3) { // Partially submerged only for orifices this.debug( "Structure.getFlowRegime(h1=" + this.prms.h1.v + ",h2=" + this.prms.h2.v + ",W=" + this.prms.W.v + ")=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.prms.W.v + ")=SUBMERGED"); return StructureFlowRegime.SUBMERGED; } } }
211