add generate constant height in IC

compare_results
Theophile Terraz 2024-09-18 17:22:26 +02:00
parent c698f2af2b
commit 8250efcd62
8 changed files with 205 additions and 26 deletions

View File

@ -374,8 +374,8 @@ class InitialConditions(SQLSubModel):
key=lambda p: p.rk
)
def generate_growing_constante_height(self, height: float,
compute_discharge: bool):
def generate_growing_constant_depth(self, height: float,
compute_discharge: bool):
profiles = self._reach.reach.profiles.copy()
self._sort_by_z_and_rk(profiles)
@ -492,6 +492,25 @@ class InitialConditions(SQLSubModel):
self._generate_resort_data(profiles)
def generate_height(self, elevation: float):
profiles = self._reach.reach.profiles.copy()
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"]
self._data = []
for profile in profiles:
new = Data(reach=self._reach, status=self._status)
new["rk"] = profile.rk
new["discharge"] = data_discharge[profile.rk]
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:

View File

@ -0,0 +1,56 @@
# DialogDepth.py -- Pamhyr
# Copyright (C) 2023-2024 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from View.Tools.PamhyrWindow import PamhyrDialog
from PyQt5.QtGui import (
QKeySequence,
)
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
)
from PyQt5.QtWidgets import (
QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
QDoubleSpinBox, QCheckBox,
)
class DepthDialog(PamhyrDialog):
_pamhyr_ui = "InitialConditions_Dialog_Generator_Depth"
_pamhyr_name = "Depth"
def __init__(self, trad=None, parent=None):
super(DepthDialog, self).__init__(
title=trad[self._pamhyr_name],
options=[],
trad=trad,
parent=parent
)
self.value = None
self.option = None
def accept(self):
self.value = self.find(QDoubleSpinBox, "doubleSpinBox").value()
self.option = self.find(QCheckBox, "checkBox").isChecked()
super().accept()
def reject(self):
self.close()

View File

@ -28,7 +28,7 @@ from PyQt5.QtCore import (
from PyQt5.QtWidgets import (
QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
QDoubleSpinBox, QCheckBox,
QDoubleSpinBox
)
@ -45,11 +45,9 @@ class HeightDialog(PamhyrDialog):
)
self.value = None
self.option = None
def accept(self):
self.value = self.find(QDoubleSpinBox, "doubleSpinBox").value()
self.option = self.find(QCheckBox, "checkBox").isChecked()
super().accept()
def reject(self):

View File

@ -188,8 +188,10 @@ class GenerateCommand(QUndoCommand):
def redo(self):
if self._generator == "growing":
self._ics.generate_growing_constante_height(self._param,
self._option)
self._ics.generate_growing_constant_depth(self._param,
self._option)
elif self._generator == "discharge":
self._ics.generate_discharge(self._param,
self._option)
elif self._generator == "height":
self._ics.generate_height(self._param)

View File

@ -58,6 +58,7 @@ from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
from View.InitialConditions.PlotDRK import PlotDRK
from View.InitialConditions.PlotDischarge import PlotDischarge
from View.InitialConditions.translate import ICTranslate
from View.InitialConditions.DialogDepth import DepthDialog
from View.InitialConditions.DialogHeight import HeightDialog
from View.InitialConditions.DialogDischarge import DischargeDialog
from View.Results.ReadingResultsDialog import ReadingResultsDialog
@ -174,13 +175,17 @@ class InitialConditionsWindow(PamhyrWindow):
.connect(self.import_from_file)
self.find(QPushButton, "pushButton_generate_1").clicked.connect(
self.generate_growing_constante_height
self.generate_growing_constant_depth
)
self.find(QPushButton, "pushButton_generate_2").clicked.connect(
self.generate_discharge
)
self.find(QPushButton, "pushButton_generate_3").clicked.connect(
self.generate_height
)
self._table.dataChanged.connect(self._update_plot)
def index_selected_row(self):
@ -345,8 +350,8 @@ class InitialConditionsWindow(PamhyrWindow):
self._table.redo()
self._update()
def generate_growing_constante_height(self):
dlg = HeightDialog(trad=self._trad, parent=self)
def generate_growing_constant_depth(self):
dlg = DepthDialog(trad=self._trad, parent=self)
if dlg.exec():
value = dlg.value
compute_discharge = dlg.option
@ -357,6 +362,13 @@ class InitialConditionsWindow(PamhyrWindow):
dlg = DischargeDialog(trad=self._trad, parent=self)
if dlg.exec():
value = dlg.value
compute_height = dlg.option
self._table.generate("discharge", value, compute_height)
compute_depth = dlg.option
self._table.generate("discharge", value, compute_depth)
self._update()
def generate_height(self):
dlg = HeightDialog(trad=self._trad, parent=self)
if dlg.exec():
value = dlg.value
self._table.generate("height", value, None)
self._update()

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<width>849</width>
<height>576</height>
</rect>
</property>
@ -27,7 +27,7 @@
<item>
<widget class="QPushButton" name="pushButton_generate_1">
<property name="text">
<string>Generate height</string>
<string>Generate depth</string>
</property>
</widget>
</item>
@ -38,6 +38,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_generate_3">
<property name="text">
<string>Generate elevation</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -65,7 +72,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<width>849</width>
<height>22</height>
</rect>
</property>

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>284</width>
<height>107</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="locale">
<locale language="English" country="Europe"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Depth (m)</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Generate discharge</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -17,7 +17,7 @@
<locale language="English" country="Europe"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -45,16 +45,6 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Generate discharge</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>