Пример #1
0
    def setUp(self):
        dsp = Dispatcher()
        dsp.add_function(function=max, inputs=['a', 'b'], outputs=['c'])
        dsp.add_function(function=min, inputs=['c', 'b'], outputs=['a'],
                         input_domain=lambda c, b: c * b > 0)
        self.dsp_1 = dsp

        dsp = Dispatcher()

        def f(a, b):
            return a + b, a - b

        dsp.add_function(function=f, inputs=['a', 'b'], outputs=['c', SINK])
        dsp.add_function(function=f, inputs=['c', 'b'], outputs=[SINK, 'd'])
        self.dsp_2 = dsp

        dsp = Dispatcher()

        dsp.add_function(function=f, inputs=['a', 'b'], outputs=['c', 'd'],
                         out_weight={'d': 100})
        dsp.add_dispatcher(dsp=self.dsp_1.copy(), inputs={'a': 'a', 'b': 'b'},
                           outputs={'c': 'd'})
        self.dsp_3 = dsp

        dsp = Dispatcher()

        dsp.add_function(function=SubDispatchFunction(
            self.dsp_3, 'f', ['b', 'a'], ['c', 'd']),
            inputs=['b', 'a'], outputs=['c', 'd'], out_weight={'d': 100}
        )
        dsp.add_dispatcher(dsp=self.dsp_1.copy(), inputs={'a': 'a', 'b': 'b'},
                           outputs={'c': 'd'})
        self.dsp_4 = dsp
Пример #2
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
Пример #3
0
def cycle():
    """
    Defines the cycle model.

    .. dispatcher:: dsp

        >>> dsp = cycle()

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

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

    from .NEDC import nedc_cycle
    dsp.add_dispatcher(include_defaults=True,
                       dsp=nedc_cycle(),
                       inputs={
                           'cycle_type': dsp_utl.SINK,
                           'k1': 'k1',
                           'k2': 'k2',
                           'k5': 'k5',
                           'max_gear': 'max_gear',
                           'gear_box_type': 'gear_box_type',
                           'times': 'times',
                           'time_sample_frequency': 'time_sample_frequency',
                           'gears': 'gears'
                       },
                       outputs={
                           'velocities': 'velocities',
                           'gears': 'gears',
                           'time_length': 'time_length',
                           'initial_temperature': 'initial_temperature'
                       },
                       input_domain=is_nedc)

    from .WLTP import wltp_cycle
    dsp.add_dispatcher(include_defaults=True,
                       dsp=wltp_cycle(),
                       inputs={
                           'cycle_type': dsp_utl.SINK,
                           'gear_box_type': 'gear_box_type',
                           'times': 'times',
                           'wltp_base_model': 'wltp_base_model',
                           'velocities': 'velocities',
                           'accelerations': 'accelerations',
                           'motive_powers': 'motive_powers',
                           'speed_velocity_ratios': 'speed_velocity_ratios',
                           'idle_engine_speed': 'idle_engine_speed',
                           'inertial_factor': 'inertial_factor',
                           'downscale_phases': 'downscale_phases',
                           'climbing_force': 'climbing_force',
                           'full_load_curve': 'full_load_curve',
                           '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',
                           'time_sample_frequency': 'time_sample_frequency',
                           'gears': 'gears'
                       },
                       outputs={
                           'velocities': 'velocities',
                           'gears': 'gears',
                           'time_length': 'time_length',
                           'initial_temperature': 'initial_temperature'
                       },
                       input_domain=is_wltp)

    dsp.add_function(function=cycle_times,
                     inputs=['time_sample_frequency', 'time_length'],
                     outputs=['times'])

    dsp.add_function(function=len,
                     inputs=['velocities'],
                     outputs=['time_length'])

    dsp.add_function(function=len,
                     inputs=['gears'],
                     outputs=['time_length'],
                     weight=1)

    return dsp
Пример #4
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
Пример #5
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
Пример #6
0
def physical():
    """
    Defines the CO2MPAS physical model.

    .. dispatcher:: dsp

        >>> dsp = physical()

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

    dsp = Dispatcher(
        name='CO2MPAS physical model',
        description='Wraps all functions needed to calibrate and predict '
        'light-vehicles\' CO2 emissions.')

    from .cycle import cycle
    dsp.add_dispatcher(include_defaults=True,
                       dsp_id='cycle_model',
                       dsp=cycle(),
                       inputs={
                           'wltp_base_model': 'wltp_base_model',
                           'cycle_type': 'cycle_type',
                           'k1': 'k1',
                           'k2': 'k2',
                           'k5': 'k5',
                           'max_gear': 'max_gear',
                           'time_sample_frequency': 'time_sample_frequency',
                           'gear_box_type': 'gear_box_type',
                           'times': 'times',
                           'velocities': 'velocities',
                           'accelerations': 'accelerations',
                           'motive_powers': 'motive_powers',
                           'speed_velocity_ratios': 'speed_velocity_ratios',
                           'idle_engine_speed': 'idle_engine_speed',
                           'inertial_factor': 'inertial_factor',
                           'downscale_phases': 'downscale_phases',
                           'climbing_force': 'climbing_force',
                           'full_load_curve': 'full_load_curve',
                           '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',
                           'gears': 'gears'
                       },
                       outputs={
                           'times': 'times',
                           'velocities': 'velocities',
                           'gears': 'gears',
                           'initial_temperature': 'initial_temperature'
                       })

    from .vehicle import vehicle

    dsp.add_dispatcher(include_defaults=True,
                       dsp_id='vehicle_model',
                       dsp=vehicle(),
                       inputs={
                           'obd_velocities': 'obd_velocities',
                           'n_dyno_axes': 'n_dyno_axes',
                           'aerodynamic_drag_coefficient':
                           'aerodynamic_drag_coefficient',
                           'frontal_area': 'frontal_area',
                           'air_density': 'air_density',
                           'angle_slope': 'angle_slope',
                           'cycle_type': 'cycle_type',
                           'f0_uncorrected': 'f0_uncorrected',
                           'correct_f0': 'correct_f0',
                           'f0': 'f0',
                           'f1': 'f1',
                           'f2': 'f2',
                           'inertial_factor': 'inertial_factor',
                           'rolling_resistance_coeff':
                           'rolling_resistance_coeff',
                           'times': 'times',
                           'vehicle_mass': 'vehicle_mass',
                           'velocities': 'velocities',
                           'road_loads': 'road_loads',
                       },
                       outputs={
                           'f0': 'f0',
                           'velocities': 'velocities',
                           'climbing_force': 'climbing_force',
                           'inertial_factor': 'inertial_factor',
                           'accelerations': 'accelerations',
                           'motive_powers': 'motive_powers',
                           'road_loads': 'road_loads',
                           'n_dyno_axes': 'n_dyno_axes',
                       })

    from .wheels import wheels

    dsp.add_dispatcher(include_defaults=True,
                       dsp_id='wheels_model',
                       dsp=wheels(),
                       inputs={
                           'times': 'times',
                           'idle_engine_speed': 'idle_engine_speed',
                           'accelerations': 'accelerations',
                           'tyre_code': 'tyre_code',
                           'tyre_dimensions': 'tyre_dimensions',
                           'r_wheels': 'r_wheels',
                           'tyre_dynamic_rolling_coefficient':
                           'tyre_dynamic_rolling_coefficient',
                           'r_dynamic': 'r_dynamic',
                           'velocities': 'velocities',
                           'gears': 'gears',
                           'engine_speeds_out': 'engine_speeds_out',
                           'gear_box_ratios': 'gear_box_ratios',
                           'final_drive_ratio': 'final_drive_ratio',
                           'velocity_speed_ratios': 'velocity_speed_ratios',
                           'motive_powers': 'motive_powers',
                           'stop_velocity': 'stop_velocity',
                           'plateau_acceleration': 'plateau_acceleration',
                           'change_gear_window_width':
                           'change_gear_window_width'
                       },
                       outputs={
                           'tyre_code': 'tyre_code',
                           'tyre_dynamic_rolling_coefficient':
                           'tyre_dynamic_rolling_coefficient',
                           'r_wheels': 'r_wheels',
                           'r_dynamic': 'r_dynamic',
                           'wheel_powers': 'wheel_powers',
                           'wheel_speeds': 'wheel_speeds',
                           'wheel_torques': 'wheel_torques'
                       },
                       inp_weight={'r_dynamic': 3})

    from .final_drive import final_drive

    dsp.add_dispatcher(include_defaults=True,
                       dsp_id='final_drive_model',
                       dsp=final_drive(),
                       inputs={
                           'n_dyno_axes': 'n_dyno_axes',
                           'n_wheel_drive': 'n_wheel_drive',
                           'final_drive_efficiency': 'final_drive_efficiency',
                           'final_drive_ratio': 'final_drive_ratio',
                           'final_drive_torque_loss':
                           'final_drive_torque_loss',
                           'wheel_powers': 'final_drive_powers_out',
                           'wheel_speeds': 'final_drive_speeds_out',
                           'wheel_torques': 'final_drive_torques_out'
                       },
                       outputs={
                           'final_drive_powers_in': 'final_drive_powers_in',
                           'final_drive_speeds_in': 'final_drive_speeds_in',
                           'final_drive_torques_in': 'final_drive_torques_in',
                       })

    from .gear_box import gear_box

    dsp.add_dispatcher(include_defaults=True,
                       dsp_id='gear_box_model',
                       dsp=gear_box(),
                       inputs={
                           'on_engine':
                           'on_engine',
                           'CVT':
                           'CVT',
                           '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',
                           'cycle_type':
                           'cycle_type',
                           'use_dt_gear_shifting':
                           'use_dt_gear_shifting',
                           'specific_gear_shifting':
                           'specific_gear_shifting',
                           'ignition_type':
                           'ignition_type',
                           'full_load_curve':
                           'full_load_curve',
                           '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',
                           'vehicle_mass':
                           'vehicle_mass',
                           'accelerations':
                           'accelerations',
                           'motive_powers':
                           'motive_powers',
                           'engine_max_torque':
                           'engine_max_torque',
                           'engine_speeds_out':
                           'engine_speeds_out',
                           'final_drive_ratio':
                           'final_drive_ratio',
                           'final_drive_powers_in':
                           'gear_box_powers_out',
                           'final_drive_speeds_in':
                           'gear_box_speeds_out',
                           'gear_box_efficiency_constants':
                           'gear_box_efficiency_constants',
                           'gear_box_efficiency_parameters_cold_hot':
                           'gear_box_efficiency_parameters_cold_hot',
                           'gear_box_ratios':
                           'gear_box_ratios',
                           'initial_temperature':
                           'initial_gear_box_temperature',
                           'initial_engine_temperature':
                           'initial_gear_box_temperature',
                           'initial_gear_box_temperature':
                           'initial_gear_box_temperature',
                           'gear_box_type':
                           'gear_box_type',
                           'gears':
                           'gears',
                           'idle_engine_speed':
                           'idle_engine_speed',
                           'r_dynamic':
                           'r_dynamic',
                           'gear_box_temperature_references':
                           'gear_box_temperature_references',
                           'engine_thermostat_temperature':
                           'engine_thermostat_temperature',
                           'times':
                           'times',
                           'velocities':
                           'velocities',
                           'velocity_speed_ratios':
                           'velocity_speed_ratios',
                           'stop_velocity':
                           'stop_velocity',
                           'plateau_acceleration':
                           'plateau_acceleration',
                           'change_gear_window_width':
                           'change_gear_window_width',
                           'min_engine_on_speed':
                           'min_engine_on_speed',
                           'max_velocity_full_load_correction':
                           'max_velocity_full_load_correction'
                       },
                       outputs={
                           'CVT': 'CVT',
                           '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',
                           'equivalent_gear_box_heat_capacity':
                           'equivalent_gear_box_heat_capacity',
                           'gears': 'gears',
                           'gear_box_ratios': 'gear_box_ratios',
                           'speed_velocity_ratios': 'speed_velocity_ratios',
                           'gear_box_efficiencies': 'gear_box_efficiencies',
                           'gear_box_speeds_in': 'gear_box_speeds_in',
                           'gear_box_temperatures': 'gear_box_temperatures',
                           'gear_box_torque_losses': 'gear_box_torque_losses',
                           'gear_box_torques_in': 'gear_box_torques_in',
                           'gear_box_powers_in': 'gear_box_powers_in',
                           'max_gear': 'max_gear',
                           'gear_shifts': 'gear_shifts',
                           'velocity_speed_ratios': 'velocity_speed_ratios',
                           'max_speed_velocity_ratio':
                           'max_speed_velocity_ratio',
                           'specific_gear_shifting': 'specific_gear_shifting'
                       },
                       inp_weight={'initial_temperature': 5})

    from .clutch_tc import clutch_torque_converter

    dsp.add_dispatcher(include_defaults=True,
                       dsp=clutch_torque_converter(),
                       dsp_id='clutch_torque_converter_model',
                       inputs={
                           'times': 'times',
                           'velocities': 'velocities',
                           'accelerations': 'accelerations',
                           'gear_box_type': 'gear_box_type',
                           'clutch_model': 'clutch_model',
                           'clutch_window': 'clutch_window',
                           'gears': 'gears',
                           'gear_shifts': 'gear_shifts',
                           'engine_speeds_out': 'engine_speeds_out',
                           'engine_speeds_out_hot': 'engine_speeds_out_hot',
                           'cold_start_speeds_delta':
                           'cold_start_speeds_delta',
                           'torque_converter_model': 'torque_converter_model',
                           'stand_still_torque_ratio':
                           'stand_still_torque_ratio',
                           'lockup_speed_ratio': 'lockup_speed_ratio',
                           'gear_box_speeds_in': 'gear_box_speeds_in',
                           'gear_box_powers_in': 'gear_box_powers_in',
                           'lock_up_tc_limits': 'lock_up_tc_limits',
                           'calibration_tc_speed_threshold':
                           'calibration_tc_speed_threshold',
                           'stop_velocity': 'stop_velocity',
                       },
                       outputs={
                           'clutch_tc_speeds_delta': 'clutch_tc_speeds_delta',
                           'clutch_window': 'clutch_window',
                           'clutch_model': 'clutch_model',
                           'torque_converter_model': 'torque_converter_model',
                           'stand_still_torque_ratio':
                           'stand_still_torque_ratio',
                           'lockup_speed_ratio': 'lockup_speed_ratio',
                           'clutch_tc_powers': 'clutch_tc_powers'
                       })

    from .electrics import electrics

    dsp.add_dispatcher(include_defaults=True,
                       dsp_id='electric_model',
                       dsp=electrics(),
                       inputs={
                           'delta_time_engine_starter':
                           'delta_time_engine_starter',
                           'alternator_charging_currents':
                           'alternator_charging_currents',
                           'alternator_current_model':
                           'alternator_current_model',
                           'alternator_currents':
                           'alternator_currents',
                           'alternator_efficiency':
                           'alternator_efficiency',
                           'alternator_nominal_voltage':
                           'alternator_nominal_voltage',
                           'alternator_nominal_power':
                           'alternator_nominal_power',
                           'accelerations':
                           'accelerations',
                           'state_of_charge_balance':
                           'state_of_charge_balance',
                           'state_of_charge_balance_window':
                           'state_of_charge_balance_window',
                           'has_energy_recuperation':
                           'has_energy_recuperation',
                           'alternator_status_model':
                           'alternator_status_model',
                           'idle_engine_speed':
                           'idle_engine_speed',
                           'battery_capacity':
                           'battery_capacity',
                           'battery_currents':
                           'battery_currents',
                           'electric_load':
                           'electric_load',
                           'engine_moment_inertia':
                           'engine_moment_inertia',
                           'engine_starts':
                           'engine_starts',
                           'gear_box_powers_in':
                           'gear_box_powers_in',
                           'initial_state_of_charge':
                           'initial_state_of_charge',
                           'max_battery_charging_current':
                           'max_battery_charging_current',
                           'on_engine':
                           'on_engine',
                           'start_demand':
                           'start_demand',
                           'times':
                           'times',
                           'velocities':
                           'velocities',
                           'alternator_statuses':
                           'alternator_statuses',
                           'state_of_charges':
                           'state_of_charges',
                           'stop_velocity':
                           'stop_velocity',
                           'alternator_start_window_width':
                           'alternator_start_window_width',
                           'alternator_off_threshold':
                           'alternator_off_threshold',
                           'alternator_initialization_time':
                           'alternator_initialization_time'
                       },
                       outputs={
                           'alternator_current_model':
                           'alternator_current_model',
                           'alternator_nominal_power':
                           'alternator_nominal_power',
                           'alternator_currents':
                           'alternator_currents',
                           'alternator_statuses':
                           'alternator_statuses',
                           'alternator_powers_demand':
                           'alternator_powers_demand',
                           'alternator_status_model':
                           'alternator_status_model',
                           'battery_currents':
                           'battery_currents',
                           'electric_load':
                           'electric_load',
                           'max_battery_charging_current':
                           'max_battery_charging_current',
                           'state_of_charges':
                           'state_of_charges',
                           'start_demand':
                           'start_demand',
                           'electrics_model':
                           'electrics_model',
                           'alternator_initialization_time':
                           'alternator_initialization_time'
                       })

    from .engine import engine

    dsp.add_dispatcher(
        include_defaults=True,
        dsp_id='engine_model',
        dsp=engine(),
        inputs={
            'is_hybrid': 'is_hybrid',
            'state_of_charges': 'state_of_charges',
            'auxiliaries_torque_loss': 'auxiliaries_torque_loss',
            'auxiliaries_power_loss': 'auxiliaries_power_loss',
            'alternator_powers_demand': 'alternator_powers_demand',
            'on_engine': 'on_engine',
            'on_idle': 'on_idle',
            'correct_start_stop_with_gears': 'correct_start_stop_with_gears',
            'is_cycle_hot': 'is_cycle_hot',
            'engine_capacity': 'engine_capacity',
            'engine_is_turbo': 'engine_is_turbo',
            'engine_max_power': 'engine_max_power',
            'engine_max_speed_at_max_power': 'engine_max_speed_at_max_power',
            'engine_max_torque': 'engine_max_torque',
            'engine_speeds_out': 'engine_speeds_out',
            'engine_coolant_temperatures': 'engine_coolant_temperatures',
            'engine_temperature_regression_model':
            'engine_temperature_regression_model',
            'cold_start_speed_model': 'cold_start_speed_model',
            'ignition_type': 'ignition_type',
            'fuel_type': 'fuel_type',
            'full_load_speeds': 'full_load_speeds',
            'full_load_torques': 'full_load_torques',
            'full_load_powers': 'full_load_powers',
            'idle_engine_speed_median': 'idle_engine_speed_median',
            'idle_engine_speed_std': 'idle_engine_speed_std',
            'initial_temperature': 'initial_engine_temperature',
            'initial_engine_temperature': 'initial_engine_temperature',
            'velocities': 'velocities',
            'accelerations': 'accelerations',
            '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_params': 'co2_params',
            'co2_params_calibrated': 'co2_params_calibrated',
            'cycle_type': 'cycle_type',
            '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_stroke': 'engine_stroke',
            'engine_thermostat_temperature_window':
            'engine_thermostat_temperature_window',
            'engine_thermostat_temperature': 'engine_thermostat_temperature',
            'engine_type': 'engine_type',
            'fuel_carbon_content_percentage': 'fuel_carbon_content_percentage',
            'fuel_carbon_content': 'fuel_carbon_content',
            'gear_box_speeds_in': 'gear_box_speeds_in',
            'final_drive_powers_in': 'final_drive_powers_in',
            'gear_box_type': 'gear_box_type',
            'clutch_tc_powers': 'clutch_tc_powers',
            'gears': 'gears',
            'idle_engine_speed': 'idle_engine_speed',
            'start_stop_model': 'start_stop_model',
            'start_stop_activation_time': 'start_stop_activation_time',
            'times': 'times',
            'clutch_tc_speeds_delta': 'clutch_tc_speeds_delta',
            'calibration_status': 'calibration_status',
            'co2_normalization_references': 'co2_normalization_references',
            'fuel_density': 'fuel_density',
            'phases_integration_times': 'phases_integration_times',
            'enable_phases_willans': 'enable_phases_willans',
            'enable_willans': 'enable_willans',
            'motive_powers': 'motive_powers',
            'engine_starts': 'engine_starts',
            'engine_speeds_out_hot': 'engine_speeds_out_hot',
            'stop_velocity': 'stop_velocity',
            'plateau_acceleration': 'plateau_acceleration',
            'min_time_engine_on_after_start': 'min_time_engine_on_after_start',
            'min_engine_on_speed': 'min_engine_on_speed',
            'initial_friction_params': 'initial_friction_params',
            'use_basic_start_stop': 'use_basic_start_stop',
            'has_start_stop': 'has_start_stop',
            'max_engine_coolant_temperature': 'max_engine_coolant_temperature'
        },
        outputs={
            'ignition_type': 'ignition_type',
            'has_sufficient_power': 'has_sufficient_power',
            'idle_engine_speed_median': 'idle_engine_speed_median',
            'idle_engine_speed_std': 'idle_engine_speed_std',
            'fuel_carbon_content_percentage': 'fuel_carbon_content_percentage',
            'fuel_carbon_content': 'fuel_carbon_content',
            'auxiliaries_torque_losses': 'auxiliaries_torque_losses',
            'auxiliaries_power_losses': 'auxiliaries_power_losses',
            'calibration_status': 'calibration_status',
            'correct_start_stop_with_gears': 'correct_start_stop_with_gears',
            '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',
            'cold_start_speed_model': 'cold_start_speed_model',
            'engine_max_torque': 'engine_max_torque',
            'engine_moment_inertia': 'engine_moment_inertia',
            'engine_powers_out': 'engine_powers_out',
            'engine_speeds_out': 'engine_speeds_out',
            'engine_speeds_out_hot': 'engine_speeds_out_hot',
            'cold_start_speeds_delta': 'cold_start_speeds_delta',
            'engine_starts': 'engine_starts',
            'engine_coolant_temperatures': 'engine_coolant_temperatures',
            'engine_thermostat_temperature': 'engine_thermostat_temperature',
            'engine_type': 'engine_type',
            'engine_thermostat_temperature_window':
            'engine_thermostat_temperature_window',
            'engine_temperature_regression_model':
            'engine_temperature_regression_model',
            'fuel_consumptions': 'fuel_consumptions',
            'idle_engine_speed': 'idle_engine_speed',
            'initial_engine_temperature': 'initial_engine_temperature',
            'on_engine': 'on_engine',
            'on_idle': 'on_idle',
            'phases_co2_emissions': 'phases_co2_emissions',
            'start_stop_model': 'start_stop_model',
            'full_load_curve': 'full_load_curve',
            'engine_max_power': 'engine_max_power',
            'engine_max_speed_at_max_power': 'engine_max_speed_at_max_power',
            'willans_factors': 'willans_factors',
            'optimal_efficiency': 'optimal_efficiency',
            '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_fuel_consumptions': 'phases_fuel_consumptions',
            'fuel_density': 'fuel_density',
            'phases_willans_factors': 'phases_willans_factors',
            'missing_powers': 'missing_powers',
            'brake_powers': 'brake_powers',
            'initial_friction_params': 'initial_friction_params',
            'use_basic_start_stop': 'use_basic_start_stop',
            'max_engine_coolant_temperature': 'max_engine_coolant_temperature',
            'engine_temperature_derivatives': 'engine_temperature_derivatives',
            'engine_fuel_lower_heating_value':
            'engine_fuel_lower_heating_value',
            'cold_start_speeds_phases': 'cold_start_speeds_phases',
            'full_load_speeds': 'full_load_speeds',
            'full_load_powers': 'full_load_powers'
        },
        inp_weight={'initial_temperature': 5})

    dsp.add_function(
        function=predict_vehicle_electrics_and_engine_behavior,
        inputs=[
            'electrics_model', 'start_stop_model',
            'engine_temperature_regression_model',
            'initial_engine_temperature', 'initial_state_of_charge',
            'idle_engine_speed', 'times', 'final_drive_powers_in',
            'gear_box_speeds_in', 'gear_box_powers_in', 'velocities',
            'accelerations', 'gears', 'start_stop_activation_time',
            'correct_start_stop_with_gears', 'min_time_engine_on_after_start',
            'has_start_stop', 'use_basic_start_stop',
            'max_engine_coolant_temperature'
        ],
        outputs=[
            'alternator_currents', 'battery_currents', 'state_of_charges',
            'alternator_statuses', 'on_engine', 'engine_starts',
            'engine_speeds_out_hot', 'engine_coolant_temperatures'
        ],
        weight=10)

    return dsp
Пример #7
0
def clutch_torque_converter():
    """
    Defines the clutch and torque-converter model.

    .. dispatcher:: dsp

        >>> dsp = clutch_torque_converter()

    :return:
        The clutch and torque-converter model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(name='Clutch and torque-converter',
                     description='Models the clutch and torque-converter.')

    dsp.add_function(function=calculate_clutch_tc_powers,
                     inputs=[
                         'clutch_tc_speeds_delta', 'k_factor_curve',
                         'gear_box_speeds_in', 'gear_box_powers_in',
                         'engine_speeds_out'
                     ],
                     outputs=['clutch_tc_powers'])

    from .clutch import clutch

    def clutch_domain(kwargs):
        for k, v in kwargs.items():
            if ':gear_box_type' in k or 'gear_box_type' == k:
                return v == 'manual'
        return False

    dsp.add_dispatcher(include_defaults=True,
                       input_domain=clutch_domain,
                       dsp=clutch(),
                       dsp_id='clutch',
                       inputs={
                           'times': 'times',
                           'accelerations': 'accelerations',
                           'gear_box_type': dsp_utl.SINK,
                           'clutch_model': 'clutch_model',
                           'clutch_window': 'clutch_window',
                           'clutch_tc_speeds_delta': 'clutch_speeds_delta',
                           'gear_shifts': 'gear_shifts',
                           'stand_still_torque_ratio':
                           'stand_still_torque_ratio',
                           'lockup_speed_ratio': 'lockup_speed_ratio',
                           'max_clutch_window_width':
                           'max_clutch_window_width',
                           'engine_speeds_out': 'engine_speeds_out',
                           'engine_speeds_out_hot': 'engine_speeds_out_hot',
                           'cold_start_speeds_delta': 'cold_start_speeds_delta'
                       },
                       outputs={
                           'clutch_speeds_delta': 'clutch_tc_speeds_delta',
                           'clutch_window': 'clutch_window',
                           'clutch_model': 'clutch_model',
                           'k_factor_curve': 'k_factor_curve'
                       })

    from .torque_converter import torque_converter

    def torque_converter_domain(kwargs):
        for k, v in kwargs.items():
            if ':gear_box_type' in k or 'gear_box_type' == k:
                return v in ('cvt', 'automatic')
        return False

    dsp.add_dispatcher(include_defaults=True,
                       input_domain=torque_converter_domain,
                       dsp=torque_converter(),
                       dsp_id='torque_converter',
                       inputs={
                           'lock_up_tc_limits':
                           'lock_up_tc_limits',
                           'calibration_tc_speed_threshold':
                           'calibration_tc_speed_threshold',
                           'stop_velocity':
                           'stop_velocity',
                           'velocities':
                           'velocities',
                           'accelerations':
                           'accelerations',
                           'gear_box_type':
                           dsp_utl.SINK,
                           'gears':
                           'gears',
                           'clutch_tc_speeds_delta':
                           'torque_converter_speeds_delta',
                           'engine_speeds_out_hot':
                           ('gear_box_speeds_in', 'engine_speeds_out_hot'),
                           'torque_converter_model':
                           'torque_converter_model',
                           'stand_still_torque_ratio':
                           'stand_still_torque_ratio',
                           'lockup_speed_ratio':
                           'lockup_speed_ratio',
                           'engine_speeds_out':
                           'engine_speeds_out',
                           'cold_start_speeds_delta':
                           'cold_start_speeds_delta'
                       },
                       outputs={
                           'torque_converter_speeds_delta':
                           'clutch_tc_speeds_delta',
                           'torque_converter_model': 'torque_converter_model',
                           'k_factor_curve': 'k_factor_curve'
                       })

    return dsp
Пример #8
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
Пример #9
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