From 88205954e449c359566d9f4b65b3f6e139473fc9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Mon, 16 Jan 2023 14:26:18 +0100
Subject: [PATCH] test: Lechat-Calmon: add tests with specific values (taken
 from execution with master release at this time and Lechapt-Calmon original
 paper, see https://gitlab.irstea.fr/cassiopee/nghyd/-/issues/585#note_73402)

refs #334
---
 spec/pipe_flow/lechaptcalmon.spec.ts | 83 ++++++++++++++++++++++++++++
 src/index.ts                         |  1 +
 2 files changed, 84 insertions(+)

diff --git a/spec/pipe_flow/lechaptcalmon.spec.ts b/spec/pipe_flow/lechaptcalmon.spec.ts
index a7fa7bc2..3b6a1419 100644
--- a/spec/pipe_flow/lechaptcalmon.spec.ts
+++ b/spec/pipe_flow/lechaptcalmon.spec.ts
@@ -1,3 +1,4 @@
+import { LCMaterial } from "../../src/lc-material";
 import { ParamCalculability } from "../../src/param/param-definition";
 import { PL_LechaptCalmon } from "../../src/pipe_flow/pl_lechaptcalmon";
 import { PL_LechaptCalmonParams } from "../../src/pipe_flow/pl_lechaptcalmon_params";
@@ -22,6 +23,25 @@ function getLechapt(): PL_LechaptCalmon {
     return l;
 }
 
+function getLechaptWith(Q: number, D: number, Lg: number, Kloc: number, mat: LCMaterial): PL_LechaptCalmon {
+    const lc = new PL_LechaptCalmon(
+        new PL_LechaptCalmonParams(
+            Q, // débit
+            D, // diamètre
+            0, /// perte de charge
+            Lg, // longueur du toyo
+            Kloc, // coef de perte de charge singulière
+            1.863, // paramètre L du matériau
+            2, // paramètre M du matériau
+            5.33 // paramètre N du matériau
+        )
+    );
+    lc.calculatedParam = lc.prms.J;
+    lc.material = mat;
+    lc.prms.J.singleValue = lc.CalcSerie().vCalc;
+    return lc;
+}
+
 let lechapt: PL_LechaptCalmon = getLechapt();
 
 describe("Class LechaptCalmon : ", () => {
@@ -65,3 +85,66 @@ describe("Class LechaptCalmon : ", () => {
         });
     });
 });
+
+describe("article original", () => {
+    it("", () => {
+        const oldMaxIter = SessionSettings.maxIterations;
+        const oldPrec = SessionSettings.precision;
+
+        try {
+            SessionSettings.maxIterations = 100;
+            SessionSettings.precision = 1e-7;
+
+            // L,M,N : cf. pl_lechaptcalmon.ts
+            const lechaptPrms = new PL_LechaptCalmonParams(
+                0.0085, // débit
+                0.175, // diamètre
+                0, /// perte de charge
+                1000, // longueur du toyo
+                0, // Ks
+                1.863, // paramètre L du matériau
+                2, // paramètre M du matériau
+                5.33, // paramètre N du matériau
+            );
+
+            const lechapt = new PL_LechaptCalmon(lechaptPrms);
+            lechapt.material = LCMaterial.HydraulicallySmoothPipe005D02;
+            lechapt.calculatedParam = lechaptPrms.J;
+
+            const res = lechapt.CalcSerie();
+            expect(res.vCalc).toBeCloseTo(0.784, 3);
+        }
+        finally {
+            SessionSettings.maxIterations = oldMaxIter;
+            SessionSettings.precision = oldPrec;
+        }
+    });
+});
+
+describe("specific values -", () => {
+    it("test 1", () => {
+        const lc = getLechaptWith(3, 1.2, 100, 0, LCMaterial.HydraulicallySmoothPipe025D1);
+        expect(lc.prms.J.singleValue).toBeCloseTo(0.295085, 6);
+        expect(lc.result.resultElements[0].getValue("V")).toBeCloseTo(2.652582, 6);
+        expect(lc.result.resultElements[0].getValue("Jl")).toBeCloseTo(0.295085, 6);
+        expect(lc.result.resultElements[0].getValue("Kl")).toBeCloseTo(0.822826, 6);
+        expect(lc.result.resultElements[0].getValue("fD")).toBeCloseTo(0.009874, 6);
+
+        lc.material = LCMaterial.UnlinedCastIronCoarseConcrete;
+        lc.prms.J.singleValue = lc.CalcSerie().vCalc;
+        expect(lc.prms.J.singleValue).toBeCloseTo(0.634482, 6);
+        expect(lc.result.resultElements[0].getValue("V")).toBeCloseTo(2.652582, 6);
+        expect(lc.result.resultElements[0].getValue("Jl")).toBeCloseTo(0.634482, 6);
+        expect(lc.result.resultElements[0].getValue("Kl")).toBeCloseTo(1.769215, 6);
+        expect(lc.result.resultElements[0].getValue("fD")).toBeCloseTo(0.021231, 6);
+    });
+
+    it("test 2", () => {
+        const lc = getLechaptWith(0.05, 0.5, 100, 1, LCMaterial.RolledSteelSmoothConcrete);
+        expect(lc.prms.J.singleValue).toBeCloseTo(0.015625, 6);
+        expect(lc.result.resultElements[0].getValue("V")).toBeCloseTo(0.254648, 6);
+        expect(lc.result.resultElements[0].getValue("Jl")).toBeCloseTo(0.012320, 6);
+        expect(lc.result.resultElements[0].getValue("Kl")).toBeCloseTo(3.727563, 6);
+        expect(lc.result.resultElements[0].getValue("fD")).toBeCloseTo(0.023638, 6);
+    });
+});
diff --git a/src/index.ts b/src/index.ts
index 5b315a80..6c8a97af 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -61,6 +61,7 @@ export * from "./pab/pab_puissance";
 export * from "./pab/pab_puissance_params";
 export * from "./pab/cloison_aval";
 export * from "./pipe_flow/pl_lechaptcalmon";
+export * from "./pipe_flow/pl_lechaptcalmon_params";
 export * from "./pipe_flow/pressureloss";
 export * from "./pipe_flow/pressureloss_law";
 export * from "./lc-material";
-- 
GitLab