From e165086cf9af7b6a10aece45b75655179ec16e0f Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Wed, 7 Feb 2018 15:52:18 +0100 Subject: [PATCH] =?UTF-8?q?#30=20passage=20de=20CheckEquation=20en=20m?= =?UTF-8?q?=C3=A9thode=20statique=20et=20modification=20du=20domaine=20de?= =?UTF-8?q?=20Z1,=20Z2=20et=20ZDV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/structure/structure.spec.ts | 37 +------------------ spec/structure/structure_test.ts | 35 ++++++++++++++++++ src/structure/rectangular_structure_params.ts | 1 + src/structure/structure.ts | 19 ++++------ src/structure/structure_cem88d.ts | 2 +- src/structure/structure_cem88v.ts | 2 +- src/structure/structure_cunge80.ts | 2 +- src/structure/structure_orifice_free.ts | 2 +- src/structure/structure_orifice_submerged.ts | 2 +- src/structure/structure_params.ts | 8 ++-- src/structure/structure_weir_free.ts | 2 +- 11 files changed, 55 insertions(+), 57 deletions(-) create mode 100644 spec/structure/structure_test.ts diff --git a/spec/structure/structure.spec.ts b/spec/structure/structure.spec.ts index 53e0a674..81391e6c 100644 --- a/spec/structure/structure.spec.ts +++ b/spec/structure/structure.spec.ts @@ -6,42 +6,9 @@ */ // import { describe, expect, it, xdescribe } from "../mock_jasmine"; -import { Structure, StructureFlowMode, StructureFlowRegime, StructureParams } from "../../src/structure/structure"; -import { Result } from "../../src/util/result"; +import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { checkResult } from "../test_func"; - -class StructureTest extends Structure { - - constructor(prms: StructureParams, dbg: boolean = false) { - super(prms, dbg); - } - - /** - * Test of getFlowMode - */ - public testGetFlowMode() { - this.prms.update_h1h2(); - return this.getFlowMode(); - } - - /** - * Test of getFlowRegime - */ - public testGetFlowRegime() { - this.prms.update_h1h2(); - return this.getFlowRegime(); - } - - public Equation(sVarCalc: string): Result { - this.prms.update_h1h2(); - this.CheckEquation(sVarCalc); - return new Result(this.prms.Z1.v - this.prms.Z2.v); - } - -} - -const structTestPrm: StructureParams = new StructureParams(1, 0, 30, 15); -const structTest: StructureTest = new StructureTest(structTestPrm, false); +import { structTest } from "./structure_test"; describe("Class Structure: ", () => { diff --git a/spec/structure/structure_test.ts b/spec/structure/structure_test.ts new file mode 100644 index 00000000..20c03c76 --- /dev/null +++ b/spec/structure/structure_test.ts @@ -0,0 +1,35 @@ +import { Structure, StructureParams } from "../../src/structure/structure"; +import { Result } from "../../src/util/result"; + +class StructureTest extends Structure { + + constructor(prms: StructureParams, dbg: boolean = false) { + super(prms, dbg); + } + + /** + * Test of getFlowMode + */ + public testGetFlowMode() { + this.prms.update_h1h2(); + return this.getFlowMode(); + } + + /** + * Test of getFlowRegime + */ + public testGetFlowRegime() { + this.prms.update_h1h2(); + return this.getFlowRegime(); + } + + public Equation(sVarCalc: string): Result { + this.prms.update_h1h2(); + Structure.CheckEquation(sVarCalc); + return new Result(this.prms.Z1.v - this.prms.Z2.v); + } + +} + +export const structTestPrm: StructureParams = new StructureParams(1, 0, 30, 15); +export const structTest: StructureTest = new StructureTest(structTestPrm, false); diff --git a/src/structure/rectangular_structure_params.ts b/src/structure/rectangular_structure_params.ts index 4d5d267e..485d540b 100644 --- a/src/structure/rectangular_structure_params.ts +++ b/src/structure/rectangular_structure_params.ts @@ -10,6 +10,7 @@ export class RectangularStructureParams extends StructureParams { public L: ParamDefinition; /** Discharge coefficient */ + // tslint:disable-next-line:variable-name public Cd: ParamDefinition; /** diff --git a/src/structure/structure.ts b/src/structure/structure.ts index 612c197f..ca8abac0 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -38,6 +38,13 @@ export enum StructureFlowRegime { */ export abstract class Structure extends Nub { + /** + * Test générique si VarCalc="Q" pour l'utilisation de Equation + */ + public static CheckEquation(sVarCalc: string) { + if (sVarCalc !== "Q") { throw new Error("Structure.Equation() : invalid parameter name " + sVarCalc); } + } + /** Constante utile : Racine de 2g */ protected static readonly R2G: number = Math.sqrt(2 * 9.81); @@ -52,11 +59,6 @@ export abstract class Structure extends Nub { return this._prms as StructureParams; } - /** - * Calcul du mode et du régime d'écoulement - */ - public abstract Equation(sVarCalc: string): Result; - /** * Calcul d'une équation quelque soit l'inconnue à calculer. * Gestion du débit nul et de l'inversion de débit @@ -164,11 +166,4 @@ export abstract class Structure extends Nub { return StructureFlowRegime.SUBMERGED; } } - - /** - * Test générique si VarCalc="Q" pour l'utilisation de Equation - */ - protected CheckEquation(sVarCalc: string) { - if (sVarCalc !== "Q") { throw new Error("Structure.Equation() : invalid parameter name " + sVarCalc); } - } } diff --git a/src/structure/structure_cem88d.ts b/src/structure/structure_cem88d.ts index 345e6825..99c675de 100644 --- a/src/structure/structure_cem88d.ts +++ b/src/structure/structure_cem88d.ts @@ -15,7 +15,7 @@ export class StructureCem88d extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être "Q") */ public Equation(sVarCalc: string): Result { - super.CheckEquation(sVarCalc); + Structure.CheckEquation(sVarCalc); const data = super.defaultResultData(); let v: number; diff --git a/src/structure/structure_cem88v.ts b/src/structure/structure_cem88v.ts index cef783f7..b636fc0e 100644 --- a/src/structure/structure_cem88v.ts +++ b/src/structure/structure_cem88v.ts @@ -15,7 +15,7 @@ export class StructureCem88v extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être "Q") */ public Equation(sVarCalc: string): Result { - super.CheckEquation(sVarCalc); + Structure.CheckEquation(sVarCalc); const data = super.defaultResultData(); let v: number; diff --git a/src/structure/structure_cunge80.ts b/src/structure/structure_cunge80.ts index bc8b05c4..38435d55 100644 --- a/src/structure/structure_cunge80.ts +++ b/src/structure/structure_cunge80.ts @@ -14,7 +14,7 @@ export class StructureCunge80 extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être égale à Q ici) */ public Equation(sVarCalc: string): Result { - super.CheckEquation(sVarCalc); + Structure.CheckEquation(sVarCalc); const data = super.defaultResultData(); let v: number; diff --git a/src/structure/structure_orifice_free.ts b/src/structure/structure_orifice_free.ts index 39272136..1f4b266f 100644 --- a/src/structure/structure_orifice_free.ts +++ b/src/structure/structure_orifice_free.ts @@ -14,7 +14,7 @@ export class StructureOrificeFree extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être égale à Q ici) */ public Equation(sVarCalc: string): Result { - super.CheckEquation(sVarCalc); + Structure.CheckEquation(sVarCalc); const data = super.defaultResultData(); // TODO : Warning si les conditions hydrauliques ne correspondent pas à un écoulement dénoyé diff --git a/src/structure/structure_orifice_submerged.ts b/src/structure/structure_orifice_submerged.ts index c8a67015..c4f42b50 100644 --- a/src/structure/structure_orifice_submerged.ts +++ b/src/structure/structure_orifice_submerged.ts @@ -14,7 +14,7 @@ export class StructureOrificeSubmerged extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être égale à Q ici) */ public Equation(sVarCalc: string): Result { - super.CheckEquation(sVarCalc); + Structure.CheckEquation(sVarCalc); const data = super.defaultResultData(); // TODO : Warning si les conditions hydrauliques ne correspondent pas à un écoulement dénoyé diff --git a/src/structure/structure_params.ts b/src/structure/structure_params.ts index 5929b5bc..468fd6a4 100644 --- a/src/structure/structure_params.ts +++ b/src/structure/structure_params.ts @@ -38,13 +38,13 @@ export class StructureParams extends ParamsEquation { */ constructor(rQ: number, rZDV: number, rZ1: number, rZ2: number, rW: number = Infinity ) { super(); - this.Q = new ParamDefinition(ComputeNodeType.CondDistri, "Q", ParamDomainValue.POS_NULL, rQ); + this.Q = new ParamDefinition(ComputeNodeType.CondDistri, "Q", ParamDomainValue.ANY, rQ); this.addParamDefinition(this.Q); - this.ZDV = new ParamDefinition(ComputeNodeType.CondDistri, "ZDV", ParamDomainValue.POS_NULL, rZDV); + this.ZDV = new ParamDefinition(ComputeNodeType.CondDistri, "ZDV", ParamDomainValue.ANY, rZDV); this.addParamDefinition(this.ZDV); - this.Z1 = new ParamDefinition(ComputeNodeType.CondDistri, "Z1", ParamDomainValue.POS_NULL, rZ1); + this.Z1 = new ParamDefinition(ComputeNodeType.CondDistri, "Z1", ParamDomainValue.ANY, rZ1); this.addParamDefinition(this.Z1); - this.Z2 = new ParamDefinition(ComputeNodeType.CondDistri, "Z2", ParamDomainValue.POS_NULL, rZ2); + this.Z2 = new ParamDefinition(ComputeNodeType.CondDistri, "Z2", ParamDomainValue.ANY, rZ2); this.addParamDefinition(this.Z2); this.h1 = new ParamDefinition(ComputeNodeType.CondDistri, "h1", ParamDomainValue.POS_NULL, Math.max(0, this.Z1.v - this.ZDV.v)); diff --git a/src/structure/structure_weir_free.ts b/src/structure/structure_weir_free.ts index 4f862723..57ff2f15 100644 --- a/src/structure/structure_weir_free.ts +++ b/src/structure/structure_weir_free.ts @@ -14,7 +14,7 @@ export class StructureWeirFree extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être "Q") */ public Equation(sVarCalc: string): Result { - super.CheckEquation(sVarCalc); + Structure.CheckEquation(sVarCalc); const data = super.defaultResultData(); // TODO : Warning si les conditions hydrauliques ne correspondent pas à un seuil dénoyé -- GitLab