From fcdf56f2700b3e67585c29f891b0506d1a0a68c7 Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Mon, 8 Feb 2021 18:33:26 +0100
Subject: [PATCH] feat(macrorugo): warning pour concentration hors 8-20%

Refs #284
---
 .../macrorugo_compound_jalhyd284.spec.ts      | 47 +++++++++++++++++++
 spec/macrorugo/macrorugo_jalhyd284.spec.ts    | 26 ++++++++++
 src/macrorugo/macrorugo.ts                    |  9 ++++
 src/macrorugo/macrorugo_compound.ts           |  6 +++
 src/util/message.ts                           |  3 ++
 5 files changed, 91 insertions(+)
 create mode 100644 spec/macrorugo/macrorugo_compound_jalhyd284.spec.ts
 create mode 100644 spec/macrorugo/macrorugo_jalhyd284.spec.ts

diff --git a/spec/macrorugo/macrorugo_compound_jalhyd284.spec.ts b/spec/macrorugo/macrorugo_compound_jalhyd284.spec.ts
new file mode 100644
index 00000000..1c6fe7ef
--- /dev/null
+++ b/spec/macrorugo/macrorugo_compound_jalhyd284.spec.ts
@@ -0,0 +1,47 @@
+import { CalculatorType } from "../../src/compute-node";
+import { MacrorugoCompound, MessageCode } from "../../src/index";
+import { MRCInclination } from "../../src/macrorugo/mrc-inclination";
+import { Props } from "../../src/props";
+import { Session } from "../../src/session";
+
+let nub: MacrorugoCompound;
+
+describe("MacroRugoCompound: ", () => {
+    beforeEach(() => {
+        nub = Session.getInstance().createNub(
+            new Props({ calcType: CalculatorType.MacroRugoCompound })
+        ) as MacrorugoCompound;
+        nub.properties.setPropValue("inclinedApron", MRCInclination.INCLINED);
+    });
+
+    describe("jalhyd #284 warnings about block concentration − ", () => {
+        it("case 1: no warnings", () => {
+            nub.prms.BR.singleValue = 3.328;
+            const res = nub.CalcSerie();
+            expect(res.log.messages.length).toBe(0);
+            // children should not have any width-related warning
+            for (const c of nub.children) {
+                for (const re of c.result.resultElements) {
+                    for (const m of re.log.messages) {
+                        expect(m.code).not.toBe(MessageCode.WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS);
+                    }
+                }
+            }
+        });
+        it("case 2: block concentration is out of bounds", () => {
+            nub.prms.BR.singleValue = 3.024;
+            nub.prms.C.singleValue = 0.07;
+            const res = nub.CalcSerie();
+            expect(res.log.messages.length).toBe(1);
+            expect(res.log.messages[0].code).toBe(MessageCode.WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS);
+            // children should not have any width-related warning
+            for (const c of nub.children) {
+                for (const re of c.result.resultElements) {
+                    for (const m of re.log.messages) {
+                        expect(m.code).not.toBe(MessageCode.WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS);
+                    }
+                }
+            }
+        });
+    });
+});
diff --git a/spec/macrorugo/macrorugo_jalhyd284.spec.ts b/spec/macrorugo/macrorugo_jalhyd284.spec.ts
new file mode 100644
index 00000000..e887a327
--- /dev/null
+++ b/spec/macrorugo/macrorugo_jalhyd284.spec.ts
@@ -0,0 +1,26 @@
+import { CalculatorType } from "../../src/compute-node";
+import { MessageCode } from "../../src/index";
+import { MacroRugo } from "../../src/macrorugo/macrorugo";
+import { Props } from "../../src/props";
+import { Session } from "../../src/session";
+
+let nub: MacroRugo;
+
+describe("Class MacroRugo: ", () => {
+    describe("jalhyd #284 warnings about block concentration - ", () => {
+        it("case 1: no warnings", () => {
+            nub = Session.getInstance().createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo;
+            nub.prms.B.singleValue = 1.109;
+            const res = nub.CalcSerie();
+            expect(res.log.messages.length).toBe(0);
+        });
+        it("case 2: concentration out of bounds", () => {
+            nub = Session.getInstance().createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo;
+            nub.prms.C.singleValue = 0.07;
+            nub.prms.B.singleValue = 3.024;
+            const res = nub.CalcSerie();
+            expect(res.log.messages.length).toBe(1);
+            expect(res.log.messages[0].code).toBe(MessageCode.WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS);
+        });
+    });
+});
diff --git a/src/macrorugo/macrorugo.ts b/src/macrorugo/macrorugo.ts
index 242f251f..1bde85f2 100644
--- a/src/macrorugo/macrorugo.ts
+++ b/src/macrorugo/macrorugo.ts
@@ -90,6 +90,15 @@ export class MacroRugo extends FishPass {
             }
         }
 
+        // La concentration est-elle dans les valeurs admissibles 8-20% (#284)
+        if (this.parent === undefined) {
+            if(this.prms.C.V < 0.08 || this.prms.C.V > 0.2) {
+                r.resultElement.log.add(
+                    new Message(MessageCode.WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS)
+                );
+            }
+        }
+
         // Ajout des résultats complémentaires
         // Cote de fond aval
         r.resultElement.values.ZF2 = this.prms.ZF1.v - this.prms.If.v * this.prms.L.v;
diff --git a/src/macrorugo/macrorugo_compound.ts b/src/macrorugo/macrorugo_compound.ts
index 25627f67..0d96cef5 100644
--- a/src/macrorugo/macrorugo_compound.ts
+++ b/src/macrorugo/macrorugo_compound.ts
@@ -112,6 +112,12 @@ export class MacrorugoCompound extends MacroRugo implements Observer {
                 this._result.resultElement.log.add(m);
             }
         }
+        // Check block concentration bounds
+        if(this.prms.C.v < 0.08 || this.prms.C.v > 0.2) {
+            this._result.resultElement.log.add(
+                new Message(MessageCode.WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS)
+            );
+        }
         return this._result;
     }
 
diff --git a/src/util/message.ts b/src/util/message.ts
index 9d5fb1f9..219d5ca5 100644
--- a/src/util/message.ts
+++ b/src/util/message.ts
@@ -563,6 +563,9 @@ export enum MessageCode {
     /** Macrorugo : la largeur de la rampe devrait être un multiple de la demie-largeur d'un motif de plot */
     WARNING_RAMP_WIDTH_NOT_MULTIPLE_OF_HALF_PATTERN_WIDTH,
 
+    //** MacroRugo : concentration des blocs hors 8-20% */
+    WARNING_MACRORUGO_CONCENTRATION_OUT_OF_BOUNDS,
+
     /** section : le tirant d'eau dépasse la hauteur de berge */
     WARNING_SECTION_OVERFLOW,
 
-- 
GitLab