From a181f04f3928e36099147e144fea0fe1119aae00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Tue, 9 May 2023 12:51:16 +0200
Subject: [PATCH] fix: inhibit submergence error during computed parameter
 computation in predams Calc()

refs #302
---
 src/dichotomie.ts             |  2 +-
 src/prebarrage/pre_barrage.ts | 13 ++++++++++++-
 src/structure/structure.ts    |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/dichotomie.ts b/src/dichotomie.ts
index e748417c..140cc546 100644
--- a/src/dichotomie.ts
+++ b/src/dichotomie.ts
@@ -73,7 +73,7 @@ export class Dichotomie extends Debug {
         this._startIntervalMaxSteps = n;
     }
 
-    public static get inDico(): boolean {
+    public static get inDicho(): boolean {
         return Dichotomie._inDicho > 0;
     }
 
diff --git a/src/prebarrage/pre_barrage.ts b/src/prebarrage/pre_barrage.ts
index cf57be9e..db125335 100644
--- a/src/prebarrage/pre_barrage.ts
+++ b/src/prebarrage/pre_barrage.ts
@@ -1,4 +1,4 @@
-import { Nub } from "../internal_modules";
+import { Nub, Structure } from "../internal_modules";
 import { ParamCalculability, ParamDefinition } from "../internal_modules";
 import { Result } from "../internal_modules";
 import { PreBarrageParams } from "../internal_modules";
@@ -333,7 +333,18 @@ export class PreBarrage extends Nub {
             return this.result;
         }
 
+        for (const c of this._children) {
+            if (c instanceof PbCloison) {
+                c.inhibitSubmergenceError = true;
+            }
+        }
         const res = super.Calc(sVarCalc, rInit);
+        for (const c of this._children) {
+            if (c instanceof PbCloison) {
+                c.inhibitSubmergenceError = false;
+            }
+        }
+
         // calculate basins so that they have a proper .result
         for (const b of this._bassins) {
             b.Calc();
diff --git a/src/structure/structure.ts b/src/structure/structure.ts
index 763bcb45..7cb91b8c 100644
--- a/src/structure/structure.ts
+++ b/src/structure/structure.ts
@@ -83,7 +83,7 @@ export abstract class Structure extends ChildNub {
      */
     protected checkSubmergenceMin(res: Result, min: number) {
         // on fait le test si on est pas dans un calcul par dichotomie
-        if (!Dichotomie.inDico && !(this.parent as ParallelStructure)?.inhibitSubmergenceError) {
+        if (!Dichotomie.inDicho && !(this.parent as ParallelStructure)?.inhibitSubmergenceError) {
             const h2h1ratio = this.prms.h2.v / this.prms.h1.v;
             if (h2h1ratio < min) {
                 res.resultElement.addMessage(new Message(
-- 
GitLab