Commit 0177f41e authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Fix #16 added fish ladder number of basins calculation

Showing with 164 additions and 11 deletions
+164 -11
......@@ -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);
});
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);
});
});
......@@ -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
}
/**
......
......@@ -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);
......
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
};
}
}
......@@ -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(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment