From 05fc70f2c342349c93ebda385d9aeec0d9c09ab0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 22 Mar 2023 15:33:37 +0100
Subject: [PATCH] feat: add error message to weir structure when submergence
 percentage is low (Larinier, Rajaratnam)

refs #302
---
 src/structure/parallel_structure.ts |  9 ++++++++-
 src/structure/structure.ts          | 20 ++++++++++++++++++++
 src/util/message.ts                 |  5 +++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts
index e22531ae..2a17ac83 100644
--- a/src/structure/parallel_structure.ts
+++ b/src/structure/parallel_structure.ts
@@ -74,7 +74,14 @@ export class ParallelStructure extends Nub {
             this._result.globalLog.insert(new Message(MessageCode.ERROR_STRUCTURE_AU_MOINS_UNE));
             return this._result;
         }
-        return super.CalcSerie(rInit);
+        const res = super.CalcSerie(rInit);
+
+        // check structures submergence for some discharge laws
+        for (const st of this.structures) {
+            st.checkSubmergence();
+        }
+
+        return res;
     }
 
     /**
diff --git a/src/structure/structure.ts b/src/structure/structure.ts
index 09e64c33..3f5b891a 100644
--- a/src/structure/structure.ts
+++ b/src/structure/structure.ts
@@ -77,6 +77,26 @@ export abstract class Structure extends ChildNub {
         return 100;
     }
 
+    private checkSubmergenceMin(loi: LoiDebit, min: number) {
+        if (this.loiDebit === loi) {
+            const h2h1ratio = this.prms.h2.v / this.prms.h1.v;
+            if (h2h1ratio < min) {
+                this._result.resultElement.addMessage(new Message(
+                    MessageCode.ERROR_STRUCTURE_SUBMERGENCE_LOWER_THAN,
+                    {
+                        submergencePerc: this.computeSubmergencePercentage().toString(),
+                        min: min
+                    }
+                ));
+            }
+        }
+    }
+
+    public checkSubmergence() {
+        this.checkSubmergenceMin(LoiDebit.WeirSubmergedLarinier, 0.5);
+        this.checkSubmergenceMin(LoiDebit.WeirSubmerged, 0.6);
+    }
+
     /** Constante utile : Racine de 2g */
     protected static readonly R2G: number = Math.sqrt(2 * 9.81);
 
diff --git a/src/util/message.ts b/src/util/message.ts
index 7f5e56d0..77253f68 100644
--- a/src/util/message.ts
+++ b/src/util/message.ts
@@ -512,6 +512,11 @@ export enum MessageCode {
      */
     ERROR_STRUCTURE_Z_EGAUX_Q_NON_NUL,
 
+    /**
+     * Structure : l'ennoiement %submergencePerc% est inférieur à %min%
+     */
+    ERROR_STRUCTURE_SUBMERGENCE_LOWER_THAN,
+
     /**
      * Il faut au moins un ouvrage dans une structure
      */
-- 
GitLab