cloison_aval.ts 4.90 KiB
import { ParamCalculability } from "../param/param-definition";
import { ParallelStructure } from "../structure/parallel_structure";
import { loiAdmissiblesCloisonAval, LoiDebit } from "../structure/structure_props";
import { StructureVanLevLarinier, StructureVanLevVillemonte } from "../structure/structure_vanlev";
import { Message, MessageCode } from "../util/message";
import { Result } from "../util/result";
export { ParallelStructureParams } from "../structure/parallel_structure_params";
export class CloisonAval extends ParallelStructure {
    /**
     * Returns admissible LoiDebit grouped by StructureType
     * Only one vanne levante is allowed on a CloisonAval
    public getLoisAdmissibles(): { [key: string]: LoiDebit[]; } {
        const loiAdmissibles = JSON.parse(JSON.stringify(loiAdmissiblesCloisonAval));
        if (this.hasVanneLevante()) {
            delete loiAdmissibles.VanneLevante;
        return loiAdmissibles;
    /**
     * Calcul de la cote amont de la cloison
     * @param sVarCalc Nom du paramètre à calculer : seul Z1 est admis
     * @param rInit Valeur initiale
    public Calc(sVarCalc: string | any, rInit?: number): Result {
        if (sVarCalc !== "Z1") {
            throw new Error("CloisonAval sVarCalc should be Z1");
        // if Calc() is called outside of CalcSerie(), _result might not be initialized
        if (! this._result) {
            this.initNewResultElement();
        this.checkVanneLevante();
        let m: Message;
        if (this.hasVanneLevante()) {
            const s = this.structures[this.indexVanneLevante] as StructureVanLevVillemonte | StructureVanLevLarinier;
            this.prms.Z1.v = this.prms.Z2.v + s.getParameter("DH").v;
            this.currentResult = this.CalcStructPrm(this.indexVanneLevante, "ZDV");
            if (this.result.ok) {
                // Suppression des extraResults : ils sont complétés plus bas pour chaque ouvrage
                this.result.resultElement.extraResults = {};
                s.prms.ZDV.v = this.result.vCalc;
            // Check if calculated ZDV is between minZDV and maxZDV
            if (this.result.vCalc < s.prms.minZDV.v) {
                m = new Message(MessageCode.WARNING_VANLEV_ZDV_INF_MIN);
                s.prms.ZDV.v = s.prms.minZDV.v;
            } else if (this.result.vCalc > s.prms.maxZDV.v) {
                m = new Message(MessageCode.WARNING_VANLEV_ZDV_SUP_MAX);
                s.prms.ZDV.v = s.prms.maxZDV.v;
        if (!this.hasVanneLevante() || this.result.ok) {
            // Calculation of Z1 with the new ZDV in case of existing vanne levante
            this.currentResult = super.Calc("Z1", rInit);
            if (this.result.ok) {
                this.getParameter(sVarCalc).v = this.result.vCalc;
                // Recalcul du débit total pour récupérer les résultats des ouvrages dans les résultats complémentaires
                const resQtot: Result = this.CalcQ();
                for (const extraResKey in resQtot.extraResults) {
                    if (resQtot.extraResults.hasOwnProperty(extraResKey)) {
                        this.result.resultElement.addExtraResult(extraResKey, resQtot.extraResults[extraResKey]);
                if (this.hasVanneLevante()) {
                    this.result.extraResults.ZDV = this.structures[this.indexVanneLevante].prms.ZDV.v;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
if (m !== undefined) { this.result.resultElement.addMessage(m); } } } } return this.result; } /** * paramétrage de la calculabilité des paramètres */ protected setParametersCalculability() { this.prms.Q.calculability = ParamCalculability.EQUATION; this.prms.Z1.calculability = ParamCalculability.DICHO; } /** * Is there at least one Vanne Levante in the Cloison ? */ private hasVanneLevante(): boolean { return !(this.indexVanneLevante === null); } /** * Return index structure of vanne levante */ private get indexVanneLevante(): number { for (let i = 0; i < this.structures.length; i++) { // tslint:disable-next-line:max-line-length if (loiAdmissiblesCloisonAval.VanneLevante.includes(this.structures[i].properties.getPropValue("loiDebit"))) { return i; } } return null; } /** * Check if there is more than one vanne levante and throw an error */ private checkVanneLevante() { let n: number = 0; for (const st of this.structures) { if (loiAdmissiblesCloisonAval.VanneLevante.includes(st.properties.getPropValue("loiDebit"))) { n += 1; } } if (n > 1) { throw new Error("CloisonAval: maximum 1 vanne levante allowed"); } } }