Commit 768a0b9f authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Sediment: Add solid BC, QSO export and profile + point sediment layers export.

Showing with 107 additions and 14 deletions
+107 -14
...@@ -83,7 +83,8 @@ class BoundaryCondition(SQLSubModel): ...@@ -83,7 +83,8 @@ class BoundaryCondition(SQLSubModel):
def _get_ctor_from_type(cls, t): def _get_ctor_from_type(cls, t):
from Model.BoundaryCondition.BoundaryConditionTypes import ( from Model.BoundaryCondition.BoundaryConditionTypes import (
NotDefined, PonctualContribution, NotDefined, PonctualContribution,
TimeOverZ, TimeOverDischarge, ZOverDischarge TimeOverZ, TimeOverDischarge, ZOverDischarge,
Solid,
) )
res = NotDefined res = NotDefined
...@@ -95,6 +96,8 @@ class BoundaryCondition(SQLSubModel): ...@@ -95,6 +96,8 @@ class BoundaryCondition(SQLSubModel):
res = TimeOverDischarge res = TimeOverDischarge
elif t == "ZD": elif t == "ZD":
res = ZOverDischarge res = ZOverDischarge
elif t == "SL":
res = Solid
return res return res
@classmethod @classmethod
......
...@@ -26,7 +26,8 @@ from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition ...@@ -26,7 +26,8 @@ from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
from Model.BoundaryCondition.BoundaryConditionTypes import ( from Model.BoundaryCondition.BoundaryConditionTypes import (
NotDefined, NotDefined,
PonctualContribution, PonctualContribution,
TimeOverZ, TimeOverDischarge, ZOverDischarge TimeOverZ, TimeOverDischarge, ZOverDischarge,
Solid,
) )
class BoundaryConditionList(SQLSubModel): class BoundaryConditionList(SQLSubModel):
......
...@@ -83,3 +83,16 @@ class ZOverDischarge(BoundaryCondition): ...@@ -83,3 +83,16 @@ class ZOverDischarge(BoundaryCondition):
@property @property
def _default_0(self): def _default_0(self):
return 0.0 return 0.0
class Solid(BoundaryCondition):
def __init__(self, id:int = -1, name:str = "", status = None):
super(Solid, self).__init__(id=id, name=name, status=status)
self._type = "SL"
self._header = ["time", "solid"]
self._types = [TimeOverDischarge.time_convert, float]
@classmethod
def compatibility(cls):
return ["solid"]
...@@ -213,12 +213,22 @@ class AbstractSolver(object): ...@@ -213,12 +213,22 @@ class AbstractSolver(object):
# Command line executable path is between " char # Command line executable path is between " char
cmd = cmd.split("\"") cmd = cmd.split("\"")
exe = cmd[1].replace("\ ", " ") exe = cmd[1].replace("\ ", " ")
args = "\"".join(cmd[2:]).split(" ")[1:] args = list(
filter(
lambda s: s != "",
"\"".join(cmd[2:]).split(" ")[1:]
)
)
else: else:
# We suppose the command line executable path as no space char # We suppose the command line executable path as no space char
cmd = cmd.replace("\ ", "&_&").split(" ") cmd = cmd.replace("\ ", "&_&").split(" ")
exe = cmd[0].replace("&_&", " ") exe = cmd[0].replace("&_&", " ")
args = list(map(lambda s: s.replace("&_&", "\ "), cmd[1:])) args = list(
filter(
lambda s: s != "",
map(lambda s: s.replace("&_&", "\ "), cmd[1:])
)
)
logger.info(f"! {exe} {args}") logger.info(f"! {exe} {args}")
return exe, args return exe, args
......
...@@ -127,23 +127,47 @@ class Mage(AbstractSolver): ...@@ -127,23 +127,47 @@ class Mage(AbstractSolver):
with mage_file_open(os.path.join(repertory, f"{name}.ST"), "w+") as f: with mage_file_open(os.path.join(repertory, f"{name}.ST"), "w+") as f:
files.append(f"{name}.ST") files.append(f"{name}.ST")
cnt_num = 1
for profile in edge.reach.profiles: for profile in edge.reach.profiles:
num = f"{profile.num:>6}" num = f"{cnt_num:>6}"
c1 = f"{profile.code1:>6}" c1 = f"{profile.code1:>6}"
c2 = f"{profile.code2:>6}" c2 = f"{profile.code2:>6}"
t = f"{len(profile.points):>6}" t = f"{len(profile.points):>6}"
kp = f"{profile.kp:>13.4f}" kp = f"{profile.kp:>13.4f}"
name = profile.name pname = profile.name
if profile.name == "":
pname = f"p{profile.id:>3}".replace(" ", "p")
name = f"{pname}"
f.write(f"{num}{c1}{c2}{t}{kp} {name}\n") sediment = ""
if profile.sl is not None:
if not any(filter(lambda f: ".GRA" in f, files)):
files.append("0.GRA")
nl = len(profile.sl)
sediment = f" {nl:>3}"
for l in profile.sl.layers:
sediment += f" {l.height:>10} {l.d50:>10} {l.sigma:>10} {l.critical_constraint:>10}"
f.write(f"{num}{c1}{c2}{t}{kp} {name} {sediment}\n")
cnt_num += 1
for point in profile.points: for point in profile.points:
x = f"{point.x:>13.4f}" x = f"{point.x:>13.4f}"
y = f"{point.y:>13.4f}" y = f"{point.y:>13.4f}"
z = f"{point.z:>13.4f}" z = f"{point.z:>13.4f}"
n = point.name n = f"{point.name:<3}"
f.write(f"{x}{y}{z} {n}\n") sediment = ""
prev = point.z
if point.sl is not None:
nl = len(point.sl)
sediment = f"{nl:>3}"
for l in point.sl.layers:
prev = round(prev - l.height, 5)
sediment += f" {prev:>10} {l.d50:>10} {l.sigma:>10} {l.critical_constraint:>10}"
f.write(f"{x}{y}{z} {n} {sediment}\n")
f.write(f" 999.9990 999.9990 999.9990\n") f.write(f" 999.9990 999.9990 999.9990\n")
...@@ -182,6 +206,7 @@ class Mage(AbstractSolver): ...@@ -182,6 +206,7 @@ class Mage(AbstractSolver):
AVA = [] AVA = []
HYD = [] HYD = []
LIM = [] LIM = []
QSO = []
for tab in ["liquid", "solid", "suspenssion"]: for tab in ["liquid", "solid", "suspenssion"]:
for bound in lst.get_tab(tab): for bound in lst.get_tab(tab):
...@@ -191,10 +216,13 @@ class Mage(AbstractSolver): ...@@ -191,10 +216,13 @@ class Mage(AbstractSolver):
HYD.append(bound) HYD.append(bound)
elif bound.bctype == "TZ": elif bound.bctype == "TZ":
LIM.append(bound) LIM.append(bound)
elif bound.bctype == "SL":
QSO.append(bound)
files = files + self._export_BC("AVA", AVA, repertory, qlog) files = files + self._export_BC("AVA", AVA, repertory, qlog)
files = files + self._export_BC("HYD", HYD, repertory, qlog) files = files + self._export_BC("HYD", HYD, repertory, qlog)
files = files + self._export_BC("LIM", LIM, repertory, qlog) files = files + self._export_BC("LIM", LIM, repertory, qlog)
files = files + self._export_QSO(QSO, repertory, qlog)
return files return files
...@@ -332,12 +360,20 @@ class Mage(AbstractSolver): ...@@ -332,12 +360,20 @@ class Mage(AbstractSolver):
for file in files: for file in files:
EXT = file.split('.')[1] EXT = file.split('.')[1]
f.write(f"{EXT} {file}\n") if EXT not in ["ST", "GRA"]:
f.write(f"{EXT} {file}\n")
f.write("* OUTPUT\n") f.write("* OUTPUT\n")
f.write(f"TRA 0.TRA\n") f.write(f"TRA 0.TRA\n")
f.write(f"BIN 0.BIN\n") f.write(f"BIN 0.BIN\n")
for file in files:
EXT = file.split('.')[1]
if EXT in ["GRA"]:
f.write(f"{EXT} {file}\n")
@timer @timer
def export(self, study, repertory, qlog = None): def export(self, study, repertory, qlog = None):
self._export_ST(study, repertory, qlog) self._export_ST(study, repertory, qlog)
...@@ -459,11 +495,37 @@ class Mage8(Mage): ...@@ -459,11 +495,37 @@ class Mage8(Mage):
return files return files
@timer
def _export_QSO(self, bounds, repertory, qlog):
files = []
if len(bounds) == 0:
return files
if qlog is not None:
qlog.put(f"Export QSO file")
with mage_file_open(os.path.join(repertory, f"0.QSO"), "w+") as f:
files.append(f"0.QSO")
for bound in bounds:
name = f"{bound.node.id:3}".replace(" ", "x")
f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n")
f.write(f"${name}\n")
header = bound.header
f.write(f"*{header[0]:>9}|{header[1]:>10}\n")
for d in bound.data:
f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n")
return files
@timer @timer
def export(self, study, repertory, qlog = None): def export(self, study, repertory, qlog = None):
files = [] files = []
self._export_ST(study, repertory, qlog) files = self._export_ST(study, repertory, qlog)
files = files + self._export_PAR(study, repertory, qlog) files = files + self._export_PAR(study, repertory, qlog)
files = files + self._export_NET(study, repertory, qlog) files = files + self._export_NET(study, repertory, qlog)
files = files + self._export_bound_cond(study, repertory, qlog) files = files + self._export_bound_cond(study, repertory, qlog)
......
...@@ -26,5 +26,6 @@ table_headers = { ...@@ -26,5 +26,6 @@ table_headers = {
"time": _translate("BoundaryCondition", "Time"), "time": _translate("BoundaryCondition", "Time"),
"date": _translate("BoundaryCondition", "Date"), "date": _translate("BoundaryCondition", "Date"),
"discharge": _translate("BoundaryCondition", "Discharge (m³/s)"), "discharge": _translate("BoundaryCondition", "Discharge (m³/s)"),
"z": _translate("BoundaryCondition", "Z (m)") "z": _translate("BoundaryCondition", "Z (m)"),
"solid": _translate("BoundaryCondition", "Solid (kg/s)"),
} }
...@@ -20,7 +20,8 @@ from PyQt5.QtCore import QCoreApplication ...@@ -20,7 +20,8 @@ from PyQt5.QtCore import QCoreApplication
from Model.BoundaryCondition.BoundaryConditionTypes import ( from Model.BoundaryCondition.BoundaryConditionTypes import (
NotDefined, PonctualContribution, NotDefined, PonctualContribution,
TimeOverZ, TimeOverDischarge, ZOverDischarge TimeOverZ, TimeOverDischarge, ZOverDischarge,
Solid
) )
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
...@@ -31,6 +32,7 @@ long_types = { ...@@ -31,6 +32,7 @@ long_types = {
"TZ": _translate("BoundaryCondition", "Time over Z"), "TZ": _translate("BoundaryCondition", "Time over Z"),
"TD": _translate("BoundaryCondition", "Time over Discharge"), "TD": _translate("BoundaryCondition", "Time over Discharge"),
"ZD": _translate("BoundaryCondition", "Z over Discharge"), "ZD": _translate("BoundaryCondition", "Z over Discharge"),
"SL": _translate("BoundaryCondition", "Solid"),
} }
table_headers = { table_headers = {
...@@ -44,5 +46,6 @@ BC_types = { ...@@ -44,5 +46,6 @@ BC_types = {
"PC": PonctualContribution, "PC": PonctualContribution,
"TZ": TimeOverZ, "TZ": TimeOverZ,
"TD": TimeOverDischarge, "TD": TimeOverDischarge,
"ZD": ZOverDischarge "ZD": ZOverDischarge,
"SL": Solid,
} }
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment