mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
11
Commits
opt-result
...
v2.0.0rc5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49eb28056e | ||
|
|
5fb36e7fbe | ||
|
|
71914fdf57 | ||
|
|
2d7409debb | ||
|
|
92fb653676 | ||
|
|
defcb3af84 | ||
|
|
5cf0a0ec76 | ||
|
|
1c44590def | ||
|
|
c09c62f077 | ||
|
|
7a2e93a995 | ||
|
|
cfbc2d96a1 |
No files matched your search
@@ -57,6 +57,13 @@ class InternalMeshing(AMeshingTool):
|
||||
|
||||
# we never modify original profiles, we work on the copies
|
||||
m_profiles = self.st_to_m(profiles, guide_list)
|
||||
|
||||
# Adapt the spacing to the kilometre-point direction. The value from
|
||||
# the dialog is a distance, so only its magnitude is significant.
|
||||
step = self.signed_step(
|
||||
step, m_profiles[0].rk, m_profiles[-1].rk
|
||||
)
|
||||
|
||||
new_profiles = self.interpolate_transversal_step(m_profiles, step)
|
||||
|
||||
for new_profiles2 in new_profiles:
|
||||
@@ -65,6 +72,12 @@ class InternalMeshing(AMeshingTool):
|
||||
|
||||
return new_profiles
|
||||
|
||||
@staticmethod
|
||||
def signed_step(step, begin_rk, end_rk):
|
||||
if end_rk < begin_rk:
|
||||
return -abs(step)
|
||||
return abs(step)
|
||||
|
||||
def st_to_m(self, profiles, guide_list):
|
||||
guide_list = ["un"] + guide_list + ["np"]
|
||||
max_values = [0] * (len(guide_list) - 1)
|
||||
|
||||
@@ -95,12 +95,11 @@ class PointXYZ(Point):
|
||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
if major == "0" and minor == "2":
|
||||
if int(release) < 5:
|
||||
execute(
|
||||
"CREATE INDEX idx_point " +
|
||||
"ON geometry_pointXYZ(profile, scenario);"
|
||||
)
|
||||
# Try to create index at each update
|
||||
execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_point " +
|
||||
"ON geometry_pointXYZ(profile, scenario);"
|
||||
)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
|
||||
@@ -158,11 +158,15 @@ class CommandLineSolver(AbstractSolver):
|
||||
txt = add_file.text
|
||||
txt = txt.replace("@version", get_version())
|
||||
txt = txt.replace("@date", datetime.now().isoformat(sep=" "))
|
||||
txt = self._prepare_additional_file_text(add_file.path, txt)
|
||||
|
||||
f.write(txt)
|
||||
|
||||
return files
|
||||
|
||||
def _prepare_additional_file_text(self, path, text):
|
||||
return text
|
||||
|
||||
def export_study_description(self, study, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
||||
|
||||
+21
-2
@@ -407,7 +407,7 @@ class Mage(CommandLineSolver):
|
||||
# name = f"Reach_{lateral.reach.id + 1:>3}".replace(" ", "0")
|
||||
f.write(f"* {lateral.reach.name} ({name}) {lateral.lctype}\n")
|
||||
f.write(
|
||||
f"${name} " +
|
||||
f"${name} " +
|
||||
f"{lateral.begin_rk:>10.4f} {lateral.end_rk:>10.4f}\n"
|
||||
)
|
||||
header = lateral.header
|
||||
@@ -679,6 +679,23 @@ class Mage(CommandLineSolver):
|
||||
|
||||
return res
|
||||
|
||||
def _prepare_additional_file_text(self, path, text):
|
||||
if os.path.splitext(path)[1].lower() != ".var":
|
||||
return text
|
||||
|
||||
lines = []
|
||||
for line in text.splitlines(keepends=True):
|
||||
stripped = line.lstrip()
|
||||
fields = stripped.split()
|
||||
if stripped.startswith("$"):
|
||||
# MAGE only recognizes rule markers in the first column.
|
||||
line = stripped
|
||||
elif (not stripped.startswith("*") and len(fields) >= 2
|
||||
and fields[1] == "W2Z"):
|
||||
line = "$ " + stripped
|
||||
lines.append(line)
|
||||
return "".join(lines)
|
||||
|
||||
def _export_VAR(self, study, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
||||
@@ -729,9 +746,11 @@ class Mage(CommandLineSolver):
|
||||
name = bhs.name
|
||||
if name == "":
|
||||
name = f"HS_{bhs.id:>3}".replace(" ", "0")
|
||||
else:
|
||||
name = name.replace(" ", "_")
|
||||
|
||||
f.write(
|
||||
f"${name} clapet"
|
||||
f"${name} clapet\n"
|
||||
)
|
||||
return files
|
||||
|
||||
|
||||
@@ -143,21 +143,43 @@ class TableModel(PamhyrTableModel):
|
||||
self.update()
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
if not rows:
|
||||
return
|
||||
|
||||
rows = list(map(
|
||||
lambda r: self.get_true_data_row(r),
|
||||
rows))
|
||||
rows = sorted(set(rows))
|
||||
rows = [
|
||||
self.get_true_data_row(row)
|
||||
for row in rows
|
||||
]
|
||||
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, rows
|
||||
# A multiple selection may contain non-contiguous rows. A model reset
|
||||
# accurately represents this atomic undo command, unlike one
|
||||
# beginRemoveRows() call spanning rows that are not all removed.
|
||||
self.beginResetModel()
|
||||
try:
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, rows
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.endRemoveRows()
|
||||
finally:
|
||||
self.endResetModel()
|
||||
self.update()
|
||||
|
||||
def undo(self):
|
||||
self.beginResetModel()
|
||||
try:
|
||||
self._undo.undo()
|
||||
finally:
|
||||
self.endResetModel()
|
||||
|
||||
def redo(self):
|
||||
self.beginResetModel()
|
||||
try:
|
||||
self._undo.redo()
|
||||
finally:
|
||||
self.endResetModel()
|
||||
|
||||
def sort(self, _reverse, parent=QModelIndex()):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
|
||||
@@ -97,12 +97,11 @@ class DelCommand(QUndoCommand):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._rows = rows
|
||||
|
||||
self._bc = []
|
||||
for row in rows:
|
||||
self._bc.append(self._data.get_i(row))
|
||||
self._bc.sort()
|
||||
self._rows = sorted(set(rows))
|
||||
self._bc = [
|
||||
self._data.get_i(row)
|
||||
for row in self._rows
|
||||
]
|
||||
|
||||
def undo(self):
|
||||
for el in self._bc:
|
||||
@@ -120,13 +119,17 @@ class SortCommand(QUndoCommand):
|
||||
self._data = data
|
||||
self._reverse = _reverse
|
||||
|
||||
self._old = self._data.data
|
||||
self._indexes = None
|
||||
# Keep the order of the complete underlying list, including soft
|
||||
# deleted items. ``data`` only exposes visible items and therefore
|
||||
# cannot reliably restore a sort after a delete/undelete operation.
|
||||
self._old_positions = {
|
||||
id(item): index
|
||||
for index, item in enumerate(self._data._data)
|
||||
}
|
||||
|
||||
def undo(self):
|
||||
ll = self._data.data
|
||||
self._data.sort(
|
||||
key=lambda x: self._indexes[ll.index(x)]
|
||||
key=lambda item: self._old_positions[id(item)]
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
@@ -134,14 +137,6 @@ class SortCommand(QUndoCommand):
|
||||
_reverse=self._reverse,
|
||||
key=lambda x: x[0]
|
||||
)
|
||||
if self._indexes is None:
|
||||
self._indexes = list(
|
||||
map(
|
||||
lambda p: self._old.index(p),
|
||||
self._data.data
|
||||
)
|
||||
)
|
||||
self._old = None
|
||||
|
||||
|
||||
class MoveCommand(QUndoCommand):
|
||||
|
||||
@@ -124,7 +124,7 @@ class DelCommand(QUndoCommand):
|
||||
self._bcs.insert(self._tab, row, el)
|
||||
|
||||
def redo(self):
|
||||
self._bcs.delete_i(self._tab, self._rows)
|
||||
self._bcs.delete(self._tab, [el for _, el in self._bc])
|
||||
|
||||
|
||||
class SortCommand(QUndoCommand):
|
||||
|
||||
@@ -259,6 +259,9 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
**data
|
||||
)
|
||||
|
||||
self.apply_meshing(new_profiles, data, tableView)
|
||||
|
||||
def apply_meshing(self, new_profiles, data, tableView):
|
||||
if new_profiles is None:
|
||||
return
|
||||
|
||||
|
||||
@@ -350,14 +350,22 @@ class GeometryWindow(PamhyrWindow):
|
||||
tableview = self.tableView
|
||||
|
||||
def fn():
|
||||
self._table.meshing(mesher, data, tableview)
|
||||
# self._table.meshing(mesher, data, tableview)
|
||||
return mesher.meshing(self._reach, **data)
|
||||
|
||||
dlg2 = WaitingDialog(
|
||||
payload_fn=fn,
|
||||
title="waiting_mesh",
|
||||
parent=self
|
||||
)
|
||||
dlg2.exec_()
|
||||
|
||||
if dlg2.worker_exception is not None:
|
||||
raise dlg2.worker_exception
|
||||
|
||||
# Models, undo stacks and selections belong to the GUI thread.
|
||||
self._table.apply_meshing(
|
||||
dlg2.worker_result, data, tableview
|
||||
)
|
||||
self._table.update()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -95,7 +95,7 @@ class CustomPlot(PamhyrPlot):
|
||||
table = results.get("table")["zfd"]
|
||||
ts = results.get_timestamp_id(self._current_timestamp)
|
||||
|
||||
rk = reach.geometry.get_rk()
|
||||
# rk = reach.geometry.get_rk()
|
||||
z = list(
|
||||
map(
|
||||
lambda p: table[ts, p.global_index],
|
||||
|
||||
@@ -1150,7 +1150,6 @@ class ResultsWindow(PamhyrWindow):
|
||||
z = table["Z"][:, profile.global_index]
|
||||
q = table["Q"][:, profile.global_index]
|
||||
v = table["V"][:, profile.global_index]
|
||||
zfd = table["zfd"][:, profile.global_index]
|
||||
|
||||
if self._current_results == 2:
|
||||
reach1 = self._results[0].river.reach(self._reach)
|
||||
@@ -1169,8 +1168,8 @@ class ResultsWindow(PamhyrWindow):
|
||||
v2 = table["V"][:, profile2.global_index]
|
||||
|
||||
if "bed_elevation" in y:
|
||||
if reach.has_bedload():
|
||||
z_min = zfd
|
||||
if reach.has_bedload() and "zfd" in table:
|
||||
z_min = table["zfd"][:, profile.global_index]
|
||||
else:
|
||||
z_min = [profile.geometry.z_min()] * len(self._timestamps)
|
||||
|
||||
|
||||
@@ -47,10 +47,16 @@ class Worker(QObject):
|
||||
super(self.__class__, self).__init__(parent)
|
||||
|
||||
self._payload_fn = payload_fn
|
||||
self.result = None
|
||||
self.exception = None
|
||||
|
||||
def process(self):
|
||||
self._payload_fn()
|
||||
self.signalStatus.emit('end')
|
||||
try:
|
||||
self.result = self._payload_fn()
|
||||
except Exception as exception:
|
||||
self.exception = exception
|
||||
finally:
|
||||
self.signalStatus.emit('end')
|
||||
|
||||
|
||||
class WaitingDialog(PamhyrDialog):
|
||||
@@ -123,6 +129,14 @@ class WaitingDialog(PamhyrDialog):
|
||||
self._timer = QTimer(self)
|
||||
self._timer.timeout.connect(self.update_spinner)
|
||||
|
||||
@property
|
||||
def worker_result(self):
|
||||
return self._worker.result
|
||||
|
||||
@property
|
||||
def worker_exception(self):
|
||||
return self._worker.exception
|
||||
|
||||
def update_spinner(self):
|
||||
self._spinner_step += 1
|
||||
self._spinner_step %= len(self._spin)
|
||||
|
||||
Reference in new issue
Block a user