diff --git a/spec/pab/pab.spec.ts b/spec/pab/pab.spec.ts index cd7c1587c97acd23560281e96437f9529c64f174..807e406e80350bd6806cb95a12d141389a02e00d 100644 --- a/spec/pab/pab.spec.ts +++ b/spec/pab/pab.spec.ts @@ -82,10 +82,11 @@ for (let i = 0; i < 14; i++) { describe("Class Pab: ", () => { describe("Exemple Formation 2018-09 p.14", () => { - it("vCalc(Z1) should return 78.27", () => { - expect(pab.Calc("Z1").vCalc).toBeCloseTo(78.27, 2); + it("CalcSerie(Z1) should return 78.27", () => { + pab.calculatedParam = pab.prms.Z1; + expect(pab.CalcSerie().vCalc).toBeCloseTo(78.27, 2); }); - it("vCalc(Q) should return 0.773", () => { + it("Calc(Q) should return 0.773", () => { expect(pab.Calc("Q").vCalc).toBeCloseTo(0.773, 2); }); }); diff --git a/spec/param/param_modes.spec.ts b/spec/param/param_modes.spec.ts index ab9a2c1a1943f5be6aceb708043a5f1dc0280198..9ed7a9cc66b6ced69e6ae2adedb9c80f0e8c1273 100644 --- a/spec/param/param_modes.spec.ts +++ b/spec/param/param_modes.spec.ts @@ -1,5 +1,8 @@ -import { cSnTrapez, LinkedValue, Nub, ParallelStructure, ParallelStructureParams, - ParamsSectionTrapez, ParamValueMode, SectionParametree, Session } from "../../src/index"; +import { + cSnTrapez, LinkedValue, Nub, ParallelStructure, ParallelStructureParams, + ParamCalculability, ParamsSectionTrapez, ParamValueMode, SectionParametree, + Session +} from "../../src/index"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; import { Cloisons } from "../../src/structure/cloisons"; @@ -162,23 +165,22 @@ function testModesPermutations(nubToTest: Nub) { // set every parameter to CALC mode for (const p of nubToTest.parameterIterator) { - if (p.symbol === "Pr" || ! p.visible) { - continue; + if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(p.calculability) && p.visible) { + p.setCalculated(); + checkConsistency(nubToTest); } - p.setCalculated(); - checkConsistency(nubToTest); } // set every parameter to MINMAX / LISTE mode let i = 0; for (const p of nubToTest.parameterIterator) { - if (p.symbol === "Pr" || ! p.visible) { + if (p.symbol === "Pr" || !p.visible) { continue; } 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } checkConsistency(nubToTest); i++; @@ -186,18 +188,17 @@ function testModesPermutations(nubToTest: Nub) { // set every parameter to CALC then to SINGLE mode for (const p of nubToTest.parameterIterator) { - if (p.symbol === "Pr" || ! p.visible) { - continue; + if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(p.calculability) && p.visible) { + p.setCalculated(); + checkConsistency(nubToTest); + p.valueMode = ParamValueMode.SINGLE; + checkConsistency(nubToTest); } - p.setCalculated(); - checkConsistency(nubToTest); - p.valueMode = ParamValueMode.SINGLE; - checkConsistency(nubToTest); } // set every parameter to LINK mode then to SINGLE mode for (const p of nubToTest.parameterIterator) { - if (p.symbol === "Pr" || ! p.visible) { + if (p.symbol === "Pr" || !p.visible) { continue; } const lv: LinkedValue[] = Session.getInstance().getLinkableValues(p); @@ -248,7 +249,7 @@ describe("cohérence des modes de paramètres : ", () => { prm1.Q.setValues(0.6, 2.4, 0.09); // link other Nubs Q to nub1.Q - for (const n of [ nub2, nub3, nub4 ]) { + for (const n of [nub2, nub3, nub4]) { n.prms.Q.defineReference(nub1.section, "Q"); // set every parameter to MINMAX / LISTE mode let i = 0; @@ -257,7 +258,7 @@ describe("cohérence des modes de paramètres : ", () => { 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } } checkConsistency(n); @@ -275,7 +276,7 @@ describe("cohérence des modes de paramètres : ", () => { prm6.Q.defineReference(nub1.section, "Q"); // link other Nubs Q to nub6.Q - for (const n of [ nub2, nub3, nub4 ]) { + for (const n of [nub2, nub3, nub4]) { n.prms.Q.defineReference(nub6.section, "Q"); // set every parameter to MINMAX / LISTE mode let i = 0; @@ -284,7 +285,7 @@ describe("cohérence des modes de paramètres : ", () => { 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } } checkConsistency(n); @@ -300,7 +301,7 @@ describe("cohérence des modes de paramètres : ", () => { prm1.Q.setCalculated(); // link other Nubs Q to nub1.Q - for (const n of [ nub2, nub3, nub4 ]) { + for (const n of [nub2, nub3, nub4]) { n.prms.Q.defineReference(nub1, "Q"); // set every parameter to MINMAX / LISTE mode let i = 0; @@ -309,7 +310,7 @@ describe("cohérence des modes de paramètres : ", () => { 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } } checkConsistency(n); @@ -328,7 +329,7 @@ describe("cohérence des modes de paramètres : ", () => { prm6.Q.defineReference(nub1, "Q"); // link other Nubs Q to nub6.Q - for (const n of [ nub2, nub3, nub4 ]) { + for (const n of [nub2, nub3, nub4]) { n.prms.Q.defineReference(nub6.section, "Q"); // set every parameter to MINMAX / LISTE mode let i = 0; @@ -337,7 +338,7 @@ describe("cohérence des modes de paramètres : ", () => { 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } } checkConsistency(n); @@ -353,7 +354,7 @@ describe("cohérence des modes de paramètres : ", () => { prm5.Q.setCalculated(); // link other Nubs Q to nub5.CvQT - for (const n of [ nub2, nub3, nub4 ]) { + for (const n of [nub2, nub3, nub4]) { n.prms.Q.defineReference(nub5, "CvQT"); // set every parameter to MINMAX / LISTE mode let i = 0; @@ -362,7 +363,7 @@ describe("cohérence des modes de paramètres : ", () => { 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } } checkConsistency(n); @@ -381,7 +382,7 @@ describe("cohérence des modes de paramètres : ", () => { prm6.Q.defineReference(nub5, "CvQT"); // link other Nubs Q to nub6.Q - for (const n of [ nub2, nub3, nub4 ]) { + for (const n of [nub2, nub3, nub4]) { n.prms.Q.defineReference(nub6.section, "Q"); // set every parameter to MINMAX / LISTE mode let i = 0; @@ -390,7 +391,7 @@ describe("cohérence des modes de paramètres : ", () => { 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 + p.setValues([1, 2, 3, 4, 5]); // sets valueMode to LISTE } } checkConsistency(n); diff --git a/spec/structure/cloisons.spec.ts b/spec/structure/cloisons.spec.ts index 6245b0bb77d6b0508ac45adfc42ca0fbd04aecb8..9b94ae13615142bdd42927e088448e796fbf1c7a 100644 --- a/spec/structure/cloisons.spec.ts +++ b/spec/structure/cloisons.spec.ts @@ -70,7 +70,7 @@ describe("Class Cloisons: ", () => { LoiDebit.WeirSubmergedLarinier, LoiDebit.KIVI ]; - for (let i = 0; i < 3; i++ ) { + for (let i = 0; i < 3; i++) { c2.addChild(CreateStructure(iLoiDebits[i], c2, false)); } const prmsKivi: StructureKiviParams = c2.structures[2].prms as StructureKiviParams; @@ -142,4 +142,36 @@ describe("Class Cloisons: ", () => { }); } }); + + describe("Exemple Formation Cassiopée 2018-09", () => { + it("Calc(Z1) Exemple Formation Cassiopée 2018-09", () => { + // Modèle de cloison + const modelCloisons = new Cloisons( + new CloisonsParams( + 0.773, // Débit total (m3/s) + 102, // Cote de l'eau amont (m) + 3.1, // Longueur des bassins (m) + 2.5, // Largeur des bassins (m) + 1.5, // Profondeur moyenne (m) + 0.23 // Hauteur de chute (m) + ) + ); + + const rectStructPrms = new RectangularStructureParams( + 0.773, // Q + 76.67, // ZDV + 0, // Z1 + 0, // Z2 + 0.35, // L + 0.65 // Cd pour un seuil rectangulaire + // W = Infinity par défaut pour un seuil + ); + + // Ajout d'ouvrage dans la cloison + modelCloisons.addChild(new StructureWeirSubmergedLarinier(rectStructPrms)); + modelCloisons.calculatedParam = modelCloisons.prms.Z1; + expect(modelCloisons.CalcSerie().vCalc).toBeCloseTo(78.27, 2); + }); + }); + }); diff --git a/spec/structure/functions.ts b/spec/structure/functions.ts index 65863fbd5f7be392c62905cf5dd0a7b8607eb854..cb7dfc4dac08ba17787efb750177e8d98a01170a 100644 --- a/spec/structure/functions.ts +++ b/spec/structure/functions.ts @@ -95,6 +95,17 @@ export function testStructure( export function testParallelStructures(oPS: ParallelStructure, iLoiDebits: number[]) { oPS.prms.Q.v = oPS.Calc("Q").vCalc; + // Mémorisation des valeurs initiales pour les références + for (const prm of oPS.prms) { + prm.currentValue = prm.v; + } + for (const st of oPS.structures) { + for (const prm of st.prms) { + prm.currentValue = prm.v; + } + } + + // Tests sur tous les ouvrages for (let i = 0; i < oPS.structures.length; i++) { const st: Structure = oPS.structures[i]; describe(`this.structures[${i}]: Structure${LoiDebit[iLoiDebits[i]]}: `, () => { @@ -113,7 +124,8 @@ export function testParallelStructures(oPS: ParallelStructure, iLoiDebits: numbe prm.calculability === ParamCalculability.DICHO && prm.symbol !== "Z1" && prm.symbol !== "Z2" ) { - const ref: number = prm.v; + const ref: number = prm.currentValue; + prm.v += 100; // Pour éviter de donner la bonne solution en valeur initiale if (prm.symbol === "W" && prm.v === Infinity) { // Le calcul de l'ouverture sur les seuils doit renvoyer une exception (cas impossible) it(`Calc(${prm.symbol}) should return exception`, () => { diff --git a/src/pab/pab.ts b/src/pab/pab.ts index cd9f157d14698e7782362c9cb6d55de76b9771f1..3d542531c0b0f15f10595ebe4c2bde6fdbb5b814 100644 --- a/src/pab/pab.ts +++ b/src/pab/pab.ts @@ -76,16 +76,22 @@ export class Pab extends Nub { // Calculation of upstream water elevation Z = this.calcZ1(cl, Q, Z); if (this.debug) { + console.log("Bassin n°" + i); + let s: string = ""; for (const p of cl.prms) { // tslint:disable-next-line:no-console - console.log(p.symbol + " = " + p.v); + s += p.symbol + " = " + p.v + "; " ; } + console.log(s); + for (const c of cl.getChildren()) { console.log("Ouvrage"); + s = ""; for (const p of c.prms) { // tslint:disable-next-line:no-console - console.log(p.symbol + " = " + p.v); + s += p.symbol + " = " + p.v; } + console.log(s); } } Q -= cl.prms.QA.v; diff --git a/src/structure/cloisons.ts b/src/structure/cloisons.ts index 70c53d652a19b553392cebc59db21dac23327a25..cbd761d18b392cdfd9440ba118efa6b6c66a6279 100644 --- a/src/structure/cloisons.ts +++ b/src/structure/cloisons.ts @@ -26,6 +26,16 @@ export class Cloisons extends ParallelStructure { return loiAdmissiblesCloisons; } + public Equation(sVarCalc: string): Result { + // Mise à jour de ZRAM pour Kivi à partir de Z1 - PB + this.updateKiviZRAM(); + + // Transformation DH => Z2 + this.prms.Z2.v = this.prms.Z1.v - this.prms.DH.v; + + return super.Equation(sVarCalc); + } + /** * Calcul du débit total, de la cote amont ou aval ou d'un paramètre d'une structure * @param sVarCalc Nom du paramètre à calculer : @@ -33,33 +43,12 @@ export class Cloisons extends ParallelStructure { * @param rInit Valeur initiale */ public Calc(sVarCalc: string, rInit?: number): Result { - // Mise à jour de ZRAM pour Kivi à partir de Z1 - PB - this.updateKiviZRAM(); - - // Transformation DH => Z2 - this.prms.Z2.v = this.prms.Z1.v - this.prms.DH.v; let sVC: string = sVarCalc; if (sVarCalc === "DH") { sVC = "Z2"; } - // let r: Result = super.Calc(sVC, rInit); - let r: Result; - switch (sVC) { - case "Z1": - case "Z2": - case "Q": - case "LB": - case "PB": - case "BB": - r = this.nubCalc(sVC, rInit); - if (r.ok) { - this.getParameter(sVC).v = r.vCalc; - } - break; - default: - r = super.Calc(sVC, rInit); - } + const r: Result = super.Calc(sVC, rInit); if (r.ok) { // Recalcul du débit total pour récupérer les résultats des ouvrages dans les résultats complémentaires diff --git a/src/structure/dever.ts b/src/structure/dever.ts index 368510fea9558dc5a089ccfd74e5ef47e65806c4..24cfeb68011b83d1747189374143b08f6ae3a2a7 100644 --- a/src/structure/dever.ts +++ b/src/structure/dever.ts @@ -50,42 +50,6 @@ export class Dever extends ParallelStructure { return r; } - /** - * Calcul du débit total, de la cote amont ou aval, de la largeur du lit amont, de la cote - * du lit amont, ou d'un paramètre d'une structure - * @param sVarCalc Nom du paramètre à calculer : - * "Q", "Z1", "Z2", "BR", "ZR" ou "n.X" avec "n" l'index de l'ouvrage et "X" son paramètre - * @param rInit Valeur initiale - */ - public Calc(sVarCalc: string, rInit?: number): Result { - let res: Result; - switch (sVarCalc) { - case "Z1": - case "Z2": - case "Q": - case "BR": - case "ZR": - res = this.nubCalc(sVarCalc, rInit); - if (res.ok) { - this.getParameter(sVarCalc).v = res.vCalc; - } - break; - default: - res = super.Calc(sVarCalc, rInit); - } - if (res.ok) { - // Recalcul du débit total pour récupérer les résultats des ouvrages dans les résultats complémentaires - const resQtot: Result = this.CalcQ(); - for (const extraResKey in resQtot.extraResults) { - if (resQtot.extraResults.hasOwnProperty(extraResKey)) { - res.resultElement.addExtraResult(extraResKey, resQtot.extraResults[extraResKey]); - } - } - } - this._result = res; - return res; - } - /** * paramétrage de la calculabilité des paramètres */