mirror of https://gitlab.com/pamhyr/pamhyr2
Solver: RubarBE: Add tps export.
parent
4c927eb7c7
commit
982d346264
|
|
@ -330,7 +330,6 @@ class RubarBE(CommandLineSolver):
|
|||
)
|
||||
)
|
||||
|
||||
|
||||
ind = 1
|
||||
for mail in edge.reach.inter_profiles_kp():
|
||||
coef = get_stricklers_from_kp(mail)
|
||||
|
|
@ -339,3 +338,75 @@ class RubarBE(CommandLineSolver):
|
|||
|
||||
ind += 1
|
||||
f.write("\n")
|
||||
|
||||
def _export_tps(self, study, repertory, files, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
qlog.put("Export TPS file")
|
||||
|
||||
with open(
|
||||
os.path.join(
|
||||
repertory, f"tps.{name}"
|
||||
), "w+"
|
||||
) as f:
|
||||
for reach in study.river.enable_edges():
|
||||
f.write(f"0.0\n")
|
||||
|
||||
ics = study.river.initial_conditions.get(reach)
|
||||
data = self._export_tps_init_data(ics)
|
||||
|
||||
profiles = edge.reach.profiles
|
||||
first = profiles[0]
|
||||
last = profiles[-1]
|
||||
|
||||
f_h_s = self._export_tps_profile_height_speed(first, data)
|
||||
l_h_s = self._export_tps_profile_height_speed(last, data)
|
||||
|
||||
# First mail
|
||||
f.write(f"{1:>5} {f_h_s[0]} {f_h_s[1]}")
|
||||
|
||||
ind = 2
|
||||
it = iter(profiles)
|
||||
prev = next(profiles)
|
||||
|
||||
prev_h, prev_s = f_h_s
|
||||
for profile in it:
|
||||
cur_h, cur_s = self._export_tps_profile_height_speed(
|
||||
profile, data
|
||||
)
|
||||
|
||||
# Mean of height and speed
|
||||
h = (prev_h + cur_h) / 2
|
||||
s = (prev_s + cur_s) / 2
|
||||
|
||||
f.write(f"{ind:>5} {h} {s}")
|
||||
|
||||
prev_h, prev_s = cur_h, cur_s
|
||||
ind += 1
|
||||
|
||||
# Last mail
|
||||
f.write(f"{ind:>5} {f_h_s[0]} {f_h_s[1]}")
|
||||
|
||||
|
||||
def _export_tps_init_data(self, ics):
|
||||
data = {}
|
||||
|
||||
for ic in ics:
|
||||
d = ic.data
|
||||
if len(d) == 0:
|
||||
continue
|
||||
|
||||
data[d['kp']] = (
|
||||
d['elevation'],
|
||||
d['discharge'],
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
def _export_tps_profile_height_speed(self, profile, data):
|
||||
z = data[profile.kp][0]
|
||||
q = data[profile.kp][1]
|
||||
|
||||
heiglt = z - profile.z_min()
|
||||
speed = profile.seed(q, z)
|
||||
|
||||
return height, speed
|
||||
|
|
|
|||
Loading…
Reference in New Issue