From 520f0ee7a9bd8c7d3decd50368a5a5f9ffc3ceb4 Mon Sep 17 00:00:00 2001 From: jgavalda Date: Mon, 29 May 2023 08:06:58 -0400 Subject: [PATCH] Full structure developed, with outputs as pandas dataframes --- life_cycle_costs.py | 162 ++++++++++++++++++++++++++++---------------- main.py | 7 +- 2 files changed, 108 insertions(+), 61 deletions(-) diff --git a/life_cycle_costs.py b/life_cycle_costs.py index 40a0f15..9dfdadd 100644 --- a/life_cycle_costs.py +++ b/life_cycle_costs.py @@ -14,11 +14,15 @@ import hub.helpers.constants as cte class LifeCycleCosts: - def __init__(self, building, archetype, number_of_years, consumer_price_index, discount_rate, + def __init__(self, building, archetype, number_of_years, consumer_price_index, electricity_peak_index, + electricity_price_index, gas_price_index, discount_rate, retrofitting_scenario): self._building = building self._number_of_years = number_of_years self._consumer_price_index = consumer_price_index + self._electricity_peak_index = electricity_peak_index + self._electricity_price_index = electricity_price_index + self._gas_price_index = gas_price_index self._discount_rate = discount_rate self._archetype = archetype self._end_of_life_cost = 0 @@ -38,9 +42,20 @@ class LifeCycleCosts: 'B3010_opaque_roof','B10_superstructure', 'D301010_photovoltaic_system','D3020_heat_generating_systems', 'D3030_cooling_generation_systems','D3040_distribution_systems', - 'D3080_other_hvac_ahu','D5020_lighting_and_branch_wiring', - 'D_services'], dtype='float') + 'D3080_other_hvac_ahu','D5020_lighting_and_branch_wiring'], + dtype='float') self._yearly_capital_costs.replace(np.nan, 0) + self._yearly_end_of_life_costs = pd.DataFrame(index=rng, columns=['End_of_life_costs'], dtype='float') + self._yearly_end_of_life_costs.replace(np.nan, 0) + self._yearly_operational_costs = pd.DataFrame(index=rng, columns=['Fixed_costs_electricity_peak', + 'Fixed_costs_electricity_monthly', + 'Variable_costs_electricity','Fixed_costs_gas', + 'Variable_costs_gas','Heating_maintenance', + 'Cooling_maintenance','PV_maintenance'], + dtype='float') + self._yearly_operational_costs.replace(np.nan, 0) + self._yearly_operational_incomes = pd.DataFrame(index=rng, columns=['Incomes electricity'],dtype='float') + self._yearly_operational_incomes.replace(np.nan, 0) def calculate_capital_costs(self): building = self._building @@ -66,7 +81,7 @@ class LifeCycleCosts: chapters = archetype.capital_cost capital_cost_skin = 0 capital_cost_services = 0 - reposition_cost_pv = 0 + capital_cost_pv = 0 peak_heating = building.heating_peak_load[cte.YEAR].values[0] peak_cooling = building.cooling_peak_load[cte.YEAR].values[0] @@ -86,16 +101,13 @@ class LifeCycleCosts: =[capital_cost_opaque , capital_cost_transparent , capital_cost_roof , capital_cost_ground , capital_cost_skin] if self._retrofitting_scenario == 2 or self._retrofitting_scenario == 3: + chapter = chapters.chapter('D_services') + capital_cost_pv = surface_pv * chapter.item('D301010_photovoltaic_system').initial_investment[0] + self._yearly_capital_costs.loc[0]['D301010_photovoltaic_system'] = capital_cost_pv - for year in range(1, self._number_of_years + 1): - costs_increase = math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - if (year % chapter.item('D301010_photovoltaic_system').lifetime) == 0: - reposition_cost_pv += surface_pv * chapter.item('D301010_photovoltaic_system').reposition[ - 0] * costs_increase - self._yearly_capital_costs.loc[year]['D301010_photovoltaic_system'] = surface_pv\ - * chapter.item('D301010_photovoltaic_system').reposition[0] * costs_increase + capital_cost_heating_equipment = peak_heating \ * chapter.item('D3020_heat_generating_systems').initial_investment[0] capital_cost_cooling_equipment = peak_cooling \ @@ -107,15 +119,13 @@ class LifeCycleCosts: capital_cost_lighting = total_floor_area * self._peak_lights \ * chapter.item('D5020_lighting_and_branch_wiring').initial_investment[0] - capital_cost_services = capital_cost_pv + capital_cost_heating_equipment + capital_cost_cooling_equipment\ - + capital_cost_distribution_equipment + capital_cost_other_hvac_ahu \ - + capital_cost_lighting - - self._yearly_capital_costs.loc[0]['D3020_heat_generating_systems'], self._yearly_capital_costs.loc[0]['D3030_cooling_generation_systems'], \ - self._yearly_capital_costs.loc[0]['D3040_distribution_systems'], self._yearly_capital_costs.loc[0]['D3080_other_hvac_ahu'], \ - self._yearly_capital_costs.loc[0]['D5020_lighting_and_branch_wiring'], self._yearly_capital_costs.loc[0]['D_services'] \ + self._yearly_capital_costs.loc[0]['D3020_heat_generating_systems'], \ + self._yearly_capital_costs.loc[0]['D3030_cooling_generation_systems'], \ + self._yearly_capital_costs.loc[0]['D3040_distribution_systems'], \ + self._yearly_capital_costs.loc[0]['D3080_other_hvac_ahu'], \ + self._yearly_capital_costs.loc[0]['D5020_lighting_and_branch_wiring']\ = [capital_cost_heating_equipment, capital_cost_cooling_equipment, capital_cost_distribution_equipment, - capital_cost_other_hvac_ahu, capital_cost_lighting, capital_cost_services] + capital_cost_other_hvac_ahu, capital_cost_lighting] reposition_cost_heating_equipment = 0 reposition_cost_cooling_equipment = 0 @@ -146,19 +156,12 @@ class LifeCycleCosts: * costs_increase self._yearly_capital_costs.loc[year]['D5020_lighting_and_branch_wiring'] = reposition_cost_lighting - capital_cost_subtotal = capital_cost_skin + capital_cost_services + if self._retrofitting_scenario==2 or self._retrofitting_scenario==3 : + if (year % chapter.item('D301010_photovoltaic_system').lifetime) == 0: + self._yearly_capital_costs.loc[year]['D301010_photovoltaic_system'] = surface_pv\ + * chapter.item('D301010_photovoltaic_system').reposition[0] * costs_increase - capital_cost_total = capital_cost_subtotal * (1+chapters.design_allowance) * (1+chapters.overhead_and_profit) - - reposition_cost_subtotal = reposition_cost_pv + reposition_cost_heating_equipment \ - + reposition_cost_cooling_equipment + reposition_cost_hvac_ahu \ - + reposition_cost_hvac_ahu + reposition_cost_lighting - - reposition_cost_total = reposition_cost_subtotal * (1+chapters.design_allowance) * (1+chapters.overhead_and_profit) - - life_cycle_cost_capital_total = capital_cost_total + reposition_cost_total - - return life_cycle_cost_capital_total, self._yearly_capital_costs + return self._yearly_capital_costs def calculate_end_of_life_costs(self): archetype = self._archetype @@ -167,10 +170,10 @@ class LifeCycleCosts: price_increase = 0 for year in range(1, self._number_of_years + 1): - price_increase += math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - price_increase_average = price_increase/self._number_of_years - - return total_floor_area * archetype.end_of_life_cost*price_increase_average + price_increase += math.pow(1 + self._consumer_price_index, year) + if year == self._number_of_years: + self._end_of_life_cost = total_floor_area * archetype.end_of_life_cost*price_increase + return self._end_of_life_cost def calculate_total_operational_costs(self): building = self._building @@ -187,54 +190,95 @@ class LifeCycleCosts: electricity_lighting = building.lighting_electrical_demand[cte.YEAR]['insel meb']/1000 domestic_hot_water_demand = building.domestic_hot_water_consumption[cte.YEAR][0]/1000 electricity_plug_loads = building.appliances_electrical_demand[cte.YEAR]['insel meb']/1000 + if (building.onsite_electrical_production[cte.YEAR][0] is None): onsite_electricity_production = 0 else: onsite_electricity_production= building.onsite_electrical_production[cte.YEAR][0]/1000 + total_electricity_consumption = electricity_cooling + electricity_heating + electricity_lighting \ + domestic_hot_water_demand + electricity_plug_loads print(f'total electricity consumption: {total_electricity_consumption}') print(f'total electricity production: {onsite_electricity_production}') - #todo: change when peak electricity demand is coded + #todo: change when peak electricity demand is coded. Careful with factor residential peak_electricity_demand = 100 #self._peak_electricity_demand - operational_cost_year_0 = total_electricity_consumption * archetype.operational_cost.fuels[0].variable[0] - peak_cost_year_0 = peak_electricity_demand * archetype.operational_cost.fuels[0].fixed_power * 12 - monthly_cost_year_0 = archetype.operational_cost.fuels[0].fixed_monthly * 12 * (total_floor_area/100) - incomes_year_0 = onsite_electricity_production * archetype.operational_cost.fuels[0].variable[0] + factor_residential= total_floor_area/80 + variable_electricity_cost_year_0 = total_electricity_consumption * archetype.operational_cost.fuels[0].variable[0] + peak_electricity_cost_year_0 = peak_electricity_demand * archetype.operational_cost.fuels[0].fixed_power * 12 + monthly_electricity_cost_year_0 = archetype.operational_cost.fuels[0].fixed_monthly * 12 * factor_residential + incomes_electricity_year_0 = onsite_electricity_production * archetype.operational_cost.fuels[0].variable[0] + fixed_gas_cost_year_0 = archetype.operational_cost.fuels[1].fixed_monthly*12* factor_residential + variable_gas_cost_year_0 = total_electricity_consumption * archetype.operational_cost.fuels[1].variable[0] + + price_increase_electricity = 0 + price_increase_peak_electricity = 0 + price_increase_gas = 0 for year in range(1, self._number_of_years + 1): - peak_cost += operational_cost_year_0 \ - * math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - monthly_cost += peak_cost_year_0 \ - * math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - variable_cost += monthly_cost_year_0 \ - * math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - variable_incomes += incomes_year_0 \ - * math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - total_operational_costs = peak_cost + monthly_cost + variable_cost - variable_incomes + price_increase_electricity += math.pow(1 + self._electricity_price_index, year) + price_increase_peak_electricity += math.pow(1 + self._electricity_peak_index, year) + price_increase_gas += math.pow(1 + self._gas_price_index, year) - return total_operational_costs + self._yearly_operational_costs[year]['Fixed_costs_electricity_peak']=peak_electricity_cost_year_0*\ + price_increase_peak_electricity + self._yearly_operational_costs[year]['Fixed_costs_electricity_monthly'] = monthly_electricity_cost_year_0 * \ + price_increase_peak_electricity + self._yearly_operational_costs[year]['Variable_costs_electricity'] = variable_electricity_cost_year_0 * \ + price_increase_electricity + self._yearly_operational_costs[year]['Fixed_costs_gas'] = fixed_gas_cost_year_0 * \ + price_increase_gas + self._yearly_operational_costs[year]['Variable_costs_gas'] = variable_gas_cost_year_0* \ + price_increase_peak_electricity + self._yearly_operational_costs[year]['Variable_costs_gas'] = variable_gas_cost_year_0 * \ + price_increase_peak_electricity + + + return self._yearly_operational_costs + + def calculate_total_operational_incomes(self): + building = self._building + archetype = self._archetype + variable_incomes = 0 + total_floor_area = self._total_floor_area + + if (building.onsite_electrical_production[cte.YEAR][0] is None): + onsite_electricity_production = 0 + else: + onsite_electricity_production= building.onsite_electrical_production[cte.YEAR][0]/1000 + + incomes_electricity_year_0 = onsite_electricity_production * archetype.operational_cost.fuels[0].variable[0] + + price_increase_electricity = 0 + + for year in range(1, self._number_of_years + 1): + price_increase_electricity += math.pow(1 + self._electricity_price_index, year) + + self._yearly_operational_incomes[year]['Incomes electricity']=onsite_electricity_production*\ + price_increase_electricity + + return self._yearly_operational_incomes def calculate_total_maintenance_costs(self): building = self._building archetype = self._archetype #todo: change area pv when the variable exists surface_pv = 10 #building.area_pv - maintenance_pv = 0 - maintenance_heating = 0 - maintenance_cooling = 0 + peak_heating = building.heating_peak_load peak_cooling = building.cooling_peak_load - maintenance_pv_0 = surface_pv * archetype.operational_cost.maintenance_pv maintenance_heating_0 = peak_heating * archetype.operational_cost.maintenance_heating maintenance_cooling_0 = peak_cooling * archetype.operational_cost.maintenance_cooling + maintenance_pv_0 = surface_pv * archetype.operational_cost.maintenance_pv + for year in range(1, self._number_of_years + 1): costs_increase = math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - maintenance_pv += maintenance_pv_0 * costs_increase - maintenance_heating += maintenance_heating_0 * costs_increase - maintenance_cooling += maintenance_cooling_0 * costs_increase - total_maintenance_costs = maintenance_pv + maintenance_heating + maintenance_cooling - return total_maintenance_costs + self._yearly_operational_costs[year]['Heating_maintenance'] = maintenance_heating_0 * \ + costs_increase + self._yearly_operational_costs[year]['Cooling_maintenance'] = maintenance_cooling_0 * \ + costs_increase + self._yearly_operational_costs[year]['PV_maintenance'] = maintenance_pv_0 * \ + costs_increase + return self._yearly_operational_costs diff --git a/main.py b/main.py index 713f3f5..9d1d302 100644 --- a/main.py +++ b/main.py @@ -52,6 +52,9 @@ for file in files: number_of_years = 30 consumer_price_index = 0.04 +electricity_peak_index = 0.05 +electricity_price_index = 0.05 +gas_price_index = 0.05 discount_rate = 0.03 retrofitting_year_of_construction =2020 @@ -121,8 +124,8 @@ for retrofitting_scenario in retrofitting_scenarios: # f'{building.function}\n') #continue print('lcc for first building started') - lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index, - discount_rate, retrofitting_scenario) + lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index, electricity_peak_index, + electricity_price_index, gas_price_index, discount_rate, retrofitting_scenario) total_capital_costs = lcc.calculate_capital_costs() print(f'total capital costs {total_capital_costs}')