pab.ts 9.38 KiB
import { CalculatorType } from "../compute-node";
import { Nub } from "../nub";
import { ParamCalculability } from "../param/param-definition";
import { IParamDefinitionIterator, ParamsEquation, ParamsEquationArrayIterator } from "../param/params-equation";
import { Session } from "../session";
import { ParallelStructure, ParallelStructureParams } from "../structure/parallel_structure";
import { StructureTriangularTruncWeirFree } from "../structure/structure_triangular_trunc_weir";
import { Result } from "../util/result";
import { Cloisons } from "./cloisons";
import { PabParams } from "./pab_params";
export { PabParams };
export class Pab extends Nub {
    /**
     * paramètres castés au bon type
    get prms(): PabParams {
        return this._prms as PabParams;
    /**
     * enfants castés au bon type
    get children(): Cloisons[] {
        return this._children as Cloisons[];
    private static consoleDbgWall(cl: ParallelStructure) {
        let s: string = "";
        for (const p of cl.prms) {
            // tslint:disable-next-line:no-console
            s += p.symbol + " = " + p.v + "; ";
        // tslint:disable-next-line:no-console
        console.log(s);
        for (const c of cl.getChildren()) {
            // tslint:disable-next-line:no-console
            console.log("Ouvrage");
            s = "";
            for (const p of c.prms) {
                if (p.visible) {
                    s += "*";
                s += p.symbol + " = " + p.v + "; ";
            // tslint:disable-next-line:no-console
            console.log(s);
    /**
     * Last wall at downstream
    public downWall: ParallelStructure;
    constructor(prms: PabParams, downWall: ParallelStructure, dbg: boolean = false) {
        super(prms, dbg);
        this.downWall = downWall;
        this._calcType = CalculatorType.Pab;
    /**
     * Add Cloisons to the PAB from a cloison model
     * @param cloisonModel Cloison model parametrised as first upstream basin
     * @param n Number of walls (or falls) of the PAB (Number of basin = n - 1)
    public addCloisonsFromModel(cloisonModel: Cloisons , n: number) {
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
// Fix some parameters of the upstream cloison (= Wall + basin) const DH: number = cloisonModel.prms.DH.currentValue; const ZRMB: number = this.prms.Z1.currentValue - cloisonModel.prms.PB.currentValue - DH; const ZRAM: number = ZRMB + DH / 2; // Generate an image of the object for multiplication const serialisedCloisonModel = cloisonModel.serialise(); for (let i = 0; i < n; i++) { const cl: Cloisons = Session.getInstance().unserialiseSingleNub(serialisedCloisonModel).nub as Cloisons; const p = cl.prms; for (const st of cl.structures) { if (st.prms.h1.visible) { // Set ZDV from h1 for rectangular weirs st.prms.ZDV.singleValue = this.prms.Z1.currentValue - st.prms.h1.currentValue; // Set parameter visibility for ZDV and h1 in PAB context st.prms.ZDV.visible = true; st.prms.h1.visible = false; } } p.ZRMB.singleValue = ZRMB - i * DH; p.ZRAM.singleValue = ZRAM - i * DH; // Set Structure ZDVs for (const st of cl.structures) { if (st.isZDVcalculable) { st.prms.ZDV.singleValue = st.prms.ZDV.currentValue - i * DH; if (st.getParameter("ZT") !== undefined) { const stTT = st as StructureTriangularTruncWeirFree; stTT.prms.ZT.singleValue = stTT.prms.ZT.currentValue - i * DH; } } } if (i !== n - 1) { // Add wall + basin = cloison this.addChild(cl); } else { // The last wall is a ParallelStructure (= Wall only, without basin) this.downWall = new ParallelStructure(new ParallelStructureParams(0, 0, 0)); this.downWall.structures = cl.structures; } } } /** * Calcul analytique * @warning Should be called by this.Calc only for parameter initialisations * @param sVarCalc Variable à calculer (Z1 uniquement) */ public Equation(sVarCalc: string): Result { const r: Result = new Result(0, this); // Up to down course : discharge distribution and bottom elevation if (this.children.length > 0) { this.children[0].prms.Q.v = this.prms.Q.v; } // tslint:disable-next-line:prefer-for-of for (let i = 0; i < this.children.length; i++) { let wall: ParallelStructure; if (i !== this.children.length - 1) { wall = this.children[i + 1]; } else { wall = this.downWall; } // Set discharge for the next wall from the current basin wall.prms.Q.v = this.children[i].prms.Q.v + this.children[i].prms.QA.v; } // Down to up course : water surface calculation let Z: number = this.prms.Z2.v; Z = this.calcCloisonZ1(this.downWall, Z); this.downWall.result.extraResults.ZRAM =
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
this.children[this.children.length - 1].prms.ZRMB.v - this.children[this.children.length - 1].prms.DH.v / 2; this.downWall.result.extraResults.Q = this.downWall.prms.Q.v; if (this.debug) { console.log("Downstream wall"); Pab.consoleDbgWall(this.downWall); } for (let i = this.children.length - 1; i >= 0; i--) { // Initialisations for current cloison const cl: Cloisons = this.children[i]; // Calculation of upstream water elevation cl.prms.PB.v = Z - cl.prms.ZRMB.v; Z = this.calcCloisonZ1(cl, Z); // Add extraresults: mean depth in pool and discharge cl.result.extraResults.YMOY = cl.prms.PB.v; cl.result.extraResults.Q = cl.prms.Q.v; cl.result.extraResults.QA = cl.prms.QA.v; if (this.debug) { console.log("Bassin n°" + i); Pab.consoleDbgWall(cl); } } r.vCalc = Z; return r; } /** * Finds the ParallelStructure targetted by modelUid and defines it as the current downWall */ public setDownWall(modelUid: string) { // TODO: check if this is still necessary this.properties.setPropValue("modeleCloisonAval", modelUid); const dw = (Session.getInstance().findNubByUid(modelUid) as ParallelStructure); if (dw) { this.downWall = dw; } /* else { console.error("Pab.setDownWall : cannot find target ParallelStructure"); } */ } /** * Returns an iterator over : * - own parameters (this._prms) * - children parameters (this._children[*]._prms) * Special treatment for PAB's downwall */ public get parameterIterator(): IParamDefinitionIterator { const prms: ParamsEquation[] = []; prms.push(this._prms); if (this._children) { Nub.concatPrms(prms, this.childrenPrms); } if (this.downWall) { Nub.concatPrms(prms, this.downWall.childrenPrms); } return new ParamsEquationArrayIterator(prms); } /** * Once session is loaded, run a second pass on all PAB's Cloisons to * reinit their target if needed */ public fixPAB(obj: any) { // TODO: check if this is still necessary if (obj.children && Array.isArray(obj.children)) {
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
// Cloisons models for (const c of obj.children) { if (c.props.calcType === CalculatorType.Cloisons) { // who knows ? const childUid = c.uid; const targetCloisonsUid = c.props.modeleCloisons; // find child Cloisons to relink const cloisons = (this.getChild(childUid) as Cloisons); if (cloisons) { // cloisons.setModel(targetCloisonsUid); } // else cannot find target } } // Downstream wall if (obj.props.modeleCloisonAval) { this.setDownWall(obj.props.modeleCloisonAval); } } } /** * paramétrage de la calculabilité des paramètres */ protected setParametersCalculability() { this.prms.Z1.calculability = ParamCalculability.EQUATION; this.prms.Z2.calculability = ParamCalculability.FREE; this.prms.Q.calculability = ParamCalculability.DICHO; } /** * Remove Calculability of DH for not updating Z2 during calculation * @param child Cloison newly added to the PAB */ protected adjustChildParameters(child: Cloisons) { child.prms.DH.calculability = ParamCalculability.NONE; } private calcCloisonZ1(cl: ParallelStructure, Z: number): number { // Initialisations for current cloison cl.prms.Z2.v = Z; // Calculation of upstream water elevation cl.Calc("Z1", Z + 0.1); // Fall on this wall cl.result.extraResults.DH = cl.result.vCalc - cl.prms.Z2.v; // Return Update elevation for next pool return cl.result.vCalc; } }