An error occurred while loading the file. Please try again.
-
Mathias Chouet authoredbd53550e
import { CalculatorType } from "../compute-node";
import { Nub } from "../nub";
import { ParamCalculability } from "../param/param-definition";
import { Session } from "../session";
import { ParallelStructure } from "../structure/parallel_structure";
import { Result } from "../util/result";
import { PabCloisons } from "./pab_cloisons";
import { PabParams } from "./pab_params";
export { PabParams };
export class Pab extends Nub {
/**
* 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;
}
/**
* paramètres castés au bon type
*/
get prms(): PabParams {
return this._prms as PabParams;
}
/**
* enfants castés au bon type
*/
get children(): PabCloisons[] {
return this._children as PabCloisons[];
}
public Calc(sVarCalc?: string, rInit?: number): Result {
// Update array of PabCloisons with last Models current values
/* for (const cl of this.children) {
cl.prms.setCurrentValuesFromModel();
} */
return super.Calc(sVarCalc, rInit);
}
/**
* 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
let Q: number = this.prms.Q.v; // Upstream discharge
// upstream basin apron elevation
let rZRam: number = this.children[0].prms.Z1.currentValue - this.children[0].Yam;
for (const cl of this.children) {
Q += cl.prms.QA.v; // Discharge in the current basin
rZRam -= cl.prms.DH.currentValue;
}
// Down to up course : water surface calculation
let Z: number = this.prms.Z2.v;
Z = this.calcCloisonZ1(this.downWall, Q, Z);
this.downWall.result.extraResults.ZRAM = rZRam;
for (let i = this.children.length - 1; i >= 0; i--) {
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
// Initialisations for current cloison
const cl: PabCloisons = this.children[i];
rZRam += cl.prms.DH.currentValue;
cl.updateZDV(rZRam);
// Calculation of upstream water elevation
Z = this.calcCloisonZ1(cl, Q, Z);
if (this.debug) {
console.log("Bassin n°" + i);
let s: string = "";
for (const p of cl.prms) {
// tslint:disable-next-line:no-console
s += p.symbol + " = " + p.v + "; " ;
}
console.log(s);
for (const c of cl.getChildren()) {
console.log("Ouvrage");
s = "";
for (const p of c.prms) {
// tslint:disable-next-line:no-console
s += p.symbol + " = " + p.v;
}
console.log(s);
}
}
Q -= cl.prms.QA.v;
}
r.vCalc = Z;
return r;
}
/**
* Finds the ParallelStructure targetted by modelUid and defines it as the current downWall
*/
public setDownWall(modelUid: string) {
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");
} */
}
/**
* Once session is loaded, run a second pass on all PabCloisons to
* reinit their target if needed
*/
public fixPAB(obj: any) {
if (obj.children && Array.isArray(obj.children)) {
// Cloisons models
for (const c of obj.children) {
if (c.props.calcType === CalculatorType.PabCloisons) { // who knows ?
const childUid = c.uid;
const targetCloisonsUid = c.props.modeleCloisons;
// find child PabCloisons to relink
const pabCloisons = (this.getChild(childUid) as PabCloisons);
if (pabCloisons) {
pabCloisons.setModel(targetCloisonsUid);
} // else cannot find target
}
}
// Downstream wall
if (obj.props.modeleCloisonAval) {
this.setDownWall(obj.props.modeleCloisonAval);
}
}
141142143144145146147148149150151152153154155156157158159160161162163164165166167
}
/**
* paramétrage de la calculabilité des paramètres
*/
protected setParametersCalculability() {
this.prms.Z1.calculability = ParamCalculability.EQUATION;
this.prms.Z2.calculability = ParamCalculability.DICHO;
this.prms.Q.calculability = ParamCalculability.DICHO;
}
private calcCloisonZ1(cl: ParallelStructure, Q: number, Z: number): number {
// Initialisations for current cloison
cl.prms.Q.v = Q;
cl.prms.Z2.v = Z;
// Calculation of upstream water elevation
cl.Calc("Z1");
// TODO: Add extraresults: discharge, apron elevation upstream the wall, apron elevation at half basin
cl.result.extraResults.YMOY = cl.prms.Z2.v - cl.result.extraResults.ZRMB;
// Update elevation and discharge for next basin
return cl.prms.Z1.v;
}
}