From cd2fda82249e04fe253f4876ee72f352b23d4ab4 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 13 Dec 2023 16:30:18 +0100
Subject: [PATCH] HS, Mage: Rewrite some code for coding style.

---
 src/Model/HydraulicStructures/Basic/Types.py |  34 ++---
 src/Solver/Mage.py                           | 131 +++++++++----------
 2 files changed, 76 insertions(+), 89 deletions(-)

diff --git a/src/Model/HydraulicStructures/Basic/Types.py b/src/Model/HydraulicStructures/Basic/Types.py
index ce80678c..1d1d0930 100644
--- a/src/Model/HydraulicStructures/Basic/Types.py
+++ b/src/Model/HydraulicStructures/Basic/Types.py
@@ -125,22 +125,22 @@ class OrificeCirculaire(BasicHS):
         ]
 
 
-#class OrificeVoute(BasicHS):
-    #def __init__(self, id: int = -1, name: str = "",
-                 #status=None):
-        #super(OrificeVoute, self).__init__(
-            #id=id, name=name,
-            #status=status
-        #)
-
-        #self._type = "OV"
-        #self._data = [
-            #BHSValue("Cote", float, 1.0, status=status),
-            #BHSValue("Largeur", float, 1.0, status=status),
-            #BHSValue("Haut de la voute", float, 0.0, status=status),
-            #BHSValue("Bas de la voute", float, 0.0, status=status),
-            #BHSValue("Coefficient de debit", float, 0.4, status=status),
-        #]
+# class OrificeVoute(BasicHS):
+#     def __init__(self, id: int = -1, name: str = "",
+#                  status=None):
+#         super(OrificeVoute, self).__init__(
+#             id=id, name=name,
+#             status=status
+#         )
+
+#         self._type = "OV"
+#         self._data = [
+#             BHSValue("Cote", float, 1.0, status=status),
+#             BHSValue("Largeur", float, 1.0, status=status),
+#             BHSValue("Haut de la voute", float, 0.0, status=status),
+#             BHSValue("Bas de la voute", float, 0.0, status=status),
+#             BHSValue("Coefficient de debit", float, 0.4, status=status),
+#         ]
 
 
 class VanneRectangulaire(BasicHS):
@@ -220,7 +220,7 @@ BHS_types = {
     "S3": SeuilTriangulaire,
     "OR": OrificeRectangulaire,
     "OC": OrificeCirculaire,
-    #"OV": OrificeVoute,
+    # "OV": OrificeVoute,
     "V1": VanneRectangulaire,
     "V2": VanneRectangulaireSimplifiee,
     "BO": Borda,
diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py
index adb53886..53646213 100644
--- a/src/Solver/Mage.py
+++ b/src/Solver/Mage.py
@@ -31,77 +31,6 @@ from Model.Results.River.River import River, Reach, Profile
 logger = logging.getLogger()
 
 
-def mage_param(bhs):
-    params = []
-
-    if bhs._type == "S1": # D
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  0.0,
-                  bhs._data[2].value,
-                  9999.999,
-                  ]
-    elif bhs._type == "S2": # T
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  bhs._data[4].value,
-                  ]
-    elif bhs._type == "S3": # T
-        params = [0.0,bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  ]
-    elif bhs._type == "OR": # O
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  bhs._data[4].value,
-                  ]
-    elif bhs._type == "OC": # B
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  0.0,
-                  ]
-    elif bhs._type == "V1": # V
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  bhs._data[4].value,
-                  ]
-    elif bhs._type == "V2": # W
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  bhs._data[4].value,
-                  ]
-    elif bhs._type == "BO": # B
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  0.0,
-                  0.0,
-                  ]
-    elif bhs._type == "UD": # X
-        params = [bhs._data[0].value,
-                  bhs._data[1].value,
-                  bhs._data[2].value,
-                  bhs._data[3].value,
-                  bhs._data[4].value,
-                  ]
-    else:
-        params = [9999.999]*5
-
-    return params
-
-
 def mage_file_open(filepath, mode):
     f = open(filepath, mode)
 
@@ -549,7 +478,7 @@ class Mage(CommandLineSolver):
                         param_str = ' '.join(
                             [
                                 f'{p:>10.3f}'
-                                for p in mage_param(bhs)
+                                for p in self._export_SIN_parameters(bhs)
                             ]
                         )
 
@@ -561,6 +490,64 @@ class Mage(CommandLineSolver):
 
         return files
 
+    def _export_SIN_parameters(self, bhs):
+        res = [9999.999]*5
+
+        if len(bhs) == 5:
+            res = self._export_SIN_parameters_5(bhs)
+        elif len(bhs) == 4:
+            res = self._export_SIN_parameters_4(bhs)
+        elif len(bhs) == 3:
+            res = self._export_SIN_parameters_3(bhs)
+
+        return res
+
+    def _export_SIN_parameters_5(self, bhs):
+        # S2, OR, V1, V2, UD
+        return [
+            bhs._data[0].value,
+            bhs._data[1].value,
+            bhs._data[2].value,
+            bhs._data[3].value,
+            bhs._data[4].value,
+        ]
+
+    def _export_SIN_parameters_4(self, bhs):
+        # S3, OC
+        res = [
+            bhs._data[0].value,
+            bhs._data[1].value,
+            bhs._data[2].value,
+            bhs._data[3].value,
+            0.0,
+        ]
+
+        if bhs._type == "T":    # S3
+            res = [0.0] + res[:-1]
+
+        return res
+
+    def _export_SIN_parameters_3(self, bhs):
+        # S1, BO
+        if bhs._type == "S1":
+            res = [
+                bhs._data[0].value,
+                bhs._data[1].value,
+                0.0,
+                bhs._data[2].value,
+                9999.99,
+            ]
+        else:
+            res = [
+                bhs._data[0].value,
+                bhs._data[1].value,
+                bhs._data[2].value,
+                0.0,
+                0.0,
+            ]
+
+        return res
+
     @timer
     def _export_DEV(self, study, repertory, qlog, name="0"):
         files = []
-- 
GitLab