structure.ts 11.77 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 {
    /** Sans objet (orifice) */
    SO,
    /** Plongeant */
    PLONGEANT,
    /** De surface */
    SURFACE
/**
 * 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;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
this._isZDVcalculable = true; // Q is always the only calculated variable; setting another parameter // 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); } get isZDVcalculable(): boolean { return this._isZDVcalculable; } /** * paramètres castés au bon type */ get prms(): StructureParams { return this._prms as StructureParams; } get W(): number { if (this.prms.W.visible) { return this.prms.W.v; } else { return Infinity; } } /** * 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; } if (sVarCalc === "W" && rInit === Infinity) { throw new Error("Structure:Calc : Calcul de W impossible sur un seuil");
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
} // 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; } }