diff --git a/src/Solver/RubarBE.py b/src/Solver/RubarBE.py index f3d6a5af419ea2697b3d545604af28f7e00ff03f..d32e0fdba01fd98dcea061f225449ddaeaf9ae1a 100644 --- a/src/Solver/RubarBE.py +++ b/src/Solver/RubarBE.py @@ -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