diff --git a/src/Solver/RubarBE.py b/src/Solver/RubarBE.py index ed697e23..52ae75bb 100644 --- a/src/Solver/RubarBE.py +++ b/src/Solver/RubarBE.py @@ -220,7 +220,7 @@ class Rubar3(CommandLineSolver): def _hydraulic_data(self, study, values): """Check the single reach data needed by DONNEE, MAIL, CONDIN, - FROT, HYDRO, HAMONT and CONDAV, and return them. Raise + FROT, HYDRO and CONDAV, and return them. Raise RubarExportError with a user message""" trad = RunSolverTranslate() river = study.river @@ -240,9 +240,7 @@ class Rubar3(CommandLineSolver): reach=edge.name)) warnings = [] - boundaries = self._check_boundaries( - river, edge, values, warnings - ) + boundaries = self._check_boundaries(river, edge, values) return { "edge": edge, @@ -260,9 +258,9 @@ class Rubar3(CommandLineSolver): return float(old_pamhyr_date_to_timestamp(value)) return float(value) - def _check_boundaries(self, river, edge, values, warnings): + def _check_boundaries(self, river, edge, values): """Liquid boundary conditions used for CONDAM, REGIME and CONDAV. - Return {'hydro': bc, 'hamont': bc, 'condav': bc} (or None)""" + Return {'hydro': bc, 'condav': bc} (or None)""" trad = RunSolverTranslate() condam = values.get("rubarbe_condam", "") condav = values.get("rubarbe_condav", "") @@ -275,6 +273,17 @@ class Rubar3(CommandLineSolver): raise RubarExportError(trad["boundary_code_unsupported"].format( key="rubarbe_condav", value=condav)) + # rubar_init.f90 reads HAMONT only when REGIME=1 and the + # computation never uses its values (HIMP, TA, NT3); CONDAM=2 reads + # no upstream level at all. The upstream level would be silently + # ignored: refuse both settings. + for key, value, unsupported in (("REGIME", regime, "1"), + ("CONDAM", condam, "2")): + if value == unsupported: + raise RubarExportError( + trad["upstream_level_unsupported"].format( + setting=f"{key}={value}")) + liquid = [ bc for bc in river.boundary_condition.get_tab("liquid") if not bc.is_deleted() and bc.bctype in self._boundary_kinds @@ -283,13 +292,9 @@ class Rubar3(CommandLineSolver): def at(node): return [bc for bc in liquid if bc.node == node] - upstream_types = list(self._upstream_types[condam]) - if regime == "1": - upstream_types.append("TZ") upstream = self._select_boundaries( - at(edge.node1), upstream_types, edge.node1, - {"TD": f"CONDAM={condam}", "TZ": "REGIME=1"}, - f"CONDAM={condam}, REGIME={regime}" + at(edge.node1), self._upstream_types[condam], edge.node1, + {"TD": f"CONDAM={condam}"}, f"CONDAM={condam}" ) downstream = self._select_boundaries( at(edge.node2), self._downstream_types[condav], edge.node2, @@ -297,14 +302,8 @@ class Rubar3(CommandLineSolver): f"CONDAV={condav}" ) - # rubar_init.f90: HAMONT is read when REGIME=1, but the 2021 - # code never uses it; CONDAM=2 reads no upstream level at all - if regime == "1" or condam == "2": - warnings.append(trad["upstream_level_unused"]) - return { "hydro": upstream.get("TD"), - "hamont": upstream.get("TZ"), "condav": downstream.get("ZD", downstream.get("TZ")), } @@ -818,9 +817,10 @@ class Rubar3(CommandLineSolver): self._write_parameters(repertory, f"condin.{name}", lines) def _export_boundaries(self, hydraulics, repertory, qlog, name="0"): - """HYDRO (Q, t), HAMONT (Z, t) and CONDAV ((Q, Z) for a rating - curve, (t, Z) for a Z(t) condition), notice annex 1. A file is - written only when the matching condition is used""" + """HYDRO (Q, t) and CONDAV ((Q, Z) for a rating curve, (t, Z) for + a Z(t) condition), notice annex 1. A file is written only when the + matching condition is used. HAMONT is not written: REGIME=1 and + CONDAM=2 are refused (see _check_boundaries)""" bcs = hydraulics["boundaries"] def records(bc, columns): @@ -831,10 +831,6 @@ class Rubar3(CommandLineSolver): files.append(("hydro", bcs["hydro"], lambda t, q: f"{float(q)!r} {float(t)!r}\n", lambda n: f"{n}\n")) - if bcs["hamont"] is not None: - files.append(("hamont", bcs["hamont"], - lambda t, z: f"{float(z):15.6f} {float(t):15.6f}\n", - lambda n: f"{n:>6}\n")) if bcs["condav"] is not None: bc = bcs["condav"] if bc.bctype == "ZD": diff --git a/src/View/RunSolver/Translate.py b/src/View/RunSolver/Translate.py index dce8b5eb..72e663f2 100644 --- a/src/View/RunSolver/Translate.py +++ b/src/View/RunSolver/Translate.py @@ -101,10 +101,11 @@ class RunSolverTranslate(PamhyrTranslate): "Export cancelled: the times of boundary condition {name} at " "node {node} must be increasing." ) - self._dict["upstream_level_unused"] = _translate( + self._dict["upstream_level_unsupported"] = _translate( "Solver", - "The upstream water level (REGIME=1 or CONDAM=2) is not used " - "by the current RubarBE version: the computation ignores it." + "Export cancelled: {setting} imposes an upstream water level, " + "which the current RubarBE version reads but does not use in " + "the computation. Choose another upstream boundary setting." ) self._dict["missing_friction"] = _translate( "Solver",