@sh.add_function(dsp, outputs=['engine_max_speed_95'])
def calculate_engine_max_speed_95(
full_load_speeds, idle_engine_speed, engine_max_speed, full_load_curve,
engine_max_power):
"""
Calculates the maximum engine speed [RPM] at 95% of the nominal power.
:param full_load_speeds:
T1 map speed vector [RPM].
:type full_load_speeds: numpy.array
:param idle_engine_speed:
Engine speed idle median and std [RPM].
:type idle_engine_speed: (float, float)
:param engine_max_speed:
Maximum allowed engine speed [RPM].
:type engine_max_speed: float
:param full_load_curve:
Vehicle full load curve.
:type full_load_curve: function
:param engine_max_power:
Engine nominal power [kW].
:type engine_max_power: float
:return:
Maximum engine speed [RPM] at 95% of the nominal power.
:rtype: float
"""
from scipy.interpolate import InterpolatedUnivariateSpline as Spl
speeds = [idle_engine_speed[0] - idle_engine_speed[1], engine_max_speed]
speeds.extend(full_load_speeds)
speeds = np.unique(speeds)
n = [engine_max_speed]
n.extend(
Spl(speeds, full_load_curve(speeds) / engine_max_power - 0.95).roots()
)
return max(n)