mirror of https://gitlab.com/pamhyr/pamhyr2
Geometry: ProfileXYZ: Minor optimisation of computation.
parent
a61d130baa
commit
1adf24ce77
|
|
@ -875,7 +875,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
if z in self._get_water_limits_cache:
|
||||
return self._get_water_limits_cache[z]
|
||||
|
||||
return self.get_water_limits_compute(z)
|
||||
v = self.get_water_limits_compute(z)
|
||||
|
||||
return v
|
||||
|
||||
def get_water_limits_compute(self, z):
|
||||
"""
|
||||
|
|
@ -883,54 +885,59 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
"""
|
||||
# Get the index of first point with elevation lesser than water
|
||||
# elevation (for the right and left river side)
|
||||
i_left = -1
|
||||
i_right = -1
|
||||
i_left = next(
|
||||
filter(
|
||||
lambda i: self.point(i).z <= z,
|
||||
range(self.number_points)
|
||||
),
|
||||
-1
|
||||
)
|
||||
|
||||
for i in range(self.number_points):
|
||||
if self.point(i).z <= z:
|
||||
i_left = i
|
||||
break
|
||||
|
||||
for i in reversed(range(self.number_points)):
|
||||
if self.point(i).z <= z:
|
||||
i_right = i
|
||||
break
|
||||
i_right = next(
|
||||
filter(
|
||||
lambda i: self.point(i).z <= z,
|
||||
reversed(range(self.number_points))
|
||||
),
|
||||
-1
|
||||
)
|
||||
|
||||
# Interpolate points at river left side
|
||||
if (i_left > 0):
|
||||
if abs(self.point(i_left - 1).z - self.point(i_left).z) < 1e-20:
|
||||
pt_left = self.point(i_left)
|
||||
pi = self.point(i_left)
|
||||
pim1 = self.point(i_left - 1)
|
||||
|
||||
if abs(pim1.z - pi.z) < 1e-20:
|
||||
pt_left = pi
|
||||
else:
|
||||
fact = (z - self.point(i_left).z) / \
|
||||
(self.point(i_left - 1).z - self.point(i_left).z)
|
||||
x = self.point(i_left).x + fact * \
|
||||
(self.point(i_left - 1).x - self.point(i_left).x)
|
||||
y = self.point(i_left).y + fact * \
|
||||
(self.point(i_left - 1).y - self.point(i_left).y)
|
||||
fact = (z - pi.z) / (pim1.z - pi.z)
|
||||
x = pi.x + fact * (pim1.x - pi.x)
|
||||
y = pi.y + fact * (pim1.y - pi.y)
|
||||
pt_left = PointXYZ(x=x, y=y, z=z, name="wl_left")
|
||||
else:
|
||||
pt_left = self.point(0)
|
||||
|
||||
# Interpolate points at river right side
|
||||
if (i_right < self.number_points - 1):
|
||||
if abs(self.point(i_right + 1).z - self.point(i_right).z) < 1e-20:
|
||||
pt_right = self.point(i_right)
|
||||
pi = self.point(i_right)
|
||||
pip1 = self.point(i_right + 1)
|
||||
|
||||
if abs(pip1.z - pi.z) < 1e-20:
|
||||
pt_right = pi
|
||||
else:
|
||||
fact = (z - self.point(i_right).z) / \
|
||||
(self.point(i_right + 1).z - self.point(i_right).z)
|
||||
x = self.point(i_right).x + fact * \
|
||||
(self.point(i_right + 1).x - self.point(i_right).x)
|
||||
y = self.point(i_right).y + fact * \
|
||||
(self.point(i_right + 1).y - self.point(i_right).y)
|
||||
fact = (z - pi.z) / (pip1.z - pi.z)
|
||||
x = pi.x + fact * (pip1.x - pi.x)
|
||||
y = pi.y + fact * (pip1.y - pi.y)
|
||||
pt_right = PointXYZ(x=x, y=y, z=z, name="wl_right")
|
||||
else:
|
||||
pt_right = self.point(self.number_points - 1)
|
||||
|
||||
v = (pt_left, pt_right)
|
||||
|
||||
# Put results in cache
|
||||
self._get_water_limits_cache[z] = (pt_left, pt_right)
|
||||
self._get_water_limits_cache[z] = v
|
||||
|
||||
# Create a generator to improve results data reading speed
|
||||
yield pt_left, pt_right
|
||||
yield v
|
||||
|
||||
@timer
|
||||
def compute_tabulation(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue