Commit 7664d4e2 authored by Dorchies David's avatar Dorchies David Committed by Mathias Chouet
Browse files

#32 PreBarrage 1st basic test passed!

Showing with 59 additions and 33 deletions
+59 -33
......@@ -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);
});
});
......@@ -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
......@@ -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;
......
......@@ -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;
}
}
......@@ -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)
......
......@@ -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,
......
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