From 986889a2ef06f67cfc8ee8cfa97dc370216dfe6e Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Mon, 20 May 2019 10:37:13 +0200 Subject: [PATCH] Fix #95 --- spec/param/param_modes.spec.ts | 83 -------------------- spec/session/serialisation.spec.ts | 6 +- spec/value_ref/value_ref_circularity.spec.ts | 4 +- src/nub.ts | 3 +- src/param/param-definition.ts | 3 +- 5 files changed, 9 insertions(+), 90 deletions(-) diff --git a/spec/param/param_modes.spec.ts b/spec/param/param_modes.spec.ts index 9ed7a9cc..0b6d2570 100644 --- a/spec/param/param_modes.spec.ts +++ b/spec/param/param_modes.spec.ts @@ -267,33 +267,6 @@ describe("cohérence des modes de paramètres : ", () => { } }); - it("paramètre varié lié indirectement", () => { - createEnv(); - // vary Q on nub1 - prm1.Q.setValues(0.6, 2.4, 0.09); - - // link nub6.Q to nub1.Q - prm6.Q.defineReference(nub1.section, "Q"); - - // link other Nubs Q to nub6.Q - for (const n of [nub2, nub3, nub4]) { - n.prms.Q.defineReference(nub6.section, "Q"); - // set every parameter to MINMAX / LISTE mode - let i = 0; - for (const p of n.parameterIterator) { - if (p.symbol !== "Q") { - if (i % 2 === 0) { - p.setValues(1, 5, 0.5); // sets valueMode to MINMAX - } else { - p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE - } - } - checkConsistency(n); - i++; - } - } - }); - it("résultat varié lié", () => { createEnv(); // vary LargeurBerge and compute Q on nub1 @@ -319,34 +292,6 @@ describe("cohérence des modes de paramètres : ", () => { } }); - it("résultat varié lié indirectement", () => { - createEnv(); - // vary LargeurBerge and compute Q on nub1 - prm1.LargeurBerge.setValues(1.25, 5, 0.188); - prm1.Q.setCalculated(); - - // link nub6.Q to nub1.Q - prm6.Q.defineReference(nub1, "Q"); - - // link other Nubs Q to nub6.Q - for (const n of [nub2, nub3, nub4]) { - n.prms.Q.defineReference(nub6.section, "Q"); - // set every parameter to MINMAX / LISTE mode - let i = 0; - for (const p of n.parameterIterator) { - if (p.symbol !== "Q") { - if (i % 2 === 0) { - p.setValues(1, 5, 0.5); // sets valueMode to MINMAX - } else { - p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE - } - } - checkConsistency(n); - i++; - } - } - }); - it("résultat complémentaire varié lié", () => { createEnv(); // vary LargeurBerge and compute Q on nub1 @@ -371,32 +316,4 @@ describe("cohérence des modes de paramètres : ", () => { } } }); - - it("résultat complémentaire varié lié indirectement", () => { - createEnv(); - // vary LargeurBerge and compute Q on nub5 - prm5.Z1.setValues(50, 200, 10); - prm5.Q.setCalculated(); - - // link nub6.Q to nub5.CvQT - prm6.Q.defineReference(nub5, "CvQT"); - - // link other Nubs Q to nub6.Q - for (const n of [nub2, nub3, nub4]) { - n.prms.Q.defineReference(nub6.section, "Q"); - // set every parameter to MINMAX / LISTE mode - let i = 0; - for (const p of n.parameterIterator) { - if (p.symbol !== "Q") { - if (i % 2 === 0) { - p.setValues(1, 5, 0.5); // sets valueMode to MINMAX - } else { - p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE - } - } - checkConsistency(n); - i++; - } - } - }); }); diff --git a/spec/session/serialisation.spec.ts b/spec/session/serialisation.spec.ts index 6a6e93e9..b3688fdc 100644 --- a/spec/session/serialisation.spec.ts +++ b/spec/session/serialisation.spec.ts @@ -206,7 +206,7 @@ describe("serialising / deserialising session - ", () => { it ("loaded serialized spaghetti session should have the right target for every link", () => { Session.getInstance().clear(); // tslint:disable-next-line:max-line-length - const session = `{"header":{"source":"jalhyd","format_version":"1.0","created":"2019-04-26T10:25:29.891Z"},"session":[{"uid":"ZHh1YW","props":{"calcType":2,"nodeType":2},"meta":{"title":"Sec. param."},"children":[{"uid":"bXB1Y3","props":{"calcType":14,"nodeType":2},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Ks","mode":"SINGLE","value":40},{"symbol":"Q","mode":"SINGLE","value":1.2},{"symbol":"If","mode":"SINGLE","value":0.001},{"symbol":"YB","mode":"SINGLE","value":1},{"symbol":"Y","mode":"SINGLE","value":0.8},{"symbol":"LargeurBerge","mode":"LINK","targetNub":"YTBjcm","targetParam":"L"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001}]},{"uid":"eTgwMG","props":{"calcType":11,"nodeType":0},"meta":{"title":"Macro-rugo."},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"ZF1","mode":"LINK","targetNub":"dGx0em","targetParam":"Z1"},{"symbol":"L","mode":"SINGLE","value":6},{"symbol":"B","mode":"CALCUL"},{"symbol":"If","mode":"SINGLE","value":0.05},{"symbol":"Q","mode":"LINK","targetNub":"bXB1Y3","targetParam":"Q"},{"symbol":"Y","mode":"SINGLE","value":0.6},{"symbol":"Ks","mode":"SINGLE","value":0.01},{"symbol":"C","mode":"SINGLE","value":0.05},{"symbol":"PBD","mode":"SINGLE","value":0.5},{"symbol":"PBH","mode":"MINMAX","min":0.4,"max":1.6,"step":0.06000000000000001},{"symbol":"Cd0","mode":"SINGLE","value":1.5}]},{"uid":"dGx0em","props":{"calcType":8,"nodeType":0},"meta":{"title":"Ouvrages"},"children":[{"uid":"ZmZ3bX","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"CALCUL"},{"symbol":"Cd","mode":"SINGLE","value":0.6}]},{"uid":"aWo0M2","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"LINK","targetNub":"dGx0em","targetParam":"L"},{"symbol":"Cd","mode":"SINGLE","value":0.6}]},{"uid":"YTBjcm","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"LINK","targetNub":"aWo0M2","targetParam":"W"},{"symbol":"L","mode":"SINGLE","value":2},{"symbol":"Cd","mode":"LINK","targetNub":"ZmZ3bX","targetParam":"Cd"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Q","mode":"SINGLE","value":0.5},{"symbol":"Z1","mode":"SINGLE","value":102},{"symbol":"Z2","mode":"LINK","targetNub":"eTgwMG","targetParam":"ZF1"}]},{"uid":"dzA1OX","props":{"calcType":3,"nodeType":2},"meta":{"title":"R. uniforme"},"children":[{"uid":"Ynlna2","props":{"calcType":14,"nodeType":2},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Ks","mode":"SINGLE","value":40},{"symbol":"Q","mode":"LINK","targetNub":"cXFraW","targetParam":"CvQT"},{"symbol":"If","mode":"MINMAX","min":0.0005,"max":0.002,"step":0.00007500000000000001},{"symbol":"YB","mode":"SINGLE","value":1},{"symbol":"Y","mode":"SINGLE","value":0.8},{"symbol":"LargeurBerge","mode":"CALCUL"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001}]},{"uid":"cXFraW","props":{"calcType":9,"nodeType":0},"meta":{"title":"Déver. dénoyés"},"children":[{"uid":"Zzd1cH","props":{"calcType":7,"nodeType":5,"structureType":0,"loiDebit":7},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"L","mode":"SINGLE","value":2},{"symbol":"Cd","mode":"SINGLE","value":0.4}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Q","mode":"CALCUL"},{"symbol":"Z1","mode":"SINGLE","value":102},{"symbol":"BR","mode":"LINK","targetNub":"bXB1Y3","targetParam":"LargeurBerge"},{"symbol":"ZR","mode":"SINGLE","value":99}]}]}`; + const session = `{"header":{"source":"jalhyd","format_version":"1.0","created":"2019-04-26T10:25:29.891Z"},"session":[{"uid":"ZHh1YW","props":{"calcType":2,"nodeType":2},"meta":{"title":"Sec. param."},"children":[{"uid":"bXB1Y3","props":{"calcType":14,"nodeType":2},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Ks","mode":"SINGLE","value":40},{"symbol":"Q","mode":"SINGLE","value":1.2},{"symbol":"If","mode":"SINGLE","value":0.001},{"symbol":"YB","mode":"SINGLE","value":1},{"symbol":"Y","mode":"SINGLE","value":0.8},{"symbol":"LargeurBerge","mode":"LINK","targetNub":"YTBjcm","targetParam":"L"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001}]},{"uid":"eTgwMG","props":{"calcType":11,"nodeType":0},"meta":{"title":"Macro-rugo."},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"ZF1","mode":"LINK","targetNub":"dGx0em","targetParam":"Z1"},{"symbol":"L","mode":"SINGLE","value":6},{"symbol":"B","mode":"CALCUL"},{"symbol":"If","mode":"SINGLE","value":0.05},{"symbol":"Q","mode":"LINK","targetNub":"bXB1Y3","targetParam":"Q"},{"symbol":"Y","mode":"SINGLE","value":0.6},{"symbol":"Ks","mode":"SINGLE","value":0.01},{"symbol":"C","mode":"SINGLE","value":0.05},{"symbol":"PBD","mode":"SINGLE","value":0.5},{"symbol":"PBH","mode":"MINMAX","min":0.4,"max":1.6,"step":0.06000000000000001},{"symbol":"Cd0","mode":"SINGLE","value":1.5}]},{"uid":"dGx0em","props":{"calcType":8,"nodeType":0},"meta":{"title":"Ouvrages"},"children":[{"uid":"ZmZ3bX","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"CALCUL"},{"symbol":"Cd","mode":"SINGLE","value":0.6}]},{"uid":"aWo0M2","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"LINK","targetNub":"dGx0em","targetParam":"L"},{"symbol":"Cd","mode":"SINGLE","value":0.6}]},{"uid":"YTBjcm","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"LINK","targetNub":"aWo0M2","targetParam":"W"},{"symbol":"L","mode":"SINGLE","value":2},{"symbol":"Cd","mode":"LINK","targetNub":"ZmZ3bX","targetParam":"Cd"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Q","mode":"SINGLE","value":0.5},{"symbol":"Z1","mode":"SINGLE","value":102},{"symbol":"Z2","mode":"LINK","targetNub":"cXFraW","targetParam":"Z1"}]},{"uid":"dzA1OX","props":{"calcType":3,"nodeType":2},"meta":{"title":"R. uniforme"},"children":[{"uid":"Ynlna2","props":{"calcType":14,"nodeType":2},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Ks","mode":"SINGLE","value":40},{"symbol":"Q","mode":"LINK","targetNub":"cXFraW","targetParam":"CvQT"},{"symbol":"If","mode":"MINMAX","min":0.0005,"max":0.002,"step":0.00007500000000000001},{"symbol":"YB","mode":"SINGLE","value":1},{"symbol":"Y","mode":"SINGLE","value":0.8},{"symbol":"LargeurBerge","mode":"CALCUL"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001}]},{"uid":"cXFraW","props":{"calcType":9,"nodeType":0},"meta":{"title":"Déver. dénoyés"},"children":[{"uid":"Zzd1cH","props":{"calcType":7,"nodeType":5,"structureType":0,"loiDebit":7},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"L","mode":"SINGLE","value":2},{"symbol":"Cd","mode":"SINGLE","value":0.4}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Q","mode":"CALCUL"},{"symbol":"Z1","mode":"SINGLE","value":102},{"symbol":"BR","mode":"LINK","targetNub":"ZHh1YW","targetParam":"B"},{"symbol":"ZR","mode":"SINGLE","value":99}]}]}`; Session.getInstance().unserialise(session); expect(Session.getInstance().getNumberOfNubs()).toBe(5); @@ -228,7 +228,7 @@ describe("serialising / deserialising session - ", () => { // 3. check Ouvrages expect(OU).toBeDefined(); - checkLink(OU.prms.Z2, MR, "ZF1"); + checkLink(OU.prms.Z2, DD, "Z1"); const struct2 = (OU.structures[1] as RectangularStructure); checkLink(struct2.prms.L, OU, "L"); // @TODO devrait être interdit ! :/ const struct3 = (OU.structures[2] as RectangularStructure); @@ -241,7 +241,7 @@ describe("serialising / deserialising session - ", () => { // 5. check Déversoirs dénoyés expect(DD).toBeDefined(); - checkLink(DD.prms.BR, SP.section, "LargeurBerge"); + checkLink(DD.prms.BR, SP, "B"); }); diff --git a/spec/value_ref/value_ref_circularity.spec.ts b/spec/value_ref/value_ref_circularity.spec.ts index 0d24a7b0..7c703614 100644 --- a/spec/value_ref/value_ref_circularity.spec.ts +++ b/spec/value_ref/value_ref_circularity.spec.ts @@ -1,5 +1,5 @@ -import { NubTest, NubTestParams } from "../nubtest"; import { Session } from "../../src/index"; +import { NubTest, NubTestParams } from "../nubtest"; /** * IMPORTANT ! @@ -89,7 +89,7 @@ describe("référence d'un paramètre à un autre : ", () => { try { prm1.A.defineReference(nub2, "A"); // ne doit pas échouer - prm3.A.defineReference(nub1, "A"); // ne doit pas échouer + prm3.A.defineReference(nub2, "A"); // ne doit pas échouer } catch (e) { fail(); } diff --git a/src/nub.ts b/src/nub.ts index c5543579..e5a8c7f7 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -857,7 +857,8 @@ export abstract class Nub extends ComputeNode implements IObservable { try { param.defineReference(destNub, p.targetParam); } catch (err) { - console.error("fixLinks: defineReference error"); + console.error(`fixLinks: defineReference error` + + ` (${this.uid}.${param.symbol} => ${destNub.uid}.${p.targetParam})`); } } else { // quit diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index be4a0880..16bfdb5c 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -849,7 +849,8 @@ export class ParamDefinition implements INamedIterableValues, IObservable { try { this.defineReference(destNub, obj.targetParam); } catch (err) { - console.error("loadObjectRepresentation: defineReference error"); + console.error("loadObjectRepresentation: defineReference error" + + ` ${this.symbol} => ${destNub.uid}.${obj.targetParam})`); } } // si la cible du lien n'existe pas, Session.fixLinks() est censé s'en occuper break; -- GitLab