diff --git a/spec/pab/pab.spec.ts b/spec/pab/pab.spec.ts index 9aa599eed56fc6837150ec43d5a9b2f85044d7e6..280fe0d9e59e5534d6c2b7b9021bd60359ccb394 100644 --- a/spec/pab/pab.spec.ts +++ b/spec/pab/pab.spec.ts @@ -11,9 +11,10 @@ import { Cloisons, CloisonsParams } from "../../src/pab/cloisons"; import { Pab, PabParams } from "../../src/pab/pab"; import { ParallelStructureParams } from "../../src/structure/parallel_structure"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; +import { StructureVanLevParams, StructureVanLevVillemonte } from "../../src/structure/structure_vanlev"; import { StructureWeirSubmergedLarinier } from "../../src/structure/structure_weir_submerged_larinier"; import { StructureWeirVillemonte } from "../../src/structure/structure_weir_villemonte"; -import { StructureVanLevVillemonte, StructureVanLevParams } from "../../src/structure/structure_vanlev"; +import { MessageCode } from "../../src/util/message"; const dbg: boolean = false; @@ -164,7 +165,7 @@ describe("Class Pab: ", () => { pab.calculatedParam = pab.prms.Z1; checkPabResults(pab, 78.27); }); - it("Calc(Q) should return 0.773", () => { + it("CalcSerie(Q) should return 0.773", () => { pab.calculatedParam = pab.prms.Q; checkPabResults(pab, 0.773); }); @@ -187,5 +188,15 @@ describe("Class Pab: ", () => { pab.calculatedParam = pab.prms.Q; checkPabResults(pab, 0.773); }); + it("CalcSerie(Z1) should return an error", () => { + pab.downWall.addChild( + new StructureVanLevVillemonte( + new StructureVanLevParams(0.773, 73, 75.090, 74.86, 0.6, 0.4, 0.217, 73.5, 74) + ) + ); + pab.calculatedParam = pab.prms.Z1; + expect(pab.CalcSerie().resultElement.log.messages[0].code) + .toBe(MessageCode.ERROR_CLOISON_AVAL_UN_OUVRAGE_REGULE); + }); }); }); diff --git a/src/compute-node.ts b/src/compute-node.ts index 732c33005e1530097fa87bd088ab5fabbbf1e9ed..88f82d6316abe0d4d7d6475c179221b943469698 100644 --- a/src/compute-node.ts +++ b/src/compute-node.ts @@ -22,7 +22,8 @@ export enum CalculatorType { PabChute, PabNombre, Section, - Pab // Passe à bassins; + Pab, // Passe à bassins; + CloisonAval } /** diff --git a/src/pab/cloison_aval.ts b/src/pab/cloison_aval.ts index 7896be9c33d607b631bc7f83bc7e1469259be3b0..abdc819ad783e84b3bc061ad3c1162c679fab278 100644 --- a/src/pab/cloison_aval.ts +++ b/src/pab/cloison_aval.ts @@ -9,16 +9,25 @@ export { ParallelStructureParams } from "../structure/parallel_structure_params" export class CloisonAval extends ParallelStructure { + /** + * Return index structure of vanne levante + */ + private get indexVanneLevante(): number { + for (let i = 0; i < this.structures.length; i++) { + // tslint:disable-next-line:max-line-length + if (loiAdmissiblesCloisonAval.VanneLevante.includes(this.structures[i].properties.getPropValue("loiDebit"))) { + return i; + } + } + return null; + } + /** * Returns admissible LoiDebit grouped by StructureType * Only one vanne levante is allowed on a CloisonAval */ public getLoisAdmissibles(): { [key: string]: LoiDebit[]; } { - const loiAdmissibles = JSON.parse(JSON.stringify(loiAdmissiblesCloisonAval)); - if (this.hasVanneLevante()) { - delete loiAdmissibles.VanneLevante; - } - return loiAdmissibles; + return loiAdmissiblesCloisonAval; } /** @@ -30,7 +39,10 @@ export class CloisonAval extends ParallelStructure { if (sVarCalc !== "Z1") { throw new Error("CloisonAval sVarCalc should be Z1"); } - this.checkVanneLevante(); + if (!this.checkVanneLevante()) { + this.currentResult.addMessage(new Message(MessageCode.ERROR_CLOISON_AVAL_UN_OUVRAGE_REGULE)); + return this.result; + } let m: Message; if (this.hasVanneLevante()) { const s = this.structures[this.indexVanneLevante] as StructureVanLevVillemonte | StructureVanLevLarinier; @@ -73,6 +85,19 @@ export class CloisonAval extends ParallelStructure { return this.result; } + /** + * return false if there is more than one vanne levante in the cloison + */ + public checkVanneLevante() { + let n: number = 0; + for (const st of this.structures) { + if (loiAdmissiblesCloisonAval.VanneLevante.includes(st.properties.getPropValue("loiDebit"))) { + n += 1; + } + } + return n < 2; + } + /** * paramétrage de la calculabilité des paramètres */ @@ -87,32 +112,4 @@ export class CloisonAval extends ParallelStructure { private hasVanneLevante(): boolean { return !(this.indexVanneLevante === null); } - - /** - * Return index structure of vanne levante - */ - private get indexVanneLevante(): number { - for (let i = 0; i < this.structures.length; i++) { - // tslint:disable-next-line:max-line-length - if (loiAdmissiblesCloisonAval.VanneLevante.includes(this.structures[i].properties.getPropValue("loiDebit"))) { - return i; - } - } - return null; - } - - /** - * Check if there is more than one vanne levante and throw an error - */ - private checkVanneLevante() { - let n: number = 0; - for (const st of this.structures) { - if (loiAdmissiblesCloisonAval.VanneLevante.includes(st.properties.getPropValue("loiDebit"))) { - n += 1; - } - } - if (n > 1) { - throw new Error("CloisonAval: maximum 1 vanne levante allowed"); - } - } } diff --git a/src/pab/pab.ts b/src/pab/pab.ts index abceced2a286f18081b07d82694ae59908aada9b..1692a7a2f632fa957457310d74e0878ae27c79ac 100644 --- a/src/pab/pab.ts +++ b/src/pab/pab.ts @@ -10,6 +10,7 @@ import { Result } from "../util/result"; import { CloisonAval, ParallelStructureParams } from "./cloison_aval"; import { Cloisons } from "./cloisons"; import { PabParams } from "./pab_params"; +import { Message, MessageCode } from "../util/message"; export { PabParams }; @@ -92,6 +93,18 @@ export class Pab extends Nub { } } + /** + * + * @param sVarCalc Calcul + */ + public Calc(sVarCalc: string, rInit?: number): Result { + if (!this.downWall.checkVanneLevante()) { + this.currentResult = new Result(new Message(MessageCode.ERROR_CLOISON_AVAL_UN_OUVRAGE_REGULE)); + return this.result; + } + return super.Calc(sVarCalc, rInit); + } + /** * Calcul analytique * @warning Should be called by this.Calc only for parameter initialisations diff --git a/src/session.ts b/src/session.ts index 949f18b9882556bf424861cd628f673364dd49f0..ed9d87be139fe5cfb317b708d1dbc9da34b16ef7 100644 --- a/src/session.ts +++ b/src/session.ts @@ -33,6 +33,7 @@ import { Dever, DeverParams } from "./structure/dever"; import { CreateStructure } from "./structure/factory_structure"; import { ParallelStructure, ParallelStructureParams } from "./structure/parallel_structure"; import { LoiDebit } from "./structure/structure_props"; +import { CloisonAval } from "./pab/cloison_aval"; export class Session { @@ -145,7 +146,7 @@ export class Session { if (data.session && Array.isArray(data.session)) { // for each Nub representation, create the corresponding Nub in the session data.session.forEach((e: any) => { - if (! uids || uids.length === 0 || uids.includes(e.uid)) { + if (!uids || uids.length === 0 || uids.includes(e.uid)) { const nubPointer = this.createNubFromObjectRepresentation(e); ret.nubs.push(nubPointer); // forward errors @@ -211,175 +212,175 @@ export class Session { switch (calcType) { case CalculatorType.ConduiteDistributrice: - { - prms = new ConduiteDistribParams( - 3, // débit Q - 1.2, // diamètre D - 0.6, // perte de charge J - 100, // Longueur de la conduite Lg - 1e-6, // Viscosité dynamique Nu - ); - nub = new ConduiteDistrib(prms, dbg); - break; - } + { + prms = new ConduiteDistribParams( + 3, // débit Q + 1.2, // diamètre D + 0.6, // perte de charge J + 100, // Longueur de la conduite Lg + 1e-6, // Viscosité dynamique Nu + ); + nub = new ConduiteDistrib(prms, dbg); + break; + } case CalculatorType.LechaptCalmon: - { - prms = new LechaptCalmonParams( - 3, // débit - 1.2, // diamètre - 0.6, /// perte de charge - 100, // longueur du toyo - 1.863, // paramètre L du matériau - 2, // paramètre M du matériau - 5.33// paramètre N du matériau - ); - nub = new LechaptCalmon(prms, dbg); - break; - } + { + prms = new LechaptCalmonParams( + 3, // débit + 1.2, // diamètre + 0.6, /// perte de charge + 100, // longueur du toyo + 1.863, // paramètre L du matériau + 2, // paramètre M du matériau + 5.33// paramètre N du matériau + ); + nub = new LechaptCalmon(prms, dbg); + break; + } case CalculatorType.SectionParametree: - { - nub = new SectionParametree(undefined, dbg); - break; - } + { + nub = new SectionParametree(undefined, dbg); + break; + } case CalculatorType.RegimeUniforme: - { - nub = new RegimeUniforme(undefined, dbg); - break; - } + { + nub = new RegimeUniforme(undefined, dbg); + break; + } case CalculatorType.CourbeRemous: - { - prms = new CourbeRemousParams( - 0.15, // Yamont = tirant amont - 0.4, // Yaval = tirant aval - 100, // Long= Longueur du bief - 5, // Dx=Pas d'espace - ); - nub = new CourbeRemous(undefined, prms, MethodeResolution.EulerExplicite, dbg); - break; - } + { + prms = new CourbeRemousParams( + 0.15, // Yamont = tirant amont + 0.4, // Yaval = tirant aval + 100, // Long= Longueur du bief + 5, // Dx=Pas d'espace + ); + nub = new CourbeRemous(undefined, prms, MethodeResolution.EulerExplicite, dbg); + break; + } case CalculatorType.PabDimensions: - { - prms = new PabDimensionParams( - 2, // Longueur L - 1, // Largeur W - 0.5, // Tirant d'eau Y - 2 // Volume V - ); - nub = new PabDimension(prms, dbg); - break; - } + { + prms = new PabDimensionParams( + 2, // Longueur L + 1, // Largeur W + 0.5, // Tirant d'eau Y + 2 // Volume V + ); + nub = new PabDimension(prms, dbg); + break; + } case CalculatorType.PabPuissance: - { - prms = new PabPuissanceParams( - 0.3, // Chute entre bassins DH (m) - 0.1, // Débit Q (m3/s) - 0.5, // Volume V (m3) - 588.6 // Puissance dissipée PV (W/m3) - ); - nub = new PabPuissance(prms, dbg); - break; - } + { + prms = new PabPuissanceParams( + 0.3, // Chute entre bassins DH (m) + 0.1, // Débit Q (m3/s) + 0.5, // Volume V (m3) + 588.6 // Puissance dissipée PV (W/m3) + ); + nub = new PabPuissance(prms, dbg); + break; + } case CalculatorType.Structure: - { - const loiDebit: LoiDebit = params.getPropValue("loiDebit"); - nub = CreateStructure(loiDebit, (parentNub as ParallelStructure)); - break; - } + { + const loiDebit: LoiDebit = params.getPropValue("loiDebit"); + nub = CreateStructure(loiDebit, (parentNub as ParallelStructure)); + break; + } case CalculatorType.ParallelStructure: - { - prms = new ParallelStructureParams( - 0.5, // Q - 102, // Z1 - 101.5 // Z2 - ); - nub = new ParallelStructure(prms, dbg); - break; - } + { + prms = new ParallelStructureParams( + 0.5, // Q + 102, // Z1 + 101.5 // Z2 + ); + nub = new ParallelStructure(prms, dbg); + break; + } case CalculatorType.Dever: - { - const deverPrms = new DeverParams( - 0.5, // Q - 102, // Z1 - 10, // BR : largeur du cours d'eau - 99 // ZR : cote du lit du cours d'eau - ); - nub = new Dever(deverPrms, dbg); - break; - } + { + const deverPrms = new DeverParams( + 0.5, // Q + 102, // Z1 + 10, // BR : largeur du cours d'eau + 99 // ZR : cote du lit du cours d'eau + ); + nub = new Dever(deverPrms, dbg); + break; + } case CalculatorType.Cloisons: - { - nub = new Cloisons( - new CloisonsParams( - 1.5, // Débit total (m3/s) - 102, // Cote de l'eau amont (m) - 10, // Longueur des bassins (m) - 1, // Largeur des bassins (m) - 1, // Profondeur moyenne (m) - 0.5 // Hauteur de chute (m) - ), dbg - ); - break; - } + { + nub = new Cloisons( + new CloisonsParams( + 1.5, // Débit total (m3/s) + 102, // Cote de l'eau amont (m) + 10, // Longueur des bassins (m) + 1, // Largeur des bassins (m) + 1, // Profondeur moyenne (m) + 0.5 // Hauteur de chute (m) + ), dbg + ); + break; + } case CalculatorType.MacroRugo: - { - nub = new MacroRugo( - new MacrorugoParams( - 12.5, // ZF1 - 6, // L - 1, // B - 0.05, // If - 1.57, // Q - 0.6, // h - 0.01, // Ks - 0.05, // C - 0.5, // D - 0.8, // k - 1.5 // Cd0 - ), dbg - ); - break; - } + { + nub = new MacroRugo( + new MacrorugoParams( + 12.5, // ZF1 + 6, // L + 1, // B + 0.05, // If + 1.57, // Q + 0.6, // h + 0.01, // Ks + 0.05, // C + 0.5, // D + 0.8, // k + 1.5 // Cd0 + ), dbg + ); + break; + } case CalculatorType.PabChute: - { - nub = new PabChute( - new PabChuteParams( - 2, // Z1 - 0.5, // Z2 - 1.5 // DH - ), dbg - ); - break; - } + { + nub = new PabChute( + new PabChuteParams( + 2, // Z1 + 0.5, // Z2 + 1.5 // DH + ), dbg + ); + break; + } case CalculatorType.PabNombre: - { - nub = new PabNombre( - new PabNombreParams( - 6, // DHT - 10, // N - 0.6 // DH - ), dbg - ); - break; - } + { + nub = new PabNombre( + new PabNombreParams( + 6, // DHT + 10, // N + 0.6 // DH + ), dbg + ); + break; + } case CalculatorType.Section: - { - nub = this.createSection(nodeType, dbg); - break; - } + { + nub = this.createSection(nodeType, dbg); + break; + } case CalculatorType.Pab: nub = new Pab( @@ -391,13 +392,24 @@ export class Session { ); break; + case CalculatorType.CloisonAval: + { + prms = new ParallelStructureParams( + 0.5, // Q + 102, // Z1 + 101.5 // Z2 + ); + nub = new CloisonAval(prms, dbg); + break; + } + default: - { - throw new Error( - // tslint:disable-next-line:max-line-length - `Session.createNub() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge` - ); - } + { + throw new Error( + // tslint:disable-next-line:max-line-length + `Session.createNub() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge` + ); + } } // propagate properties @@ -538,7 +550,7 @@ export class Session { // create the Nub const newNub = this.createSessionNub(new Props(obj.props)); // try to keep the original ID - if (! this.uidAlreadyUsed(obj.uid)) { + if (!this.uidAlreadyUsed(obj.uid)) { newNub.setUid(obj.uid); } const res = newNub.loadObjectRepresentation(obj); @@ -566,7 +578,7 @@ export class Session { if (data.session && Array.isArray(data.session)) { // find each corresponding Nub in the session data.session.forEach((e: any) => { - if (! uids || uids.length === 0 || uids.includes(e.uid)) { + if (!uids || uids.length === 0 || uids.includes(e.uid)) { const nub = this.findNubByUid(e.uid); // find linked parameters const ret = nub.fixLinks(e); diff --git a/src/structure/factory_structure.ts b/src/structure/factory_structure.ts index d1ba8ca41a6059371b17d018b6bab1766b5d709f..342d7245761b7f53b46647d78f7ecd9951075d19 100755 --- a/src/structure/factory_structure.ts +++ b/src/structure/factory_structure.ts @@ -19,9 +19,10 @@ import { StructureTriangularWeir, TriangularStructureParams } from "./structure_ import { StructureWeirFree } from "./structure_weir_free"; import { StructureWeirSubmergedLarinier } from "./structure_weir_submerged_larinier"; import { StructureWeirVillemonte } from "./structure_weir_villemonte"; +import { StructureVanLevParams, StructureVanLevVillemonte, StructureVanLevLarinier } from "./structure_vanlev"; export function CreateStructure(loiDebit: LoiDebit, parentNub?: ParallelStructure, - dbg: boolean = false + dbg: boolean = false ): Structure { let ret: Structure; const oCd: { [s: string]: number } = { SeuilR: 0.4, VanneR: 0.6, SeuilT: 1.36 }; @@ -34,6 +35,17 @@ export function CreateStructure(loiDebit: LoiDebit, parentNub?: ParallelStructur oCd.SeuilR // Cd pour un seuil rectangulaire // W = Infinity par défaut pour un seuil ); + const vanLevPrms: StructureVanLevParams = new StructureVanLevParams( + 0, + 100, + 102, + 101.5, + 0.4, + 0.4, + 0.5, + 99.5, + 100.5 + ); // Control of validity of structure type and definition of parameters switch (loiDebit) { @@ -86,12 +98,11 @@ export function CreateStructure(loiDebit: LoiDebit, parentNub?: ParallelStructur break; case LoiDebit.WeirSubmergedLarinier: + rectStructPrms.L.singleValue = 0.2; + rectStructPrms.Cd.singleValue = 0.65; + rectStructPrms.ZDV.singleValue = 101; + rectStructPrms.h1.singleValue = 1; ret = new StructureWeirSubmergedLarinier(rectStructPrms, dbg); - const prms = ret.prms as RectangularStructureParams; - prms.L.singleValue = 0.2; - prms.Cd.singleValue = 0.65; - prms.ZDV.singleValue = 101; - prms.h1.singleValue = 1; break; case LoiDebit.KIVI: @@ -152,6 +163,15 @@ export function CreateStructure(loiDebit: LoiDebit, parentNub?: ParallelStructur ret = new StructureWeirVillemonte(rectStructPrms, dbg); break; + case LoiDebit.VanLevVillemonte: + ret = new StructureVanLevVillemonte(vanLevPrms, dbg); + break; + + case LoiDebit.VanLevLarinier: + vanLevPrms.Cd.singleValue = 0.65; + ret = new StructureVanLevLarinier(vanLevPrms, dbg); + break; + default: throw new Error(`type de LoiDebit ${LoiDebit[loiDebit]} non pris en charge`); } diff --git a/src/structure/structure_vanlev.ts b/src/structure/structure_vanlev.ts index 0447d0ba8ae03e2e045d3faa115e9293e0b47633..a8037669d82475d1dbc49bf8885891336f6206c5 100644 --- a/src/structure/structure_vanlev.ts +++ b/src/structure/structure_vanlev.ts @@ -41,6 +41,7 @@ export class StructureVanLevParams extends RectangularStructureParams { this.addParamDefinition(this.maxZDV); this.DH = new ParamDefinition(this, "DH", ParamDomainValue.ANY, rDH, ParamFamily.BASINFALLS); this.addParamDefinition(this.DH); + this.ZDV.visible = false; } } diff --git a/src/util/message.ts b/src/util/message.ts index d9d752af499d9463fd323db2806b6d6922094f96..4c2778db457e6b4d2a186cb5f928fe988c7b6094 100644 --- a/src/util/message.ts +++ b/src/util/message.ts @@ -113,6 +113,11 @@ export enum MessageCode { */ ERROR_INTERVAL_OUTSIDE, + /** + * Un seul ouvrage régulé est autorisé sur la cloison aval + */ + ERROR_CLOISON_AVAL_UN_OUVRAGE_REGULE, + /** * internationalisation : langue non prise en charge */