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

MacrorugoCompound: calculate children depths once for all in CalcSerie()

Showing with 49 additions and 3 deletions
+49 -3
......@@ -28,7 +28,7 @@ function getMacroRugoRef(i: number = 0): MacroRugo {
describe("MacroRugoCompound", () => {
describe("Default 1 apron", () => {
it("should return same result as Macrorugo", () => {
it("should return same result as Macrorugo (1)", () => {
const mrc = Session.getInstance().createNub(
new Props({ calcType: CalculatorType.MacroRugoCompound })
) as MacrorugoCompound;
......@@ -36,7 +36,7 @@ describe("MacroRugoCompound", () => {
const mr = getMacroRugoRef();
expect(mrc.CalcSerie().vCalc).toBeCloseTo(mr.result.vCalc, 3);
});
it("should return same result as Macrorugo", () => {
it("should return same result as Macrorugo (2)", () => {
const mrc = Session.getInstance().createNub(
new Props({ calcType: CalculatorType.MacroRugoCompound })
) as MacrorugoCompound;
......@@ -48,6 +48,17 @@ describe("MacroRugoCompound", () => {
mr.CalcSerie();
compareTwoResults(mrc.children[0].result, mr.result, 3, [ "ZF2" ]);
});
it("variating Z1, children Y should not always be 0.6", () => {
const mrc = Session.getInstance().createNub(
new Props({ calcType: CalculatorType.MacroRugoCompound })
) as MacrorugoCompound;
mrc.addDefaultChild();
mrc.children[0].prms.L.singleValue = 0.5;
mrc.prms.Z1.setValues(10, 15, 5);
mrc.CalcSerie();
const childYs = mrc.children[0].prms.Y.getInferredValuesList();
expect(childYs).toEqual([ 0, 2.5 ]);
});
});
describe("Default inclined but flat apron", () => {
beforeAll(() => {
......
......@@ -33,6 +33,42 @@ export class MacrorugoCompound extends MacroRugo implements Observer {
// important to regenerate it here, at every iteration of CalcSerie()
this.generateInclinedFishway();
}
// calculate and store depths once for all
for (const child of this.children) {
// do we have a series of values ?
if (this.prms.Z1.hasMultipleValues || child.prms.ZF1.hasMultipleValues) {
let valsZ1;
let valsChildZF1;
if (this.prms.Z1.hasMultipleValues) {
valsZ1 = this.prms.Z1.getInferredValuesList();
} else {
valsZ1 = new Array(child.prms.ZF1.getInferredValuesList().length)
.fill(this.prms.Z1.singleValue);
}
if (child.prms.ZF1.hasMultipleValues) {
valsChildZF1 = child.prms.ZF1.getInferredValuesList();
} else {
valsChildZF1 = new Array(this.prms.Z1.getInferredValuesList().length)
.fill(child.prms.ZF1.singleValue);
}
// adjust lengths (should never happen when only one of the paramters is varying)
if (valsZ1.length > valsChildZF1.length) {
valsChildZF1 = child.prms.ZF1.getInferredValuesList(valsZ1.length);
} else if (valsZ1.length < valsChildZF1.length) {
valsZ1 = this.prms.Z1.getInferredValuesList(valsChildZF1.length);
}
// define calculated values list on child
const valsY: number[] = [];
for (let i = 0; i < valsZ1.length; i++) {
valsY.push(Math.max(valsZ1[i] - valsChildZF1[i], 0));
}
child.prms.Y.setValues(valsY);
} else {
// or just a single value ?
child.prms.Y.setValue(Math.max(this.prms.Z1.singleValue - child.prms.ZF1.singleValue, 0));
}
}
return super.CalcSerie(rInit);
}
......@@ -141,7 +177,6 @@ export class MacrorugoCompound extends MacroRugo implements Observer {
}
// Calculate Length and depth from other parameters
child.prms.L.v = this.prms.DH.v / this.prms.If.v;
child.prms.Y.v = Math.max(this.prms.Z1.v - child.prms.ZF1.v, 0);
}
}
......
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