Commit 410281da authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Merge branch '26-ajout-de-la-calculette-passe-a-bassins-calcul-du-nombre-de-bassins' into 'master'

Resolve "Ajout de la calculette : "Passe à bassins : Calcul du nombre de bassins""

Closes #26 and #16

See merge request cassiopee/jalhyd!25
parents 244138cd 1585889c
stable - 2019-04-12
===================
new features
------------
* improved session management
* moved calculated parameter, value modes and value modes consistency check to model
* chain computation and results invalidation
* easier access to variated results
* new linked parameters system with families
* updated jasmine tests
bug fixes
---------
* fixed many parameters-related bugs in Section / Remous / Structure
stable - 2019-03-05
===================
......
import { PabChute, PabChuteParams } from "../../src/pab/pab_chute";
import { checkResult } from "../test_func";
function pabChuteTest(varTest: string, expected: number) {
describe("Calc(): ", () => {
it(varTest + " should be " + expected, () => {
const prms = new PabChuteParams(
2, // Cote Hamont Z1
0.5, // Cote aval Z2
1.5, // Chute DH
);
const nub = new PabChute(prms);
prms[varTest].v = undefined;
checkResult(nub.Calc(varTest, 0), expected);
});
});
}
describe("Class PabChute: ", () => {
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);
});
});
......@@ -18,7 +18,9 @@ export enum CalculatorType {
ParallelStructure, // ouvrages hydrauliques en parallèle
Dever, // Outil Cassiopée Dever
Cloisons, // Outil Cassiopée PAB Cloisons
MacroRugo // Passe à enrochement simple (Cassan et al., 2016)
MacroRugo, // Passe à enrochement simple (Cassan et al., 2016)
PabChute,
PabNombre
}
/**
......
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 PabChuteParams extends ParamsEquation {
[key: string]: any; // pour pouvoir faire this['methode']();
/** Cote amont Z1 */
private _Z1: ParamDefinition;
/** Cote aval Z2 */
private _Z2: ParamDefinition;
/** Chute DH */
private _DH: ParamDefinition;
constructor(rZ1: number, rZ2: number, rDH: number) {
super();
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);
this.addParamDefinition(this._DH);
}
get Z1() {
return this._Z1;
}
get Z2() {
return this._Z2;
}
get DH() {
return this._DH;
}
}
// tslint:disable-next-line:max-classes-per-file
export class PabChute extends Nub {
constructor(prms: PabChuteParams, dbg: boolean = false) {
super(prms, dbg);
this._defaultCalculatedParam = prms.DH;
this.resetDefaultCalculatedParam();
}
/**
* paramètres castés au bon type
*/
get prms(): PabChuteParams {
return this._prms as PabChuteParams;
}
public Equation(sVarCalc: string): Result {
let v: number;
switch (sVarCalc) {
case "Z1":
v = this.prms.Z2.v + this.prms.DH.v;
break;
case "Z2":
v = this.prms.Z1.v - this.prms.DH.v;
break;
case "DH":
v = this.prms.Z1.v - this.prms.Z2.v;
break;
default:
throw new Error("PabChute.Equation() : invalid variable name " + sVarCalc);
}
return new Result(v);
}
/**
* paramétrage de la calculabilité des paramètres
*/
protected setParametersCalculability() {
this.prms.Z1.calculability = ParamCalculability.EQUATION;
this.prms.Z2.calculability = ParamCalculability.EQUATION;
this.prms.DH.calculability = ParamCalculability.EQUATION;
}
}
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);
this._defaultCalculatedParam = prms.N;
this.resetDefaultCalculatedParam();
}
/**
* 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
};
}
}
......@@ -24,6 +24,8 @@ 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";
......@@ -326,6 +328,7 @@ export class Session {
);
break;
}
case CalculatorType.MacroRugo:
{
nub = new MacroRugo(
......@@ -346,6 +349,30 @@ export class Session {
break;
}
case CalculatorType.PabChute:
{
nub = new PabChute(
new PabChuteParams(
2, // Z1
0.5, // Z2
1.5 // DH
)
);
break;
}
case CalculatorType.PabNombre:
{
nub = new PabNombre(
new PabNombreParams(
6, // DHT
10, // N
0.6 // DH
)
);
break;
}
default:
{
throw new Error(
......
Markdown is supported
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