Compare commits

..

2 Commits

Author SHA1 Message Date
Theophile Terraz 879c151524 pep8 2025-10-29 17:13:09 +01:00
Theophile Terraz 7990a60d8b take care of frictions in update_rk 2025-10-29 17:09:42 +01:00
2 changed files with 45 additions and 12 deletions

View File

@ -17,7 +17,7 @@
# -*- coding: utf-8 -*-
import logging
from numpy import sign
from numpy import sign, interp
from copy import deepcopy
from tools import logger_color_red, logger_color_reset, logger_exception
@ -273,7 +273,7 @@ class InternalMeshing(AMeshingTool):
sect2.point(start2+len2).name = tag2
sect2.modified()
def update_rk(self, reach,
def update_rk(self, reach, begin_rk, end_rk,
step: float = 50,
limites=[-1, -1],
origin=0,
@ -297,15 +297,25 @@ class InternalMeshing(AMeshingTool):
# 1: up -> downstream
# 2: down -> upstream
# else: keep current orientation
old_orientation = sign(reach.profiles[-1].rk - reach.profiles[0].rk)
if orientation == 1:
sgn = 1.0
elif orientation == 2:
sgn = -1.0
else:
sgn = sign(reach.profiles[-1].rk - reach.profiles[0].rk)
sgn = old_orientation
rk = [0.0]*nprof
rk[origin] = origin_value
new_rk = [0.0]*nprof
new_rk[origin] = origin_value
frictions = reach._parent.frictions
old_begin_rk = list(map(lambda x: x * old_orientation,
begin_rk))
old_end_rk = list(map(lambda x: x * old_orientation,
end_rk))
old_rk = list(map(lambda x: x * old_orientation,
reach.get_rk()))
if origin < nprof - 1:
for i in range(origin+1, nprof):
@ -316,7 +326,7 @@ class InternalMeshing(AMeshingTool):
d2 = reach.profiles[i-1].named_point(
directrices[1]
).dist_2d(reach.profiles[i].named_point(directrices[1]))
rk[i] = rk[i-1] + (sgn * (d1 + d2) / 2)
new_rk[i] = new_rk[i-1] + (sgn * (d1 + d2) / 2)
if origin > 0:
for i in reversed(range(0, origin)):
# 2D
@ -326,6 +336,11 @@ class InternalMeshing(AMeshingTool):
d2 = reach.profiles[i+1].named_point(
directrices[1]
).dist_2d(reach.profiles[i].named_point(directrices[1]))
rk[i] = rk[i+1] - (sgn * (d1 + d2) / 2)
new_rk[i] = new_rk[i+1] - (sgn * (d1 + d2) / 2)
return rk
new_begin_rk = interp(old_begin_rk, old_rk, new_rk)
new_end_rk = interp(old_end_rk, old_rk, new_rk)
if abs(sgn - old_orientation) > 0.1: # orientation changed
return new_rk, new_end_rk, new_begin_rk
else:
return new_rk, new_begin_rk, new_end_rk

View File

@ -237,22 +237,40 @@ class UpdateRKCommand(QUndoCommand):
self._data = data
self._mesher = mesher
self._rks = reach.get_rk()
self._frictions = [f for f in reach._parent.frictions.frictions
if f.is_full_defined()]
self._begin_rk = [f.begin_rk for f in self._frictions]
self._end_rk = [f.end_rk for f in self._frictions]
self._new_rks = None
self._new_begin_rk = None
self._new_end_rk = None
def undo(self):
for rk, profile in zip(self._rks, self._reach.profiles):
profile.rk = rk
for begin_rk, end_rk, friction in zip(self._begin_rk,
self._end_rk,
self._frictions):
friction.begin_rk = begin_rk
friction.end_rk = end_rk
def redo(self):
if self._new_rks is None:
self._new_rks = self._mesher.update_rk(
self._reach,
**self._data
)
self._new_rks, self._new_begin_rk, self._new_end_rk = \
self._mesher.update_rk(
self._reach, self._begin_rk, self._end_rk,
**self._data
)
for rk, profile in zip(self._new_rks, self._reach.profiles):
profile.rk = rk
for begin_rk, end_rk, friction in zip(self._new_begin_rk,
self._new_end_rk,
self._frictions):
friction.begin_rk = begin_rk
friction.end_rk = end_rk
class MeshingCommand(QUndoCommand):