From b707274b66326dfc542953485fc634ed214b01ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Tue, 13 Dec 2022 07:05:57 +0100
Subject: [PATCH] feat: add skeleton of pressure loss nub

refs #334
---
 src/compute-node.ts                      |  3 +-
 src/index.ts                             |  1 +
 src/pipe_flow/pl_lechaptcalmon.ts        |  5 +-
 src/pipe_flow/pl_lechaptcalmon_params.ts | 52 ++-------------------
 src/pipe_flow/pressureloss.ts            |  7 +++
 src/pipe_flow/pressureloss_law.ts        | 20 ++++++++
 src/pipe_flow/pressureloss_params.ts     | 58 ++++++++++++++++++++++++
 7 files changed, 94 insertions(+), 52 deletions(-)
 create mode 100644 src/pipe_flow/pressureloss_law.ts
 create mode 100644 src/pipe_flow/pressureloss_params.ts

diff --git a/src/compute-node.ts b/src/compute-node.ts
index adc2ae4f..2f5548ee 100644
--- a/src/compute-node.ts
+++ b/src/compute-node.ts
@@ -42,7 +42,8 @@ export enum CalculatorType {
     PbCloison,          // Cloison de pré-barrage
     PbBassin,           // Bassin de pré-barrage
     Espece,             // Critères de vérification pour une espèce de poissons
-    Verificateur        // Vérificateur de contraintes sur une passe pour une ou plusieurs espèces
+    Verificateur,       // Vérificateur de contraintes sur une passe pour une ou plusieurs espèces
+    PressureLoss        // Pertes de charge (Lechapt-Calmon, Colebrook-White, Strickler, ...)
 }
 
 /** types de sections */
diff --git a/src/index.ts b/src/index.ts
index 68b08263..88adf880 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -62,6 +62,7 @@ export * from "./pab/pab_puissance_params";
 export * from "./pab/cloison_aval";
 export * from "./pipe_flow/pl_lechaptcalmon";
 export * from "./pipe_flow/pressureloss";
+export * from "./pipe_flow/pressureloss_law";
 export * from "./lc-material";
 export * from "./structure/dever";
 export * from "./macrorugo/macrorugo";
diff --git a/src/pipe_flow/pl_lechaptcalmon.ts b/src/pipe_flow/pl_lechaptcalmon.ts
index 46f6f33d..64ed7519 100644
--- a/src/pipe_flow/pl_lechaptcalmon.ts
+++ b/src/pipe_flow/pl_lechaptcalmon.ts
@@ -1,16 +1,16 @@
 import { CalculatorType } from "../compute-node";
 import { LCMaterial } from "../lc-material";
-import { Nub } from "../nub";
 import { ParamCalculability } from "../param/param-definition";
 import { Message, MessageCode } from "../util/message";
 import { Observer } from "../util/observer";
 import { Result } from "../util/result";
 import { PL_LechaptCalmonParams } from "./pl_lechaptcalmon_params";
+import { PressureLossLaw, PressureLossType } from "./pressureloss_law";
 
 /**
  * Calcul des pertes de charge dans un tube à partir des tables de Lechapt et Calmon
  */
-export class PL_LechaptCalmon extends Nub implements Observer {
+export class PL_LechaptCalmon extends PressureLossLaw implements Observer {
 
     private static _materials: { L: number, M: number, N: number, title: string }[] = [
         {
@@ -72,6 +72,7 @@ export class PL_LechaptCalmon extends Nub implements Observer {
     constructor(prms: PL_LechaptCalmonParams, dbg: boolean = false) {
         super(prms, dbg);
         this.setCalculatorType(CalculatorType.LechaptCalmon);
+        this._pressureLossType = PressureLossType.LechaptCalmon;
         this._props.addObserver(this);
         this.material = LCMaterial.PVCPolyethylene;
     }
diff --git a/src/pipe_flow/pl_lechaptcalmon_params.ts b/src/pipe_flow/pl_lechaptcalmon_params.ts
index 147183f3..9bd1f4c4 100644
--- a/src/pipe_flow/pl_lechaptcalmon_params.ts
+++ b/src/pipe_flow/pl_lechaptcalmon_params.ts
@@ -1,22 +1,11 @@
 import { ParamDefinition, ParamFamily } from "../param/param-definition";
 import { ParamDomain, ParamDomainValue } from "../param/param-domain";
-import { ParamsEquation } from "../param/params-equation";
+import { PressureLossParams } from "./pressureloss_params";
 
 /**
  * paramètres pour le calcul Lechapt et Calmon
  */
-export class PL_LechaptCalmonParams extends ParamsEquation {
-    /** Débit */
-    private _Q: ParamDefinition;
-
-    /** Diamètre */
-    private _D: ParamDefinition;
-
-    /** Perte de charge */
-    private _J: ParamDefinition;
-
-    /** Longueur de la conduite */
-    private _Lg: ParamDefinition;
+export class PL_LechaptCalmonParams extends PressureLossParams {
 
     /** Paramètre de rugosité L */
     private _L: ParamDefinition;
@@ -27,50 +16,19 @@ export class PL_LechaptCalmonParams extends ParamsEquation {
     /** Paramètre de rugosité N */
     private _N: ParamDefinition;
 
-    /** Perte de charge singulière Ks */
-    private _Ks: ParamDefinition;
-
     constructor(rQ: number, rD: number, rJ: number, rLg: number, rL: number, rM: number, rN: number, rKs: number,
         nullParams: boolean = false) {
-        super();
-        this._Q = new ParamDefinition(this, "Q", ParamDomainValue.POS, "m³/s", rQ, ParamFamily.FLOWS, undefined, nullParams);
-        this._D = new ParamDefinition(
-            this, "D", new ParamDomain(ParamDomainValue.INTERVAL, 0, 20), "m", rD, ParamFamily.DIAMETERS, undefined, nullParams
-        );
-        this._J = new ParamDefinition(this, "J", ParamDomainValue.POS_NULL, "m", rJ, undefined, undefined, nullParams);
-        this._Lg = new ParamDefinition(this, "Lg", ParamDomainValue.POS, "m", rLg, ParamFamily.LENGTHS, undefined, nullParams);
+        super(rQ, rD, rJ, rLg, rKs, nullParams);
         this._L = new ParamDefinition(this, "L", new ParamDomain(ParamDomainValue.INTERVAL, 0.8, 2), undefined, rL,
             undefined, false, nullParams);
         this._M = new ParamDefinition(this, "M", new ParamDomain(ParamDomainValue.INTERVAL, 1.5, 2.5), undefined, rM,
             undefined, false, nullParams);
         this._N = new ParamDefinition(this, "N", new ParamDomain(ParamDomainValue.INTERVAL, 4.5, 5.5), undefined, rN,
             undefined, false, nullParams);
-        this._Ks = new ParamDefinition(this, "Ks", ParamDomainValue.POS_NULL, undefined, rKs, ParamFamily.STRICKLERS, undefined, nullParams);
 
-        this.addParamDefinition(this._Q);
-        this.addParamDefinition(this._D);
-        this.addParamDefinition(this._J);
-        this.addParamDefinition(this._Lg);
         this.addParamDefinition(this._L);
         this.addParamDefinition(this._M);
         this.addParamDefinition(this._N);
-        this.addParamDefinition(this._Ks);
-    }
-
-    get Q() {
-        return this._Q;
-    }
-
-    get D() {
-        return this._D;
-    }
-
-    get J() {
-        return this._J;
-    }
-
-    get Lg() {
-        return this._Lg;
     }
 
     get L() {
@@ -84,8 +42,4 @@ export class PL_LechaptCalmonParams extends ParamsEquation {
     get N() {
         return this._N;
     }
-
-    get Ks() {
-        return this._Ks;
-    }
 }
diff --git a/src/pipe_flow/pressureloss.ts b/src/pipe_flow/pressureloss.ts
index 65b051d1..4dc7fa7c 100644
--- a/src/pipe_flow/pressureloss.ts
+++ b/src/pipe_flow/pressureloss.ts
@@ -1,9 +1,16 @@
 import { Nub } from "../nub";
 import { Observer } from "../util/observer";
 import { Result } from "../util/result";
+import { CalculatorType } from "../compute-node";
+import { PressureLossParams } from "./pressureloss_params";
 
 export class PressureLoss extends Nub implements Observer {
 
+    constructor(prms: PressureLossParams, dbg: boolean = false) {
+        super(prms, dbg);
+        this.setCalculatorType(CalculatorType.PressureLoss);
+    }
+
     /**
      * paramétrage de la calculabilité des paramètres
      */
diff --git a/src/pipe_flow/pressureloss_law.ts b/src/pipe_flow/pressureloss_law.ts
new file mode 100644
index 00000000..39686a43
--- /dev/null
+++ b/src/pipe_flow/pressureloss_law.ts
@@ -0,0 +1,20 @@
+import { Nub } from "../nub";
+
+/**
+ * Loi de perte de charge
+ */
+export enum PressureLossType {
+    LechaptCalmon
+}
+
+/**
+ * generic pressure loss law (analogous to acSection with respect to SectionParametree nub)
+ */
+export abstract class PressureLossLaw extends Nub {
+
+    protected _pressureLossType: PressureLossType;
+
+    public get pressureLossType(): PressureLossType {
+        return this._pressureLossType;
+    }
+}
diff --git a/src/pipe_flow/pressureloss_params.ts b/src/pipe_flow/pressureloss_params.ts
new file mode 100644
index 00000000..539eca4c
--- /dev/null
+++ b/src/pipe_flow/pressureloss_params.ts
@@ -0,0 +1,58 @@
+import { ParamDefinition, ParamFamily } from "../param/param-definition";
+import { ParamsEquation } from "../param/params-equation";
+import { ParamDomain, ParamDomainValue } from "../param/param-domain";
+
+/**
+ * generic pressure loss parameters
+ */
+export class PressureLossParams extends ParamsEquation {
+    /** Débit */
+    private _Q: ParamDefinition;
+
+    /** Diamètre */
+    private _D: ParamDefinition;
+
+    /** Perte de charge */
+    private _J: ParamDefinition;
+
+    /** Longueur de la conduite */
+    private _Lg: ParamDefinition;
+
+    /** Perte de charge singulière Ks */
+    private _Ks: ParamDefinition;
+
+    constructor(rQ: number, rD: number, rJ: number, rLg: number, rKs: number, nullParams: boolean = false) {
+        super();
+        this._Q = new ParamDefinition(this, "Q", ParamDomainValue.POS, "m³/s", rQ, ParamFamily.FLOWS, undefined, nullParams);
+        this._D = new ParamDefinition(this, "D", new ParamDomain(ParamDomainValue.INTERVAL, 0, 20), "m", rD, ParamFamily.DIAMETERS, undefined, nullParams);
+        this._J = new ParamDefinition(this, "J", ParamDomainValue.POS_NULL, "m", rJ, undefined, undefined, nullParams);
+        this._Lg = new ParamDefinition(this, "Lg", ParamDomainValue.POS, "m", rLg, ParamFamily.LENGTHS, undefined, nullParams);
+        this._Ks = new ParamDefinition(this, "Ks", ParamDomainValue.POS_NULL, undefined, rKs, ParamFamily.STRICKLERS, undefined, nullParams);
+
+        this.addParamDefinition(this._Q);
+        this.addParamDefinition(this._D);
+        this.addParamDefinition(this._J);
+        this.addParamDefinition(this._Lg);
+        this.addParamDefinition(this._Ks);
+    }
+
+    get Q() {
+        return this._Q;
+    }
+
+    get D() {
+        return this._D;
+    }
+
+    get J() {
+        return this._J;
+    }
+
+    get Lg() {
+        return this._Lg;
+    }
+
+    get Ks() {
+        return this._Ks;
+    }
+}
-- 
GitLab