def wltp_gears(
full_load_curve, velocities, accelerations, motive_powers,
speed_velocity_ratios, idle_engine_speed, engine_speed_at_max_power,
engine_max_power, engine_max_speed, base_model, initial_gears=None):
"""
Returns the gear shifting profile according to WLTP [-].
:param full_load_curve:
Vehicle full load curve.
:type full_load_curve: function
:param velocities:
Velocity vector [km/h].
:type velocities: numpy.array
:param accelerations:
Acceleration vector [m/s2].
:type accelerations: numpy.array
:param motive_powers:
Motive power [kW].
:type motive_powers: numpy.array
:param speed_velocity_ratios:
Speed velocity ratios of the gear box [h*RPM/km].
:type speed_velocity_ratios: dict[int | float]
:param idle_engine_speed:
Engine speed idle median and std [RPM].
:type idle_engine_speed: (float, float)
:param engine_speed_at_max_power:
Rated engine speed [RPM].
:type engine_speed_at_max_power: float
:param engine_max_power:
Maximum power [kW].
:type engine_max_power: float
:param engine_max_speed:
Maximum allowed engine speed [RPM].
:type engine_max_speed: float
:param base_model:
WLTP base model params.
:type base_model: dict
:param initial_gears:
Initial gear vector [-].
:type initial_gears: numpy.array
:return:
Gear vector [-].
:rtype: numpy.array
"""
import numpy as np
import wltp.experiment as wltp_exp
n_min_drive = None
svr = [v for k, v in sorted(speed_velocity_ratios.items()) if k]
idle = idle_engine_speed[0]
n_norm = np.arange(
0.0, (engine_max_speed - idle) / (engine_speed_at_max_power - idle), .01
)
load_curve = {
'n_norm': n_norm,
'p_norm': full_load_curve(
idle + n_norm * (engine_speed_at_max_power - idle)
) / engine_max_power
}
b = velocities < 0
if b.any():
v = velocities.copy()
v[b] = 0
else:
v = velocities
res = wltp_exp.run_cycle(
v, accelerations, motive_powers, svr, idle_engine_speed[0], n_min_drive,
engine_speed_at_max_power, engine_max_power, load_curve, base_model
)
if initial_gears:
gears = initial_gears.copy()
else:
# noinspection PyUnresolvedReferences
gears = res[0]
# Apply Driveability-rules.
# noinspection PyUnresolvedReferences
wltp_exp.applyDriveabilityRules(v, accelerations, gears, res[1], res[-1])
gears[gears < 0] = 0
log.warning('The WLTP gear-shift profile generation is for engineering '
'purposes and the results are by no means valid according to '
'the legislation.\nActually they are calculated based on a pre '
'phase-1a version of the GTR spec.\n '
'Please provide the gear-shifting profile '
'within `prediction.WLTP` sheet.')
return gears