From fe4ae467840aaf230a33c4fea5b1769010650a75 Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Thu, 19 Sep 2024 10:03:44 +0200 Subject: [PATCH] work on initial conditions --- .../InitialConditions/InitialConditions.py | 35 +++++--- src/View/InitialConditions/DialogHeight.py | 23 +++++- src/View/InitialConditions/UndoCommand.py | 5 +- src/View/InitialConditions/Window.py | 3 +- ...itialConditions_Dialog_Generator_Height.ui | 82 ++++++++++++++++--- src/View/ui/Results.ui | 2 +- 6 files changed, 121 insertions(+), 29 deletions(-) diff --git a/src/Model/InitialConditions/InitialConditions.py b/src/Model/InitialConditions/InitialConditions.py index c16c87ac..82756070 100644 --- a/src/Model/InitialConditions/InitialConditions.py +++ b/src/Model/InitialConditions/InitialConditions.py @@ -21,6 +21,7 @@ import logging from copy import copy, deepcopy from tools import trace, timer from functools import reduce +from numpy import interp from Model.Tools.PamhyrDB import SQLSubModel @@ -492,25 +493,39 @@ class InitialConditions(SQLSubModel): self._generate_resort_data(profiles) - def generate_height(self, elevation: float): + def generate_height(self, + elevation1: float, + elevation2: float, + compute_discharge: bool, + discharge: float): profiles = self._reach.reach.profiles.copy() + upstream_rk = profiles[0].rk + downstream_rk = profiles[-1].rk data_discharge = {} - if len(self._data) == 0: - for profile in profiles: - data_discharge[profile.rk] = 0.0 - else: - for data in self._data: - data_discharge[data["rk"]] = data["discharge"] + if not compute_discharge: + if len(self._data) == 0: + for profile in profiles: + data_discharge[profile.rk] = 0.0 + else: + for data in self._data: + data_discharge[data["rk"]] = data["discharge"] + self._data = [] for profile in profiles: + + if not compute_discharge: + d = data_discharge[profile.rk] + else: + d = discharge + elevation = interp(profile.rk, + [upstream_rk, downstream_rk], + [elevation1, elevation2]) new = Data(reach=self._reach, status=self._status) new["rk"] = profile.rk - new["discharge"] = data_discharge[profile.rk] + new["discharge"] = d new["elevation"] = elevation self._data.append(new) - self._generate_resort_data(profiles) - def _generate_resort_data(self, profiles): is_reverse = False if profiles[0].rk > profiles[-1].rk: diff --git a/src/View/InitialConditions/DialogHeight.py b/src/View/InitialConditions/DialogHeight.py index e835716d..f65bf24f 100644 --- a/src/View/InitialConditions/DialogHeight.py +++ b/src/View/InitialConditions/DialogHeight.py @@ -28,7 +28,7 @@ from PyQt5.QtCore import ( from PyQt5.QtWidgets import ( QDialogButtonBox, QComboBox, QUndoStack, QShortcut, - QDoubleSpinBox + QDoubleSpinBox, QCheckBox, QLabel ) @@ -44,10 +44,27 @@ class HeightDialog(PamhyrDialog): parent=parent ) - self.value = None + self.value = [None, None, None] + self.option = None + self.find(QCheckBox, "checkBox").clicked.connect( + self.enable_discharge + ) + + def enable_discharge(self): + cb = self.find(QCheckBox, "checkBox") + dsb = self.find(QDoubleSpinBox, "doubleSpinBox_3") + l = self.find(QLabel, "label_3") + dsb.setEnabled(cb.isChecked()) + l.setEnabled(cb.isChecked()) def accept(self): - self.value = self.find(QDoubleSpinBox, "doubleSpinBox").value() + self.value[0] = self.find(QDoubleSpinBox, "doubleSpinBox_1").value() + self.value[1] = self.find(QDoubleSpinBox, "doubleSpinBox_2").value() + self.option = self.find(QCheckBox, "checkBox").isChecked() + if self.option: + self.value[2] = self.find(QDoubleSpinBox, "doubleSpinBox_3").value() + else: + self.value[2] = None super().accept() def reject(self): diff --git a/src/View/InitialConditions/UndoCommand.py b/src/View/InitialConditions/UndoCommand.py index b461e643..64fb1a37 100644 --- a/src/View/InitialConditions/UndoCommand.py +++ b/src/View/InitialConditions/UndoCommand.py @@ -194,4 +194,7 @@ class GenerateCommand(QUndoCommand): self._ics.generate_discharge(self._param, self._option) elif self._generator == "height": - self._ics.generate_height(self._param) + self._ics.generate_height(self._param[0], + self._param[1], + self._option, + self._param[2]) diff --git a/src/View/InitialConditions/Window.py b/src/View/InitialConditions/Window.py index 739f4974..5c6589e6 100644 --- a/src/View/InitialConditions/Window.py +++ b/src/View/InitialConditions/Window.py @@ -370,5 +370,6 @@ class InitialConditionsWindow(PamhyrWindow): dlg = HeightDialog(trad=self._trad, parent=self) if dlg.exec(): value = dlg.value - self._table.generate("height", value, None) + compute_discharge = dlg.option + self._table.generate("height", value, compute_discharge) self._update() diff --git a/src/View/ui/InitialConditions_Dialog_Generator_Height.ui b/src/View/ui/InitialConditions_Dialog_Generator_Height.ui index 40e9cd9b..ee015bd1 100644 --- a/src/View/ui/InitialConditions_Dialog_Generator_Height.ui +++ b/src/View/ui/InitialConditions_Dialog_Generator_Height.ui @@ -6,8 +6,8 @@ 0 0 - 284 - 80 + 396 + 182 @@ -17,7 +17,70 @@ + + + + + + Upstream Height (m) + + + + + + + -1000000.000000000000000 + + + 1000000.000000000000000 + + + + + + + + + + + false + + + Discharge + + + + + + + false + + + + + + + + + + Downstream Height (m) + + + + + + + -1000000.000000000000000 + + + 0.000000000000000 + + + + + + Qt::Horizontal @@ -27,19 +90,12 @@ - - + + - + - Height (m) - - - - - - - 1000000.000000000000000 + Generate Constant Discharge diff --git a/src/View/ui/Results.ui b/src/View/ui/Results.ui index 256ab368..1b4a93ee 100644 --- a/src/View/ui/Results.ui +++ b/src/View/ui/Results.ui @@ -132,7 +132,7 @@ - 0 + 1 true