Commit 20ce79d7 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

fix #222 - linked variating params: use a different iterator for each param

parent a55fa4f0
import { MessageCode, ParamDefinition, ParamDomainValue, ExtensionStrategy } from "../../src/index";
import { MessageCode, ParamDefinition, ParamDomainValue, ExtensionStrategy, Session, Cloisons } from "../../src/index";
import { PabChute } from "../../src/pab/pab_chute";
import { PabChuteParams } from "../../src/pab/pab_chute_params";
......@@ -35,7 +35,7 @@ describe("when a parameter is varying, ", () => {
for (let i = 0; i < values.length; i++) {
expect(values[i]).toBeCloseTo(expected[i], 2, `values[${i}]`);
}
})
});
it("check inferredValuesList, recycle mode", () => {
const foo = new ParamDefinition(undefined, "FOO", ParamDomainValue.ANY);
......@@ -47,5 +47,14 @@ describe("when a parameter is varying, ", () => {
for (let i = 0; i < values.length; i++) {
expect(values[i]).toBeCloseTo(expected[i], 2, `values[${i}]`);
}
})
});
it("jalhyd#222 iterator should not be shared by linked parameter", () => {
const sess = `{"header":{"source":"jalhyd","format_version":"1.3","created":"2020-05-14T12:32:41.289Z"},"settings":{"precision":1e-7,"maxIterations":100,"displayPrecision":3},"documentation":"","session":[{"uid":"ODBiMG","props":{"calcType":"ParallelStructure"},"meta":{"title":"Orifice -> seuil"},"children":[{"uid":"aGR2eW","props":{"calcType":"Structure","structureType":"VanneRectangulaire","loiDebit":"GateCunge80"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"MINMAX","min":0.7,"max":1.01,"step":0.01,"extensionStrategy":0},{"symbol":"L","mode":"SINGLE","value":1},{"symbol":"CdGR","mode":"LINK","targetNub":"dnhrNW","targetParam":"CdGR"}]},{"uid":"dnhrNW","props":{"calcType":"Structure","structureType":"VanneRectangulaire","loiDebit":"GateCem88d"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"LINK","targetNub":"aGR2eW","targetParam":"W"},{"symbol":"L","mode":"SINGLE","value":1},{"symbol":"CdWR","mode":"SINGLE","value":0.4}]}],"parameters":[{"symbol":"Q","mode":"CALCUL"},{"symbol":"Z1","mode":"SINGLE","value":101},{"symbol":"Z2","mode":"SINGLE","value":100.8}]}]}`;
Session.getInstance().clear();
Session.getInstance().unserialise(sess);
const n = Session.getInstance().findNubByUid("ODBiMG") as Cloisons;
const res = n.CalcSerie();
expect(res.resultElements.length).toBe(32);
});
});
......@@ -543,10 +543,11 @@ export abstract class Nub extends ComputeNode implements IObservable {
// (re)init all iterators
for (const v of variated) {
// copy iterators, for linked params @see bug #222
if (v === variated[longest]) {
v.values.initValuesIterator(false, undefined, true);
v.iterator = v.values.initValuesIterator(false, undefined, true);
} else {
v.values.initValuesIterator(false, size, true);
v.iterator = v.values.initValuesIterator(false, size, true);
}
}
......@@ -555,7 +556,7 @@ export abstract class Nub extends ComputeNode implements IObservable {
while (variated[longest].values.hasNext && l < size) {
// get next value for all variating parameters
for (const v of variated) {
const currentIteratorValue = v.values.next();
const currentIteratorValue = v.iterator.next();
v.param.v = currentIteratorValue.value;
}
// prepare a new slot to store results
......
import { ParamDefinition } from "./param/param-definition";
import { ParamValues } from "./param/param-values";
import { INumberIterator } from "./param/param-value-iterator";
export interface VariatedDetails {
param: ParamDefinition;
values: ParamValues;
// copy of iterator, for linked params: calling initValuesIterator() overwrites this._iterator, so
// that calling .next() or .hasNext() on linked variating params returns a pointer to the same
// iterator @see bug #222
iterator?: INumberIterator
};
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