pab.ts 10.48 KiB
import { CalculatorType } from "../compute-node";
import { Nub } from "../nub";
import { ParamCalculability, ParamDefinition } from "../param/param-definition";
import { IParamDefinitionIterator, ParamsEquation, ParamsEquationArrayIterator } from "../param/params-equation";
import { Props } from "../props";
import { Session } from "../session";
import { ParallelStructure } from "../structure/parallel_structure";
import { StructureTriangularTruncWeirFree } from "../structure/structure_triangular_trunc_weir";
import { Result } from "../util/result";
import { CloisonAval, ParallelStructureParams } from "./cloison_aval";
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[];
    /**
     * Last wall at downstream
    private _downWall: CloisonAval;
    constructor(prms: PabParams, downWall: CloisonAval, dbg: boolean = false) {
        super(prms, dbg);
        this.downWall = downWall;
        this._calcType = CalculatorType.Pab;
    public get downWall() {
        return this._downWall;
    public set downWall(dw: CloisonAval) {
        this._downWall = dw;
        if (dw) { // might be undefined
            dw.parent = this; // important
            // postprocessing
            this.adjustDownwallParameters(this.downWall);
    /**
     * 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) {
        // 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;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
const p = cl.prms; 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 = (this.prms.Z1.currentValue - st.prms.h1.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 CloisonAval (= Wall only, without basin) this.downWall = new CloisonAval(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; } let l: number = 0; // Lenght of the fishway and wall abscissas for (let i = 0; i < this.children.length; i++) { let wall: CloisonAval | Cloisons; if (i !== this.children.length - 1) { wall = this.children[i + 1]; } else { wall = this.downWall; } l += this.children[i].prms.LB.v; // 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 = 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; this.downWall.result.extraResults.x = l; this.debug("Downstream wall"); this.dbgWall(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;
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
cl.result.extraResults.Q = cl.prms.Q.v; cl.result.extraResults.QA = cl.prms.QA.v; l -= cl.prms.LB.v; cl.result.extraResults.x = l; this.debug("Bassin n°" + i); this.dbgWall(cl); } r.vCalc = Z; return r; } /** * 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); } /** * Returns an object representation of the Nub's current state * @param extra extra key-value pairs, for ex. calculator title in GUI */ public objectRepresentation(extra?: object) { // regular serialization const ret: any = super.objectRepresentation(extra); // downwall ret.downWall = this.downWall.objectRepresentation(); return ret; } /** * Fills the current Nub with parameter values, provided an object representation * @param obj object representation of a Nub content (parameters) * @returns the calculated parameter found, if any - used by child Nub to notify * its parent of the calculated parameter to set */ public loadObjectRepresentation(obj: any): { p: ParamDefinition, hasErrors: boolean } { // return value const ret: { p: ParamDefinition, hasErrors: boolean } = super.loadObjectRepresentation(obj); // load downwall if any if (obj.downWall) { // create the Nub const dw = Session.getInstance().createNub(new Props(obj.downWall.props), this) as CloisonAval; // try to keep the original ID if (! Session.getInstance().uidAlreadyUsed(obj.downWall.uid)) { dw.setUid(obj.downWall.uid); } const childRet = dw.loadObjectRepresentation(obj.downWall); // add downWall to parent this.downWall = dw; // forward errors if (childRet.hasErrors) { ret.hasErrors = true; } } return ret; }
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
/** * Adds a new empty resultElement to the current Result object, so that * computation result is stored into it, via set currentResult(); does * the same for all children and downWall */ public initNewResultElement() { super.initNewResultElement(); this.downWall.initNewResultElement(); } /** * 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; adjust * visibility for PAB display and serialisation * @param child Cloison newly added to the PAB */ protected adjustChildParameters(child: Cloisons) { child.prms.DH.calculability = ParamCalculability.NONE; child.prms.QA.visible = true; child.prms.ZRAM.visible = true; child.prms.ZRMB.visible = true; child.prms.Q.visible = false; child.prms.Z1.visible = false; child.prms.PB.visible = false; child.prms.DH.visible = false; for (const st of child.structures) { if (st.prms.h1.visible) { // Set parameter visibility for ZDV and h1 in PAB context st.prms.ZDV.visible = true; st.prms.h1.visible = false; } } } /** * Remove visibility of downwall hydraulic parameters, for serialisation * @param dw */ protected adjustDownwallParameters(dw: CloisonAval) { dw.prms.Q.visible = false; dw.prms.Z1.visible = false; dw.prms.Z2.visible = false; } private calcCloisonZ1(cl: CloisonAval | Cloisons, 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; } private dbgWall(cl: ParallelStructure) { let s: string = ""; for (const p of cl.prms) {
281282283284285286287288289290291292293294295296297298
s += p.symbol + " = " + p.v + "; "; } this.debug(s); for (const c of cl.getChildren()) { this.debug("Ouvrage"); s = ""; for (const p of c.prms) { if (p.visible) { s += "*"; } s += p.symbol + " = " + p.v + "; "; } this.debug(s); } } }