示例#1
0
def nedc_cycle():
    """
    Defines the wltp cycle model.

    .. dispatcher:: dsp

        >>> dsp = nedc_cycle()

    :return:
        The wltp cycle model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='NEDC cycle model',
        description='Returns the theoretical times, velocities, and gears of '
        'NEDC.')

    dsp.add_data(data_id='initial_temperature',
                 default_value=dfl.values.initial_temperature_NEDC,
                 description='Initial temperature of the test cell [°C].')

    dsp.add_data(data_id='k1', default_value=dfl.values.k1)

    dsp.add_data(data_id='k2', default_value=dfl.values.k2)

    dsp.add_function(function_id='set_max_gear_as_default_k5',
                     function=dsp_utl.bypass,
                     inputs=['max_gear'],
                     outputs=['k5'])

    dsp.add_data(data_id='k5', default_value=dfl.values.k5, initial_dist=10)

    dsp.add_data(data_id='time_sample_frequency',
                 default_value=dfl.values.time_sample_frequency)

    dsp.add_function(
        function_id='nedc_gears',
        function=dsp_utl.add_args(nedc_gears),
        inputs=['gear_box_type', 'times', 'max_gear', 'k1', 'k2', 'k5'],
        outputs=['gears'],
        input_domain=lambda *args: args[0] == 'manual')

    dsp.add_function(function=nedc_velocities,
                     inputs=['times', 'gear_box_type'],
                     outputs=['velocities'])

    dsp.add_function(function=nedc_time_length,
                     inputs=['time_sample_frequency'],
                     outputs=['time_length'],
                     weight=5)

    return dsp
示例#2
0
        def setUp(self):
            dsp = Dispatcher()
            dsp.add_data('a', default_value=5)

            def f(a):
                return a + 1

            self.fun_id = dsp.add_function(function=f,
                                           inputs=['a'],
                                           outputs=['b'])

            self.dsp = dsp

            self.tmp = mkstemp()[1]
示例#3
0
    def setUp(self):
        ss_dsp = Dispatcher()

        fun = lambda a: (a + 1, 5, a - 1)
        dom = lambda kw: True
        c = '|!"£$%&/()=?^*+éè[]#¶ù§çò@:;-_.,<>'
        ss_dsp.add_function(function=fun,
                            inputs=['a'],
                            outputs=['b', SINK, c],
                            input_domain=dom,
                            weight=1)

        def raise_fun(a):
            raise ValueError('Error')

        ss_dsp.add_function(function=raise_fun, inputs=['a'], outputs=['b'])

        sdspfunc = SubDispatchFunction(ss_dsp, 'SubDispatchFunction', ['a'],
                                       ['b', c])

        sdsppipe = SubDispatchPipe(ss_dsp, 'SubDispatchPipe', ['a'], ['b', c])

        sdsp = SubDispatch(ss_dsp, ['b', c], output_type='list')

        s_dsp = Dispatcher()
        s_dsp.add_function(None, sdspfunc, ['a'], ['b', 'c'], weight=2)
        s_dsp.add_function(None,
                           sdsppipe, ['a'], ['b', 'c'],
                           out_weight={'c': 5})
        s_dsp.add_function('SubDispatch', sdsp, ['d'], ['e', 'f'])

        dsp = Dispatcher()
        import numpy as np
        dsp.add_data('A', default_value=np.zeros(1000))
        dsp.add_data('D', default_value={'a': 3})

        dsp.add_dispatcher(dsp=s_dsp,
                           inputs={
                               'A': 'a',
                               'D': 'd'
                           },
                           outputs={
                               'b': 'B',
                               'c': 'C',
                               'e': 'E',
                               'f': 'F'
                           },
                           inp_weight={'A': 3})
        self.sol = dsp.dispatch()
        self.dsp = dsp
示例#4
0
def cvt_model():
    """
    Defines the gear box model.

    .. dispatcher:: dsp

        >>> dsp = cvt_model()

    :return:
        The gear box model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='CVT model',
        description='Models the gear box.'
    )

    dsp.add_function(
        function=calibrate_cvt,
        inputs=['on_engine', 'engine_speeds_out', 'velocities', 'accelerations',
                'gear_box_powers_out'],
        outputs=['CVT']
    )

    dsp.add_function(
        function=predict_gear_box_speeds_in__gears_and_max_gear,
        inputs=['CVT', 'velocities', 'accelerations',
                'gear_box_powers_out'],
        outputs=['gear_box_speeds_in', 'gears', 'max_gear'],
        out_weight={'gear_box_speeds_in': 10}
    )

    dsp.add_data(
        data_id='stop_velocity',
        default_value=dfl.values.stop_velocity
    )

    dsp.add_function(
        function=identify_max_speed_velocity_ratio,
        inputs=['velocities', 'engine_speeds_out', 'idle_engine_speed',
                'stop_velocity'],
        outputs=['max_speed_velocity_ratio']
    )

    return dsp
示例#5
0
def _selector(name, data_in, data_out, setting):

    dsp = Dispatcher(
        name='%s selector' % name,
        description='Select the calibrated %s.' % name,
    )

    errors, setting = [], setting or {}
    _sort_models = setting.pop('sort_models', sort_models)

    if 'weights' in setting:
        _weights = dsp_utl.map_list(setting['targets'],
                                    *setting.pop('weights'))
    else:
        _weights = None

    _get_best_model = partial(setting.pop('get_best_model', get_best_model),
                              models_wo_err=setting.pop('models_wo_err', None),
                              selector_id=dsp.name)

    dsp.add_data(data_id='error_settings', default_value={})

    for i in data_in:
        e = 'error/%s' % i

        errors.append(e)

        dsp.add_function(function=_errors(name, i, data_out, setting),
                         inputs=['error_settings', i] +
                         [k for k in data_out if k != i],
                         outputs=[e])

    dsp.add_function(function_id='sort_models',
                     function=partial(_sort_models, weights=_weights),
                     inputs=errors,
                     outputs=['rank'])

    dsp.add_function(function_id='get_best_model',
                     function=_get_best_model,
                     inputs=['rank'],
                     outputs=['model', 'errors'])

    return dsp_utl.SubDispatch(dsp,
                               outputs=['model', 'errors'],
                               output_type='list')
示例#6
0
    def setUp(self):
        ss_dsp = Dispatcher()

        fun = lambda a: (a + 1, 5, a - 1)
        c = '|!"£$%&/()=?^*+éè[]#¶ù§çò@:;-_.,<>'
        ss_dsp.add_function(function=fun, inputs=['a'], outputs=['b', SINK, c])

        sub_dispatch = SubDispatch(ss_dsp, ['a', 'b', c], output_type='list')
        s_dsp = Dispatcher()

        s_dsp.add_function('sub_dispatch', sub_dispatch, ['a'],
                           ['b', 'c', 'd'])

        dispatch = SubDispatch(s_dsp, ['b', 'c', 'd'], output_type='list')
        dsp = Dispatcher()
        dsp.add_data('input', default_value={'a': {'a': 3, 'funcs': fun}})

        dsp.add_function('dispatch', dispatch, ['input'], [SINK, 'h', 'i'])

        dsp.dispatch()
        self.dsp = dsp
示例#7
0
def selector(*data):
    """
    Defines the models' selector model.

    .. dispatcher:: dsp

        >>> dsp = selector()

    :return:
        The models' selector model.
    :rtype: SubDispatchFunction
    """

    data = data or ('wltp_h', 'wltp_l')

    dsp = Dispatcher(
        name='Models selector',
        description='Select the calibrated models.',
    )

    dsp.add_function(function=partial(dsp_utl.map_list, data),
                     inputs=data,
                     outputs=['CO2MPAS_results'])

    dsp.add_data(data_id='models', function=combine_outputs, wait_inputs=True)

    dsp.add_data(data_id='scores', function=combine_scores, wait_inputs=True)

    setting = sub_models()

    dsp.add_data(data_id='error_settings', default_value={})

    m = list(setting)
    dsp.add_function(function=partial(split_error_settings, m),
                     inputs=['error_settings'],
                     outputs=['error_settings/%s' % k for k in m])

    for k, v in setting.items():
        v['dsp'] = v.pop('define_sub_model', define_sub_model)(**v)
        v['metrics'] = dsp_utl.map_list(v['targets'], *v['metrics'])
        dsp.add_function(function=v.pop('model_selector', _selector)(k, data,
                                                                     data, v),
                         function_id='%s selector' % k,
                         inputs=['CO2MPAS_results',
                                 'error_settings/%s' % k],
                         outputs=['models', 'scores'])

    func = dsp_utl.SubDispatchFunction(dsp=dsp,
                                       function_id='models_selector',
                                       inputs=('error_settings', ) + data,
                                       outputs=['models', 'scores'])

    return func
示例#8
0
def _errors(name, data_id, data_out, setting):

    name = ''.join(k[0].upper() for k in name.split('_'))

    dsp = Dispatcher(
        name='%s-%s errors' % (name, data_id),
        description='Calculates the error of calibrated model.',
    )

    setting = setting.copy()

    dsp.add_data(data_id='models', default_value=setting.pop('models', []))

    select_data = partial(dsp_utl.selector, allow_miss=True)

    dsp.add_function(function_id='select_models',
                     function=setting.pop('select_models', select_data),
                     inputs=['models', data_id],
                     outputs=['calibrated_models'])

    dsp.add_data(data_id='data_in', default_value=data_id)

    dsp.add_data(data_id='error_settings', default_value={})

    for o in data_out:

        dsp.add_function(function=partial(dsp_utl.map_list,
                                          ['calibrated_models', 'data']),
                         inputs=['calibrated_models', o],
                         outputs=['input/%s' % o])

        dsp.add_function(function=_error(name, data_id, o, setting),
                         inputs=['input/%s' % o, 'error_settings'],
                         outputs=['error/%s' % o])

    i = ['error_settings', data_id] + [k for k in data_out if k != data_id]
    func = dsp_utl.SubDispatchFunction(dsp=dsp, function_id=dsp.name, inputs=i)

    return func
示例#9
0
def mechanical():
    """
    Defines the mechanical gear box model.

    .. dispatcher:: dsp

        >>> dsp = mechanical()

    :return:
        The gear box model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='mechanical model',
                     description='Models the gear box.')

    dsp.add_data(data_id='stop_velocity',
                 default_value=dfl.values.stop_velocity)

    dsp.add_data(data_id='plateau_acceleration',
                 default_value=dfl.values.plateau_acceleration)

    dsp.add_data(data_id='change_gear_window_width',
                 default_value=dfl.values.change_gear_window_width)

    dsp.add_function(function=identify_gears,
                     inputs=[
                         'times', 'velocities', 'accelerations',
                         'engine_speeds_out', 'velocity_speed_ratios',
                         'stop_velocity', 'plateau_acceleration',
                         'change_gear_window_width', 'idle_engine_speed'
                     ],
                     outputs=['gears'])

    dsp.add_function(function=calculate_gear_box_speeds_in,
                     inputs=[
                         'gears', 'velocities', 'velocity_speed_ratios',
                         'stop_velocity'
                     ],
                     outputs=['gear_box_speeds_in'],
                     weight=25)

    dsp.add_function(
        function=calculate_gear_box_speeds_in_v1,
        inputs=['gears', 'gear_box_speeds_out', 'gear_box_ratios'],
        outputs=['gear_box_speeds_in'])

    dsp.add_function(
        function=calculate_speed_velocity_ratios,
        inputs=['gear_box_ratios', 'final_drive_ratio', 'r_dynamic'],
        outputs=['speed_velocity_ratios'])

    dsp.add_function(
        function=identify_speed_velocity_ratios,
        inputs=['gears', 'velocities', 'gear_box_speeds_in', 'stop_velocity'],
        outputs=['speed_velocity_ratios'],
        weight=5)

    dsp.add_function(
        function=identify_speed_velocity_ratios,
        inputs=['gears', 'velocities', 'engine_speeds_out', 'stop_velocity'],
        outputs=['speed_velocity_ratios'],
        weight=10)

    dsp.add_function(function=calculate_velocity_speed_ratios,
                     inputs=['speed_velocity_ratios'],
                     outputs=['velocity_speed_ratios'])

    dsp.add_function(function=identify_velocity_speed_ratios,
                     inputs=[
                         'engine_speeds_out', 'velocities',
                         'idle_engine_speed', 'stop_velocity'
                     ],
                     outputs=['velocity_speed_ratios'],
                     weight=50)

    dsp.add_function(
        function=calculate_gear_box_ratios,
        inputs=['velocity_speed_ratios', 'final_drive_ratio', 'r_dynamic'],
        outputs=['gear_box_ratios'])

    dsp.add_function(function=identify_max_gear,
                     inputs=['speed_velocity_ratios'],
                     outputs=['max_gear'])

    return dsp
示例#10
0
def _error(name, data_id, data_out, setting):

    dsp = Dispatcher(
        name='%s-%s error vs %s' % (name, data_id, data_out),
        description='Calculates the error of calibrated model of a reference.',
    )

    default_settings = {
        'inputs_map': {},
        'targets': [],
        'metrics_inputs': {},
        'up_limit': None,
        'dn_limit': None
    }

    default_settings.update(setting)

    it = dsp_utl.selector(['up_limit', 'dn_limit'], default_settings).items()

    for k, v in it:
        if v is not None:
            default_settings[k] = dsp_utl.map_list(setting['targets'], *v)

    dsp.add_function(function_id='select_inputs',
                     function=dsp_utl.map_dict,
                     inputs=['inputs_map', 'data'],
                     outputs=['inputs<0>'])

    dsp.add_function(function_id='select_inputs',
                     function=partial(dsp_utl.selector, allow_miss=True),
                     inputs=['inputs', 'inputs<0>'],
                     outputs=['inputs<1>'])

    dsp.add_function(function=dsp_utl.combine_dicts,
                     inputs=['calibrated_models', 'inputs<1>'],
                     outputs=['prediction_inputs'])

    dsp.add_function(function_id='select_targets',
                     function=partial(dsp_utl.selector, allow_miss=True),
                     inputs=['targets', 'data'],
                     outputs=['references'])

    dsp.add_function(function=partial(default_settings.pop('dsp', lambda x: x),
                                      {}),
                     inputs=['prediction_inputs', 'calibrated_models'],
                     outputs=['results'])

    dsp.add_function(function_id='select_outputs',
                     function=select_outputs,
                     inputs=['outputs', 'targets', 'results'],
                     outputs=['predictions'])

    dsp.add_function(function_id='select_metrics_inputs',
                     function=partial(dsp_utl.selector, allow_miss=True),
                     inputs=['metrics_inputs', 'data'],
                     outputs=['metrics_args'])

    dsp.add_function(
        function=make_metrics,
        inputs=['metrics', 'references', 'predictions', 'metrics_args'],
        outputs=['errors'])

    dsp.add_function(function=check_limits,
                     inputs=['errors', 'up_limit', 'dn_limit'],
                     outputs=['status'])

    for k, v in default_settings.items():
        dsp.add_data(k, v)

    func = dsp_utl.SubDispatch(dsp=dsp,
                               outputs=['errors', 'status'],
                               output_type='list')

    return func
示例#11
0
def torque_converter():
    """
    Defines the torque converter model.

    .. dispatcher:: dsp

        >>> dsp = torque_converter()

    :return:
        The torque converter model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='Torque_converter',
        description='Models the torque converter.'
    )

    dsp.add_data(
        data_id='calibration_tc_speed_threshold',
        default_value=dfl.values.calibration_tc_speed_threshold
    )

    dsp.add_data(
        data_id='stop_velocity',
        default_value=dfl.values.stop_velocity
    )

    dsp.add_data(
        data_id='lock_up_tc_limits',
        default_value=dfl.values.lock_up_tc_limits
    )

    dsp.add_function(
        function=identify_torque_converter_speeds_delta,
        inputs=['engine_speeds_out', 'engine_speeds_out_hot',
                'cold_start_speeds_delta'],
        outputs=['torque_converter_speeds_delta']
    )

    dsp.add_function(
        function=calibrate_torque_converter_model,
        inputs=['lock_up_tc_limits', 'calibration_tc_speed_threshold',
                'stop_velocity', 'torque_converter_speeds_delta',
                'accelerations', 'velocities', 'gear_box_speeds_in', 'gears'],
        outputs=['torque_converter_model']
    )

    dsp.add_function(
        function=predict_torque_converter_speeds_delta,
        inputs=['lock_up_tc_limits', 'torque_converter_model', 'accelerations',
                'velocities', 'gear_box_speeds_in', 'gears'],
        outputs=['torque_converter_speeds_delta']
    )

    dsp.add_function(
        function=define_k_factor_curve,
        inputs=['stand_still_torque_ratio', 'lockup_speed_ratio'],
        outputs=['k_factor_curve']
    )

    dsp.add_function(
        function=default_tc_k_factor_curve,
        outputs=['k_factor_curve'],
        weight=2
    )

    return dsp
示例#12
0
def wheels():
    """
    Defines the wheels model.

    .. dispatcher:: dsp

        >>> dsp = wheels()

    :return:
        The wheels model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='Wheel model',
                     description='It models the wheel dynamics.')

    dsp.add_function(function=calculate_wheel_torques,
                     inputs=['wheel_powers', 'wheel_speeds'],
                     outputs=['wheel_torques'])

    dsp.add_function(function=calculate_wheel_powers,
                     inputs=['wheel_torques', 'wheel_speeds'],
                     outputs=['wheel_powers'])

    dsp.add_function(function=calculate_wheel_speeds,
                     inputs=['velocities', 'r_dynamic'],
                     outputs=['wheel_speeds'])

    dsp.add_function(function=identify_r_dynamic,
                     inputs=[
                         'velocity_speed_ratios', 'gear_box_ratios',
                         'final_drive_ratio'
                     ],
                     outputs=['r_dynamic'])

    dsp.add_function(function=identify_r_dynamic_v1,
                     inputs=[
                         'velocities', 'gears', 'engine_speeds_out',
                         'gear_box_ratios', 'final_drive_ratio',
                         'stop_velocity'
                     ],
                     outputs=['r_dynamic'],
                     weight=10)

    dsp.add_data(data_id='stop_velocity',
                 default_value=dfl.values.stop_velocity)

    dsp.add_data(data_id='plateau_acceleration',
                 default_value=dfl.values.plateau_acceleration)

    dsp.add_data(data_id='change_gear_window_width',
                 default_value=dfl.values.change_gear_window_width)

    dsp.add_function(function=calculate_tyre_dimensions,
                     inputs=['tyre_code'],
                     outputs=['tyre_dimensions'])

    dsp.add_function(function=calculate_r_wheels,
                     inputs=['tyre_dimensions'],
                     outputs=['r_wheels'])

    dsp.add_function(function=define_tyre_code,
                     inputs=['tyre_dimensions'],
                     outputs=['tyre_code'])

    dsp.add_function(function=default_tyre_code,
                     inputs=['r_dynamic'],
                     outputs=['tyre_code'],
                     weight=5)

    dsp.add_data(data_id='tyre_dynamic_rolling_coefficient',
                 default_value=dfl.values.tyre_dynamic_rolling_coefficient,
                 initial_dist=50)

    dsp.add_function(function=calculate_r_dynamic,
                     inputs=['r_wheels', 'tyre_dynamic_rolling_coefficient'],
                     outputs=['r_dynamic'])

    dsp.add_function(function=identify_tyre_dynamic_rolling_coefficient,
                     inputs=['r_wheels', 'r_dynamic'],
                     outputs=['tyre_dynamic_rolling_coefficient'])

    dsp.add_function(function=identify_r_dynamic_v2,
                     inputs=[
                         'times', 'velocities', 'accelerations', 'r_wheels',
                         'engine_speeds_out', 'gear_box_ratios',
                         'final_drive_ratio', 'idle_engine_speed',
                         'stop_velocity', 'plateau_acceleration',
                         'change_gear_window_width'
                     ],
                     outputs=['r_dynamic'],
                     weight=11)

    dsp.add_function(function=dsp_utl.bypass,
                     inputs=['motive_powers'],
                     outputs=['wheel_powers'])

    return dsp
示例#13
0
def engine():
    """
    Defines the engine model.

    .. dispatcher:: dsp

        >>> dsp = engine()

    :return:
        The engine model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='Engine', description='Models the vehicle engine.')

    dsp.add_function(function=default_ignition_type,
                     inputs=['engine_type'],
                     outputs=['ignition_type'])

    dsp.add_function(function=default_ignition_type_v1,
                     inputs=['fuel_type'],
                     outputs=['ignition_type'],
                     weight=1)

    dsp.add_function(function=get_full_load,
                     inputs=['ignition_type'],
                     outputs=['full_load_curve'],
                     weight=20)

    dsp.add_data(data_id='is_cycle_hot', default_value=dfl.values.is_cycle_hot)

    dsp.add_function(function=select_initial_friction_params,
                     inputs=['co2_params_initial_guess'],
                     outputs=['initial_friction_params'])

    from ..wheels import calculate_wheel_powers, calculate_wheel_torques

    dsp.add_function(function_id='calculate_full_load_powers',
                     function=calculate_wheel_powers,
                     inputs=['full_load_torques', 'full_load_speeds'],
                     outputs=['full_load_powers'])

    dsp.add_function(function_id='calculate_full_load_speeds',
                     function=calculate_wheel_torques,
                     inputs=['full_load_powers', 'full_load_torques'],
                     outputs=['full_load_speeds'])

    dsp.add_function(function=calculate_full_load_speeds_and_powers,
                     inputs=[
                         'full_load_curve', 'engine_max_power',
                         'engine_max_speed_at_max_power', 'idle_engine_speed'
                     ],
                     outputs=['full_load_speeds', 'full_load_powers'])

    dsp.add_function(
        function=calculate_full_load,
        inputs=['full_load_speeds', 'full_load_powers', 'idle_engine_speed'],
        outputs=[
            'full_load_curve', 'engine_max_power',
            'engine_max_speed_at_max_power'
        ])

    # Idle engine speed
    dsp.add_data(data_id='idle_engine_speed_median',
                 description='Idle engine speed [RPM].')

    # default value
    dsp.add_data(data_id='idle_engine_speed_std',
                 default_value=dfl.values.idle_engine_speed_std,
                 description='Standard deviation of idle engine speed [RPM].')

    # identify idle engine speed
    dsp.add_function(
        function=identify_idle_engine_speed_out,
        inputs=[
            'velocities', 'engine_speeds_out', 'stop_velocity',
            'min_engine_on_speed'
        ],
        outputs=['idle_engine_speed_median', 'idle_engine_speed_std'])

    # set idle engine speed tuple
    dsp.add_function(
        function=dsp_utl.bypass,
        inputs=['idle_engine_speed_median', 'idle_engine_speed_std'],
        outputs=['idle_engine_speed'])

    # set idle engine speed tuple
    dsp.add_function(
        function=dsp_utl.bypass,
        inputs=['idle_engine_speed'],
        outputs=['idle_engine_speed_median', 'idle_engine_speed_std'])

    from .thermal import thermal
    dsp.add_dispatcher(include_defaults=True,
                       dsp=thermal(),
                       dsp_id='thermal',
                       inputs={
                           'times':
                           'times',
                           'on_engine':
                           'on_engine',
                           'accelerations':
                           'accelerations',
                           'engine_coolant_temperatures':
                           'engine_coolant_temperatures',
                           'final_drive_powers_in':
                           'final_drive_powers_in',
                           'idle_engine_speed':
                           'idle_engine_speed',
                           'engine_speeds_out_hot':
                           'engine_speeds_out_hot',
                           'engine_temperature_regression_model':
                           'engine_temperature_regression_model',
                           'initial_engine_temperature':
                           'initial_engine_temperature',
                           'engine_thermostat_temperature':
                           'engine_thermostat_temperature',
                           'engine_thermostat_temperature_window':
                           'engine_thermostat_temperature_window',
                           'max_engine_coolant_temperature':
                           'max_engine_coolant_temperature'
                       },
                       outputs={
                           'engine_temperature_regression_model':
                           'engine_temperature_regression_model',
                           'engine_thermostat_temperature':
                           'engine_thermostat_temperature',
                           'engine_thermostat_temperature_window':
                           'engine_thermostat_temperature_window',
                           'initial_engine_temperature':
                           'initial_engine_temperature',
                           'max_engine_coolant_temperature':
                           'max_engine_coolant_temperature',
                           'engine_temperature_derivatives':
                           'engine_temperature_derivatives'
                       })

    dsp.add_function(function=calculate_engine_max_torque,
                     inputs=[
                         'engine_max_power', 'engine_max_speed_at_max_power',
                         'ignition_type'
                     ],
                     outputs=['engine_max_torque'])

    dsp.add_function(function=calculate_engine_max_torque,
                     inputs=[
                         'engine_max_torque', 'engine_max_speed_at_max_power',
                         'ignition_type'
                     ],
                     outputs=['engine_max_power'])

    from .start_stop import start_stop
    dsp.add_dispatcher(include_defaults=True,
                       dsp=start_stop(),
                       dsp_id='start_stop',
                       inputs={
                           'is_hybrid': 'is_hybrid',
                           'use_basic_start_stop': 'use_basic_start_stop',
                           'start_stop_model': 'start_stop_model',
                           'times': 'times',
                           'velocities': 'velocities',
                           'accelerations': 'accelerations',
                           'engine_coolant_temperatures':
                           'engine_coolant_temperatures',
                           'state_of_charges': 'state_of_charges',
                           'gears': 'gears',
                           'correct_start_stop_with_gears':
                           'correct_start_stop_with_gears',
                           'start_stop_activation_time':
                           'start_stop_activation_time',
                           'min_time_engine_on_after_start':
                           'min_time_engine_on_after_start',
                           'has_start_stop': 'has_start_stop',
                           'gear_box_type': 'gear_box_type',
                           'on_engine': 'on_engine',
                           'engine_speeds_out': 'engine_speeds_out',
                           'idle_engine_speed': 'idle_engine_speed',
                           'engine_starts': 'engine_starts'
                       },
                       outputs={
                           'on_engine':
                           'on_engine',
                           'engine_starts':
                           'engine_starts',
                           'use_basic_start_stop':
                           'use_basic_start_stop',
                           'start_stop_model':
                           'start_stop_model',
                           'correct_start_stop_with_gears':
                           'correct_start_stop_with_gears'
                       })

    dsp.add_data(data_id='plateau_acceleration',
                 default_value=dfl.values.plateau_acceleration)

    dsp.add_function(
        function=calculate_engine_speeds_out_hot,
        inputs=['gear_box_speeds_in', 'on_engine', 'idle_engine_speed'],
        outputs=['engine_speeds_out_hot'])

    dsp.add_function(function=identify_on_idle,
                     inputs=[
                         'velocities', 'engine_speeds_out_hot', 'gears',
                         'stop_velocity', 'min_engine_on_speed'
                     ],
                     outputs=['on_idle'])
    from .cold_start import cold_start

    dsp.add_dispatcher(dsp=cold_start(),
                       inputs={
                           'engine_speeds_out': 'engine_speeds_out',
                           'engine_speeds_out_hot': 'engine_speeds_out_hot',
                           'engine_coolant_temperatures':
                           'engine_coolant_temperatures',
                           'engine_thermostat_temperature':
                           'engine_thermostat_temperature',
                           'on_idle': 'on_idle',
                           'cold_start_speeds_phases':
                           'cold_start_speeds_phases',
                           'idle_engine_speed': 'idle_engine_speed',
                           'on_engine': 'on_engine',
                           'cold_start_speed_model': 'cold_start_speed_model'
                       },
                       outputs={
                           'cold_start_speeds_phases':
                           'cold_start_speeds_phases',
                           'cold_start_speeds_delta':
                           'cold_start_speeds_delta',
                           'cold_start_speed_model': 'cold_start_speed_model'
                       })

    dsp.add_function(function=calculate_engine_speeds_out,
                     inputs=[
                         'on_engine', 'idle_engine_speed',
                         'engine_speeds_out_hot', 'cold_start_speeds_delta',
                         'clutch_tc_speeds_delta'
                     ],
                     outputs=['engine_speeds_out'])

    dsp.add_function(function=calculate_uncorrected_engine_powers_out,
                     inputs=[
                         'times', 'engine_moment_inertia', 'clutch_tc_powers',
                         'engine_speeds_out', 'on_engine',
                         'auxiliaries_power_losses', 'gear_box_type',
                         'on_idle', 'alternator_powers_demand'
                     ],
                     outputs=['uncorrected_engine_powers_out'])

    dsp.add_function(function=calculate_min_available_engine_powers_out,
                     inputs=[
                         'engine_stroke', 'engine_capacity',
                         'initial_friction_params', 'engine_speeds_out'
                     ],
                     outputs=['min_available_engine_powers_out'])

    dsp.add_function(function=calculate_max_available_engine_powers_out,
                     inputs=[
                         'engine_max_speed_at_max_power', 'idle_engine_speed',
                         'engine_max_power', 'full_load_curve',
                         'engine_speeds_out'
                     ],
                     outputs=['max_available_engine_powers_out'])

    dsp.add_function(
        function=correct_engine_powers_out,
        inputs=[
            'max_available_engine_powers_out',
            'min_available_engine_powers_out', 'uncorrected_engine_powers_out'
        ],
        outputs=['engine_powers_out', 'missing_powers', 'brake_powers'])

    dsp.add_function(function=check_vehicle_has_sufficient_power,
                     inputs=['missing_powers'],
                     outputs=['has_sufficient_power'])

    dsp.add_function(function=calculate_mean_piston_speeds,
                     inputs=['engine_speeds_out', 'engine_stroke'],
                     outputs=['mean_piston_speeds'])

    dsp.add_data(data_id='engine_is_turbo',
                 default_value=dfl.values.engine_is_turbo)

    dsp.add_function(function=calculate_engine_type,
                     inputs=['ignition_type', 'engine_is_turbo'],
                     outputs=['engine_type'])

    dsp.add_function(function=calculate_engine_moment_inertia,
                     inputs=['engine_capacity', 'ignition_type'],
                     outputs=['engine_moment_inertia'])

    dsp.add_data(data_id='auxiliaries_torque_loss',
                 default_value=dfl.values.auxiliaries_torque_loss)

    dsp.add_data(data_id='auxiliaries_power_loss',
                 default_value=dfl.values.auxiliaries_power_loss)

    dsp.add_function(function=calculate_auxiliaries_torque_losses,
                     inputs=['times', 'auxiliaries_torque_loss'],
                     outputs=['auxiliaries_torque_losses'])

    dsp.add_function(function=calculate_auxiliaries_power_losses,
                     inputs=[
                         'auxiliaries_torque_losses', 'engine_speeds_out',
                         'on_engine', 'auxiliaries_power_loss'
                     ],
                     outputs=['auxiliaries_power_losses'])

    from .co2_emission import co2_emission

    dsp.add_dispatcher(include_defaults=True,
                       dsp=co2_emission(),
                       dsp_id='CO2_emission_model',
                       inputs={
                           'co2_emission_low':
                           'co2_emission_low',
                           'co2_emission_medium':
                           'co2_emission_medium',
                           'co2_emission_high':
                           'co2_emission_high',
                           'co2_emission_extra_high':
                           'co2_emission_extra_high',
                           'co2_emission_UDC':
                           'co2_emission_UDC',
                           'co2_emission_EUDC':
                           'co2_emission_EUDC',
                           'co2_params':
                           'co2_params',
                           'co2_params_calibrated':
                           ('co2_params_calibrated', 'co2_params'),
                           'cycle_type':
                           'cycle_type',
                           'is_cycle_hot':
                           'is_cycle_hot',
                           'engine_capacity':
                           'engine_capacity',
                           'engine_fuel_lower_heating_value':
                           'engine_fuel_lower_heating_value',
                           'engine_idle_fuel_consumption':
                           'engine_idle_fuel_consumption',
                           'engine_powers_out':
                           'engine_powers_out',
                           'engine_speeds_out':
                           'engine_speeds_out',
                           'engine_stroke':
                           'engine_stroke',
                           'engine_coolant_temperatures':
                           'engine_coolant_temperatures',
                           'engine_thermostat_temperature':
                           'engine_thermostat_temperature',
                           'engine_type':
                           'engine_type',
                           'fuel_carbon_content_percentage':
                           'fuel_carbon_content_percentage',
                           'fuel_carbon_content':
                           'fuel_carbon_content',
                           'idle_engine_speed':
                           'idle_engine_speed',
                           'mean_piston_speeds':
                           'mean_piston_speeds',
                           'on_engine':
                           'on_engine',
                           'engine_thermostat_temperature_window':
                           'engine_thermostat_temperature_window',
                           'times':
                           'times',
                           'velocities':
                           'velocities',
                           'calibration_status':
                           'calibration_status',
                           'initial_engine_temperature':
                           'initial_engine_temperature',
                           'fuel_consumptions':
                           'fuel_consumptions',
                           'co2_emissions':
                           'co2_emissions',
                           'co2_normalization_references':
                           'co2_normalization_references',
                           'fuel_type':
                           'fuel_type',
                           'phases_integration_times':
                           'phases_integration_times',
                           'enable_willans':
                           'enable_willans',
                           'enable_phases_willans':
                           'enable_phases_willans',
                           'accelerations':
                           'accelerations',
                           'motive_powers':
                           'motive_powers',
                           'missing_powers':
                           'missing_powers',
                           'stop_velocity':
                           'stop_velocity',
                           'min_engine_on_speed':
                           'min_engine_on_speed',
                           'fuel_density':
                           'fuel_density',
                       },
                       outputs={
                           'co2_emissions_model':
                           'co2_emissions_model',
                           'co2_emission_value':
                           'co2_emission_value',
                           'co2_emissions':
                           'co2_emissions',
                           'identified_co2_emissions':
                           'identified_co2_emissions',
                           'co2_error_function_on_emissions':
                           'co2_error_function_on_emissions',
                           'co2_error_function_on_phases':
                           'co2_error_function_on_phases',
                           'co2_params_calibrated':
                           'co2_params_calibrated',
                           'co2_params_initial_guess':
                           'co2_params_initial_guess',
                           'fuel_consumptions':
                           'fuel_consumptions',
                           'phases_co2_emissions':
                           'phases_co2_emissions',
                           'calibration_status':
                           'calibration_status',
                           'willans_factors':
                           'willans_factors',
                           'optimal_efficiency':
                           'optimal_efficiency',
                           'phases_fuel_consumptions':
                           'phases_fuel_consumptions',
                           'extended_phases_integration_times':
                           'extended_phases_integration_times',
                           'extended_phases_co2_emissions':
                           'extended_phases_co2_emissions',
                           'after_treatment_temperature_threshold':
                           'after_treatment_temperature_threshold',
                           'phases_willans_factors':
                           'phases_willans_factors',
                           'fuel_carbon_content_percentage':
                           'fuel_carbon_content_percentage',
                           'fuel_carbon_content':
                           'fuel_carbon_content',
                           'engine_fuel_lower_heating_value':
                           'engine_fuel_lower_heating_value',
                       },
                       inp_weight={'co2_params': EPS})

    return dsp
示例#14
0
def vehicle_processing_model():
    """
    Defines the vehicle-processing model.

    .. dispatcher:: dsp

        >>> dsp = vehicle_processing_model()

    :return:
        The vehicle-processing model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='CO2MPAS vehicle_processing_model',
        description='Processes a vehicle from the file path to the write of its'
        ' outputs.')

    dsp.add_data(data_id='overwrite_cache', default_value=False)

    dsp.add_data(data_id='soft_validation', default_value=False)

    dsp.add_data(data_id='with_output_file', default_value=False)

    dsp.add_function(function=default_vehicle_name,
                     inputs=['input_file_name'],
                     outputs=['vehicle_name'])

    dsp.add_function(function=default_start_time, outputs=['start_time'])

    dsp.add_function(function=default_timestamp,
                     inputs=['start_time'],
                     outputs=['timestamp'])

    dsp.add_function(function=dsp_utl.add_args(default_output_file_name),
                     inputs=[
                         'with_output_file', 'output_folder', 'vehicle_name',
                         'timestamp'
                     ],
                     outputs=['output_file_name'],
                     input_domain=lambda *args: args[0])

    from .io import load_inputs, write_outputs

    dsp.add_dispatcher(dsp=load_inputs(),
                       inputs={
                           'input_file_name': 'input_file_name',
                           'overwrite_cache': 'overwrite_cache',
                           'soft_validation': 'soft_validation'
                       },
                       outputs={
                           'validated_data': 'validated_data',
                           'validated_plan': 'validated_plan'
                       })

    from .model import model
    dsp.add_function(function=dsp_utl.add_args(
        dsp_utl.SubDispatch(model(), output_type='dsp')),
                     inputs=['plan', 'validated_data'],
                     outputs=['dsp_model'],
                     input_domain=lambda *args: not args[0])

    dsp.add_function(function=parse_dsp_model,
                     inputs=['dsp_model'],
                     outputs=['output_data'])

    from .report import report
    dsp.add_function(
        function=report(),
        inputs=['output_data', 'vehicle_name'],
        outputs=['report', 'summary'],
    )

    dsp.add_function(function=dsp_utl.bypass,
                     inputs=['output_data'],
                     outputs=['report'],
                     weight=1)

    dsp.add_function(function=get_template_file_name,
                     inputs=['output_template', 'input_file_name'],
                     outputs=['template_file_name'])

    dsp.add_data(data_id='output_template', default_value='', initial_dist=10)

    main_flags = ('template_file_name', 'overwrite_cache', 'soft_validation',
                  'with_output_file', 'plot_workflow')

    dsp.add_function(function=partial(dsp_utl.map_list, main_flags),
                     inputs=main_flags,
                     outputs=['main_flags'])

    dsp.add_function(function=write_outputs(),
                     inputs=[
                         'output_file_name', 'template_file_name', 'report',
                         'start_time', 'main_flags'
                     ],
                     outputs=[dsp_utl.SINK],
                     input_domain=check_first_arg)

    dsp.add_function(function_id='has_plan',
                     function=check_first_arg,
                     inputs=['validated_plan'],
                     outputs=['plan'])

    from .plan import make_simulation_plan
    dsp.add_function(function=dsp_utl.add_args(make_simulation_plan),
                     inputs=[
                         'plan', 'validated_plan', 'timestamp',
                         'output_folder', 'main_flags'
                     ],
                     outputs=['summary'],
                     input_domain=check_first_arg)

    return dsp
示例#15
0
def gear_box():
    """
    Defines the gear box model.

    .. dispatcher:: dsp

        >>> dsp = gear_box()

    :return:
        The gear box model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='Gear box model', description='Models the gear box.')

    dsp.add_function(function=calculate_gear_shifts,
                     inputs=['gears'],
                     outputs=['gear_shifts'])

    dsp.add_function(
        function=get_gear_box_efficiency_constants,
        inputs=['gear_box_type'],
        outputs=['gear_box_efficiency_constants'],
    )

    dsp.add_function(
        function=calculate_gear_box_efficiency_parameters_cold_hot,
        inputs=['gear_box_efficiency_constants', 'engine_max_torque'],
        outputs=['gear_box_efficiency_parameters_cold_hot'],
    )

    dsp.add_data(data_id='min_engine_on_speed',
                 default_value=dfl.values.min_engine_on_speed)

    dsp.add_function(
        function=calculate_gear_box_torques,
        inputs=[
            'gear_box_powers_out', 'gear_box_speeds_in', 'gear_box_speeds_out',
            'min_engine_on_speed'
        ],
        outputs=['gear_box_torques'],
    )

    dsp.add_data(data_id='gear_box_temperature_references',
                 default_value=dfl.values.gear_box_temperature_references)

    dsp.add_function(function=calculate_gear_box_torques_in,
                     inputs=[
                         'gear_box_torques', 'gear_box_speeds_in',
                         'gear_box_speeds_out', 'gear_box_temperatures',
                         'gear_box_efficiency_parameters_cold_hot',
                         'gear_box_temperature_references',
                         'min_engine_on_speed'
                     ],
                     outputs=['gear_box_torques_in<0>'])

    dsp.add_function(
        function=correct_gear_box_torques_in,
        inputs=[
            'gear_box_torques', 'gear_box_torques_in<0>', 'gears',
            'gear_box_ratios'
        ],
        outputs=['gear_box_torques_in'],
    )

    dsp.add_function(
        function=dsp_utl.bypass,
        inputs=['gear_box_torques_in<0>'],
        outputs=['gear_box_torques_in'],
        weight=100,
    )

    dsp.add_function(
        function=calculate_gear_box_efficiencies_v2,
        inputs=[
            'gear_box_powers_out', 'gear_box_speeds_in', 'gear_box_torques',
            'gear_box_torques_in', 'min_engine_on_speed'
        ],
        outputs=['gear_box_efficiencies'],
    )

    dsp.add_function(
        function=calculate_torques_losses,
        inputs=['gear_box_torques_in', 'gear_box_torques'],
        outputs=['gear_box_torque_losses'],
    )

    dsp.add_function(
        function=calculate_gear_box_efficiencies_torques_temperatures,
        inputs=[
            'gear_box_powers_out', 'gear_box_speeds_in', 'gear_box_speeds_out',
            'gear_box_torques', 'gear_box_efficiency_parameters_cold_hot',
            'equivalent_gear_box_heat_capacity',
            'engine_thermostat_temperature', 'gear_box_temperature_references',
            'initial_gear_box_temperature', 'gears', 'gear_box_ratios'
        ],
        outputs=[
            'gear_box_efficiencies', 'gear_box_torques_in',
            'gear_box_temperatures'
        ],
        weight=50)

    dsp.add_function(
        function=calculate_gear_box_efficiencies_torques_temperatures,
        inputs=[
            'gear_box_powers_out', 'gear_box_speeds_in', 'gear_box_speeds_out',
            'gear_box_torques', 'gear_box_efficiency_parameters_cold_hot',
            'equivalent_gear_box_heat_capacity',
            'engine_thermostat_temperature', 'gear_box_temperature_references',
            'initial_gear_box_temperature'
        ],
        outputs=[
            'gear_box_efficiencies', 'gear_box_torques_in',
            'gear_box_temperatures'
        ],
        weight=100)

    dsp.add_function(function=calculate_gear_box_powers_in,
                     inputs=['gear_box_torques_in', 'gear_box_speeds_in'],
                     outputs=['gear_box_powers_in'])

    dsp.add_function(function=calculate_equivalent_gear_box_heat_capacity,
                     inputs=['ignition_type', 'engine_max_power'],
                     outputs=['equivalent_gear_box_heat_capacity'])

    from .mechanical import mechanical
    dsp.add_dispatcher(include_defaults=True,
                       dsp=mechanical(),
                       inputs={
                           'times': 'times',
                           'velocities': 'velocities',
                           'accelerations': 'accelerations',
                           'velocity_speed_ratios': 'velocity_speed_ratios',
                           'engine_speeds_out': 'engine_speeds_out',
                           'final_drive_ratio': 'final_drive_ratio',
                           'gear_box_speeds_out': 'gear_box_speeds_out',
                           'gear_box_ratios': 'gear_box_ratios',
                           'gear_box_type': dsp_utl.SINK,
                           'gears': 'gears',
                           'idle_engine_speed': 'idle_engine_speed',
                           'r_dynamic': 'r_dynamic',
                           'stop_velocity': 'stop_velocity',
                           'plateau_acceleration': 'plateau_acceleration',
                           'change_gear_window_width':
                           'change_gear_window_width'
                       },
                       outputs={
                           'gears': 'gears',
                           'gear_box_ratios': 'gear_box_ratios',
                           'velocity_speed_ratios': 'velocity_speed_ratios',
                           'speed_velocity_ratios': 'speed_velocity_ratios',
                           'gear_box_speeds_in': 'gear_box_speeds_in',
                           'max_gear': 'max_gear',
                       },
                       input_domain=not_cvt)

    from .at_gear import at_gear
    dsp.add_dispatcher(
        include_defaults=True,
        dsp=at_gear(),
        dsp_id='at_gear_shifting',
        inputs={
            'fuel_saving_at_strategy': 'fuel_saving_at_strategy',
            'MVL': 'MVL',
            'CMV': 'CMV',
            'CMV_Cold_Hot': 'CMV_Cold_Hot',
            'DT_VA': 'DT_VA',
            'DT_VAT': 'DT_VAT',
            'DT_VAP': 'DT_VAP',
            'DT_VATP': 'DT_VATP',
            'GSPV': 'GSPV',
            'GSPV_Cold_Hot': 'GSPV_Cold_Hot',
            'accelerations': 'accelerations',
            'use_dt_gear_shifting': 'use_dt_gear_shifting',
            'specific_gear_shifting': 'specific_gear_shifting',
            'engine_speeds_out': 'engine_speeds_out',
            'full_load_curve': 'full_load_curve',
            'gears': 'gears',
            'motive_powers': 'motive_powers',
            'gear_box_type': dsp_utl.SINK,
            'idle_engine_speed': 'idle_engine_speed',
            'engine_max_power': 'engine_max_power',
            'engine_max_speed_at_max_power': 'engine_max_speed_at_max_power',
            'road_loads': 'road_loads',
            'engine_coolant_temperatures': 'engine_coolant_temperatures',
            'time_cold_hot_transition': 'time_cold_hot_transition',
            'times': 'times',
            'vehicle_mass': 'vehicle_mass',
            'velocities': 'velocities',
            'velocity_speed_ratios': 'velocity_speed_ratios',
            'stop_velocity': 'stop_velocity',
            'plateau_acceleration': 'plateau_acceleration',
            'change_gear_window_width': 'change_gear_window_width',
            'max_velocity_full_load_correction':
            'max_velocity_full_load_correction',
            'cycle_type': 'cycle_type'
        },
        outputs={
            'specific_gear_shifting': 'specific_gear_shifting',
            'gears': 'gears',
            'MVL': 'MVL',
            'CMV': 'CMV',
            'CMV_Cold_Hot': 'CMV_Cold_Hot',
            'DT_VA': 'DT_VA',
            'DT_VAT': 'DT_VAT',
            'DT_VAP': 'DT_VAP',
            'DT_VATP': 'DT_VATP',
            'GSPV': 'GSPV',
            'GSPV_Cold_Hot': 'GSPV_Cold_Hot',
        },
        input_domain=is_automatic)

    from .cvt import cvt_model
    dsp.add_dispatcher(include_defaults=True,
                       dsp=cvt_model(),
                       dsp_id='cvt_model',
                       inputs={
                           'on_engine': 'on_engine',
                           'gear_box_type': dsp_utl.SINK,
                           'engine_speeds_out': 'engine_speeds_out',
                           'velocities': 'velocities',
                           'accelerations': 'accelerations',
                           'gear_box_powers_out': 'gear_box_powers_out',
                           'CVT': 'CVT',
                           'idle_engine_speed': 'idle_engine_speed',
                           'stop_velocity': 'stop_velocity'
                       },
                       outputs={
                           'CVT': 'CVT',
                           'gear_box_speeds_in': 'gear_box_speeds_in',
                           'gears': 'gears',
                           'max_gear': 'max_gear',
                           'max_speed_velocity_ratio':
                           'max_speed_velocity_ratio'
                       },
                       input_domain=is_cvt)

    return dsp
示例#16
0
def load_inputs():
    """
    Defines a module to load the input file of the CO2MPAS model.

    .. dispatcher:: dsp

        >>> dsp = load_inputs()

    :return:
        The load input module.
    :rtype: SubDispatchFunction
    """

    dsp = Dispatcher(
        name='load_inputs',
        description='Loads from files the inputs for the CO2MPAS model.'
    )

    dsp.add_function(
        function=get_cache_fpath,
        inputs=['input_file_name'],
        outputs=['cache_file_name']
    )

    dsp.add_data(
        data_id='overwrite_cache',
        default_value=False,
    )

    dsp.add_function(
        function_id='load_data_from_cache',
        function=dsp_utl.add_args(load_from_dill, n=2),
        inputs=['overwrite_cache', 'input_file_name', 'cache_file_name'],
        outputs=['data'],
        input_domain=check_cache_fpath_exists
    )

    dsp.add_function(
        function=parse_excel_file,
        inputs=['input_file_name'],
        outputs=['data'],
        input_domain=partial(check_file_format, extensions=('.xlsx', '.xls')),
        weight=5
    )

    dsp.add_function(
        function=load_from_dill,
        inputs=['input_file_name'],
        outputs=['data'],
        input_domain=partial(check_file_format, extensions=('.dill',)),
        weight=5
    )

    dsp.add_function(
        function_id='load_from_xlasso',
        function=lasso,
        inputs=['input_file_name'],
        outputs=['data'],
        input_domain=check_xlasso,
        weight=5
    )

    dsp.add_function(
        function_id='cache_parsed_data',
        function=save_dill,
        inputs=['data', 'cache_file_name']
    )

    dsp.add_function(
        function=partial(validate_data, read_schema=define_data_schema()),
        inputs=['data', 'soft_validation'],
        outputs=['validated_data', 'validated_plan'],
        weight=1
    )

    dsp.add_data(
        data_id='validated_data',
        function=check_data_version
    )

    return dsp
示例#17
0
def model():
    """
    Defines the CO2MPAS model.

    .. dispatcher:: dsp

        >>> dsp = model()

    :return:
        The CO2MPAS model.
    :rtype: Dispatcher
    """

    from .physical import physical
    dsp = Dispatcher(
        name='CO2MPAS model',
        description='Calibrates the models with WLTP data and predicts NEDC '
        'cycle.')

    ############################################################################
    #                          PRECONDITIONING CYCLE
    ############################################################################

    dsp.add_data(
        data_id='input.precondition.wltp_p',
        description='Dictionary that has all inputs of the calibration cycle.')

    dsp.add_function(
        function_id='calculate_precondition_output',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['input.precondition.wltp_p'],
        outputs=['output.precondition.wltp_p'],
        description='Wraps all functions needed to calculate the precondition '
        'outputs.')

    ############################################################################
    #                          WLTP - HIGH CYCLE
    ############################################################################

    dsp.add_function(
        function=select_calibration_data,
        inputs=['input.calibration.wltp_h', 'output.precondition.wltp_p'],
        outputs=['data.calibration.wltp_h'],
    )

    dsp.add_function(
        function_id='calibrate_with_wltp_h',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['data.calibration.wltp_h'],
        outputs=['output.calibration.wltp_h'],
        description='Wraps all functions needed to calibrate the models to '
        'predict light-vehicles\' CO2 emissions.')

    dsp.add_data(data_id='input.prediction.wltp_h', default_value={})

    dsp.add_function(
        function=select_prediction_data,
        inputs=['output.calibration.wltp_h', 'input.prediction.wltp_h'],
        outputs=['data.prediction.wltp_h'])

    dsp.add_function(
        function_id='predict_wltp_h',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['data.prediction.models', 'data.prediction.wltp_h'],
        outputs=['output.prediction.wltp_h'],
        description='Wraps all functions needed to predict CO2 emissions.')

    ############################################################################
    #                          WLTP - LOW CYCLE
    ############################################################################

    dsp.add_function(
        function=select_calibration_data,
        inputs=['input.calibration.wltp_l', 'output.precondition.wltp_p'],
        outputs=['data.calibration.wltp_l'],
    )

    dsp.add_function(
        function_id='calibrate_with_wltp_l',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['data.calibration.wltp_l'],
        outputs=['output.calibration.wltp_l'],
        description='Wraps all functions needed to calibrate the models to '
        'predict light-vehicles\' CO2 emissions.')

    dsp.add_data(data_id='input.prediction.wltp_l', default_value={})

    dsp.add_function(
        function=select_prediction_data,
        inputs=['output.calibration.wltp_l', 'input.prediction.wltp_l'],
        outputs=['data.prediction.wltp_l'])

    dsp.add_function(
        function_id='predict_wltp_l',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['data.prediction.models', 'data.prediction.wltp_l'],
        outputs=['output.prediction.wltp_l'],
        description='Wraps all functions needed to predict CO2 emissions.')

    ############################################################################
    #                            MODEL SELECTOR
    ############################################################################

    from .selector import selector

    selector = selector('wltp_h', 'wltp_l')

    dsp.add_data(data_id='config.error_settings', default_value={})

    dsp.add_function(
        function_id='extract_calibrated_models',
        function=selector,
        inputs=[
            'config.error_settings', 'output.calibration.wltp_h',
            'output.calibration.wltp_l'
        ],
        outputs=['data.calibration.models', 'data.calibration.model_scores'])

    dsp.add_data(data_id='input.prediction.models', default_value={})

    dsp.add_function(
        function=dsp_utl.combine_dicts,
        inputs=['data.calibration.models', 'input.prediction.models'],
        outputs=['data.prediction.models'])

    ############################################################################
    #                            NEDC - HIGH CYCLE
    ############################################################################

    dsp.add_function(
        function_id='predict_nedc_h',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['data.prediction.models', 'input.prediction.nedc_h'],
        outputs=['output.prediction.nedc_h'],
    )

    ############################################################################
    #                            NEDC - LOW CYCLE
    ############################################################################

    dsp.add_function(
        function_id='predict_nedc_l',
        function=dsp_utl.SubDispatch(physical()),
        inputs=['data.prediction.models', 'input.prediction.nedc_l'],
        outputs=['output.prediction.nedc_l'],
    )

    return dsp
示例#18
0
def calculate_wltp_velocities():
    """
    Defines the wltp cycle model.

    .. dispatcher:: dsp

        >>> dsp = calculate_wltp_velocities()

    :return:
        The wltp cycle model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='WLTP velocities model',
        description='Returns the theoretical velocities of WLTP.'
    )

    dsp.add_function(
        function=get_dfl,
        inputs=['base_model'],
        outputs=['driver_mass', 'resistance_coeffs_regression_curves',
                 'wltc_data']
    )

    dsp.add_function(
        function=calculate_unladen_mass,
        inputs=['vehicle_mass', 'driver_mass'],
        outputs=['unladen_mass']
    )

    dsp.add_function(
        function=calc_default_resistance_coeffs,
        inputs=['vehicle_mass', 'resistance_coeffs_regression_curves'],
        outputs=['road_loads'],
        weight=15
    )

    dsp.add_function(
        function=calculate_max_speed_velocity_ratio,
        inputs=['speed_velocity_ratios'],
        outputs=['max_speed_velocity_ratio']
    )

    dsp.add_function(
        function=calculate_max_velocity,
        inputs=['engine_max_speed_at_max_power', 'max_speed_velocity_ratio'],
        outputs=['max_velocity']
    )

    dsp.add_function(
        function=calculate_wltp_class,
        inputs=['wltc_data', 'engine_max_power', 'unladen_mass',
                'max_velocity'],
        outputs=['wltp_class']
    )

    dsp.add_function(
        function=get_class_data,
        inputs=['wltc_data', 'wltp_class'],
        outputs=['class_data']
    )

    dsp.add_function(
        function=get_class_velocities,
        inputs=['class_data', 'times'],
        outputs=['class_velocities'],
        weight=25
    )

    from ..vehicle import vehicle
    func = dsp_utl.SubDispatchFunction(
        dsp=vehicle(),
        function_id='calculate_class_powers',
        inputs=['vehicle_mass', 'velocities', 'climbing_force', 'road_loads',
                'inertial_factor', 'times'],
        outputs=['motive_powers']
    )

    dsp.add_function(
        function=func,
        inputs=['vehicle_mass', 'class_velocities', 'climbing_force',
                'road_loads', 'inertial_factor', 'times'],
        outputs=['class_powers']
    )

    dsp.add_data(
        data_id='downscale_factor_threshold',
        default_value=dfl.values.downscale_factor_threshold
    )

    dsp.add_function(
        function=calculate_downscale_factor,
        inputs=['class_data', 'downscale_factor_threshold', 'max_velocity',
                'engine_max_power', 'class_powers', 'times'],
        outputs=['downscale_factor']
    )

    dsp.add_function(
        function=get_downscale_phases,
        inputs=['class_data'],
        outputs=['downscale_phases']
    )

    dsp.add_function(
        function=wltp_velocities,
        inputs=['downscale_factor', 'class_velocities', 'downscale_phases',
                'times'],
        outputs=['velocities']
    )

    return dsp
示例#19
0
def clutch():
    """
    Defines the clutch model.

    .. dispatcher:: dsp

        >>> dsp = clutch()

    :return:
        The clutch model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='Clutch',
        description='Models the clutch.'
    )

    dsp.add_function(
        function=calculate_clutch_phases,
        inputs=['times', 'gear_shifts', 'clutch_window'],
        outputs=['clutch_phases']
    )

    dsp.add_function(
        function=calculate_clutch_speed_threshold,
        inputs=['clutch_speeds_delta'],
        outputs=['clutch_speed_threshold']
    )

    dsp.add_data(
        data_id='max_clutch_window_width',
        default_value=dfl.values.max_clutch_window_width
    )

    dsp.add_function(
        function=identify_clutch_window,
        inputs=['times', 'accelerations', 'gear_shifts', 'engine_speeds_out',
                'engine_speeds_out_hot', 'cold_start_speeds_delta',
                'max_clutch_window_width'],
        outputs=['clutch_window']
    )

    dsp.add_function(
        function=identify_clutch_speeds_delta,
        inputs=['clutch_phases', 'engine_speeds_out', 'engine_speeds_out_hot',
                'cold_start_speeds_delta'],
        outputs=['clutch_speeds_delta']
    )

    dsp.add_function(
        function=calibrate_clutch_prediction_model,
        inputs=['clutch_phases', 'accelerations', 'clutch_speeds_delta'],
        outputs=['clutch_model']
    )

    dsp.add_function(
        function=predict_clutch_speeds_delta,
        inputs=['clutch_model', 'clutch_phases', 'accelerations'],
        outputs=['clutch_speeds_delta']
    )

    dsp.add_function(
        function=define_k_factor_curve,
        inputs=['stand_still_torque_ratio', 'lockup_speed_ratio'],
        outputs=['k_factor_curve']
    )

    dsp.add_function(
        function=default_clutch_k_factor_curve,
        outputs=['k_factor_curve'],
        weight=2
    )

    return dsp
示例#20
0
def electrics():
    """
    Defines the electrics model.

    .. dispatcher:: dsp

        >>> dsp = electrics()

    :return:
        The electrics model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='Electrics',
                     description='Models the vehicle electrics.')

    dsp.add_data(data_id='alternator_efficiency',
                 default_value=dfl.values.alternator_efficiency)

    dsp.add_data(data_id='delta_time_engine_starter',
                 default_value=dfl.values.delta_time_engine_starter)

    dsp.add_function(function=calculate_engine_start_demand,
                     inputs=[
                         'engine_moment_inertia', 'idle_engine_speed',
                         'alternator_efficiency', 'delta_time_engine_starter'
                     ],
                     outputs=['start_demand'],
                     weight=100)

    dsp.add_function(function=identify_electric_loads,
                     inputs=[
                         'alternator_nominal_voltage', 'battery_currents',
                         'alternator_currents', 'gear_box_powers_in', 'times',
                         'on_engine', 'engine_starts',
                         'alternator_start_window_width'
                     ],
                     outputs=['electric_load', 'start_demand'])

    dsp.add_data(data_id='initial_state_of_charge',
                 default_value=dfl.values.initial_state_of_charge)

    dsp.add_function(function=identify_charging_statuses,
                     inputs=[
                         'times', 'alternator_currents', 'gear_box_powers_in',
                         'on_engine', 'alternator_current_threshold',
                         'starts_windows', 'alternator_initialization_time'
                     ],
                     outputs=['alternator_statuses'])

    dsp.add_function(
        function=identify_charging_statuses_and_alternator_initialization_time,
        inputs=[
            'times', 'alternator_currents', 'gear_box_powers_in', 'on_engine',
            'alternator_current_threshold', 'starts_windows',
            'state_of_charges', 'accelerations'
        ],
        outputs=['alternator_statuses', 'alternator_initialization_time'],
        weight=1)

    dsp.add_function(function=identify_alternator_initialization_time,
                     inputs=[
                         'alternator_currents', 'gear_box_powers_in',
                         'on_engine', 'accelerations', 'state_of_charges',
                         'alternator_statuses', 'times',
                         'alternator_current_threshold'
                     ],
                     outputs=['alternator_initialization_time'])

    dsp.add_function(function=calculate_state_of_charges,
                     inputs=[
                         'battery_capacity', 'times',
                         'initial_state_of_charge', 'battery_currents',
                         'max_battery_charging_current'
                     ],
                     outputs=['state_of_charges'])

    dsp.add_data(data_id='stop_velocity',
                 default_value=dfl.values.stop_velocity)

    dsp.add_data(data_id='alternator_off_threshold',
                 default_value=dfl.values.alternator_off_threshold)

    dsp.add_function(function=identify_alternator_current_threshold,
                     inputs=[
                         'alternator_currents', 'velocities', 'on_engine',
                         'stop_velocity', 'alternator_off_threshold'
                     ],
                     outputs=['alternator_current_threshold'])

    dsp.add_data(data_id='alternator_start_window_width',
                 default_value=dfl.values.alternator_start_window_width)

    dsp.add_function(function=identify_alternator_starts_windows,
                     inputs=[
                         'times', 'engine_starts', 'alternator_currents',
                         'alternator_start_window_width',
                         'alternator_current_threshold'
                     ],
                     outputs=['starts_windows'])

    dsp.add_function(function=calculate_alternator_powers_demand,
                     inputs=[
                         'alternator_nominal_voltage', 'alternator_currents',
                         'alternator_efficiency'
                     ],
                     outputs=['alternator_powers_demand'])

    dsp.add_function(
        function=define_alternator_status_model,
        inputs=['state_of_charge_balance', 'state_of_charge_balance_window'],
        outputs=['alternator_status_model'])

    dsp.add_data(data_id='has_energy_recuperation',
                 default_value=dfl.values.has_energy_recuperation)

    dsp.add_function(function=calibrate_alternator_status_model,
                     inputs=[
                         'times', 'alternator_statuses', 'state_of_charges',
                         'gear_box_powers_in'
                     ],
                     outputs=['alternator_status_model'],
                     weight=10)

    dsp.add_function(function=identify_max_battery_charging_current,
                     inputs=['battery_currents'],
                     outputs=['max_battery_charging_current'])

    dsp.add_function(function=define_alternator_current_model,
                     inputs=['alternator_charging_currents'],
                     outputs=['alternator_current_model'])

    dsp.add_function(function=calibrate_alternator_current_model,
                     inputs=[
                         'alternator_currents', 'on_engine', 'times',
                         'state_of_charges', 'alternator_statuses',
                         'gear_box_powers_in', 'accelerations',
                         'alternator_initialization_time'
                     ],
                     outputs=['alternator_current_model'])

    dsp.add_function(function=define_electrics_model,
                     inputs=[
                         'battery_capacity', 'alternator_status_model',
                         'max_alternator_current', 'alternator_current_model',
                         'max_battery_charging_current',
                         'alternator_nominal_voltage', 'start_demand',
                         'electric_load', 'has_energy_recuperation',
                         'alternator_initialization_time', 'times'
                     ],
                     outputs=['electrics_model'])

    dsp.add_function(function=predict_vehicle_electrics,
                     inputs=[
                         'electrics_model', 'initial_state_of_charge', 'times',
                         'gear_box_powers_in', 'on_engine', 'engine_starts',
                         'accelerations'
                     ],
                     outputs=[
                         'alternator_currents', 'battery_currents',
                         'state_of_charges', 'alternator_statuses'
                     ])

    dsp.add_function(function_id='identify_alternator_nominal_power',
                     function=lambda x: max(x),
                     inputs=['alternator_powers_demand'],
                     outputs=['alternator_nominal_power'])

    dsp.add_function(function=calculate_max_alternator_current,
                     inputs=[
                         'alternator_nominal_voltage',
                         'alternator_nominal_power', 'alternator_efficiency'
                     ],
                     outputs=['max_alternator_current'])

    return dsp
示例#21
0
def vehicle():
    """
    Defines the vehicle model.

    .. dispatcher:: dsp

        >>> dsp = vehicle()

    :return:
        The vehicle model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='Vehicle free body diagram',
        description='Calculates forces and power acting on the vehicle.'
    )

    dsp.add_function(
        function=calculate_velocities,
        inputs=['times', 'obd_velocities'],
        outputs=['velocities']
    )

    dsp.add_function(
        function=calculate_accelerations,
        inputs=['times', 'velocities'],
        outputs=['accelerations']
    )

    dsp.add_function(
        function=calculate_aerodynamic_resistances,
        inputs=['f2', 'velocities'],
        outputs=['aerodynamic_resistances']
    )

    dsp.add_data(
        data_id='air_density',
        default_value=dfl.values.air_density,
    )

    dsp.add_function(
        function=calculate_f2,
        inputs=['air_density', 'aerodynamic_drag_coefficient', 'frontal_area'],
        outputs=['f2'],
        weight=5
    )

    dsp.add_function(
        function=calculate_f0,
        inputs=['vehicle_mass', 'rolling_resistance_coeff'],
        outputs=['f0'],
        weight=5
    )

    dsp.add_data(
        data_id='angle_slope',
        default_value=dfl.values.angle_slope,
    )

    dsp.add_function(
        function=calculate_rolling_resistance,
        inputs=['f0', 'angle_slope'],
        outputs=['rolling_resistance']
    )

    dsp.add_function(
        function=calculate_velocity_resistances,
        inputs=['f1', 'velocities'],
        outputs=['velocity_resistances']
    )

    dsp.add_function(
        function=calculate_climbing_force,
        inputs=['vehicle_mass', 'angle_slope'],
        outputs=['climbing_force']
    )

    dsp.add_function(
        function=select_default_n_dyno_axes,
        inputs=['cycle_type'],
        outputs=['n_dyno_axes']
    )

    dsp.add_function(
        function=select_inertial_factor,
        inputs=['n_dyno_axes'],
        outputs=['inertial_factor']
    )

    dsp.add_function(
        function=calculate_rotational_inertia_forces,
        inputs=['vehicle_mass', 'inertial_factor', 'accelerations'],
        outputs=['rotational_inertia_forces']
    )

    dsp.add_function(
        function=calculate_motive_forces,
        inputs=['vehicle_mass', 'accelerations', 'climbing_force',
                'aerodynamic_resistances', 'rolling_resistance',
                'velocity_resistances', 'rotational_inertia_forces'],
        outputs=['motive_forces']
    )

    dsp.add_function(
        function=calculate_motive_powers,
        inputs=['motive_forces', 'velocities'],
        outputs=['motive_powers']
    )

    dsp.add_function(
        function_id='grouping',
        function=dsp_utl.bypass,
        inputs=['f0', 'f1', 'f2'],
        outputs=['road_loads']
    )

    dsp.add_data(
        data_id='road_loads',
        description='Cycle road loads [N, N/(km/h), N/(km/h)^2].'
    )

    dsp.add_function(
        function_id='splitting',
        function=dsp_utl.bypass,
        inputs=['road_loads'],
        outputs=['f0', 'f1', 'f2']
    )

    dsp.add_data(
        data_id='correct_f0',
        default_value=dfl.values.correct_f0
    )

    dsp.add_function(
        function=apply_f0_correction,
        inputs=['f0_uncorrected', 'correct_f0'],
        outputs=['f0']
    )

    return dsp
示例#22
0
def wltp_cycle():
    """
    Defines the wltp cycle model.

    .. dispatcher:: dsp

        >>> dsp = wltp_cycle()

    :return:
        The wltp cycle model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='WLTP cycle model',
        description='Returns the theoretical times, velocities, and gears of '
                    'WLTP.'
    )

    dsp.add_data(
        data_id='initial_temperature',
        default_value=dfl.values.initial_temperature_WLTP
    )

    dsp.add_data(
        data_id='wltp_base_model',
        default_value=deepcopy(dfl.values.wltp_base_model)
    )

    dsp.add_function(
        function=define_wltp_base_model,
        inputs=['wltp_base_model'],
        outputs=['base_model']
    )

    dsp.add_data(
        data_id='time_sample_frequency',
        default_value=dfl.values.time_sample_frequency
    )

    dsp.add_function(
        function=wltp_time_length,
        inputs=['time_sample_frequency'],
        outputs=['time_length'],
        weight=5
    )

    dsp.add_dispatcher(
        dsp=calculate_wltp_velocities(),
        inputs={
            'times': 'times',
            'base_model': 'base_model',
            'velocities': 'velocities',
            'speed_velocity_ratios': 'speed_velocity_ratios',
            'inertial_factor': 'inertial_factor',
            'downscale_phases': 'downscale_phases',
            'climbing_force': 'climbing_force',
            'downscale_factor': 'downscale_factor',
            'downscale_factor_threshold': 'downscale_factor_threshold',
            'vehicle_mass': 'vehicle_mass',
            'driver_mass': 'driver_mass',
            'road_loads': 'road_loads',
            'engine_max_power': 'engine_max_power',
            'engine_max_speed_at_max_power': 'engine_max_speed_at_max_power',
            'max_velocity': 'max_velocity',
            'wltp_class': 'wltp_class',
            'max_speed_velocity_ratio': 'max_speed_velocity_ratio'
        },
        outputs={
            'velocities': 'velocities'
        }
    )

    dsp.add_function(
        function=dsp_utl.add_args(wltp_gears),
        inputs=['gear_box_type', 'full_load_curve', 'velocities',
                'accelerations', 'motive_powers', 'speed_velocity_ratios',
                'idle_engine_speed', 'engine_max_speed_at_max_power',
                'engine_max_power', 'base_model'],
        outputs=['gears'],
        input_domain=lambda *args: args[0] == 'manual'
    )

    return dsp
示例#23
0
            Other args.

            error
        :type args: None

        :returns:
            Nice f.

            error
        :rtype: None
        """
        return

    #: Docstring 1
    #:
    #: good
    dsp = Dispatcher(name='Pippo', description='Docstring 2\n\ngood')
    dsp.add_data(data_id='a', description='Description of a\n\nerror')
    dsp.add_function(function_id='fun1', description='Fun1\n\nerror')
    dsp.add_function('fun2', fun2, ['b', 'e', 'd'], ['c'])
    dsp.add_function('fun3', fun2, description='Fun3\n\nerror')


    dsp_1 = dsp

    dsp_2 = dsp
    """
    Docstring 3

    good
    """
示例#24
0
def start_stop():
    """
    Defines the engine start/stop model.

    .. dispatcher:: dsp

        >>> dsp = start_stop()

    :return:
        The engine start/stop model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='start_stop',
                     description='Models the engine start/stop strategy.')

    dsp.add_function(function=identify_on_engine,
                     inputs=[
                         'times', 'engine_speeds_out', 'idle_engine_speed',
                         'min_time_engine_on_after_start'
                     ],
                     outputs=['on_engine'])

    dsp.add_function(function=identify_engine_starts,
                     inputs=['on_engine'],
                     outputs=['engine_starts'])

    dsp.add_data(data_id='start_stop_activation_time',
                 default_value=dfl.values.start_stop_activation_time)

    dsp.add_function(function=calibrate_start_stop_model,
                     inputs=[
                         'on_engine', 'velocities', 'accelerations',
                         'engine_coolant_temperatures', 'state_of_charges'
                     ],
                     outputs=['start_stop_model'])

    dsp.add_function(function=default_correct_start_stop_with_gears,
                     inputs=['gear_box_type'],
                     outputs=['correct_start_stop_with_gears'])

    dsp.add_data(data_id='min_time_engine_on_after_start',
                 default_value=dfl.values.min_time_engine_on_after_start)

    dsp.add_data(data_id='has_start_stop',
                 default_value=dfl.values.has_start_stop)

    dsp.add_data(data_id='is_hybrid', default_value=dfl.values.is_hybrid)

    dsp.add_function(function=default_use_basic_start_stop_model,
                     inputs=['is_hybrid'],
                     outputs=['use_basic_start_stop'])

    dsp.add_function(
        function=predict_engine_start_stop,
        inputs=[
            'start_stop_model', 'times', 'velocities', 'accelerations',
            'engine_coolant_temperatures', 'state_of_charges', 'gears',
            'correct_start_stop_with_gears', 'start_stop_activation_time',
            'min_time_engine_on_after_start', 'has_start_stop',
            'use_basic_start_stop'
        ],
        outputs=['on_engine', 'engine_starts'])

    return dsp
示例#25
0
def thermal():
    """
    Defines the gear box thermal sub model.

    .. dispatcher:: dsp

        >>> dsp = thermal()

    :return:
        The gear box thermal sub model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='Gear box thermal sub model',
        description='Calculates temperature, efficiency, '
                    'torque loss of gear box'
    )

    dsp.add_data(
        data_id='gear_box_temperature_references',
        default_value=dfl.values.gear_box_temperature_references
    )

    dsp.add_function(
        function=calculate_gear_box_torque_in,
        inputs=['gear_box_torque_out', 'gear_box_speed_in',
                'gear_box_speed_out', 'gear_box_temperature',
                'gear_box_efficiency_parameters_cold_hot',
                'gear_box_temperature_references'],
        outputs=['gear_box_torque_in<0>']
    )

    dsp.add_function(
        function=correct_gear_box_torque_in,
        inputs=['gear_box_torque_out', 'gear_box_torque_in<0>', 'gear',
                'gear_box_ratios'],
        outputs=['gear_box_torque_in']
    )

    dsp.add_function(
        function=dsp_utl.bypass,
        inputs=['gear_box_torque_in<0>'],
        outputs=['gear_box_torque_in'],
        weight=100,
    )

    dsp.add_function(
        function=calculate_gear_box_efficiency,
        inputs=['gear_box_power_out', 'gear_box_speed_in',
                'gear_box_torque_out', 'gear_box_torque_in'],
        outputs=['gear_box_efficiency'],
    )

    dsp.add_function(
        function=calculate_gear_box_heat,
        inputs=['gear_box_efficiency', 'gear_box_power_out'],
        outputs=['gear_box_heat']
    )

    dsp.add_function(
        function=calculate_gear_box_temperature,
        inputs=['gear_box_heat', 'gear_box_temperature',
                'equivalent_gear_box_heat_capacity', 'thermostat_temperature'],
        outputs=['gear_box_temperature']
    )

    return dsp