mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
7 Commits
6d58c09104
...
36c93a0c93
| Author | SHA1 | Date |
|---|---|---|
|
|
36c93a0c93 | |
|
|
3cd1dbab49 | |
|
|
4e3da95b1d | |
|
|
0d0c4f913e | |
|
|
600f86aeb4 | |
|
|
c9bb222bff | |
|
|
456559ffe2 |
|
|
@ -397,24 +397,21 @@ class WeatherParameters(SQLSubModel):
|
|||
wp._begin_section = None
|
||||
wp._end_section = None
|
||||
|
||||
if row[3] != -1:
|
||||
if reach not in (-1, None):
|
||||
wp.reach = next(
|
||||
filter(
|
||||
lambda e: e.id == reach,
|
||||
edges
|
||||
)
|
||||
(edge for edge in edges if edge.id == reach), None
|
||||
)
|
||||
profiles = (
|
||||
wp.reach.reach.profiles
|
||||
if wp.reach is not None else []
|
||||
)
|
||||
wp._begin_section = next(
|
||||
filter(
|
||||
lambda p: p.id == b_section,
|
||||
wp.reach.reach.profiles
|
||||
)
|
||||
(profile for profile in profiles
|
||||
if profile.id == b_section), None
|
||||
)
|
||||
wp._end_section = next(
|
||||
filter(
|
||||
lambda p: p.id == e_section,
|
||||
wp.reach.reach.profiles
|
||||
)
|
||||
(profile for profile in profiles
|
||||
if profile.id == e_section), None
|
||||
)
|
||||
|
||||
data["wp"] = wp
|
||||
|
|
@ -537,9 +534,14 @@ class WeatherParameters(SQLSubModel):
|
|||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self._begin_section = None
|
||||
self._end_section = None
|
||||
|
||||
if reach is not None:
|
||||
self._begin_section = self._reach.reach.profiles[0]
|
||||
self._end_section = self._reach.reach.profiles[-1]
|
||||
profiles = reach.reach.profiles
|
||||
if profiles:
|
||||
self._begin_section = profiles[0]
|
||||
self._end_section = profiles[-1]
|
||||
|
||||
self.modified()
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class AbstractSolver(object):
|
|||
def default_parameters(cls):
|
||||
lst = [
|
||||
("all_init_time", "000:00:00:00"),
|
||||
("all_final_time", "999:99:00:00"),
|
||||
("all_final_time", "10:00:00:00"),
|
||||
("all_timestep", "300.0"),
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -505,12 +505,13 @@ class AdisTSwc(AdisTS):
|
|||
study, pollutant._data, f, qlog
|
||||
)
|
||||
|
||||
POL_ICs = next(filter(
|
||||
lambda ic: ic.pollutant == pollutant.id,
|
||||
POL_ICs = next((
|
||||
ic for ic in
|
||||
study.river.ic_adists.Initial_Conditions_List
|
||||
))
|
||||
if ic.pollutant == pollutant.id
|
||||
), None)
|
||||
|
||||
if POL_ICs.concentration is not None:
|
||||
if POL_ICs is not None and POL_ICs.concentration is not None:
|
||||
f.write(f"file_ini = {name}.INI\n")
|
||||
self._export_ICs_AdisTS(
|
||||
study, repertory, POL_ICs, qlog, name
|
||||
|
|
@ -550,15 +551,18 @@ class AdisTSwc(AdisTS):
|
|||
os.path.join(repertory, f"{POL_name}.ALD"), "w+"
|
||||
) as f:
|
||||
for LC in POL_LC:
|
||||
reach = next(filter(
|
||||
lambda edge: edge.id == LC.edge, study.river.enable_edges()
|
||||
)) # .name
|
||||
reach = next((
|
||||
edge for edge in study.river.enable_edges()
|
||||
if edge.id == LC.edge
|
||||
), None)
|
||||
if reach is None:
|
||||
continue
|
||||
reach_name = self.get_reach_name(reach)
|
||||
f.write(f"${reach_name} {LC.begin_rk} {LC.end_rk}\n")
|
||||
f.write(f"*temps |débit massique (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for LC_data in LC._data:
|
||||
for LC_data in LC.data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(LC_data[0]))
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{LC_data[1]}\n")))
|
||||
|
|
@ -575,9 +579,10 @@ class AdisTSwc(AdisTS):
|
|||
repertory, f"{POL_name}.CDT"), "w+"
|
||||
) as f:
|
||||
for BC in POL_BC:
|
||||
node = next(filter(
|
||||
lambda x: x.id == BC.node, study.river._nodes
|
||||
))
|
||||
node = next((node for node in study.river.nodes()
|
||||
if node.id == BC.node), None)
|
||||
if node is None:
|
||||
continue
|
||||
f.write(f"${self.get_node_name(node)}\n")
|
||||
|
||||
if BC.type == "Concentration":
|
||||
|
|
@ -589,7 +594,7 @@ class AdisTSwc(AdisTS):
|
|||
f.write(f"*JJ:HH:MM | (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for BC_data in BC._data:
|
||||
for BC_data in BC.data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(BC_data[0]))
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{BC_data[1]}\n")))
|
||||
|
|
@ -623,6 +628,9 @@ class AdisTSwc(AdisTS):
|
|||
|
||||
edges = study.river.enable_edges()
|
||||
for ic_spec in pol_ics_spec_data:
|
||||
if ic_spec.is_deleted():
|
||||
continue
|
||||
|
||||
id_reach = ic_spec.reach
|
||||
reach = next((x for x in edges if x.id == id_reach), None)
|
||||
if reach is None:
|
||||
|
|
@ -646,7 +654,9 @@ class AdisTSwc(AdisTS):
|
|||
list_characteristics = ["type", "diametre", "rho", "porosity",
|
||||
"cdc_riv", "cdc_cas", "apd", "ac", "bc"]
|
||||
|
||||
if len(list_characteristics) <= (len(pol_data[0])):
|
||||
pol_data = [data for data in pol_data if not data.is_deleted()]
|
||||
|
||||
if pol_data and len(list_characteristics) <= len(pol_data[0]):
|
||||
for i in range(len(list_characteristics)):
|
||||
f.write(f"{list_characteristics[i]} = {pol_data[0][i]}\n")
|
||||
|
||||
|
|
@ -675,6 +685,9 @@ class AdisTSwc(AdisTS):
|
|||
def _export_d90_spec(self, study, d90_spec_data, f, qlog, name="0"):
|
||||
|
||||
for d90_spec in d90_spec_data:
|
||||
if d90_spec.is_deleted():
|
||||
continue
|
||||
|
||||
if (d90_spec.name is None
|
||||
or d90_spec.reach is None
|
||||
or d90_spec.start_rk is None
|
||||
|
|
@ -734,6 +747,9 @@ class AdisTSwc(AdisTS):
|
|||
def _export_dif_spec(self, study, dif_spec_data, f, qlog, name="0"):
|
||||
|
||||
for dif_spec in dif_spec_data:
|
||||
if dif_spec.is_deleted():
|
||||
continue
|
||||
|
||||
if (dif_spec.reach is None
|
||||
or dif_spec.start_rk is None
|
||||
or dif_spec.end_rk is None
|
||||
|
|
|
|||
|
|
@ -75,11 +75,11 @@ class AdisTT(CommandLineSolver):
|
|||
|
||||
lst += [
|
||||
("adistt_implicitation_parameter", "0.5"),
|
||||
("adistt_timestep_screen", "60"),
|
||||
("adistt_timestep_bin", "60"),
|
||||
("adistt_timestep_csv", "60"),
|
||||
("adistt_timestep_mage", "60"),
|
||||
("adistt_initial_concentration", "60"),
|
||||
("adistt_timestep_screen", "86400"),
|
||||
("adistt_timestep_bin", "3600"),
|
||||
("adistt_timestep_csv", "3600"),
|
||||
("adistt_timestep_mage", "300"),
|
||||
("adistt_initial_concentration", "0"),
|
||||
]
|
||||
|
||||
return lst
|
||||
|
|
@ -444,115 +444,6 @@ class AdisTTwc(AdisTT):
|
|||
|
||||
return lst
|
||||
|
||||
def _export_TEMs(self, study, repertory, qlog=None, name="0"):
|
||||
|
||||
files = []
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export TEMs files")
|
||||
|
||||
name = "TEM"
|
||||
with adistt_file_open(
|
||||
os.path.join(repertory, f"{name}.POL"), "w+"
|
||||
) as f:
|
||||
|
||||
TEM_ICs = (
|
||||
study.river._InitialConditionsTemperature
|
||||
.Initial_Conditions_List
|
||||
)
|
||||
|
||||
TEM_IC = TEM_ICs[0] if TEM_ICs else None
|
||||
print(f"TEM_IC: {TEM_IC}")
|
||||
|
||||
if TEM_IC and TEM_IC._temperature is not None:
|
||||
print(f"TEM_IC._temperature: {TEM_IC._temperature}")
|
||||
f.write(f"file_ini = {name}.INI\n")
|
||||
self._export_ICs_AdisTT(
|
||||
study, repertory, TEM_IC, qlog, name
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"No TEM initial conditions defined, skipping export"
|
||||
)
|
||||
|
||||
TEM_BCs = (
|
||||
study.river._BoundaryConditionsTemperature
|
||||
.BCs_Temperature_List
|
||||
)
|
||||
|
||||
if TEM_BCs:
|
||||
f.write(f"file_cl = {name}.CDT\n")
|
||||
self._export_BCs_AdisTT(
|
||||
study, repertory, TEM_BCs, qlog, name
|
||||
)
|
||||
|
||||
return files
|
||||
|
||||
def _export_BCs_AdisTT(self, study, repertory, TEM_BC, qlog, TEM_name):
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export TEM BCs files")
|
||||
|
||||
with adistt_file_open(os.path.join(
|
||||
repertory, f"{TEM_name}.CDT"), "w+"
|
||||
) as f:
|
||||
for BC in TEM_BC:
|
||||
node = next(filter(
|
||||
lambda x: x.id == BC.node, study.river._nodes
|
||||
))
|
||||
f.write(f"${self.get_node_name(node)}\n")
|
||||
|
||||
f.write(f"*temps |temperature\n")
|
||||
f.write(f"*JJ:HH:MM | (°C)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for BC_data in BC._data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(BC_data[0]))
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{BC_data[1]}\n")))
|
||||
f.write(f"*\n")
|
||||
|
||||
return True
|
||||
|
||||
def _export_ICs_AdisTT(self, study, repertory,
|
||||
TEM_IC_default, qlog, TEM_name):
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export TEM ICs files")
|
||||
|
||||
with adistt_file_open(os.path.join(
|
||||
repertory, f"{TEM_name}.INI"
|
||||
), "w+") as f:
|
||||
f.write(f"*État initial pour le polluant {TEM_name}\n")
|
||||
f.write(" ".join(("DEFAULT =",
|
||||
f"{TEM_IC_default.temperature}",
|
||||
"0.0 0.0 0.0\n"))) # fake 0 to match adists
|
||||
|
||||
if len(TEM_IC_default._data) != 0:
|
||||
self._export_ICs_AdisTT_Spec(
|
||||
study, TEM_IC_default._data, f, qlog
|
||||
)
|
||||
|
||||
def _export_ICs_AdisTT_Spec(self, study, tem_ics_spec_data,
|
||||
f, qlog, name="0"):
|
||||
|
||||
edges = study.river.enable_edges()
|
||||
for ic_spec in tem_ics_spec_data:
|
||||
id_reach = ic_spec.reach
|
||||
reach = next((x for x in edges if x.id == id_reach), None)
|
||||
if reach is None:
|
||||
continue
|
||||
|
||||
f.write(" ".join((f"{ic_spec.name}",
|
||||
"=",
|
||||
f"{study.river.get_edge_id(reach)+1}",
|
||||
f"{ic_spec.start_rk}",
|
||||
f"{ic_spec.end_rk}",
|
||||
f"{ic_spec.temperature}",
|
||||
f"0.0 0.0 0.0 0.0\n"))) # fake 0 to match adists
|
||||
|
||||
return True
|
||||
|
||||
# def _export_D90(self, study, repertory, qlog=None, name="0"):
|
||||
|
||||
# files = []
|
||||
|
|
@ -978,7 +869,7 @@ class AdisTTwc(AdisTT):
|
|||
filename = "TEM.CDT"
|
||||
with adistt_file_open(os.path.join(repertory, filename), "w+") as f:
|
||||
for boundary_condition in boundary_conditions:
|
||||
node = next((node for node in study.river._nodes
|
||||
node = next((node for node in study.river.nodes()
|
||||
if node.id == boundary_condition.node), None)
|
||||
if node is None:
|
||||
continue
|
||||
|
|
@ -1018,6 +909,10 @@ class AdisTTwc(AdisTT):
|
|||
if qlog is not None:
|
||||
qlog.put("Export TEM files")
|
||||
|
||||
legacy_pol = os.path.join(repertory, "TEM.POL")
|
||||
if os.path.exists(legacy_pol):
|
||||
os.remove(legacy_pol)
|
||||
|
||||
# Weather files are appended range by range below. Remove files from
|
||||
# a previous export first so rerunning an unchanged study is stable.
|
||||
for _, extension in self._weather_files.values():
|
||||
|
|
@ -1035,7 +930,8 @@ class AdisTTwc(AdisTT):
|
|||
weather_files = {}
|
||||
for weather_parameter in study.river.weather_parameters.lst:
|
||||
config = self._weather_files.get(weather_parameter.type)
|
||||
if config is None or weather_parameter.reach is None:
|
||||
if (config is None or weather_parameter.reach is None
|
||||
or weather_parameter.reach.is_deleted()):
|
||||
continue
|
||||
_, extension = config
|
||||
exported = self._export_weather_file(
|
||||
|
|
@ -1049,7 +945,7 @@ class AdisTTwc(AdisTT):
|
|||
defaults = study.river.weather_parameters
|
||||
for type_, (parameter, _) in self._weather_files.items():
|
||||
default = defaults.default_for_type(type_)
|
||||
if default is not None:
|
||||
if default is not None and not default.is_deleted():
|
||||
f.write(f"{parameter} = {default.value}\n")
|
||||
|
||||
f.write(f"file_ini = {initial_file}\n")
|
||||
|
|
@ -1066,8 +962,7 @@ class AdisTTwc(AdisTT):
|
|||
def export_func_dict(self):
|
||||
return [
|
||||
self._export_NUM,
|
||||
self._export_TEM,
|
||||
self._export_TEMs
|
||||
self._export_TEM
|
||||
]
|
||||
|
||||
def rm_previous_results(self, study, repertory, qlog):
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
|||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
|||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
|
|
|||
|
|
@ -73,8 +73,12 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
)
|
||||
)
|
||||
)
|
||||
elif self._mode == "rk":
|
||||
self.editor.addItems(
|
||||
list(map(str, self._data.reach.get_rk()))
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
||||
return self.editor
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
|
|
|
|||
|
|
@ -105,6 +105,13 @@ class FrictionsWindow(PamhyrWindow):
|
|||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
self._delegate_rk = ComboBoxDelegate(
|
||||
data=self._reach,
|
||||
study=self._study,
|
||||
mode="rk",
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
|
||||
if self._study.is_editable():
|
||||
editable_headers = [
|
||||
|
|
@ -120,8 +127,10 @@ class FrictionsWindow(PamhyrWindow):
|
|||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=editable_headers,
|
||||
delegates={
|
||||
"begin_rk": self._delegate_rk,
|
||||
"end_rk": self._delegate_rk,
|
||||
"begin_strickler": self._delegate_stricklers,
|
||||
"end_strickler": self._delegate_stricklers,
|
||||
# "end_strickler": self._delegate_stricklers,
|
||||
},
|
||||
data=self._reach,
|
||||
trad=self._trad,
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ class EditLateralContributionWindow(PamhyrWindow):
|
|||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
|
|
|||
|
|
@ -160,6 +160,7 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
|
|||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ class EditReservoirWindow(PamhyrWindow):
|
|||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
|
|
|||
|
|
@ -208,6 +208,14 @@ class PamhyrPlot(APlot):
|
|||
|
||||
self.toolbar_update()
|
||||
|
||||
def fit_to_data(self):
|
||||
"""Recompute the axes limits to show all currently plotted data."""
|
||||
self.canvas.axes.relim()
|
||||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
self.canvas.axes.autoscale()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
self.toolbar_update()
|
||||
|
||||
def toolbar_update(self):
|
||||
if self._toolbar is not None:
|
||||
self._toolbar.update()
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ class EditWeatherParametersWindow(PamhyrWindow):
|
|||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ def timestamp_to_old_pamhyr_date_adists(time: int):
|
|||
minutes = (dt.seconds % 3600) // 60
|
||||
seconds = dt.seconds % 60
|
||||
|
||||
s = f"{dt.days:>3}:{hours:>2}:{minutes:>2}"#:{seconds:>2}"
|
||||
s = f"{dt.days:>3}:{hours:>2}:{minutes:>2}"
|
||||
s = s.replace(" ", "0")
|
||||
|
||||
return s
|
||||
|
|
|
|||
Loading…
Reference in New Issue