From 7fd6e4469b0cc34024cbeb751ed88c897def54bf Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Tue, 23 Jan 2024 16:56:24 +0100 Subject: [PATCH] HS: Basic: Add CheckValve hydraulic structure and VAR export. --- src/Model/HydraulicStructures/Basic/Types.py | 14 +++--- src/Solver/Mage.py | 46 +++++++++++++++++++- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/Model/HydraulicStructures/Basic/Types.py b/src/Model/HydraulicStructures/Basic/Types.py index 96fde7eb..4b4cddd6 100644 --- a/src/Model/HydraulicStructures/Basic/Types.py +++ b/src/Model/HydraulicStructures/Basic/Types.py @@ -205,11 +205,13 @@ class CheckValve(BasicHS): self._type = "CV" self._data = [ - BHSValue("parameter_1", float, 0.0, status=status), - BHSValue("parameter_2", float, 0.0, status=status), - BHSValue("parameter_3", float, 0.0, status=status), - BHSValue("parameter_4", float, 0.0, status=status), - BHSValue("parameter_5", float, 0.0, status=status), + BHSValue("width", float, 0.0, status=status), + BHSValue("elevation", float, 0.0, status=status), + BHSValue("loading_elevation", float, 9999.999, + status=status), + BHSValue("discharge_coefficient", float, 0.4, status=status), + BHSValue("maximal_loading_elevation", float, 9999.999, + status=status), ] @@ -242,6 +244,6 @@ BHS_types = { "V1": RectangularGate, "V2": SimplifiedRectangularGate, "BO": Borda, - # "VC": CheckValve, + "CV": CheckValve, "UD": UserDefined } diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index 2189e7bf..5f5b80fa 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -458,6 +458,7 @@ class Mage(CommandLineSolver): "ND": "*", "S1": "D", "S2": "T", "S3": "T", "OR": "O", "OC": "B", "OV": "F", + "CV": "O", # CheckValve "V1": "V", "V2": "W", "BO": "A", "UD": "X", @@ -496,10 +497,14 @@ class Mage(CommandLineSolver): ] ) + name = bhs.name + if name == "": + name = f"HS_{bhs.id:>3}".replace(" ", "0") + f.write( f"{sin_dict[bhs._type]} " + f"{reach_id} {hs.input_kp:>12.3f} {param_str} " + - f"{bhs.name}\n" + f"{name}\n" ) return files @@ -517,7 +522,7 @@ class Mage(CommandLineSolver): return res def _export_SIN_parameters_5(self, bhs): - # S2, OR, V1, V2, UD + # S2, OR, V1, V2, UD, CV return [ bhs._data[0].value, bhs._data[1].value, @@ -562,6 +567,42 @@ class Mage(CommandLineSolver): return res + @timer + def _export_VAR(self, study, repertory, qlog, name="0"): + files = [] + + hydraulic_structures = study.river.hydraulic_structures.lst + if len(hydraulic_structures) == 0: + return files + + if qlog is not None: + qlog.put("Export VAR file") + + with mage_file_open(os.path.join(repertory, f"{name}.VAR"), "w+") as f: + files.append(f"{name}.VAR") + + for hs in hydraulic_structures: + if hs.input_reach is None: + continue + + if not hs.input_reach.is_enable(): + continue + + for bhs in hs.basic_structures: + logger.info(bhs._type) + if bhs._type != "CV" : + continue + + name = bhs.name + if name == "": + name = f"HS_{bhs.id:>3}".replace(" ", "0") + + f.write( + f"${name} clapet" + ) + + return files + @timer def _export_DEV(self, study, repertory, qlog, name="0"): files = [] @@ -835,6 +876,7 @@ class Mage8(Mage): files = files + self._export_RUG(study, repertory, qlog, name=name) files = files + self._export_INI(study, repertory, qlog, name=name) files = files + self._export_SIN(study, repertory, qlog, name=name) + files = files + self._export_VAR(study, repertory, qlog, name=name) files = files + self._export_CAS(study, repertory, qlog, name=name) files = files + self._export_DEV(study, repertory, qlog, name=name) self._export_REP(study, repertory, files, qlog, name=name) -- GitLab