diff --git a/spec/pab/pab_chute.spec.ts b/spec/pab/pab_chute.spec.ts index 56c0e9e360e606cb261b7100fee3b04705ee983b..4fe6f25d757b7b98ccac00f8bbc0a440a2b021e4 100644 --- a/spec/pab/pab_chute.spec.ts +++ b/spec/pab/pab_chute.spec.ts @@ -2,7 +2,7 @@ import { PabChute, PabChuteParams } from "../../src/pab/pab_chute"; import { checkResult } from "../test_func"; -function pabDimensionTest(varTest: string, expected: number) { +function pabChuteTest(varTest: string, expected: number) { describe("Calc(): ", () => { it(varTest + " should be " + expected, () => { const prms = new PabChuteParams( @@ -21,8 +21,8 @@ function pabDimensionTest(varTest: string, expected: number) { describe("Class PabChute: ", () => { - pabDimensionTest("Z1", 2); - pabDimensionTest("Z2", 0.5); - pabDimensionTest("DH", 1.5); + pabChuteTest("Z1", 2); + pabChuteTest("Z2", 0.5); + pabChuteTest("DH", 1.5); }); diff --git a/spec/pab/pab_nombre.spec.ts b/spec/pab/pab_nombre.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..fb5d9619e763d67cad5ce5d2e9099f74e4dba854 --- /dev/null +++ b/spec/pab/pab_nombre.spec.ts @@ -0,0 +1,40 @@ + +import { PabNombre, PabNombreParams } from "../../src/pab/pab_nombre"; +import { checkResult } from "../test_func"; + +function pabNombreTest(varTest: string, expected: number) { + describe("Calc(): ", () => { + it(varTest + " should be " + expected, () => { + const prms = new PabNombreParams( + 7.5, // Chute totale DHT + 10, // Nombre de bassins N + 0.75, // Chute entre bassins DH + ); + + const nub = new PabNombre(prms); + prms[varTest].v = undefined; + + checkResult(nub.Calc(varTest, 0), expected); + }); + }); +} + +describe("Class PabNombre: ", () => { + + pabNombreTest("DHT", 7.5); + pabNombreTest("N", 10); + pabNombreTest("DH", 0.75); + + it ("DHR should be 0.3", () => { + const prms = new PabNombreParams( + 7.5, // Chute totale DHT + 9, // Nombre de bassins N + 0.8, // Chute entre bassins DH + ); + + const nub = new PabNombre(prms); + + nub.Calc("N", 0); + expect(nub.result.getExtraResult("DHR")).toBeCloseTo(0.3); + }); +}); diff --git a/src/compute-node.ts b/src/compute-node.ts index f2d4bd9018ae001501ab0c0d10a6e1af8d407cfe..62c0fb85e8dd5e76b022e144a828facac5755c79 100644 --- a/src/compute-node.ts +++ b/src/compute-node.ts @@ -19,7 +19,8 @@ export enum CalculatorType { Dever, // Outil Cassiopée Dever Cloisons, // Outil Cassiopée PAB Cloisons MacroRugo, // Passe à enrochement simple (Cassan et al., 2016) - PabChute + PabChute, + PabNombre } /** diff --git a/src/pab/pab_chute.ts b/src/pab/pab_chute.ts index 5ad47f9f914840f60e66375f09928bab15bdc4dc..114dd0c33b2a44a850304850cef21b8a96127305 100644 --- a/src/pab/pab_chute.ts +++ b/src/pab/pab_chute.ts @@ -7,20 +7,20 @@ import { Result } from "../util/result"; export class PabChuteParams extends ParamsEquation { [key: string]: any; // pour pouvoir faire this['methode'](); - /** Longueur L */ + /** Cote amont Z1 */ private _Z1: ParamDefinition; - /** Largeur W */ + /** Cote aval Z2 */ private _Z2: ParamDefinition; - /** Tirant d'eau Y */ + /** Chute DH */ private _DH: ParamDefinition; constructor(rZ1: number, rZ2: number, rDH: number) { super(); - this._Z1 = new ParamDefinition(this, "Z1", ParamDomainValue.POS, rZ1, ParamFamily.HEIGHTS); - this._Z2 = new ParamDefinition(this, "Z2", ParamDomainValue.POS, rZ2, ParamFamily.HEIGHTS); - this._DH = new ParamDefinition(this, "DH", ParamDomainValue.POS, rDH, ParamFamily.HEIGHTS); + this._Z1 = new ParamDefinition(this, "Z1", ParamDomainValue.ANY, rZ1, ParamFamily.ELEVATIONS); + this._Z2 = new ParamDefinition(this, "Z2", ParamDomainValue.ANY, rZ2, ParamFamily.ELEVATIONS); + this._DH = new ParamDefinition(this, "DH", ParamDomainValue.POS_NULL, rDH, ParamFamily.HEIGHTS); this.addParamDefinition(this._Z1); this.addParamDefinition(this._Z2); diff --git a/src/pab/pab_nombre.ts b/src/pab/pab_nombre.ts new file mode 100644 index 0000000000000000000000000000000000000000..f56e52aba915b8a48fe2fe5631a21900ad6ecc01 --- /dev/null +++ b/src/pab/pab_nombre.ts @@ -0,0 +1,99 @@ +import { Nub } from "../nub"; +import { ParamCalculability, ParamDefinition, ParamFamily } from "../param/param-definition"; +import { ParamDomainValue } from "../param/param-domain"; +import { ParamsEquation } from "../param/params-equation"; +import { Result } from "../util/result"; + +export class PabNombreParams extends ParamsEquation { + [key: string]: any; // pour pouvoir faire this['methode'](); + + /** Chute totale DHT */ + private _DHT: ParamDefinition; + + /** Nombre de bassins N */ + private _N: ParamDefinition; + + /** Chute entre bassins DH */ + private _DH: ParamDefinition; + + constructor(rDHT: number, rN: number, rDH: number) { + super(); + this._DHT = new ParamDefinition(this, "DHT", ParamDomainValue.POS, rDHT, ParamFamily.HEIGHTS); + this._N = new ParamDefinition(this, "N", ParamDomainValue.POS, rN); + this._DH = new ParamDefinition(this, "DH", ParamDomainValue.POS, rDH, ParamFamily.HEIGHTS); + + this.addParamDefinition(this._DHT); + this.addParamDefinition(this._N); + this.addParamDefinition(this._DH); + } + + get DHT() { + return this._DHT; + } + + get N() { + return this._N; + } + + get DH() { + return this._DH; + } +} + +// tslint:disable-next-line:max-classes-per-file +export class PabNombre extends Nub { + constructor(prms: PabNombreParams, dbg: boolean = false) { + super(prms, dbg); + } + + /** + * paramètres castés au bon type + */ + get prms(): PabNombreParams { + return this._prms as PabNombreParams; + } + + public Equation(sVarCalc: string): Result { + let v: number; + let DHR = 0; + + switch (sVarCalc) { + case "DHT": + v = this.prms.N.v * this.prms.DH.v; + break; + + case "N": + v = Math.floor(this.prms.DHT.v / this.prms.DH.v); + DHR = this.prms.DHT.v % this.prms.DH.v; + break; + + case "DH": + v = this.prms.DHT.v / this.prms.N.v; + break; + + default: + throw new Error("PabNombre.Equation() : invalid variable name " + sVarCalc); + } + + const r = new Result(v); + r.extraResults.DHR = DHR; + + return r; + } + + /** + * paramétrage de la calculabilité des paramètres + */ + protected setParametersCalculability() { + this.prms.DHT.calculability = ParamCalculability.EQUATION; + this.prms.N.calculability = ParamCalculability.EQUATION; + this.prms.DH.calculability = ParamCalculability.EQUATION; + } + + protected setExtraResultsFamilies() { + this._extraResultsFamilies = { + DHR: ParamFamily.HEIGHTS + }; + } + +} diff --git a/src/session.ts b/src/session.ts index 653fdb578e53d2e748b0ddd4220e2c5360ea2f11..72fa81e189651f73a7c41206d322ad30c371daca 100644 --- a/src/session.ts +++ b/src/session.ts @@ -25,6 +25,7 @@ import { acSection } from "./section/section_type"; // Classes relatives aux structures import { LinkedValue } from "./linked-value"; import { PabChute, PabChuteParams } from "./pab/pab_chute"; +import { PabNombre, PabNombreParams } from "./pab/pab_nombre"; import { ParamDefinition } from "./param/param-definition"; import { CreateStructure } from "./structure/factory_structure"; import { Structure } from "./structure/structure"; @@ -360,6 +361,18 @@ export class Session { break; } + case CalculatorType.PabNombre: + { + nub = new PabNombre( + new PabNombreParams( + 6, // DHT + 10, // N + 0.6 // DH + ) + ); + break; + } + default: { throw new Error(