Example #1
0
def lhs_dimension():                     # Dynamic dimension of LHS - depending on no. of Vars saved as "dimension"
    cc_bev = gin.changed_compact().reindex(['FE_batt', 'E_batt', 'E_battPHEV', 'P_battEmpty', 'P_fcEmpty',
                                            'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'],
                                           axis='rows')  # for LHS-Dimension / s_ren!!!
    cg_bev = gin.changed_general().reindex(['C3_batt', 'C5_empty', 'Em_elFC', 'cd_empty', 'cd', 'Em_elBatt', 'Em_elVC',
                                            'L', 'D', 'r', 'C_fuelEl', 'C_batt', 'C_fcEmpty'], axis='rows')  # 22 (18)
    range_length = pd.concat([cc_bev, cg_bev])  # concatinate all needed lhs-variables


    dim = (len(range_length))                   # Length of Variable list
    #print("dim: ", dim)
    return dim
Example #2
0
def result_calc(var, class_sel, dimension):
    all_para_keys = [
        'FE', 'E_batt', 'E_battEmptyPHEV', 'P_batt', 'P_fc', 'c_main_bev',
        'c_main_fcev', 'c_main_phev', 'c_main_icev', 'C3', 'C5', 'Em_elFC',
        'Em_elVC', 'cd', 'cd_phev', 'Em_elBatt', 'L', 'D', 'r', 'C_fuel',
        'C_batt', 'C_fc', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9',
        'X10', 'X11', 'X12', 'X13', 'X14', 'm_curb', 'C_msrp', 'P_battSet',
        'E_battSet', 'P_fcSet', 'C_battSet', 'C_fcSet', 'CF', 'w_h2',
        'w_synth', 's_ren'
    ]

    result = np.zeros(shape=(0, 2))
    result_all = np.zeros(shape=(0, 6))

    result_tax = np.zeros(shape=(0, 2))  # Partial TCO: CAPEX, OPEX
    result_tax_total = []  # Total TCO!

    # Array of all Values
    all_values = []
    vehicle_type = 0

    # Counter for No. of Calculations
    vehicle_name_list = []

    # Array for PHEV FE's
    fe_phev_cd_array = []
    fe_phev_cs_array = []
    c_phev_el_array = []
    c_phev_synth_array = []

    if class_sel == 1:  # Compact
        E_battPHEV = gin.changed_compact().reindex(['E_battPHEV'], axis='rows')
        count_type = 0

    elif class_sel == 2:  # SUV
        E_battPHEV = gin.changed_suv().reindex(['E_battPHEV'], axis='rows')
        count_type = 1

    elif class_sel == 3:  # LDV
        E_battPHEV = gin.changed_ldv().reindex(['E_battPHEV'], axis='rows')
        count_type = 2

    while count_type < len(gin.x_vals(
    )):  # count through fix vals of class (bev, fcev, phev, icev)
        lhs_lists = var[vehicle_type]  # all result lists of one propType

        # Array for PHEV FE's
        fe_phev_cd_list = []
        fe_phev_cs_list = []
        c_phev_el_list = []
        c_phev_synth_list = []

        x_vals = list(gin.x_vals().iloc[count_type])
        spec_vals = list(gin.spec_vals().iloc[count_type])
        x_vals.extend(spec_vals)  # all fix vals saved here
        single_res = np.zeros(shape=(n, 2))
        single_all_res = np.zeros(shape=(n, 6))

        single_res_tax = np.zeros(shape=(n, 2))
        drive_res_tax_total = []

        for list_num in range(n):
            tco_res, lce_res, tco_capex, tco_opex, e_fc, e_vc, lhs_dict, fe_phev_cd, fe_phev_cs = 0, 0, 0, 0, 0, \
                                                                                                  0, 0, 0, 0

            if vehicle_type == 2:  # PHEV
                all_para_phev = [
                    'FE_bev', 'E_batt_bev', 'E_battPHEV', 'P_batt_bev',
                    'P_fc_bev', 'c_main_bev', 'c_main_fcev', 'c_main_phev',
                    'c_main_icev', 'C3_bev', 'C5_bev', 'Em_elFC', 'Em_elVC',
                    'cd_empty', 'cd_phev', 'Em_elBatt', 'L', 'D', 'r',
                    'C_fuel_bev', 'C_batt_bev', 'C_fc_bev', 'FE_icev',
                    'E_batt', 'E_battEmptyPHEV', 'P_batt', 'P_fc',
                    'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev',
                    'C3_icev', 'C5_icev', 'Em_elFC', 'Em_elVC', 'cd_empty',
                    'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuel_icev',
                    'C_batt', 'C_fc', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7',
                    'X8', 'X9', 'X10', 'X11', 'X12', 'X13', 'X14', 'm_curb',
                    'C_msrp', 'P_battSet', 'E_battSet', 'P_fcSet', 'C_battSet',
                    'C_fcSet', 'CF', 'w_h2', 'w_synth', 's_ren'
                ]
                # 58 vals - 60 with 2 x cd_phev - 68 with 2 x 4 c_maint

                all_phev_lhs = list(lhs_lists[list_num])

                if booleanCheckbox == 1 and (
                        vehicle_type == 0 or vehicle_type
                        == 1):  # Checking if there is a subsidy
                    s_ren = gin.sub_big()
                elif booleanCheckbox == 1 and (vehicle_type == 2):
                    s_ren = gin.sub_small()
                else:
                    s_ren = 0.0

                all_phev_lhs.extend(x_vals)
                all_phev_lhs.append(s_ren)
                lhs_dict = dict(zip(all_para_phev, all_phev_lhs))

                lhs_dict['E_batt_bev'] = 0  # ********** NEW
                vehicle_name = 'PHEV'

                e_inst = FuelCyclePHEV(**lhs_dict)
                e_fc = e_inst.fuel_cycle_phev()  # e_fc of PHEV

                ## Here distinguish tco icev / bev - FE
                lhs_dict['C_main'] = lhs_dict['c_main_phev']
                tco_inst = TCO(**lhs_dict)
                tco_res, tco_opex, tco_capex = tco_inst.calc_tco_phev(
                )  ## tco result PHEV

                # IF GHG TAX TURNED ON: ADDED TO TCO HERE
                if ghg_tax != 0:
                    tco_opex_tax = tco_opex + (e_fc * ghg_tax / 1000000
                                               )  # normalize t to gram
                    tco_capex_tax = tco_capex + (e_vc * ghg_tax / 1000000
                                                 )  # normalize t to gram

                    L = lhs_lists[list_num][16]
                    D = lhs_lists[list_num][17]
                    r = lhs_lists[list_num][18]
                    cd_phev = lhs_lists[list_num][13]

                    cs = 100 - cd_phev
                    # --- OPEX --- #

                    sum_tco_tax = 0
                    for years in range(1, int(round(
                            L +
                            1))):  # creating sum # FOR ABSOLUTE C_main NUMBERS
                        equation = (tco_opex_tax) / (1 + r)**(years - 1)
                        sum_tco_tax += equation

                    tco_res_tax = (tco_capex_tax / (L * D)) + sum_tco_tax

                else:
                    tco_opex_tax = 0
                    tco_capex_tax = 0
                    tco_res_tax = 0

                fe_phev_cd = lhs_dict['FE_bev']
                fe_phev_cs = lhs_dict['FE_icev']

                c_phev_el = lhs_dict['C_fuel_bev']
                c_phev_synth = lhs_dict['C_fuel_icev']

                ### UPDATE PHEV VALS TO FIT LCE CALCULATION
                phev_vals = list(e_inst.new_phev_vals())  # updated PHEV vals
                phev_vals.extend(x_vals)
                phev_vals.append(s_ren)
                lhs_dict = dict(zip(all_para_keys, phev_vals))
                lhs_dict['C_main'] = lhs_dict['c_main_phev']

                lce_inst = LCE(**lhs_dict)
                e_vc = lce_inst.vehicle_cycle()  # e_vc of PHEV

                lce_res = lce_inst.calc_lce(e_fc, e_vc)  ## LCE

            elif vehicle_type == 0 or vehicle_type == 1 or vehicle_type == 3:
                all_vals = list(
                    lhs_lists[list_num]
                )  # should be one single list of lhs_variable_results
                all_vals.extend(x_vals)  # ALL NEEDED VARS ARE HERE NOW
                if booleanCheckbox == 1 and (
                        vehicle_type == 0
                        or vehicle_type == 1):  # checks if there is a subsidy
                    s_ren = gin.sub_big()
                elif booleanCheckbox == 1 and (vehicle_type == 2):
                    s_ren = gin.sub_small()
                else:
                    s_ren = 0.0
                all_vals.append(s_ren)
                lhs_dict = dict(zip(all_para_keys, all_vals))

                lhs_dict['E_battEmptyPHEV'] = 0

                lce_inst = LCE(**lhs_dict)

                e_fc = lce_inst.fuel_cycle()  # e_fc of rest vehicles
                e_vc = lce_inst.vehicle_cycle()  # e_vc of rest vehicles

                # --- c_maintenance allocation --- #
                if vehicle_type == 0:
                    lhs_dict['C_main'] = lhs_dict['c_main_bev']
                    vehicle_name = 'BEV'
                elif vehicle_type == 1:
                    lhs_dict['C_main'] = lhs_dict['c_main_fcev']
                    vehicle_name = 'FCEV'
                elif vehicle_type == 3:
                    lhs_dict['C_main'] = lhs_dict['c_main_icev']
                    vehicle_name = 'ICEV'

                tco_inst = TCO(**lhs_dict)

                lce_res = lce_inst.calc_lce(e_fc, e_vc)  ##### LCE
                tco_res, tco_opex, tco_capex = tco_inst.calc_tco(
                )  # tco result rest

                # IF GHG TAX TURNED ON: ADDED TO TCO HERE
                if ghg_tax != 0:
                    tco_opex_tax = tco_opex + (e_fc * ghg_tax / 1000000
                                               )  # normalize t to gram
                    tco_capex_tax = tco_capex + (e_vc * ghg_tax / 1000000
                                                 )  # normalize t to gram

                    L = lhs_lists[list_num][16]
                    D = lhs_lists[list_num][17]
                    r = lhs_lists[list_num][18]

                    sum_tco_tax = 0

                    for years in range(1, int(round(L + 1))):  # creating sum
                        equation = (tco_opex_tax) / ((1 + r)**(years - 1))
                        equation = np.around(equation, decimals=4)
                        sum_tco_tax += equation

                    tco_res_tax = (tco_capex_tax / (L * D)) + sum_tco_tax

                else:
                    tco_opex_tax = 0
                    tco_capex_tax = 0
                    tco_res_tax = 0

                # Filling Zeros to PHEV specific FE Columns
                fe_phev_cd = 0
                fe_phev_cs = 0
                c_phev_el = 0
                c_phev_synth = 0

            all_values.append(lhs_dict)

            # all results of BEV, FCEV etc
            single_res[list_num] = [
                np.around(tco_res, decimals=4),
                np.around(lce_res, decimals=4)
            ]
            single_all_res[list_num] = [
                tco_res, lce_res, tco_capex, tco_opex, e_fc, e_vc
            ]
            single_all_res = np.around(single_all_res, decimals=4)

            # TAX
            drive_res_tax_total.append(
                tco_res_tax)  # Here total TCO for Tax Scenario per Drive
            single_res_tax[list_num] = [
                np.around(tco_capex_tax, decimals=4),
                np.around(tco_opex_tax, decimals=4)
            ]  # Partial TCO Results

            fe_phev_cd_list.append(fe_phev_cd)
            fe_phev_cs_list.append(fe_phev_cs)
            c_phev_el_list.append(c_phev_el)
            c_phev_synth_list.append(c_phev_synth)

            vehicle_name_list.append(vehicle_name)

        result = np.append(result, single_res, axis=0)
        result_all = np.append(result_all, single_all_res,
                               axis=0)  # --- TOTAL RESULT ---

        result_tax = np.append(result_tax, single_res_tax,
                               axis=0)  # PARTIAL TCOs
        result_tax_total.extend(drive_res_tax_total)  # WHOLE TCO!

        # Additional Values for csv
        fe_phev_cd_array.extend(fe_phev_cd_list)
        fe_phev_cs_array.extend(fe_phev_cs_list)
        c_phev_el_array.extend(c_phev_el_list)
        c_phev_synth_array.extend(c_phev_synth_list)

        # append to a longer list
        count_type += 3  # Jump from compact_bev to compact_fcev to compact_phev ...
        vehicle_type += 1  # increasing -> lhs_lists bev -> fcev

    all_values = pd.DataFrame(all_values)  # create dataframe
    all_values = round(all_values, 4)

    # Copy all_values to customly save as csv // Adding No. of Calculation, fe_phev_cd, fe_phev_cs,
    all_values_csv = all_values
    all_values_csv['Vehicle'] = vehicle_name_list

    all_values_csv['fe_phev_cd'] = fe_phev_cd_array
    all_values_csv['fe_phev_cs'] = fe_phev_cs_array
    all_values_csv['c_phev_el'] = c_phev_el_array
    all_values_csv['c_phev_synth'] = c_phev_synth_array

    all_values_csv.to_csv("results/input_values.csv", sep=";")
    all_values_csv.to_json("results/json/input_values.json", orient='index')

    result = np.around(result, decimals=4)

    columns = [
        'TCO (€/km)', "LCE (gGHG/km)", "TCO_Capex (€)", "TCO_Opex (€/km)",
        "Em_fc (gGHG/km)", "Em_vc (gGHG)"
    ]
    result_extend = np.around(result_all, decimals=4)
    result_extend = pd.DataFrame(data=result_extend, columns=columns)

    if ghg_tax != 0:
        result[:, 0] = result_tax_total

    result = np.around(result, decimals=4)

    return result, result_extend, all_values, vehicle_name, result_tax
Example #3
0
def get_variables(class_sel, vehicle):
    global lhs_vals
    if class_sel == 1:  # compact car #   cc = changed compact
        if vehicle == 0:  # BEV
            cc_bev = gin.changed_compact().reindex([
                'FE_batt', 'E_batt', 'E_battPHEV', 'P_battEmpty', 'P_fcEmpty',
                'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'
            ],
                                                   axis='rows')
            cg_bev = gin.changed_general().reindex([
                'C3_batt', 'C5_empty', 'Em_elFC', 'Em_elVC', 'cd_empty', 'cd',
                'Em_elBatt', 'L', 'D', 'r', 'C_fuelEl', 'C_batt', 'C_fcEmpty'
            ],
                                                   axis='rows')
            lhs_vals = pd.concat([cc_bev, cg_bev])

        elif vehicle == 1:  # FCEV
            cc_fcev = gin.changed_compact().reindex([
                'FE_h2', 'E_battEmpty', 'E_battEmptyPHEV', 'P_batt', 'P_fc',
                'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'
            ],
                                                    axis='rows')
            cg_fcev = gin.changed_general().reindex([
                'C3_h2', 'C5_empty', 'Em_elFC', 'Em_elVC', 'cd_empty',
                'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuelH2', 'C_batt',
                'C_fc'
            ],
                                                    axis='rows')
            lhs_vals = pd.concat([cc_fcev, cg_fcev])

        elif vehicle == 2:  # PHEV
            pass

        elif vehicle == 3:  # ICEV
            cc_icev = gin.changed_compact().reindex([
                'FE_synth', 'E_battEmpty', 'E_battEmptyPHEV', 'P_battEmpty',
                'P_fcEmpty', 'c_main_bev', 'c_main_fcev', 'c_main_phev',
                'c_main_icev'
            ],
                                                    axis='rows')
            cg_icev = gin.changed_general().reindex([
                'C3_synth', 'C5_icev', 'Em_elFC', 'Em_elVC', 'cd_empty',
                'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuelSynth',
                'C_battEmpty', 'C_fcEmpty'
            ],
                                                    axis='rows')
            lhs_vals = pd.concat([cc_icev, cg_icev])

    elif class_sel == 2:  # midsize SUV #       cs = changed suv
        if vehicle == 0:  # BEV
            cs_bev = gin.changed_suv().reindex([
                'FE_batt', 'E_batt', 'E_battPHEV', 'P_battEmpty', 'P_fcEmpty',
                'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'
            ],
                                               axis='rows')
            cg_bev = gin.changed_general().reindex([
                'C3_batt', 'C5_empty', 'Em_elFC', 'Em_elVC', 'cd_empty', 'cd',
                'Em_elBatt', 'L', 'D', 'r', 'C_fuelEl', 'C_batt', 'C_fcEmpty'
            ],
                                                   axis='rows')
            lhs_vals = pd.concat([cs_bev, cg_bev])

        elif vehicle == 1:  # FCEV
            cs_fcev = gin.changed_suv().reindex([
                'FE_h2', 'E_battEmpty', 'E_battEmptyPHEV', 'P_batt', 'P_fc',
                'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'
            ],
                                                axis='rows')
            cg_fcev = gin.changed_general().reindex([
                'C3_h2', 'C5_empty', 'Em_elFC', 'Em_elVC', 'cd_empty',
                'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuelH2', 'C_batt',
                'C_fc'
            ],
                                                    axis='rows')
            lhs_vals = pd.concat([cs_fcev, cg_fcev])

        elif vehicle == 3:  # ICEV
            cs_icev = gin.changed_suv().reindex([
                'FE_synth', 'E_battEmpty', 'E_battEmptyPHEV', 'P_battEmpty',
                'P_fcEmpty', 'c_main_bev', 'c_main_fcev', 'c_main_phev',
                'c_main_icev'
            ],
                                                axis='rows')
            cg_icev = gin.changed_general().reindex([
                'C3_synth', 'C5_icev', 'Em_elFC', 'Em_elVC', 'cd_empty',
                'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuelSynth',
                'C_battEmpty', 'C_fcEmpty'
            ],
                                                    axis='rows')
            lhs_vals = pd.concat([cs_icev, cg_icev])

    elif class_sel == 3:  # Light Duty Vehicle #       cl = changed ldv
        if vehicle == 0:  # BEV
            cl_bev = gin.changed_ldv().reindex([
                'FE_batt', 'E_batt', 'E_battPHEV', 'P_battEmpty', 'P_fcEmpty',
                'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'
            ],
                                               axis='rows')
            cg_bev = gin.changed_general().reindex([
                'C3_batt', 'C5_empty', 'Em_elFC', 'Em_elVC', 'cd_empty', 'cd',
                'Em_elBatt', 'L', 'D', 'r', 'C_fuelEl', 'C_batt', 'C_fcEmpty'
            ],
                                                   axis='rows')
            lhs_vals = pd.concat([cl_bev, cg_bev])

        elif vehicle == 1:  # FCEV
            cl_fcev = gin.changed_ldv().reindex([
                'FE_h2', 'E_battEmpty', 'E_battEmptyPHEV', 'P_batt', 'P_fc',
                'c_main_bev', 'c_main_fcev', 'c_main_phev', 'c_main_icev'
            ],
                                                axis='rows')
            cg_fcev = gin.changed_general().reindex([
                'C3_h2', 'C5_empty', 'Em_elFC', 'Em_elVC', 'cd_empty',
                'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuelH2', 'C_batt',
                'C_fc'
            ],
                                                    axis='rows')
            lhs_vals = pd.concat([cl_fcev, cg_fcev])

        elif vehicle == 3:  # ICEV
            cl_icev = gin.changed_ldv().reindex([
                'FE_synth', 'E_battEmpty', 'E_battEmptyPHEV', 'P_battEmpty',
                'P_fcEmpty', 'c_main_bev', 'c_main_fcev', 'c_main_phev',
                'c_main_icev'
            ],
                                                axis='rows')
            cg_icev = gin.changed_general().reindex([
                'C3_synth', 'C5_icev', 'Em_elFC', 'Em_elVC', 'cd_empty',
                'cd_empty', 'Em_elBatt', 'L', 'D', 'r', 'C_fuelSynth',
                'C_battEmpty', 'C_fcEmpty'
            ],
                                                    axis='rows')
            lhs_vals = pd.concat([cl_icev, cg_icev])

    else:
        print('Wrong Input! \n')
        veh_class_sel()  # repeat selection of vehicle class
    return lhs_vals