Solver: RubarBE: Factorise some code.

scenarios
Pierre-Antoine 2025-10-09 16:49:47 +02:00
parent 21e6c410e2
commit df3b3b604d
1 changed files with 22 additions and 9 deletions

View File

@ -557,6 +557,17 @@ class Rubar3(CommandLineSolver):
line = f.readline().split() line = f.readline().split()
return tuple(map(float, line)) return tuple(map(float, line))
def set_and_compute_limites(reach, ind, z, q, s):
reach.set(0, timestamp, "Z", z)
reach.set(0, timestamp, "Q", q)
reach.set(0, timestamp, "V", s)
profile = reach.profile(ind)
limits = profile.geometry.get_water_limits(z)
reach.set(
ind, timestamp, "water_limits", limits
)
ts = set() ts = set()
end = False end = False
while True: while True:
@ -565,31 +576,33 @@ class Rubar3(CommandLineSolver):
return return
timestamp = float(line) timestamp = float(line)
ts.add(timestamp)
for reach, lm in reachs: for reach, lm in reachs:
# First profile # First profile
z, s, q, e = read_data_line(f) z, s, q, e = read_data_line(f)
reach.set(0, timestamp, "Z", z) set_and_compute_limites(reach, 0, z, q, s)
reach.set(0, timestamp, "Q", q)
reach.set(0, timestamp, "V", s)
# For each profile # For each profile
ind = 1 ind = 1
pz, ps, pq, pe = read_data_line(f) pz, ps, pq, pe = read_data_line(f)
while ind < lm - 2: while ind < lm - 2:
z, s, q, e = read_data_line(f) z, s, q, e = read_data_line(f)
reach.set(ind, timestamp, "Z", (z + pz) / 2) set_and_compute_limites(
reach.set(ind, timestamp, "Q", (q + pq) / 2) reach, ind,
reach.set(ind, timestamp, "V", (q + ps) / 2) (pz + z) / 2,
(pq + q) / 2,
(ps + s) / 2
)
pz, ps, pq, pe = z, s, q, e pz, ps, pq, pe = z, s, q, e
ind += 1 ind += 1
# Last profile # Last profile
z, s, q, e = read_data_line(f) z, s, q, e = read_data_line(f)
reach.set(ind, timestamp, "Z", z) set_and_compute_limites(reach, ind, z, q, s)
reach.set(ind, timestamp, "Q", q)
reach.set(ind, timestamp, "V", s) results.set("timestamps", ts)
@timer @timer
def results(self, study, repertory, qlog=None, name="0"): def results(self, study, repertory, qlog=None, name="0"):