Beispiel #1
0
def print_to_moohst(show=True, save=False):
    if show:
        shows = True
        saves = False
    elif save:
        shows = False
        saves = True
    #*  Catalogue data
    models, data = load_catalogues()
    plot_catalogue_data(
        models,
        data,
        show_figure=shows,
        save_figure=saves,
    )
    plot_histograms(
        models,
        data,
        show_figure=shows,
        save_figure=saves,
    )
    #*  Validation
    plot_validation(show_figure=shows, save_figure=saves)
    #*  HST initialization
    hst = HST(*set_defaults('sizing'))
    hst.compute_sizes(displ=500)
    hst.compute_speed_limit(models['pump_speed'])
    #*  Oil setting
    hst.oil = 'SAE 15W40'
    hst.oil_temp = 100
    hst.load_oil()
    hst.plot_oil(show_figure=shows, save_figure=saves)
    #* Maps preparation
    input_speed, pressure_charge, pressure_discharge = set_defaults(
        'performance')
    max_speed, max_pressure, hst.max_power_input, hst.input_gear_ratio = set_defaults(
        'map')
    hst.engine = None
    #* Maps plotting
    hst.plot_eff_map(
        max_speed,
        max_pressure,
        pressure_charge=pressure_charge,
        show_figure=shows,
        save_figure=saves,
    )
    hst.plot_power_map(
        max_speed,
        max_pressure,
        pressure_charge=pressure_charge,
        show_figure=shows,
        save_figure=saves,
    )
    eff_temp(hst, save_figure=save, show_figure=show)
Beispiel #2
0
 def __init__(self):
     super().__init__(n_var=3,
                      n_obj=2,
                      n_constr=1,
                      xl=np.array([200, 1000, 100]),
                      xu=np.array([800, 3000, 700]),
                      elementwise_evaluation=True)
     self.hst = HST()
     self.hst.oil = 'SAE 15W40'
     self.hst.oil_temp = 100
     self.hst.load_oil()
     self.reg_models, _ = ha.load_catalogues()
Beispiel #3
0
    def test_motor_speed(self):
        self.assertEqual(round(test_performance['motor']['speed'], ndigits=3),
                         2068.024)

    def test_motor_torque(self):
        self.assertEqual(round(test_performance['motor']['torque'], ndigits=3),
                         489.130)

    def test_motor_power(self):
        self.assertEqual(round(test_performance['motor']['power'], ndigits=3),
                         105.927)

    def test_hst_volumetric(self):
        self.assertEqual(
            round(test_efficiency['hst']['volumetric'], ndigits=3), 68.934)

    def test_hst_mechanical(self):
        self.assertEqual(
            round(test_efficiency['hst']['mechanical'], ndigits=3), 92.266)

    def test_hst_total(self):
        self.assertEqual(round(test_efficiency['hst']['total'], ndigits=3),
                         63.603)


if __name__ == '__main__':
    test_hst = HST()
    test_hst.compute_sizes(100)
    test_hst.load_oil()
    test_efficiency, test_performance = test_hst.compute_eff(3000, 350)
    unittest.main(verbosity=2)
Beispiel #4
0
def plot_hst_comparison(displ_1,
                        displ_2,
                        speed,
                        pressure,
                        temp,
                        show_figure=True,
                        save_figure=False,
                        format='pdf'):
    """
    Prints a bar plot to compare total efficiencies of two HSTs.

    Parameters:
    ---
    displ_1, displ_2: float
        Displacements of the HSTs to be comapred
    speed, pressure, temp, charge: floats
        Operational parameters for the comparison
    """
    effs_1, effs_2 = [], []
    motor_pows_1, motor_pows_2 = [], []
    pump_pows_1, pump_pows_2 = [], []
    oils = ('SAE 15W40', 'SAE 10W40', 'SAE 10W60', 'SAE 5W40', 'SAE 0W30',
            'SAE 30')
    hst_1, hst_2 = HST(oil_temp=temp), HST(oil_temp=temp)
    hst_1.compute_sizes(displ_1)
    hst_2.compute_sizes(displ_2)
    for oil in oils:
        hst_1.oil, hst_2.oil = oil, oil
        hst_1.load_oil()
        hst_2.load_oil()
        eff_1 = hst_1.compute_eff(speed, pressure)[0]
        eff_2 = hst_2.compute_eff(speed, pressure)[0]
        effs_1.append(eff_1['hst']['total'])
        effs_2.append(eff_2['hst']['total'])
        motor_pows_1.append(hst_1.performance['motor']['power'])
        motor_pows_2.append(hst_2.performance['motor']['power'])
        pump_pows_1.append(hst_1.performance['pump']['power'])
        pump_pows_2.append(hst_2.performance['pump']['power'])
    fig_eff = go.Figure()
    fig_eff.add_trace(
        go.Bar(
            x=oils,
            y=effs_1,
            text=[f'{eff:.2f}' for eff in effs_1],
            textposition='auto',
            name=f'{displ_1} cc/rev',
            marker_color='steelblue',
        ))
    fig_eff.add_trace(
        go.Bar(x=oils,
               y=effs_2,
               text=[f'{eff:.2f}' for eff in effs_2],
               textposition='auto',
               name=f'{displ_2} cc/rev',
               marker_color='indianred'))
    fig_eff.update_layout(
        # title=
        # f'Total efficiency of {displ_1} and {displ_2} cc/rev HSTs at {speed} rpm, {pressure} bar, {temp}C oil',
        yaxis=dict(
            title='Total HST efficiency, %',
            range=[50, 90],
        ),
        template='none',
        showlegend=True,
        legend_orientation='h',
        width=800,
        height=500,
        font=dict(size=14),
    )
    fig_pow = go.Figure()
    fig_pow.add_trace(
        go.Bar(
            x=oils,
            y=pump_pows_1,
            text=[f'{pow:.2f}' for pow in pump_pows_1],
            textposition='auto',
            name=f'{displ_1} cc/rev in',
            marker_color='steelblue',
        ))
    fig_pow.add_trace(
        go.Bar(
            x=oils,
            y=motor_pows_1,
            text=[f'{pow:.2f}' for pow in motor_pows_1],
            textposition='auto',
            name=f'{displ_1} cc/rev  out',
            marker_color='lightblue',
        ))
    fig_pow.add_trace(
        go.Bar(
            x=oils,
            y=pump_pows_2,
            text=[f'{pow:.2f}' for pow in pump_pows_2],
            textposition='auto',
            name=f'{displ_2} cc/rev  in',
            marker_color='indianred',
        ))
    fig_pow.add_trace(
        go.Bar(x=oils,
               y=motor_pows_2,
               text=[f'{pow:.2f}' for pow in motor_pows_2],
               textposition='auto',
               name=f'{displ_2} cc/rev out',
               marker_color='pink'))
    fig_pow.update_layout(
        # title=
        # f'Power balance of {displ_1} and {displ_2} cc/rev HSTs at {speed} rpm, {pressure} bar, {temp}C oil',
        yaxis=dict(title='Power, kW', ),
        template='none',
        showlegend=True,
        legend_orientation='h',
        width=900,
        height=600,
        font=dict(size=14, color='black'),
    )
    if save_figure:
        if not os.path.exists('images'):
            os.mkdir('images')
        fig_eff.write_image(f'images/hst_eff_comparison.{format}')
        fig_pow.write_image(f'images/hst_power_comparison.{format}')
    if show_figure:
        fig_eff.show()
        fig_pow.show()
Beispiel #5
0
def plot_validation_plotly(show_figure=False, save_figure=False, format='pdf'):
    """Performs validation of the efficiency model by computing the volumetric efficiency of the benchmark HST, for which the test data is available containing results of measurements of the input/output speeds, and comparing the computed efficiency with the test data.
    """
    data = pd.read_csv(
        'https://raw.githubusercontent.com/ivanokhotnikov/effmap_demo/master/data/test_data.csv'
    )
    data.dropna(
        subset=['Forward Speed', 'Reverse Speed', 'Volumetric at 1780RPM'],
        inplace=True)
    speeds = data[['Forward Speed', 'Reverse Speed']].astype(float)
    speeds = speeds.stack()
    vol_eff = speeds / 1780 * 1e2
    piston_max = 1.1653 * 25.4 * 1e-3
    piston_min = 1.1650 * 25.4 * 1e-3
    bore_max = 1.1677 * 25.4 * 1e-3
    bore_min = 1.1671 * 25.4 * 1e-3
    rad_clearance_max = (bore_max - piston_min) / 2
    rad_clearance_min = (bore_min - piston_max) / 2
    benchmark = HST(swash=15, oil='SAE 30', oil_temp=60)
    benchmark.compute_sizes(displ=196,
                            k1=.7155,
                            k2=.9017,
                            k3=.47,
                            k4=.9348,
                            k5=.9068)
    benchmark.load_oil()
    eff_min = benchmark.compute_eff(speed_pump=1780,
                                    pressure_discharge=207,
                                    pressure_charge=14,
                                    h3=rad_clearance_max)[0]
    eff_max = benchmark.compute_eff(speed_pump=1780,
                                    pressure_discharge=207,
                                    pressure_charge=14,
                                    h3=rad_clearance_min)[0]
    fig = ff.create_distplot(
        [vol_eff],
        [
            f"Test data. Mean = {round(vol_eff.mean(),2)}%, SD = {round(vol_eff.std(),2)}%"
        ],
        show_hist=True,
        bin_size=.3,
        show_rug=False,
    )
    fig.add_scatter(
        x=[eff_max['hst']['volumetric'], eff_max['hst']['volumetric']],
        y=[0, .6],
        mode='lines',
        name=
        f"Prediction at min clearance, {round(eff_max['hst']['volumetric'],2)}%",
        line=dict(width=1.5, ),
    )
    fig.add_scatter(
        x=[eff_min['hst']['volumetric'], eff_min['hst']['volumetric']],
        y=[0, .6],
        mode='lines',
        name=
        f"Prediction at max clearance, {round(eff_min['hst']['volumetric'],2)}%",
        line=dict(width=1.5, ),
    )
    fig.add_scatter(
        x=[vol_eff.mean(), vol_eff.mean()],
        y=[0, .6],
        mode='lines',
        name=f"Test mean, {round(vol_eff.mean(),2)}%",
        line=dict(width=1.5, dash='dash'),
    )
    fig.add_scatter(
        x=[vol_eff.mean() + vol_eff.std(),
           vol_eff.mean() + vol_eff.std()],
        y=[0, .6],
        mode='lines',
        name='Test mean + SD',
        line=dict(width=1.5, dash='dash'),
    )
    fig.add_scatter(
        x=[vol_eff.mean() - vol_eff.std(),
           vol_eff.mean() - vol_eff.std()],
        y=[0, .6],
        mode='lines',
        name='Test mean - SD',
        line=dict(width=1.5, dash='dash'),
    )
    fig.update_layout(
        # title=
        # f'Sample of {len(vol_eff)} measurements of the {benchmark.displ} cc/rev HST with {benchmark.oil} at {benchmark.oil_temp}C',
        template='none',
        width=1000,
        height=600,
        xaxis=dict(
            title='HST volumetric efficiency, %',
            showline=True,
            linecolor='black',
            showgrid=True,
            gridcolor='LightGray',
            gridwidth=0.25,
            linewidth=0.25,
            range=[84, 94],
            dtick=2,
            mirror='all',
        ),
        yaxis=dict(
            title='Probability density',
            showline=True,
            linecolor='black',
            showgrid=True,
            gridcolor='LightGray',
            gridwidth=0.25,
            linewidth=0.25,
            range=[0, .6],
            mirror='all',
        ),
        showlegend=True,
        legend_orientation='v',
        legend=dict(x=1.05, y=1, xanchor='left', yanchor='top'),
        font=dict(size=14, color='black'))
    if save_figure:
        if not os.path.exists('images'): os.mkdir('images')
        fig.write_image(f'images/validation.{format}')
    if show_figure: fig.show()
Beispiel #6
0
def plot_validation(show_figure=False, save_figure=False, format='pdf'):
    data = pd.read_csv(
        'https://raw.githubusercontent.com/ivanokhotnikov/effmap_demo/master/data/test_data.csv'
    )
    data.dropna(
        subset=['Forward Speed', 'Reverse Speed', 'Volumetric at 1780RPM'],
        inplace=True)
    data['Reverse Speed'] = data['Reverse Speed'].astype(np.float64)
    data['Volumetric at 1780RPM'] = data['Volumetric at 1780RPM'].map(
        lambda x: float(x[:-1]))
    data.loc[data['Reverse Speed'] == 568.0, 'Reverse Speed'] = 1568.0
    data.loc[data['Volumetric at 1780RPM'] == 60.1,
             'Volumetric at 1780RPM'] = round(
                 (1571 / 1780 + 1568 / 1780) / 2 * 100, ndigits=1)
    speeds = data[['Forward Speed', 'Reverse Speed']].astype(float)
    speeds = speeds.stack()
    vol_eff = speeds / 1780 * 1e2
    piston_max = 1.1653 * 25.4 * 1e-3
    piston_min = 1.1650 * 25.4 * 1e-3
    bore_max = 1.1677 * 25.4 * 1e-3
    bore_min = 1.1671 * 25.4 * 1e-3
    rad_clearance_max = (bore_max - piston_min) / 2
    rad_clearance_min = (bore_min - piston_max) / 2
    benchmark = HST(swash=15, oil='SAE 30', oil_temp=60)
    benchmark.compute_sizes(displ=196,
                            k1=.7155,
                            k2=.9017,
                            k3=.47,
                            k4=.9348,
                            k5=.9068)
    benchmark.load_oil()
    eff_min = benchmark.compute_eff(speed_pump=1780,
                                    pressure_discharge=207,
                                    pressure_charge=14,
                                    h1=29e-6,
                                    h2=29e-6,
                                    h3=rad_clearance_max)[0]
    eff_max = benchmark.compute_eff(speed_pump=1780,
                                    pressure_discharge=207,
                                    pressure_charge=14,
                                    h1=29e-6,
                                    h2=29e-6,
                                    h3=rad_clearance_min)[0]
    eff_midrange = benchmark.compute_eff(speed_pump=1780,
                                         pressure_discharge=207,
                                         pressure_charge=14,
                                         h1=29e-6,
                                         h2=29e-6,
                                         h3=np.mean((rad_clearance_min,
                                                     rad_clearance_max)))[0]
    sns.set_style('ticks', {
        'spines.linewidth': .25,
    })
    sns.set_palette('Set1')
    plot = sns.histplot(
        data=vol_eff,
        kde=True,
        element='step',
        label='Test data',
        color='steelblue',
    )
    sns.despine()
    plot.axes.axvline(
        eff_max['hst']['volumetric'],
        label=
        f"Prediction at min clearance, {round(eff_max['hst']['volumetric'], 2)}%",
        linestyle=':',
        color='crimson',
        linewidth=1,
    )
    plot.axes.axvline(
        eff_min['hst']['volumetric'],
        label=
        f"Prediction at max clearance, {round(eff_min['hst']['volumetric'], 2)}%",
        linestyle=':',
        color='seagreen',
        linewidth=1,
    )
    plot.axes.axvline(
        eff_midrange['hst']['volumetric'],
        label=
        f"Prediction at midrange clearance, {round(eff_midrange['hst']['volumetric'], 2)}%",
        linestyle=':',
        color='royalblue',
        linewidth=1,
    )
    plot.axes.axvline(
        vol_eff.mean(),
        label=f"Test mean, {round(vol_eff.mean(), 2)}%",
        linestyle='--',
        color='steelblue',
        linewidth=1,
    )
    plot.axes.axvline(
        vol_eff.mean() + vol_eff.std(),
        label=f"Test mean + SD, {round(vol_eff.mean() + vol_eff.std(),2)}%",
        linestyle='--',
        color='darkorange',
        linewidth=1,
    )
    plot.axes.axvline(
        vol_eff.mean() - vol_eff.std(),
        label=f"Test mean - SD, {round(vol_eff.mean() - vol_eff.std(),2)}%",
        color='slateblue',
        linestyle='--',
        linewidth=1,
    )
    plt.xlim(86, 92)
    plt.ylim(0, 90)
    plt.xlabel('HST volumetric efficiency, %')
    plt.legend(loc='upper right', fontsize='x-small')
    if save_figure:
        if not os.path.exists('images'): os.mkdir('images')
        plt.savefig(f'images/validation.{format}')
    if show_figure: plt.show()
    plt.clf()
    plt.close('all')