From 485f4db6852d46ee52e9453593aa220396b2a189 Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Mon, 25 Jun 2018 18:57:45 +0200
Subject: [PATCH] =?UTF-8?q?#28=20Ajout=20des=20lois=20de=20cloison=20fente?=
 =?UTF-8?q?=20et=20orifice=20noy=C3=A9s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 spec/cloisons/cloisons_fente.spec.ts          | 26 ++++++++
 spec/cloisons/cloisons_orifice.spec.ts        | 26 ++++++++
 spec/structure/functions.ts                   |  2 +-
 ...ructure_triangular_trunc_weir_free.spec.ts |  2 +-
 src/cloisons/cloisons_fente.ts                | 45 ++++++++++++++
 src/cloisons/cloisons_fente_params.ts         | 42 +++++++++++++
 src/cloisons/cloisons_orifice.ts              | 61 +++++++++++++++++++
 src/cloisons/cloisons_orifice_params.ts       | 45 ++++++++++++++
 src/structure/structure.ts                    |  6 +-
 9 files changed, 250 insertions(+), 5 deletions(-)
 create mode 100644 spec/cloisons/cloisons_fente.spec.ts
 create mode 100644 spec/cloisons/cloisons_orifice.spec.ts
 create mode 100644 src/cloisons/cloisons_fente.ts
 create mode 100644 src/cloisons/cloisons_fente_params.ts
 create mode 100644 src/cloisons/cloisons_orifice.ts
 create mode 100644 src/cloisons/cloisons_orifice_params.ts

diff --git a/spec/cloisons/cloisons_fente.spec.ts b/spec/cloisons/cloisons_fente.spec.ts
new file mode 100644
index 00000000..d953f5df
--- /dev/null
+++ b/spec/cloisons/cloisons_fente.spec.ts
@@ -0,0 +1,26 @@
+/**
+ * IMPORTANT !
+ * Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
+ * Pour exécuter ce code dans le débugger.
+ * Faire de même avec le fichier ../structure/functions.ts
+ */
+// import { describe, expect, it, xdescribe } from "../mock_jasmine";
+
+import { CloisonsFente, CloisonsFenteParams } from "../../src/cloisons/cloisons_fente";
+import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
+import { itCalcQ } from "../structure/functions";
+
+const prms: CloisonsFenteParams = new CloisonsFenteParams(0, 102, 0.5, 0.5, 0.2, 0.65);
+const test: CloisonsFente = new CloisonsFente(prms, false);
+
+describe("Class CloisonsFente: ", () => {
+    describe("Calc(Q): ", () => {
+        const h1: number[] = [102];
+        const Q: number[] = [0.204];
+        const mode: StructureFlowMode = StructureFlowMode.WEIR;
+        const regime: StructureFlowRegime = StructureFlowRegime.SUBMERGED;
+        for (let i = 0; i < Q.length; i++) {
+            itCalcQ(test, h1[i], Infinity, Q[i], mode, regime);
+        }
+    });
+});
diff --git a/spec/cloisons/cloisons_orifice.spec.ts b/spec/cloisons/cloisons_orifice.spec.ts
new file mode 100644
index 00000000..92fa2e06
--- /dev/null
+++ b/spec/cloisons/cloisons_orifice.spec.ts
@@ -0,0 +1,26 @@
+/**
+ * IMPORTANT !
+ * Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
+ * Pour exécuter ce code dans le débugger.
+ * Faire de même avec le fichier ../structure/functions.ts
+ */
+// import { describe, expect, it, xdescribe } from "../mock_jasmine";
+
+import { CloisonsOrifice, CloisonsOrificeParams } from "../../src/cloisons/cloisons_orifice";
+import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
+import { itCalcQ } from "../structure/functions";
+
+const prms: CloisonsOrificeParams = new CloisonsOrificeParams(0, 102, 0.5, 0.7, 0.1);
+const test: CloisonsOrifice = new CloisonsOrifice(prms, false);
+
+describe("Class CloisonsOrifice: ", () => {
+    describe("Calc(Q): ", () => {
+        const h1: number[] = [102];
+        const Q: number[] = [0.219];
+        const mode: StructureFlowMode = StructureFlowMode.ORIFICE;
+        const regime: StructureFlowRegime = StructureFlowRegime.SUBMERGED;
+        for (let i = 0; i < Q.length; i++) {
+            itCalcQ(test, h1[i], Infinity, Q[i], mode, regime);
+        }
+    });
+});
diff --git a/spec/structure/functions.ts b/spec/structure/functions.ts
index 853eecc8..e00be7b8 100644
--- a/spec/structure/functions.ts
+++ b/spec/structure/functions.ts
@@ -3,7 +3,7 @@
  * Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
  * Pour exécuter ce code dans le débugger.
  */
-// import { describe, expect, it, xdescribe } from "../mock_jasmine";
+import { describe, expect, it, xdescribe } from "../mock_jasmine";
 
 import { Structure } from "../../src/structure/structure";
 import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
diff --git a/spec/structure/structure_triangular_trunc_weir_free.spec.ts b/spec/structure/structure_triangular_trunc_weir_free.spec.ts
index f0e771dc..117cdc05 100644
--- a/spec/structure/structure_triangular_trunc_weir_free.spec.ts
+++ b/spec/structure/structure_triangular_trunc_weir_free.spec.ts
@@ -4,7 +4,7 @@
  * Pour exécuter ce code dans le débugger.
  * Faire de même avec ./functions.ts
  */
-// import { describe, expect, it, xdescribe } from "../mock_jasmine";
+import { describe, expect, it, xdescribe } from "../mock_jasmine";
 
 import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
 import { StructureTriangularTruncWeirFree } from "../../src/structure/structure_triangular_trunc_weir_free";
diff --git a/src/cloisons/cloisons_fente.ts b/src/cloisons/cloisons_fente.ts
new file mode 100644
index 00000000..b714d97f
--- /dev/null
+++ b/src/cloisons/cloisons_fente.ts
@@ -0,0 +1,45 @@
+import { ParamCalculability } from "../param/param-definition";
+import { StructureWeirSubmergedLarinier } from "../structure/structure_weir_submerged_larinier";
+import { Result } from "../util/result";
+import { CloisonsFenteParams } from "./cloisons_fente_params";
+
+export { CloisonsFenteParams };
+
+/**
+ * Equation de la fente noyé pour l'outil "Cloisons"
+ * d'après Larinier, M., Travade, F., Porcher, J.-P., Gosset, C., 1992.
+ * Passes à poissons : expertise et conception des ouvrages de franchissement
+ */
+export class CloisonsFente extends StructureWeirSubmergedLarinier {
+
+    constructor(prms: CloisonsFenteParams, dbg: boolean = false) {
+        super(prms, dbg);
+        this._isZDVcalculable = false;
+    }
+
+    /**
+     * paramètres castés au bon type
+     */
+    get prms(): CloisonsFenteParams {
+        return this._prms as CloisonsFenteParams;
+    }
+
+    /**
+     * Calcul analytique Q = f(Cd, L, h1, h2, W) seuil dénoyé
+     * @param sVarCalc Variable à calculer (doit être "Q")
+     */
+    public Equation(sVarCalc: string): Result {
+        return super.Equation(sVarCalc);
+    }
+
+    /**
+     * paramétrage de la calculabilité des paramètres
+     */
+    protected setParametersCalculability() {
+        super.setParametersCalculability();
+        this.prms.H1.calculability = ParamCalculability.DICHO;
+        this.prms.DH.calculability = ParamCalculability.DICHO;
+        this.prms.Z2.calculability = ParamCalculability.FREE;
+        this.prms.ZDV.calculability = ParamCalculability.FREE;
+    }
+}
diff --git a/src/cloisons/cloisons_fente_params.ts b/src/cloisons/cloisons_fente_params.ts
new file mode 100644
index 00000000..57bb275b
--- /dev/null
+++ b/src/cloisons/cloisons_fente_params.ts
@@ -0,0 +1,42 @@
+import { ParamDefinition } from "../param/param-definition";
+import { ParamDomainValue } from "../param/param-domain";
+import { RectangularStructureParams } from "../structure/rectangular_structure_params";
+
+/**
+ * Parameters for rectangular structures (common for all rectangular structure equations)
+ */
+export class CloisonsFenteParams extends RectangularStructureParams {
+    /** Head (m) */
+    public H1: ParamDefinition;
+
+    /** Drop (m) */
+    public DH: ParamDefinition;
+
+    /**
+     * Constructeur d'une structure rectangulaire
+     * @param rQ    Débit (m3/s)
+     * @param rZ1   Cote de l'eau amont (m)
+     * @param rH1   Charge amont sur la fente (m)
+     * @param rDH   Chute (m)
+     * @param rL    Largeur de la fente (m)
+     * @param rCd   Coefficient de débit (-)
+     */
+    constructor(
+        rQ: number, rZ1: number, rH1: number, rDH: number,
+        rL: number, rCd: number
+    ) {
+        super(rQ, rZ1 - rH1, rZ1, - Infinity, rL, rCd);
+        this.H1 = new ParamDefinition("H1", ParamDomainValue.POS_NULL, rH1);
+        this.addParamDefinition(this.H1);
+        this.DH = new ParamDefinition("DH", ParamDomainValue.POS_NULL, rDH);
+        this.addParamDefinition(this.DH);
+        this.Cd = new ParamDefinition("Cd", ParamDomainValue.POS, rCd);
+        this.addParamDefinition(this.Cd);
+    }
+
+    public update_h1h2() {
+        this.ZDV.v = this.Z1.v - this.H1.v;
+        this.Z2.v = this.Z1.v - this.DH.v;
+        super.update_h1h2();
+    }
+}
diff --git a/src/cloisons/cloisons_orifice.ts b/src/cloisons/cloisons_orifice.ts
new file mode 100644
index 00000000..9cc10df7
--- /dev/null
+++ b/src/cloisons/cloisons_orifice.ts
@@ -0,0 +1,61 @@
+import { ParamCalculability } from "../param/param-definition";
+import { Structure, StructureFlowMode, StructureFlowRegime } from "../structure/structure";
+import { Result } from "../util/result";
+import { CloisonsOrificeParams } from "./cloisons_orifice_params";
+
+export { CloisonsOrificeParams };
+
+/**
+ * Equation classique orifice noyé
+ */
+export class CloisonsOrifice extends Structure {
+
+    constructor(prms: CloisonsOrificeParams, dbg: boolean = false) {
+        super(prms, dbg);
+        this._isZDVcalculable = false;
+    }
+
+    /**
+     * paramètres castés au bon type
+     */
+    get prms(): CloisonsOrificeParams {
+        return this._prms as CloisonsOrificeParams;
+    }
+
+    /**
+     * Calcul du débit avec l'équation classique d'un orifice noyé
+     * @param sVarCalc Variable à calculer (doit être égale à Q ici)
+     */
+    public Equation(sVarCalc: string): Result {
+        Structure.CheckEquation(sVarCalc);
+        const data = this.getResultData();
+
+        const v = this.prms.Cd.v * this.prms.S.v * Structure.R2G * Math.sqrt(this.prms.DH.v);
+
+        return new Result(v, data);
+    }
+
+    public calcA(): number {
+        return this.prms.S.v;
+    }
+
+    protected getFlowRegime() {
+        return StructureFlowRegime.SUBMERGED;
+    }
+
+    protected getFlowMode() {
+        return StructureFlowMode.ORIFICE;
+    }
+
+    /**
+     * paramétrage de la calculabilité des paramètres
+     */
+    protected setParametersCalculability() {
+        super.setParametersCalculability();
+        this.prms.DH.calculability = ParamCalculability.DICHO;
+        this.prms.S.calculability = ParamCalculability.DICHO;
+        this.prms.Cd.calculability = ParamCalculability.DICHO;
+        this.prms.Z2.calculability = ParamCalculability.NONE;
+        this.prms.ZDV.calculability = ParamCalculability.NONE;
+    }
+}
diff --git a/src/cloisons/cloisons_orifice_params.ts b/src/cloisons/cloisons_orifice_params.ts
new file mode 100644
index 00000000..b33a1740
--- /dev/null
+++ b/src/cloisons/cloisons_orifice_params.ts
@@ -0,0 +1,45 @@
+import { ParamDefinition } from "../param/param-definition";
+import { ParamDomainValue } from "../param/param-domain";
+import { StructureParams } from "../structure/structure_params";
+
+/**
+ * Parameters for rectangular structures (common for all rectangular structure equations)
+ */
+export class CloisonsOrificeParams extends StructureParams {
+
+    /** Drop (m) */
+    public DH: ParamDefinition;
+
+    /** Area of the orifice (m2) */
+    public S: ParamDefinition;
+
+    /** Discharge coefficient */
+    // tslint:disable-next-line:variable-name
+    public Cd: ParamDefinition;
+
+    /**
+     * Constructeur d'une structure rectangulaire
+     * @param rQ    Débit (m3/s)
+     * @param rZ1   Cote de l'eau amont (m)
+     * @param rDH   Chute (m)
+     * @param rCd   Coefficient de débit (-)
+     * @param rS    Surface de l'orifice (m2)
+     */
+    constructor(rQ: number, rZ1: number, rDH: number, rCd: number, rS: number) {
+        super(rQ, -Infinity, rZ1, rZ1 - rDH);
+        this.DH = new ParamDefinition("DH", ParamDomainValue.POS_NULL, rDH);
+        this.addParamDefinition(this.DH);
+        this.S = new ParamDefinition("S", ParamDomainValue.POS_NULL, rS);
+        this.addParamDefinition(this.S);
+        this.Cd = new ParamDefinition("Cd", ParamDomainValue.POS_NULL, rCd);
+        this.addParamDefinition(this.Cd);
+    }
+
+    /**
+     * Mise à jour de h1 et h2
+     */
+    public update_h1h2() {
+        // Inutile pour cette équation qui ne fait pas intervenir ces variables
+    }
+
+}
diff --git a/src/structure/structure.ts b/src/structure/structure.ts
index 8965a98e..fcd0e5e1 100644
--- a/src/structure/structure.ts
+++ b/src/structure/structure.ts
@@ -100,16 +100,16 @@ export abstract class Structure extends Nub {
         // Gestion du débit nul
         const flagsNull = { Mode: StructureFlowMode.NULL, Regime: StructureFlowRegime.NULL };
         if (sVarCalc === "Q") {
-            if (this.prms.h1.v === this.prms.h2.v || this.prms.W.v <= 0) {
+            if (this.prms.h1.v <= 0 || this.prms.Z1.v === this.prms.Z2.v || this.prms.W.v <= 0) {
                 return new Result(0, flagsNull);
             }
         } else if (this.prms.Q.v === 0) {
             // Débit nul <=> tirant d'eau amont = tirant d'eau aval ou tout autre paramètre nul
             switch (sVarCalc) {
                 case "Z1":
-                    return new Result(this.prms.h2.v, flagsNull);
+                    return new Result(this.prms.Z2.v, flagsNull);
                 case "Z2":
-                    return new Result(this.prms.h1.v, flagsNull);
+                    return new Result(this.prms.Z1.v, flagsNull);
                 default:
                     // Est-ce toujours vrai ? Nécessitera peut-être d'étendre la méthode
                     return new Result(0, flagsNull);
-- 
GitLab