mirror of https://gitlab.com/pamhyr/pamhyr2
Export Files 2
parent
bd4222adfa
commit
0e18d43496
|
|
@ -60,5 +60,9 @@ class BoundaryConditionsAdisTSList(PamhyrModelList):
|
|||
self._status.modified()
|
||||
return n
|
||||
|
||||
@property
|
||||
def BCs_AdisTS_List(self):
|
||||
return self.lst
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -59,3 +59,7 @@ class LateralContributionsAdisTSList(PamhyrModelList):
|
|||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
@property
|
||||
def Lat_Cont_List(self):
|
||||
return self.lst
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@ import os
|
|||
import logging
|
||||
import numpy as np
|
||||
|
||||
from tools import timer, trace, logger_exception
|
||||
from tools import (
|
||||
trace, timer, logger_exception,
|
||||
timestamp_to_old_pamhyr_date,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
timestamp_to_old_pamhyr_date_adists
|
||||
)
|
||||
|
||||
from Solver.CommandLine import CommandLineSolver
|
||||
|
||||
|
|
@ -204,10 +209,69 @@ class AdisTSlc(AdisTS):
|
|||
study.river.initial_conditions_adists.Initial_Conditions_List))
|
||||
|
||||
if POL_ICs.concentration != None:
|
||||
f.write(f"file_ini = {name}.INI\n")
|
||||
self._export_ICs_AdisTS(study, repertory, POL_ICs, qlog, name)
|
||||
|
||||
POL_BCs = list(filter(lambda bc: bc.pollutant == pollutant.id,\
|
||||
study.river.boundary_conditions_adists.BCs_AdisTS_List))
|
||||
|
||||
if len(POL_BCs) != 0:
|
||||
f.write(f"file_cl = {name}.CDT\n")
|
||||
self._export_BCs_AdisTS(study, repertory, POL_BCs, qlog, name)
|
||||
|
||||
POL_LAT_Cont = list(filter(lambda lc: lc.pollutant == pollutant.id,\
|
||||
study.river.lateral_contributions_adists.Lat_Cont_List))
|
||||
|
||||
if len(POL_LAT_Cont) != 0:
|
||||
f.write(f"file_ald = {name}.ALD\n")
|
||||
f.write(f"*\n")
|
||||
self._export_Lat_AdisTS(study, repertory, POL_LAT_Cont, qlog, name)
|
||||
|
||||
return files
|
||||
|
||||
def _export_Lat_AdisTS(self, study, repertory, POL_LC, qlog, POL_name):
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export POL LCs files")
|
||||
|
||||
with adists_file_open(os.path.join(repertory, f"{POL_name}.ALD"), "w+") as f:
|
||||
for LC in POL_LC:
|
||||
reach_name = next(filter(lambda edge: edge.id == LC.edge, study.river.edges())).name
|
||||
f.write(f"${reach_name} {LC.begin_kp} {LC.end_kp}\n")
|
||||
f.write(f"*temps |débit massique (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for LC_data in LC._data:
|
||||
f.write(f"{timestamp_to_old_pamhyr_date_adists(int(LC_data[0]))} {LC_data[1]}\n")
|
||||
f.write(f"*\n")
|
||||
|
||||
return True
|
||||
|
||||
def _export_BCs_AdisTS(self, study, repertory, POL_BC, qlog, POL_name):
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export POL BCs files")
|
||||
|
||||
with adists_file_open(os.path.join(repertory, f"{POL_name}.CDT"), "w+") as f:
|
||||
for BC in POL_BC:
|
||||
node_name = next(filter(lambda x: x.id == BC.node, study.river._nodes)).name
|
||||
f.write(f"${node_name}\n")
|
||||
|
||||
if BC.type == "Concentration":
|
||||
f.write(f"*temps |concentration\n")
|
||||
f.write(f"*JJ:HH:MM | (g/L)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
else:
|
||||
f.write(f"*temps |rate\n")
|
||||
f.write(f"*JJ:HH:MM | (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for BC_data in BC._data:
|
||||
f.write(f"{timestamp_to_old_pamhyr_date_adists(int(BC_data[0]))} {BC_data[1]}\n")
|
||||
f.write(f"*\n")
|
||||
|
||||
return True
|
||||
|
||||
def _export_ICs_AdisTS(self, study, repertory, POL_IC_default, qlog, POL_name):
|
||||
|
||||
if qlog is not None:
|
||||
|
|
@ -218,6 +282,17 @@ class AdisTSlc(AdisTS):
|
|||
f.write(f"{POL_IC_default.name} = {POL_IC_default.concentration} {POL_IC_default.eg} "+
|
||||
f"{POL_IC_default.em} {POL_IC_default.ed}\n")
|
||||
|
||||
if len(POL_IC_default._data) != 0:
|
||||
self._export_ICs_AdisTS_Spec(study, POL_IC_default._data, f, qlog)
|
||||
|
||||
def _export_ICs_AdisTS_Spec(self, study, pol_ics_spec_data, f, qlog, name="0"):
|
||||
|
||||
for ic_spec in pol_ics_spec_data:
|
||||
f.write(f"{ic_spec.name} = {ic_spec.reach} {ic_spec.start_kp} {ic_spec.end_kp} " +
|
||||
f"{ic_spec.concentration} {ic_spec.eg} {ic_spec.em} {ic_spec.ed} {ic_spec.rate}")
|
||||
|
||||
return True
|
||||
|
||||
def _export_POL_Characteristics(self, study, pol_data, f, qlog, name="0"):
|
||||
|
||||
list_characteristics = ["type", "diametre", "rho", "porosity", "cdc_riv", "cdc_cas", "apd", "ac", "bc"]
|
||||
|
|
|
|||
18
src/tools.py
18
src/tools.py
|
|
@ -299,6 +299,24 @@ def timestamp_to_old_pamhyr_date(time: int):
|
|||
|
||||
return s
|
||||
|
||||
def timestamp_to_old_pamhyr_date_adists(time: int):
|
||||
t0 = datetime.fromtimestamp(0)
|
||||
|
||||
# HACK: Windows do not accept negative timestamps
|
||||
if time < 0:
|
||||
t = t0 + timedelta(seconds=int(time))
|
||||
else:
|
||||
t = datetime.fromtimestamp(int(time))
|
||||
|
||||
dt = t - t0
|
||||
hours = dt.seconds // 3600
|
||||
minutes = (dt.seconds % 3600) // 60
|
||||
seconds = dt.seconds % 60
|
||||
|
||||
s = f"{dt.days:>3}:{hours:>2}:{minutes:>2}"
|
||||
s = s.replace(" ", "0")
|
||||
|
||||
return s
|
||||
|
||||
def get_user_name():
|
||||
if with_pwd:
|
||||
|
|
|
|||
Loading…
Reference in New Issue