@sh.add_function(dsp, outputs=['maximum_velocity', 'gear_at_maximum_velocity'])
def calculate_maximum_velocity(
full_load_curve, road_loads, speed_velocity_ratios):
"""
Calculates the maximum velocity from full load curve.
:param full_load_curve:
Vehicle full load curve.
:type full_load_curve: function
:param road_loads:
Cycle road loads [N, N/(km/h), N/(km/h)^2].
:type road_loads: list, tuple
:param speed_velocity_ratios:
Speed velocity ratios of the gear box [h*RPM/km].
:type speed_velocity_ratios: dict[int | float]
:return:
Maximum velocity and gear at maximum velocity [km/h, -].
:return: float, int
"""
d = dfl.functions.calculate_maximum_velocity
velocity = np.arange(d.MIN_VEL, d.MAX_VEL, d.DELTA_VEL, float)
g_id, svr = zip(*[(k, v) for k, v in sorted(
speed_velocity_ratios.items(), reverse=True
) if k])
p = full_load_curve(np.round(np.multiply(velocity[:, None], svr), 1))
b = (p * d.PREC_FLC) < _calculate_req_power(road_loads, velocity)[:, None]
# noinspection PyUnresolvedReferences
velocity = np.repeat(velocity[:, None], b.shape[1], 1)
velocity[b] = -1
i, j = np.unravel_index(np.argmax(velocity), velocity.shape)
return velocity[i, j], g_id[j]