costs_workflow/life_cycle_costs.py

97 lines
4.8 KiB
Python

"""
LifeCycleCosts calculates the life cycle costs of one building
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 math
import hub.catalog_factories.costs_catalog_factory as CostCatalogFactory
from hub.catalog_factories.cost.montreal_custom_catalog import MontrealCustomCatalog
from hub.helpers.dictionaries import Dictionaries
class LifeCycleCosts:
# todo: this should be (city, costs_catalog) or similar
def __init__(self, city, number_of_years, consumer_price_index, discount_rate,
retrofitting_scenario):
self._city = city
self._number_of_years = number_of_years
self._consumer_price_index = consumer_price_index
self._discount_rate = discount_rate
self._cost_catalog=CostCatalogFactory('montreal_custom').catalog
self._end_of_life_cost = 0
self._capital_costs_at_year_0 = 0
self._items = 0
self._fuels = 0
self._concepts = 0
self._retrofitting_scenario = retrofitting_scenario
def calculate_capital_costs(self):
surface_opaque=0
surface_transparent=0
city = self._city
for building in city.buildings:
try:
function = 'residential' #Dictionaries().hub_function_to_nrel_construction_function[building.function]
archetype = self._search_archetype(self._cost_catalog, function)
except KeyError:
logger.error(f'Building {building.name} has unknown construction archetype for building function: '
f'{building.function} and building year of construction: {building.year_of_construction} '
f'and climate zone reference norm {self._climate_zone}\n')
sys.stderr.write(f'Building {building.name} has unknown construction archetype for building function: '
f'{building.function} and building year of construction: {building.year_of_construction} '
f'and climate zone reference norm {self._climate_zone}\n')
# if building has no thermal zones defined from geometry, and the building will be divided in storeys,
# one thermal zone per storey is assigned
for internal_zone in building.internal_zones:
if internal_zone.thermal_zones is None:
continue
for thermal_zone in internal_zone.thermal_zones:
for thermal_boundary in thermal_zone.thermal_boundaries:
surface_opaque += thermal_boundary.opaque_area*(1-thermal_boundary.window_ratio)
surface_transparent += thermal_boundary.opaque_area*(thermal_boundary.window_ratio)
print(f'surface_opaque {surface_opaque}')
print(f'surface_transparent {surface_transparent}')
capital_cost_op = surface_opaque*self._cost_catalog.archetypes.archetype[0].capital_cost.general_chapters[0].items[1].refurbishment[0]
capital_cost_transp= surface_transparent*self._cost_catalog.archetypes.archetype[0].capital_cost.general_chapters[0].items[2].refurbishment[0]
print(f'cost_opaque {capital_cost_op}')
print(f'cost_transparent {capital_cost_transp}')
'''total_capital_costs = self._capital_costs_at_year_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)
# for item in self._items:
# total_capital_costs += item.reposition_costs[year] * costs_increase
#return total_capital_costs
def calculate_end_of_life_costs(self):
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)
return self._end_of_life_cost * price_increase
def calculate_total_operational_costs(self):
total_operational_costs = 0
for year in range(1, self._number_of_years + 1):
for fuel in self._fuels:
total_operational_costs += fuel.operational_cost \
* math.pow(1 + fuel.energy_price_index, year) / math.pow(1 + self._discount_rate, year)
return total_operational_costs
def calculate_total_maintenance_costs(self):
total_maintenance_costs = 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)
for concept in self._concepts:
total_maintenance_costs += concept.mantainance_costs * costs_increase
return total_maintenance_costs'''
@staticmethod
def _search_archetype(costs_catalog, function):
costs_archetypes = costs_catalog.entries('archetypes')
for building_archetype in costs_archetypes:
if (str(function) == str(building_archetype.function)):
return building_archetype
raise KeyError('archetype not found')