diff --git a/spec/pre_barrage/pre-barrage.spec.ts b/spec/pre_barrage/pre-barrage.spec.ts index 744fab598025ec9afa5c7fff2f31b147c3a5716e..f57c8b97b33f3a13a51565af1cf5d44dd2f8aade 100644 --- a/spec/pre_barrage/pre-barrage.spec.ts +++ b/spec/pre_barrage/pre-barrage.spec.ts @@ -23,11 +23,11 @@ function createPreBarrageTest(bMeshed: boolean = false): PreBarrage { // Pré-barrage Z1 = 101 m, Z2 = 100 m let Q: number; if(bMeshed) { - Q = 0.601266; - } else { Q = 1.350722; + } else { + Q = 0.601266; } - const pb = new PreBarrage(new PreBarrageParams(Q, 101, 100)); + const pb = new PreBarrage(new PreBarrageParams(Q, 101, 100), false); // 1 bassin intermédiaire à la cote de fond 99 m pb.addChild(new PbBassin(new PbBassinParams(20, 99))); @@ -38,12 +38,12 @@ function createPreBarrageTest(bMeshed: boolean = false): PreBarrage { // 1 cloison entre le bassin et l'aval avec une fente cote de radier 99 pb.addChild(new PbCloison(pb.children[0] as PbBassin, undefined)); - pb.children[1].addChild(createPbCloisonTest(99)); + pb.children[2].addChild(createPbCloisonTest(99)); if(bMeshed) { // 1 cloison entre l'amont et l'aval avec une fente cote de radier 99.5 pb.addChild(new PbCloison(undefined, undefined)); - pb.children[1].addChild(createPbCloisonTest(99.5)); + pb.children[3].addChild(createPbCloisonTest(99.5)); } return pb; @@ -52,6 +52,7 @@ function createPreBarrageTest(bMeshed: boolean = false): PreBarrage { describe("Class PreBarrage: ", () => { fit("Calc(Z1) should return 101", () => { const pb = createPreBarrageTest(); + pb.copySingleValuesToSandboxValues(); expect(pb.Equation("Z1").vCalc).toBeCloseTo(101,3); }); }); diff --git a/src/prebarrage/pb_bassin.ts b/src/prebarrage/pb_bassin.ts index 0829dac5ee26965b590719004a840f26292b2b85..eea3cfb51bef4b00c556cf8375f50831016955ed 100644 --- a/src/prebarrage/pb_bassin.ts +++ b/src/prebarrage/pb_bassin.ts @@ -21,8 +21,6 @@ export class PbBassin extends Nub { public parent: PreBarrage; - private _Zstat: IPbBassinZstat; - constructor(prms: PbBassinParams, dbg: boolean = false) { super(prms, dbg); this._calcType = CalculatorType.PbBassin; @@ -37,17 +35,13 @@ export class PbBassin extends Nub { return this._prms as PbBassinParams; } - get Zstat(): IPbBassinZstat { - return this._Zstat; - } - public Equation(sVarCalc: string): Result { switch(sVarCalc) { case "Q": case "Z": const r = new Result(); r.values.Q = this.CalcQ(); - r.values.Z = this.CalcZ(); + r.values.Z = this.CalcZ().moy; return r; default: throw new Error("PbBassin.Equation() : invalid variable name " + sVarCalc); @@ -72,8 +66,9 @@ export class PbBassin extends Nub { return this.prms.Q.v; } - public CalcZ(): number { - this._Zstat = this.parent.CalcZ1Cloisons(this.cloisonsAmont); - return this.Zstat.moy; + public CalcZ(): IPbBassinZstat { + const zStat = this.parent.CalcZ1Cloisons(this.cloisonsAval); + this.prms.Z.v = zStat.moy; + return zStat; } } \ No newline at end of file diff --git a/src/prebarrage/pb_cloison.ts b/src/prebarrage/pb_cloison.ts index 7331a010324828de9b74914afcaf9ae496d3ef36..347f64df49b5162245bae557c230b8921a49c022 100644 --- a/src/prebarrage/pb_cloison.ts +++ b/src/prebarrage/pb_cloison.ts @@ -3,6 +3,7 @@ import { PbBassin } from "./pb_bassin"; import { PreBarrage } from "./pre_barrage"; import { ParallelStructureParams } from "../structure/parallel_structure_params"; import { CalculatorType } from "../compute-node"; +import { Result } from "../util/result"; export class PbCloison extends ParallelStructure { @@ -24,20 +25,25 @@ export class PbCloison extends ParallelStructure { get Z1(): number { if(this.bassinAmont !== undefined) { - return this.bassinAmont.result.values.Z + return this.bassinAmont.prms.Z.v; } else { - return this.parent.prms.Z1.V; + return this.parent.prms.Z1.v; } } get Z2(): number { if(this.bassinAval !== undefined) { - return this.bassinAval.result.values.Z + return this.bassinAval.prms.Z.v } else { - return this.parent.prms.Z2.V; + return this.parent.prms.Z2.v; } } + public Calc(sVarCalc?: string, rInit?: number): Result { + this.updateZ1Z2(); + return super.Calc(sVarCalc, rInit); + } + public updateZ1Z2() { this.prms.Z1.v = this.Z1; this.prms.Z2.v = this.Z2; diff --git a/src/prebarrage/pre_barrage.ts b/src/prebarrage/pre_barrage.ts index 987e199318172369c2e1fec1f0182543f60884d6..8ce6d941417fbeea017b878376404f8331de7043 100644 --- a/src/prebarrage/pre_barrage.ts +++ b/src/prebarrage/pre_barrage.ts @@ -85,7 +85,7 @@ export class PreBarrage extends Nub { child.prms.Q.v = this.prms.Q.v; } } - let iter: number = 100; + let iter: number = 2; let bConverged = true; while (iter-- > 0) { if (this.isMeshed()) { @@ -100,10 +100,11 @@ export class PreBarrage extends Nub { } // Balayage aval-amont: Calcul des cotes amont des cloisons for (let i = this.bassins.length - 1; i >= 0; i--) { - const b = this.bassins[i]; - b.CalcZ(); - bConverged = bConverged && (b.Zstat.max - b.Zstat.min) < SessionSettings.precision; + this.debug("Bassin "+ i); + const zStat = this.bassins[i].CalcZ(); + bConverged = bConverged && (zStat.max - zStat.min) < SessionSettings.precision; } + this.debug("Cloison amont"); const z1stat = this.CalcZ1Cloisons(this.cloisonsAmont); this.prms.Z1.v = z1stat.moy; bConverged = bConverged && (z1stat.max - z1stat.min) < SessionSettings.precision @@ -140,12 +141,12 @@ export class PreBarrage extends Nub { if (cloison.bassinAmont !== undefined) { cloison.bassinAmont.cloisonsAval.push(cloison); } else { - this.cloisonsAval.push(cloison); + this.cloisonsAmont.push(cloison); } if (cloison.bassinAval !== undefined) { cloison.bassinAval.cloisonsAmont.push(cloison); } else { - this.cloisonsAmont.push(cloison); + this.cloisonsAval.push(cloison); } } else { this._bassins = []; @@ -174,27 +175,29 @@ export class PreBarrage extends Nub { let QT2: number = 0; for (const c of cloisons) { QT2 += c.Calc("Q").vCalc; + this.debug("CalcQ: Q=" + c.Calc("Q").vCalc) } // Adjustement of each Q in order to get the good sum for (const c of cloisons) { c.prms.Q.v = c.prms.Q.v * (QT / QT2); + this.debug("CalcQ: Qc=" + c.prms.Q.v) } } public CalcZ1Cloisons(cloisons: PbCloison[]): IPbBassinZstat { - let zMoy = 0; + const z: IPbBassinZstat = {moy : 0, min: Infinity, max: -Infinity}; let n: number = 0; - let zMin: number = Infinity; - let zMax: number = -Infinity; for (const c of cloisons) { const Z: number = c.Calc("Z1").vCalc; - zMoy += Z - zMin = Math.min(zMin, Z); - zMax = Math.max(zMax, Z); + z.moy += Z + z.min = Math.min(z.min, Z); + z.max = Math.max(z.max, Z); n++; + this.debug(`CalcZ1Cloisons: n= ${n} Q=${c.prms.Q.v} Z1=${c.prms.Z1.v} Z2=${c.prms.Z2.v}`); } - zMoy = zMoy / n; - return { moy: zMoy, min: zMin, max: zMax }; + z.moy = z.moy / n; + this.debug("CalcZ1Cloisons: Z="+ z.moy); + return z; } } diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts index 25d720163a3f7625236296837af856e3698cc1a3..446bc1e0fa0a1d3f89a4ba4671792dc18ff13865 100644 --- a/src/structure/parallel_structure.ts +++ b/src/structure/parallel_structure.ts @@ -7,6 +7,7 @@ import { Result } from "../util/result"; import { ParallelStructureParams } from "./parallel_structure_params"; import { Structure } from "./structure"; import { loiAdmissiblesOuvrages, LoiDebit } from "./structure_props"; +import { MessageCode, Message } from "../util/message"; /** * Calcul de une ou plusieurs structures hydrauliques en parallèles @@ -62,6 +63,21 @@ export class ParallelStructure extends Nub { return lois[Object.keys(lois)[0]][0]; } + /** + * Effectue une série de calculs sur un paramètre; déclenche le calcul en chaîne + * des modules en amont si nécessaire + * Surcharge pour les tests préalables liés à la structure du nub + * @param rInit solution approximative du paramètre + */ + public CalcSerie(rInit?: number): Result { + if (this.structures.length === 0) { + this._result = new Result(undefined, this); + this._result.globalLog.insert(new Message(MessageCode.ERROR_STRUCTURE_AU_MOINS_UNE)); + return this._result; + } + return super.CalcSerie(rInit); + } + /** * Calcul du débit des structures en parallèle (sans détail pour chaque structure) * @param sVarCalc Variable à calculer (Q uniquement) diff --git a/src/util/message.ts b/src/util/message.ts index 70d69cc016f7feddbe94ac53e9f443bfc1094c80..50aa42cabd512659621134cd2cb9bee5b17b66e4 100644 --- a/src/util/message.ts +++ b/src/util/message.ts @@ -497,6 +497,11 @@ export enum MessageCode { */ ERROR_STRUCTURE_Z_EGAUX_Q_NON_NUL, + /** + * Il faut au moins un ouvrage dans une structure + */ + ERROR_STRUCTURE_AU_MOINS_UNE, + /** On essaye d'appliquer une puissance non entière à un nombre négatif */ ERROR_NON_INTEGER_POWER_ON_NEGATIVE_NUMBER,