Skip to content
Snippets Groups Projects
Commit 61ab6372 authored by David Dorchies's avatar David Dorchies
Browse files

#35 Fuzzing test on MacrorugoCompound passed

parent aaca1fe1
No related branches found
No related tags found
No related merge requests found
import { CalculatorType } from "../src/compute-node";
import { MacrorugoCompound } from "../src/macrorugo/macrorugo_compound";
import { Nub } from "../src/nub";
import { CloisonAval } from "../src/pab/cloison_aval";
import { Pab } from "../src/pab/pab";
......@@ -110,6 +111,10 @@ function setPab(pab: Pab, nClMax = 30, nStMax = 3) {
addRandomStructures(pab.downWall, nStMax);
}
function setMacrorugoCompound(n: MacrorugoCompound) {
n.properties.setPropValue("InclinedApron", Math.random() > 0.5);
}
function CreateTestNub(iCalType: number): Nub {
const n = Session.getInstance().createNub(
new Props({ calcType: iCalType })
......@@ -129,6 +134,9 @@ function CreateTestNub(iCalType: number): Nub {
if (iCalType === CalculatorType.Pab) {
setPab(n as Pab, fuzzyCfg.Pab.poolMax, fuzzyCfg.Pab.structureMax);
}
if (iCalType === CalculatorType.MacroRugoCompound) {
setMacrorugoCompound(n as MacrorugoCompound);
}
for (const p of n.parameterIterator) {
if (p.visible) {
randomizeParameter(p);
......
......@@ -4,6 +4,8 @@ import { MacrorugoCompound } from "../../src/macrorugo/macrorugo_compound";
import { Props } from "../../src/props";
import { Session } from "../../src/session";
let B: number;
describe("MacroRugoCompound", () => {
describe("Default 1 apron", () => {
it("should return same result as Macrorugo", () => {
......@@ -14,8 +16,28 @@ describe("MacroRugoCompound", () => {
const mr = Session.getInstance().createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo;
mr.prms.Q.setCalculated();
expect(mrc.CalcSerie().vCalc).toBeCloseTo(mr.CalcSerie().vCalc, 3);
console.debug(mrc.result.vCalc);
console.debug(mr.result.vCalc);
});
});
describe("Default inclined but flat apron", () => {
beforeAll(() => {
B = 2;
});
beforeEach(() => {
B++;
});
for (let i = 2; i < 6; i++) {
it(`B = ${i} should return same result as Macrorugo`, () => {
const mrc = Session.getInstance().createNub(
new Props({ calcType: CalculatorType.MacroRugoCompound })
) as MacrorugoCompound;
mrc.properties.setPropValue("InclinedApron", true);
mrc.prms.B.singleValue = 4;
const mr = Session.getInstance()
.createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo;
mr.prms.Q.setCalculated();
expect(mrc.CalcSerie().vCalc).toBeCloseTo(mr.CalcSerie().vCalc * mrc.prms.B.currentValue, 3);
});
}
});
});
......@@ -66,6 +66,8 @@ export class MacroRugo extends Nub {
this.getParameter(sVarCalc).valueMode = ParamValueMode.CALCUL;
const r: Result = super.Calc(sVarCalc, rInit);
this.getParameter(sVarCalc).valueMode = originalValueMode;
// Ajout des résultats complémentaires
// Cote de fond aval
r.resultElement.values.ZF2 = this.prms.ZF1.v - this.prms.If.v * this.prms.L.v;
......@@ -115,9 +117,6 @@ export class MacroRugo extends Nub {
Math.pow(this.prms.If.v, cV[2]) * Math.sqrt(MacroRugo.g * this.prms.PBD.v);
}
// mode d'origine du paramètre; voir le haut de la fonction
this.getParameter(sVarCalc).valueMode = originalValueMode;
return r;
}
......@@ -125,8 +124,13 @@ export class MacroRugo extends Nub {
this.Q = this.prms.Q.v;
const q0 = Math.sqrt(2 * MacroRugo.g * this.prms.If.v * this.prms.PBD.v * ( 1 - (this.sigma * this.prms.C.v)) /
(this.prms.Cd0.v * this.prms.C.v)) * this.prms.Y.v * this.prms.B.v;
const dicho = new Dichotomie(this, "Q", false, this.resolveQ);
const r: Result = dicho.Dichotomie(0, this.prms.Pr.v, q0);
let r: Result;
if (q0 > 0) {
const dicho = new Dichotomie(this, "Q", false, this.resolveQ);
r = dicho.Dichotomie(0, this.prms.Pr.v, q0);
} else {
r = new Result(0);
}
this.prms.Q.v = this.Q;
return r;
......
......@@ -29,6 +29,9 @@ export class MacrorugoCompound extends MacroRugo {
if (sVarCalc !== "Q") {
throw new Error("MacrorugoCompound.Calc() : invalid parameter " + sVarCalc);
}
if (this.properties.getPropValue("InclinedApron")) {
this.generateInclinedFishway();
}
this.copyPrmsToChildren();
this.currentResult = this.Equation(sVarCalc);
return this._result;
......@@ -84,7 +87,7 @@ export class MacrorugoCompound extends MacroRugo {
}
// Calculate Length and depth from other parameters
child.prms.L.v = this.prms.DH.v / this.prms.If.v;
child.prms.Y.v = this.prms.Z1.v - child.prms.ZF1.v;
child.prms.Y.v = Math.max(this.prms.Z1.v - child.prms.ZF1.v, 0);
}
}
......@@ -101,27 +104,28 @@ export class MacrorugoCompound extends MacroRugo {
// Taille d'une cellule de calcul
const ax: number = this.prms.PBD.v / Math.sqrt(this.prms.C.v);
// Nombre entier de cellules et reste
const ncells: number = Math.floor(this.prms.B.v / ax);
const xRest: number = this.prms.B.v % ax;
const nCells: number = Math.floor(this.prms.BR.v / ax);
const xRest: number = this.prms.BR.v % ax;
const xCenters: number[] = [];
let iStart: number;
// Calcul du centre de la première cellule
let lastBorder: number = 0;
// Position du centre de la première cellule
if (xRest > ax / 2) {
// Ajout d'une cellule à gauche
xCenters.push(xRest / 2);
iStart = 0;
xCenters.push(xRest / 4);
} else {
// Décalage de la première cellule
xCenters.push((ax + xRest) / 2);
iStart = 1;
xCenters.push((ax + xRest / 2) / 2);
}
// Ajout des cellules centrales
for (let i = iStart; i < ncells; i++) {
xCenters.push(xCenters[xCenters.length - 1] + ax);
lastBorder = xCenters[0] * 2;
// Ajout des cellules centrales décalées de ax
for (let i = 0; i < nCells; i++) {
xCenters.push(lastBorder + ax / 2);
lastBorder += ax;
}
if (xRest > ax / 2) {
// Ajout de la cellule supplémentaire à droite
xCenters.push(this.prms.B.v - xRest / 2);
xCenters.push(this.prms.B.v - xRest / 4);
} else {
xCenters[xCenters.length - 1] = this.prms.BR.v - (ax + xRest / 2) / 2;
}
// Génération des radiers
......@@ -129,11 +133,14 @@ export class MacrorugoCompound extends MacroRugo {
while (this.children.length > 0) {
this.deleteChild(0);
}
// Ajout des radiers et calcul de la cote amont
// Ajout des radiers et calcul de leur cote amont et de leur largeur
lastBorder = 0;
for (const xCenter of xCenters) {
this.addDefaultChild();
this.children[this.children.length - 1].prms.ZF1.v =
this.prms.ZRL.v + xCenter / this.prms.B.v * (this.prms.ZRR.v - this.prms.ZRL.v);
this.prms.ZRL.v + xCenter / this.prms.BR.v * (this.prms.ZRR.v - this.prms.ZRL.v);
this.children[this.children.length - 1].prms.B.v = (xCenter - lastBorder) * 2;
lastBorder += this.children[this.children.length - 1].prms.B.v;
}
}
}
import { ParamDefinition, ParamFamily } from "../param/param-definition";
import { ParamDomainValue } from "../param/param-domain";
import { ParamDomain, ParamDomainValue } from "../param/param-domain";
import { MacrorugoParams } from "./macrorugo";
export class MacrorugoCompoundParams extends MacrorugoParams {
......@@ -16,11 +16,16 @@ export class MacrorugoCompoundParams extends MacrorugoParams {
/** Inclined apron: Right bank apron elevation (m) */
private _ZRR: ParamDefinition;
/** Inclined apron: Apron total width (m) */
private _BR: ParamDefinition;
/**
*
* @param rZ1 Cote de l'eau amont (m)
* @param rZRL Cote de radier gauche (m) (Radier incliné seulement)
* @param rZRR Cote de radier droit (m) (Radier incliné seulement)
* @param rB Largeur (m) (Radier incliné seulement)
* @param rDH Chute (m)
* @param rB Largeur (m)
* @param rIf Pente (m/m)
* @param rY Tirant d'eau (m)
* @param rRF Rugosité de fond (m)
......@@ -33,6 +38,7 @@ export class MacrorugoCompoundParams extends MacrorugoParams {
rZ1: number,
rZRL: number,
rZRR: number,
rB: number,
rDH: number,
rIf: number,
rRF: number,
......@@ -41,18 +47,23 @@ export class MacrorugoCompoundParams extends MacrorugoParams {
rPBH: number,
rCd0: number
) {
super((rZRL + rZRR) / 2, rDH / rIf, 1, rIf, 1, 1, rRF, rCB, rPBD, rPBH, rCd0);
super((rZRL + rZRR) / 2, 1, rDH / rIf, rIf, 1, 1, rRF, rCB, rPBD, rPBH, rCd0);
this._Z1 = new ParamDefinition(this, "Z1", ParamDomainValue.POS, "m", rZ1, ParamFamily.ELEVATIONS);
this._Z1 = new ParamDefinition(this, "Z1", ParamDomainValue.ANY, "m", rZ1, ParamFamily.ELEVATIONS);
this.addParamDefinition(this._Z1);
this._ZRL = new ParamDefinition(this, "ZRL", ParamDomainValue.POS, "m", rZRL, ParamFamily.ELEVATIONS);
this._ZRL = new ParamDefinition(this, "ZRL", ParamDomainValue.ANY, "m", rZRL, ParamFamily.ELEVATIONS);
this.addParamDefinition(this.ZRL);
this._ZRR = new ParamDefinition(this, "ZRR", ParamDomainValue.POS, "m", rZRR, ParamFamily.ELEVATIONS);
this._ZRR = new ParamDefinition(this, "ZRR", ParamDomainValue.ANY, "m", rZRR, ParamFamily.ELEVATIONS);
this.addParamDefinition(this._ZRR);
this._DH = new ParamDefinition(this, "DH", ParamDomainValue.POS, "m", rDH, ParamFamily.ELEVATIONS);
this._BR = new ParamDefinition(this, "BR",
new ParamDomain(ParamDomainValue.INTERVAL, 0, 100), "m", rB, ParamFamily.WIDTHS);
this.addParamDefinition(this._BR);
this._DH = new ParamDefinition(this, "DH",
new ParamDomain(ParamDomainValue.INTERVAL, 0, 100), "m", rDH, ParamFamily.ELEVATIONS);
this.addParamDefinition(this._DH);
// Width, water depth, and Bottom elevation are defined in Macrorugo children
......@@ -60,6 +71,7 @@ export class MacrorugoCompoundParams extends MacrorugoParams {
this.ZF1.visible = false;
this.Y.visible = false;
this.Q.visible = false;
}
public get Z1(): ParamDefinition {
......@@ -74,6 +86,10 @@ export class MacrorugoCompoundParams extends MacrorugoParams {
return this._ZRR;
}
public get BR(): ParamDefinition {
return this._BR;
}
public get DH(): ParamDefinition {
return this._DH;
}
......
import { ParamDefinition, ParamFamily } from "../param/param-definition";
import { ParamDomainValue } from "../param/param-domain";
import { ParamDomain, ParamDomainValue } from "../param/param-domain";
import { ParamsEquation } from "../param/params-equation";
export class MacrorugoParams extends ParamsEquation {
......@@ -65,22 +65,23 @@ export class MacrorugoParams extends ParamsEquation {
this._B = new ParamDefinition(this, "B", ParamDomainValue.POS, "m", rB, ParamFamily.WIDTHS);
this.addParamDefinition(this._B);
this._If = new ParamDefinition(this, "If", ParamDomainValue.POS, "m/m", rIf, ParamFamily.SLOPES);
this._If = new ParamDefinition(this, "If",
new ParamDomain(ParamDomainValue.INTERVAL, 0, 0.5), "m/m", rIf, ParamFamily.SLOPES);
this.addParamDefinition(this._If);
this._Q = new ParamDefinition(this, "Q", ParamDomainValue.POS, "m³/s", rQ, ParamFamily.FLOWS);
this.addParamDefinition(this._Q);
this._Y = new ParamDefinition(this, "Y", ParamDomainValue.POS, "m", rY, ParamFamily.HEIGHTS);
this._Y = new ParamDefinition(this, "Y", ParamDomainValue.POS_NULL, "m", rY, ParamFamily.HEIGHTS);
this.addParamDefinition(this._Y);
this._Ks = new ParamDefinition(this, "Ks", ParamDomainValue.POS_NULL, "m", rRF);
this._Ks = new ParamDefinition(this, "Ks", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "m", rRF);
this.addParamDefinition(this._Ks);
this._C = new ParamDefinition(this, "C", ParamDomainValue.POS, "m", rCB);
this._C = new ParamDefinition(this, "C", new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), "-", rCB);
this.addParamDefinition(this._C);
this._PBD = new ParamDefinition(this, "PBD", ParamDomainValue.POS, "m", rPBD);
this._PBD = new ParamDefinition(this, "PBD", new ParamDomain(ParamDomainValue.INTERVAL, 0, 2), "m", rPBD);
this.addParamDefinition(this._PBD);
this._PBH = new ParamDefinition(this, "PBH", ParamDomainValue.POS, "m", rPBH, ParamFamily.HEIGHTS);
......
......@@ -418,6 +418,7 @@ export class Session {
13.1, // Z1
12.5, // ZRL
12.5, // ZRR
4, // B
3, // DH
0.05, // If
0.01, // Ks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment