moved archetype search to the main function and cleaned code
This commit is contained in:
parent
9284fa989b
commit
4e19afbf98
|
@ -4,23 +4,19 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Project Author Pilar Monsalvete Alvarez de Uribarri pilar_monsalvete@concordia.ca
|
||||
Project contributor 2023 Author Oriol Gavaldà Torrellas oriol.gavalda@concordia.ca
|
||||
"""
|
||||
import sys
|
||||
|
||||
import math
|
||||
from hub.hub_logger import logger
|
||||
from hub.helpers.dictionaries import Dictionaries
|
||||
from hub.helpers import constants as cte
|
||||
|
||||
|
||||
class LifeCycleCosts:
|
||||
|
||||
# todo: this should be (city, costs_catalog) or similar
|
||||
def __init__(self, building, catalog, number_of_years, consumer_price_index, discount_rate,
|
||||
def __init__(self, building, archetype, number_of_years, consumer_price_index, discount_rate,
|
||||
retrofitting_scenario):
|
||||
self._building = building
|
||||
self._number_of_years = number_of_years
|
||||
self._consumer_price_index = consumer_price_index
|
||||
self._discount_rate = discount_rate
|
||||
self._cost_catalog = catalog
|
||||
self._archetype = archetype
|
||||
self._end_of_life_cost = 0
|
||||
self._capital_costs_at_year_0 = 0
|
||||
self._items = 0
|
||||
|
@ -30,28 +26,20 @@ class LifeCycleCosts:
|
|||
|
||||
def calculate_capital_costs(self):
|
||||
building = self._building
|
||||
archetype = self._archetype
|
||||
|
||||
surface_opaque = 0
|
||||
surface_transparent = 0
|
||||
surface_roof = 0
|
||||
surface_ground = 0
|
||||
factor_pv=0.5
|
||||
factor_heating_power=0.1 #kW/m2
|
||||
factor_cooling_power=0.1 #kW/m2
|
||||
total_floor_area=0
|
||||
|
||||
try:
|
||||
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
||||
archetype = self._search_archetype(self._cost_catalog, function)
|
||||
except KeyError:
|
||||
logger.error(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
return
|
||||
factor_pv = 0.5
|
||||
factor_heating_power = 0.1 # kW/m2
|
||||
factor_cooling_power = 0.1 # kW/m2
|
||||
total_floor_area = 0
|
||||
|
||||
for internal_zone in building.internal_zones:
|
||||
for thermal_zone in internal_zone.thermal_zones:
|
||||
total_floor_area+=thermal_zone.total_floor_area
|
||||
total_floor_area += thermal_zone.total_floor_area
|
||||
print(total_floor_area)
|
||||
for thermal_boundary in thermal_zone.thermal_boundaries:
|
||||
if thermal_boundary.type == 'Ground':
|
||||
|
@ -64,8 +52,8 @@ class LifeCycleCosts:
|
|||
print(f'total floor area {total_floor_area}')
|
||||
|
||||
chapters = archetype.capital_cost
|
||||
capital_cost_skin=0
|
||||
capital_cost_services=0
|
||||
capital_cost_skin = 0
|
||||
capital_cost_services = 0
|
||||
if self._retrofitting_scenario == 1 or self._retrofitting_scenario == 3:
|
||||
chapter = chapters.chapter('B_shell')
|
||||
capital_cost_opaque = surface_opaque * chapter.item('B2010_opaque_walls').refurbishment[0]
|
||||
|
@ -73,35 +61,41 @@ class LifeCycleCosts:
|
|||
capital_cost_roof = surface_roof * chapter.item('B3010_opaque_roof').refurbishment[0]
|
||||
capital_cost_ground = surface_ground * chapter.item('B10_superstructure').refurbishment[0]
|
||||
capital_cost_skin= capital_cost_opaque+capital_cost_transparent+capital_cost_roof+capital_cost_ground
|
||||
print (f'capital cost skin {capital_cost_skin}')
|
||||
print(f'capital cost skin {capital_cost_skin}')
|
||||
if self._retrofitting_scenario == 2 or self._retrofitting_scenario == 3:
|
||||
chapter = chapters.chapter('D_services')
|
||||
capital_cost_pv = surface_roof * factor_pv * chapter.item('D301010_photovoltaic_system').initial_investment[0]
|
||||
reposition_cost_PV = 0
|
||||
reposition_cost_pv = 0
|
||||
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_roof * factor_pv * chapter.item('D301010_photovoltaic_system').reposition[
|
||||
reposition_cost_pv += surface_roof * factor_pv * chapter.item('D301010_photovoltaic_system').reposition[
|
||||
0] * costs_increase
|
||||
|
||||
capital_cost_heating_equipment = total_floor_area * factor_heating_power * chapter.item('D3020_heat_generating_systems').initial_investment[0]
|
||||
capital_cost_heating_equipment = total_floor_area * factor_heating_power \
|
||||
* chapter.item('D3020_heat_generating_systems').initial_investment[0]
|
||||
|
||||
capital_cost_cooling_equipment = total_floor_area * factor_cooling_power * chapter.item('D3030_cooling_generation_systems').initial_investment[0]
|
||||
capital_cost_cooling_equipment = total_floor_area * factor_cooling_power \
|
||||
* chapter.item('D3030_cooling_generation_systems').initial_investment[0]
|
||||
|
||||
capital_cost_distribution_equipment = total_floor_area * factor_cooling_power * chapter.item('D3040_distribution_systems').initial_investment[0]
|
||||
capital_cost_distribution_equipment = total_floor_area * factor_cooling_power \
|
||||
* chapter.item('D3040_distribution_systems').initial_investment[0]
|
||||
|
||||
capital_cost_other_hvac_ahu = total_floor_area * factor_cooling_power * chapter.item('D3080_other_hvac_ahu').initial_investment[0]
|
||||
capital_cost_other_hvac_ahu = total_floor_area * factor_cooling_power \
|
||||
* chapter.item('D3080_other_hvac_ahu').initial_investment[0]
|
||||
|
||||
capital_cost_lighting = total_floor_area * factor_pv * chapter.item('D5020_lighting_and_branch_wiring').initial_investment[0]
|
||||
capital_cost_lighting = total_floor_area * factor_pv \
|
||||
* 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
|
||||
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
|
||||
|
||||
reposition_cost_heating_equipment = 0
|
||||
reposition_cost_cooling_equipment = 0
|
||||
reposition_cost_lighting = 0
|
||||
reposition_cost_hvac_ahu = 0
|
||||
capital_cost_pv = 0
|
||||
reposition_cost_PV = 0
|
||||
reposition_cost_pv = 0
|
||||
|
||||
for year in range(1, self._number_of_years + 1):
|
||||
chapter = chapters.chapter('D_services')
|
||||
|
@ -119,41 +113,28 @@ class LifeCycleCosts:
|
|||
chapter.item('D3080_other_hvac_ahu').reposition[
|
||||
0] * costs_increase
|
||||
if (year % chapter.item('D5020_lighting_and_branch_wiring').lifetime) == 0:
|
||||
reposition_cost_lighting = total_floor_area * chapter.item('D5020_lighting_and_branch_wiring').reposition[
|
||||
0] * costs_increase
|
||||
reposition_cost_lighting = total_floor_area * chapter.item('D5020_lighting_and_branch_wiring').reposition[0] \
|
||||
* costs_increase
|
||||
|
||||
capital_cost_subtotal = capital_cost_skin + capital_cost_services
|
||||
|
||||
capital_cost_total = capital_cost_subtotal*(1+chapters.design_allowance)*(1+chapters.overhead_and_profit)
|
||||
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_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)
|
||||
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
|
||||
@staticmethod
|
||||
def _search_archetype(costs_catalog, function):
|
||||
costs_archetypes = costs_catalog.entries('archetypes').archetypes
|
||||
for building_archetype in costs_archetypes:
|
||||
if str(function) == str(building_archetype.function):
|
||||
return building_archetype
|
||||
raise KeyError('archetype not found')
|
||||
|
||||
def calculate_end_of_life_costs(self):
|
||||
building = self._building
|
||||
total_floor_area = 0
|
||||
archetype = self._archetype
|
||||
|
||||
try:
|
||||
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
||||
archetype = self._search_archetype(self._cost_catalog, function)
|
||||
except KeyError:
|
||||
logger.error(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
return
|
||||
total_floor_area = 0
|
||||
|
||||
for internal_zone in building.internal_zones:
|
||||
for thermal_zone in internal_zone.thermal_zones:
|
||||
|
@ -165,79 +146,69 @@ class LifeCycleCosts:
|
|||
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
|
||||
|
||||
return total_floor_area * archetype.end_of_life_cost*price_increase_average
|
||||
|
||||
def calculate_total_operational_costs(self):
|
||||
total_operational_costs = 0
|
||||
peak_cost=0
|
||||
monthly_cost=0
|
||||
variable_cost=0
|
||||
|
||||
building = self._building
|
||||
total_floor_area = 0
|
||||
archetype = self._archetype
|
||||
|
||||
try:
|
||||
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
||||
archetype = self._search_archetype(self._cost_catalog, function)
|
||||
except KeyError:
|
||||
logger.error(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
return
|
||||
total_operational_costs = 0
|
||||
peak_cost = 0
|
||||
monthly_cost = 0
|
||||
variable_cost = 0
|
||||
total_floor_area = 0
|
||||
|
||||
for internal_zone in building.internal_zones:
|
||||
for thermal_zone in internal_zone.thermal_zones:
|
||||
total_floor_area += thermal_zone.total_floor_area
|
||||
|
||||
if self._retrofitting_scenario==1 or self._retrofitting_scenario==3:
|
||||
specific_heating_demand=50
|
||||
if self._retrofitting_scenario == 1 or self._retrofitting_scenario == 3:
|
||||
specific_heating_demand = 50
|
||||
else:
|
||||
specific_heating_demand=190
|
||||
specific_heating_demand = 190
|
||||
|
||||
heating_demand= specific_heating_demand * total_floor_area
|
||||
cooling_demand= 10 * total_floor_area
|
||||
heating_demand = specific_heating_demand * total_floor_area
|
||||
cooling_demand = 10 * total_floor_area
|
||||
|
||||
if self._retrofitting_scenario==2 or self._retrofitting_scenario==3:
|
||||
heating_SCOP=3
|
||||
cooling_SEER=4.5
|
||||
if self._retrofitting_scenario == 2 or self._retrofitting_scenario == 3:
|
||||
heating_scop = 3
|
||||
cooling_seer = 4.5
|
||||
else:
|
||||
heating_SCOP = 1
|
||||
cooling_SEER = 2
|
||||
heating_scop = 1
|
||||
cooling_seer = 2
|
||||
|
||||
electricity_heating=heating_demand/heating_SCOP
|
||||
electricity_cooling=cooling_demand/cooling_SEER
|
||||
electricity_lighting=11* total_floor_area
|
||||
electricity_plug_loads=19*total_floor_area
|
||||
domestic_hot_water_demand= 50* total_floor_area
|
||||
electricity_heating = heating_demand/heating_scop
|
||||
electricity_cooling = cooling_demand/cooling_seer
|
||||
electricity_lighting = 11 * total_floor_area
|
||||
electricity_plug_loads = 19 * total_floor_area
|
||||
domestic_hot_water_demand = 50 * total_floor_area
|
||||
|
||||
total_electricity_consumption= electricity_cooling+electricity_heating+electricity_lighting+domestic_hot_water_demand+electricity_plug_loads
|
||||
total_electricity_consumption = electricity_cooling + electricity_heating + electricity_lighting \
|
||||
+ domestic_hot_water_demand + electricity_plug_loads
|
||||
|
||||
peak_electricity_demand= 0.1*total_floor_area
|
||||
peak_electricity_demand = 0.1 * total_floor_area
|
||||
|
||||
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)
|
||||
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)
|
||||
print(f'operational_cost_year_0 {operational_cost_year_0}')
|
||||
print(f'peak_cost_year_0 {peak_cost_year_0}')
|
||||
print(f'monthly_cost_year_0 {monthly_cost_year_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)
|
||||
* 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)
|
||||
total_operational_costs = peak_cost + monthly_cost + variable_cost
|
||||
|
||||
return total_operational_costs
|
||||
|
||||
|
||||
def calculate_total_maintenance_costs(self):
|
||||
|
||||
building = self._building
|
||||
archetype = self._archetype
|
||||
total_floor_area = 0
|
||||
|
||||
factor_pv = 0.5
|
||||
|
@ -248,30 +219,20 @@ class LifeCycleCosts:
|
|||
maintenance_heating = 0
|
||||
maintenance_cooling = 0
|
||||
|
||||
try:
|
||||
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
||||
archetype = self._search_archetype(self._cost_catalog, function)
|
||||
except KeyError:
|
||||
logger.error(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
return
|
||||
|
||||
for internal_zone in building.internal_zones:
|
||||
for thermal_zone in internal_zone.thermal_zones:
|
||||
total_floor_area+=thermal_zone.total_floor_area
|
||||
total_floor_area += thermal_zone.total_floor_area
|
||||
for thermal_boundary in thermal_zone.thermal_boundaries:
|
||||
if thermal_boundary.type == 'Roof':
|
||||
surface_roof += thermal_boundary.opaque_area
|
||||
surface_pv = surface_roof*factor_pv
|
||||
maintenance_pv_0=surface_pv*archetype.operational_cost.maintenance_pv
|
||||
maintenance_heating_0=total_floor_area*factor_heating_power*archetype.operational_cost.maintenance_heating
|
||||
maintenance_cooling_0=total_floor_area*factor_cooling_power*archetype.operational_cost.maintenance_cooling
|
||||
maintenance_pv_0 = surface_pv * archetype.operational_cost.maintenance_pv
|
||||
maintenance_heating_0 = total_floor_area*factor_heating_power * archetype.operational_cost.maintenance_heating
|
||||
maintenance_cooling_0 = total_floor_area*factor_cooling_power * archetype.operational_cost.maintenance_cooling
|
||||
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
|
||||
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
|
||||
|
|
45
main.py
45
main.py
|
@ -6,14 +6,26 @@ Copyright © 2022 Project Author Pilar Monsalvete Álvarez de Uribarri pilar.mon
|
|||
|
||||
import glob
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
from hub.imports.construction_factory import ConstructionFactory
|
||||
from hub.helpers.dictionaries import Dictionaries
|
||||
from pathlib import Path
|
||||
from hub.hub_logger import logger
|
||||
from hub.imports.geometry_factory import GeometryFactory
|
||||
from life_cycle_costs import LifeCycleCosts
|
||||
from hub.catalog_factories.costs_catalog_factory import CostCatalogFactory
|
||||
|
||||
from life_cycle_costs import LifeCycleCosts
|
||||
|
||||
|
||||
def _search_archetype(costs_catalog, building_function):
|
||||
costs_archetypes = costs_catalog.entries('archetypes').archetypes
|
||||
for building_archetype in costs_archetypes:
|
||||
if str(building_function) == str(building_archetype.function):
|
||||
return building_archetype
|
||||
raise KeyError('archetype not found')
|
||||
|
||||
|
||||
file_path = (Path(__file__).parent.parent / 'costs_workflow' / 'input_files' / 'selected_building_2864.geojson')
|
||||
out_path = (Path(__file__).parent.parent / 'costs_workflow' / 'out_files')
|
||||
files = glob.glob(f'{out_path}/*')
|
||||
|
@ -35,19 +47,30 @@ print('enrich constructions... done')
|
|||
number_of_years = 30
|
||||
consumer_price_index = 0.04
|
||||
discount_rate = 0.03
|
||||
#retrofitting_scenario = 2
|
||||
retrofitting_scenarios = [0, 1, 2, 3]
|
||||
catalog = CostCatalogFactory('montreal_custom').catalog
|
||||
|
||||
for i in range(0,4) :
|
||||
for building in city.buildings:
|
||||
lcc = LifeCycleCosts(building, catalog, number_of_years, consumer_price_index, discount_rate, i)
|
||||
for building in city.buildings:
|
||||
try:
|
||||
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
||||
archetype = _search_archetype(catalog, function)
|
||||
except KeyError:
|
||||
logger.error(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: '
|
||||
f'{building.function}\n')
|
||||
continue
|
||||
|
||||
for retrofitting_scenario in retrofitting_scenarios:
|
||||
lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index,
|
||||
discount_rate, retrofitting_scenario)
|
||||
total_capital_costs = lcc.calculate_capital_costs()
|
||||
print(f'total capital costs scenario {i} are {total_capital_costs}')
|
||||
print(f'total capital costs scenario {retrofitting_scenario} are {total_capital_costs}')
|
||||
end_of_life_costs = lcc.calculate_end_of_life_costs()
|
||||
print(f'end_of_life_costs scenario {i} are {end_of_life_costs}')
|
||||
print(f'end_of_life_costs scenario {retrofitting_scenario} are {end_of_life_costs}')
|
||||
total_operational_costs = lcc.calculate_total_operational_costs()
|
||||
print(f'total_operational_costs scenario {i} are {total_operational_costs}')
|
||||
print(f'total_operational_costs scenario {retrofitting_scenario} are {total_operational_costs}')
|
||||
total_maintenance_costs = lcc.calculate_total_maintenance_costs()
|
||||
print(f'total_maintenance_costs scenario {i} are {total_maintenance_costs}')
|
||||
print(f'total_maintenance_costs scenario {retrofitting_scenario} are {total_maintenance_costs}')
|
||||
life_cycle_costs = total_capital_costs + end_of_life_costs + total_operational_costs + total_maintenance_costs
|
||||
print(f'life_cycle_costs scenario {i} are {life_cycle_costs}')
|
||||
print(f'life_cycle_costs scenario {retrofitting_scenario} are {life_cycle_costs}')
|
||||
|
|
Loading…
Reference in New Issue
Block a user