Frictions: Split frictions list at reach split.

scenarios
Pierre-Antoine 2025-09-30 15:54:00 +02:00
parent d222842313
commit 2a926a8d73
3 changed files with 40 additions and 2 deletions

View File

@ -213,6 +213,17 @@ class Friction(SQLSubModel):
return new return new
def cloned_for(self, reach):
new = Friction(reach=reach, status=self._status)
new.reach = reach
new.begin_rk = self._begin_rk
new.end_rk = self._end_rk
new.begin_strickler = self._begin_strickler
new.end_strickler = self._begin_strickler
return new
def must_be_saved(self): def must_be_saved(self):
ssi = self._status.scenario_id ssi = self._status.scenario_id

View File

@ -20,6 +20,7 @@ import logging
from copy import copy from copy import copy
from tools import trace, timer from tools import trace, timer
from functools import reduce
from Model.Tools.PamhyrDB import SQLSubModel from Model.Tools.PamhyrDB import SQLSubModel
from Model.Tools.PamhyrListExt import PamhyrModelList from Model.Tools.PamhyrListExt import PamhyrModelList
@ -95,3 +96,29 @@ class FrictionList(PamhyrModelList):
self._lst.insert(index, n) self._lst.insert(index, n)
self._status.modified() self._status.modified()
return n return n
def _splited_for(self, reach):
new = FrictionList(status=self._status)
rk_min, rk_max = reduce(
lambda mm, p: (
min(mm[0], p.rk),
max(mm[1], p.rk)
),
reach.reach.profiles,
((999 ** 100), -(999 ** 100))
)
frictions = list(
filter(
lambda f: ((rk_min <= f.begin_rk <= rk_max) or
(rk_min <= f.end_rk <= rk_max)),
self._lst))
for ind, friction in enumerate(frictions):
n = friction.cloned_for(reach)
new._lst.insert(ind, n)
new._status.modified()
return new

View File

@ -437,10 +437,10 @@ class RiverReach(Edge):
nr1, nr2 = self._reach._split(profile, new_reach1, new_reach2) nr1, nr2 = self._reach._split(profile, new_reach1, new_reach2)
new_reach1._reach = nr1 new_reach1._reach = nr1
new_reach1._frictions = self._frictions new_reach1._frictions = self._frictions._splited_for(new_reach1)
new_reach2._reach = nr2 new_reach2._reach = nr2
new_reach2._frictions = self._frictions new_reach2._frictions = self._frictions._splited_for(new_reach2)
self.disable() self.disable()