forked from s_ranjbar/city_retrofit
Added separate classes of water to water and air source hp. Refactored energy systems factory
This commit is contained in:
parent
a7ac455d65
commit
aa7463cb9d
51
exports/energy_systems/air_source_hp_export.py
Normal file
51
exports/energy_systems/air_source_hp_export.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
"""
|
||||||
|
AirSourceHPExport exports air source values after executing insel.
|
||||||
|
Multiple files are generated for the export
|
||||||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
|
Copyright © 2021 Project Author Peter Yefi peteryefi@gmail.com
|
||||||
|
"""
|
||||||
|
from exports.energy_systems.heat_pump_export import HeatPumpExport
|
||||||
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
|
|
||||||
|
class AirSourceHPExport(HeatPumpExport):
|
||||||
|
"""
|
||||||
|
Exports heat pump values as multiple files
|
||||||
|
after executing insel
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, base_path, city, output_path):
|
||||||
|
template_path = (base_path / 'heat_pumps/air_source_tmpl.txt')
|
||||||
|
super().__init__(base_path, city, output_path, template_path)
|
||||||
|
|
||||||
|
def _extract_model_coff(self, hp_model: str, data_type='heat') -> Union[Tuple[List, List], None]:
|
||||||
|
"""
|
||||||
|
Extracts heat pump coefficient data for a specific
|
||||||
|
model. e.g 012, 140
|
||||||
|
:param hp_model: the model type
|
||||||
|
:param data_type: indicates whether we're extracting cooling
|
||||||
|
or heating perfarmcn coefficients
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
for energy_system in self._city.energy_systems:
|
||||||
|
if energy_system.air_source_hp.model == hp_model:
|
||||||
|
if data_type == 'heat':
|
||||||
|
return energy_system.air_source_hp.heating_capacity_coff, energy_system.air_source_hp.heating_comp_power_coff
|
||||||
|
return energy_system.air_source_hp.cooling_capacity_coff, energy_system.air_source_hp.cooling_comp_power_coff
|
||||||
|
return None
|
||||||
|
|
||||||
|
def execute_insel(self, user_input, hp_model, data_type):
|
||||||
|
"""
|
||||||
|
Runs insel and produces output files
|
||||||
|
Runs insel and write the necessary files
|
||||||
|
:param user_input: a dictionary containing the user
|
||||||
|
values necessary to run insel
|
||||||
|
:param hp_model: a string that indicates the heat
|
||||||
|
pump model to be used e.g. 012, 015
|
||||||
|
:param data_type: a string that indicates whether
|
||||||
|
insel should run for heat or cooling performance
|
||||||
|
:return:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
capacity_coeff, power_coeff = self._extract_model_coff(hp_model, data_type)
|
||||||
|
super(AirSourceHPExport, self)._run_insel(user_input, capacity_coeff, power_coeff)
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
HeatPumpExport exports heatpump coefficient into several formats
|
HeatPumpExport exports heatpump outputs into several files after insel execution
|
||||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
Copyright © 2021 Project Author Peter Yefi peteryefi@gmail.com
|
Copyright © 2021 Project Author Peter Yefi peteryefi@gmail.com
|
||||||
"""
|
"""
|
||||||
|
@ -16,8 +16,9 @@ class HeatPumpExport:
|
||||||
of some defined function
|
of some defined function
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, base_path, city, output_path):
|
def __init__(self, base_path, city, output_path, template, water_temp=None):
|
||||||
self._template_path = (base_path / 'heat_pumps/template.txt')
|
self._template_path = template
|
||||||
|
self._water_temp = water_temp
|
||||||
self._constants_path = (base_path / 'heat_pumps/constants.yaml')
|
self._constants_path = (base_path / 'heat_pumps/constants.yaml')
|
||||||
# needed to compute max demand.
|
# needed to compute max demand.
|
||||||
self._demand_path = (base_path / 'heat_pumps/demand.txt')
|
self._demand_path = (base_path / 'heat_pumps/demand.txt')
|
||||||
|
@ -26,21 +27,17 @@ class HeatPumpExport:
|
||||||
self._base_path = base_path
|
self._base_path = base_path
|
||||||
self._output_path = output_path
|
self._output_path = output_path
|
||||||
|
|
||||||
def run_insel(self, user_input: Dict, hp_model: str, data_type: str) -> None:
|
def _run_insel(self, user_input: Dict, capacity_coeff: List, power_coeff: List) -> None:
|
||||||
"""
|
"""
|
||||||
Runs insel and write the necessary files
|
Runs insel and write the necessary files
|
||||||
:param user_input: a dictionary containing the user
|
:param user_input: a dictionary containing the user
|
||||||
values necessary to run insel
|
values necessary to run insel
|
||||||
:param hp_model: a string that indicates the heat
|
:param capacity_coeff: a list containing capacity coefficients
|
||||||
pump model to be used e.g. 012, 015
|
:param power_coeff: a list containing power demand coefficients
|
||||||
:param data_type: a string that indicates whether
|
|
||||||
insel should run for heat or cooling performance
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
self._input_data = user_input
|
self._input_data = user_input
|
||||||
# update input data with other data necessary to run insel
|
self._update_input_data_with_coff(capacity_coeff, power_coeff)
|
||||||
capacity_coff, comp_power_coff = self._extract_model_coff(hp_model, data_type)
|
|
||||||
self._update_input_data_with_coff(capacity_coff, comp_power_coff)
|
|
||||||
# update input data with constants
|
# update input data with constants
|
||||||
self._update_input_data_with_constants()
|
self._update_input_data_with_constants()
|
||||||
# update input data with input and output files for insel
|
# update input data with input and output files for insel
|
||||||
|
@ -99,6 +96,7 @@ class HeatPumpExport:
|
||||||
self._input_data['fileOut9']: ['Day', 'Daily Fuel Consumption of Auxiliary Heater (m3)'],
|
self._input_data['fileOut9']: ['Day', 'Daily Fuel Consumption of Auxiliary Heater (m3)'],
|
||||||
self._input_data['fileOut10']: ['Year', 'Month', 'Day', 'Hour', 'HP Electricity Demand (kWh)']
|
self._input_data['fileOut10']: ['Year', 'Month', 'Day', 'Hour', 'HP Electricity Demand (kWh)']
|
||||||
}
|
}
|
||||||
|
|
||||||
for file_path, header in header_data.items():
|
for file_path, header in header_data.items():
|
||||||
file_path = file_path.strip("'")
|
file_path = file_path.strip("'")
|
||||||
df = pd.read_csv(file_path, header=None, sep='\s+')
|
df = pd.read_csv(file_path, header=None, sep='\s+')
|
||||||
|
@ -122,6 +120,9 @@ class HeatPumpExport:
|
||||||
self._input_data["fileOut8"] = f"'{str((self._base_path / 'heat_pumps/monthly_hp_electricity_demand.csv'))}'"
|
self._input_data["fileOut8"] = f"'{str((self._base_path / 'heat_pumps/monthly_hp_electricity_demand.csv'))}'"
|
||||||
self._input_data["fileOut9"] = f"'{str((self._base_path / 'heat_pumps/daily_fossil_fuel_consumption.csv'))}'"
|
self._input_data["fileOut9"] = f"'{str((self._base_path / 'heat_pumps/daily_fossil_fuel_consumption.csv'))}'"
|
||||||
self._input_data["fileOut10"] = f"'{str((self._base_path / 'heat_pumps/hp_hourly_electricity_demand.csv'))}'"
|
self._input_data["fileOut10"] = f"'{str((self._base_path / 'heat_pumps/hp_hourly_electricity_demand.csv'))}'"
|
||||||
|
# include water temperature for water to water heat pump
|
||||||
|
if self._water_temp is not None:
|
||||||
|
self._input_data['WaterTemperature'] = f"'{str(self._water_temp)}'"
|
||||||
|
|
||||||
def _delete_existing_output_files(self):
|
def _delete_existing_output_files(self):
|
||||||
"""
|
"""
|
||||||
|
@ -161,41 +162,40 @@ class HeatPumpExport:
|
||||||
self._input_data["TESCapacity"] = self._input_data["HoursOfStorageAtMaxDemand"] * (max_demand * 3.6) / (
|
self._input_data["TESCapacity"] = self._input_data["HoursOfStorageAtMaxDemand"] * (max_demand * 3.6) / (
|
||||||
(self._input_data["Cp"] / 1000) * self._input_data["TemperatureDifference"])
|
(self._input_data["Cp"] / 1000) * self._input_data["TemperatureDifference"])
|
||||||
|
|
||||||
def _update_input_data_with_coff(self, capacity_coff: List, comp_power_coff: List):
|
def _update_input_data_with_coff(self, a_coeff: List, b_coeff: List):
|
||||||
"""
|
"""
|
||||||
Updates the user data with coefficients derived from imports
|
Updates the user data with coefficients derived from imports
|
||||||
:param capacity_coff: heat or cooling capacity coefficients
|
:param a_coeff: insel a coefficient values
|
||||||
:param comp_power_coff: heat or cooling comppressor power coefficients
|
:param b_coeff: insel b coefficient values
|
||||||
|
Meaning of a and b are in the respective models for air source heat pump
|
||||||
|
and water to water source heat pump
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
self._input_data["a1"] = capacity_coff[0]
|
self._input_data["a1"] = a_coeff[0]
|
||||||
self._input_data["a2"] = capacity_coff[1]
|
self._input_data["a2"] = a_coeff[1]
|
||||||
self._input_data["a3"] = capacity_coff[2]
|
self._input_data["a3"] = a_coeff[2]
|
||||||
self._input_data["a4"] = capacity_coff[3]
|
self._input_data["a4"] = a_coeff[3]
|
||||||
self._input_data["a5"] = capacity_coff[4]
|
self._input_data["a5"] = a_coeff[4]
|
||||||
self._input_data["a6"] = capacity_coff[5]
|
self._input_data["a6"] = a_coeff[5]
|
||||||
self._input_data["b1"] = comp_power_coff[0]
|
self._input_data["b1"] = b_coeff[0]
|
||||||
self._input_data["b2"] = comp_power_coff[1]
|
self._input_data["b2"] = b_coeff[1]
|
||||||
self._input_data["b3"] = comp_power_coff[2]
|
self._input_data["b3"] = b_coeff[2]
|
||||||
self._input_data["b4"] = comp_power_coff[3]
|
self._input_data["b4"] = b_coeff[3]
|
||||||
self._input_data["b5"] = comp_power_coff[4]
|
self._input_data["b5"] = b_coeff[4]
|
||||||
self._input_data["b6"] = comp_power_coff[5]
|
self._input_data["b6"] = b_coeff[5]
|
||||||
|
|
||||||
def _extract_model_coff(self, hp_model: str, data_type='heat') -> Union[Tuple[List, List], None]:
|
# additional coefficients for water to water source
|
||||||
"""
|
if self._water_temp is not None:
|
||||||
Extracts heat pump coefficient data for a specific
|
self._input_data["a7"] = a_coeff[6]
|
||||||
model. e.g 012, 140
|
self._input_data["a8"] = a_coeff[7]
|
||||||
:param hp_model: the model type
|
self._input_data["a9"] = a_coeff[8]
|
||||||
:param data_type: indicates whether we're extracting cooling
|
self._input_data["a10"] = a_coeff[9]
|
||||||
or heating perfarmcn coefficients
|
self._input_data["a11"] = a_coeff[10]
|
||||||
:return:
|
self._input_data["b7"] = b_coeff[6]
|
||||||
"""
|
self._input_data["b8"] = b_coeff[7]
|
||||||
for energy_system in self._city.energy_systems:
|
self._input_data["b9"] = b_coeff[8]
|
||||||
if energy_system.heat_pump.model == hp_model:
|
self._input_data["b10"] = b_coeff[9]
|
||||||
if data_type == 'heat':
|
self._input_data["b11"] = b_coeff[10]
|
||||||
return energy_system.heat_pump.heating_capacity_coff, energy_system.heat_pump.heating_comp_power_coff
|
|
||||||
return energy_system.heat_pump.cooling_capacity_coff, energy_system.heat_pump.cooling_comp_power_coff
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _get_user_out_put(self):
|
def _get_user_out_put(self):
|
||||||
"""
|
"""
|
||||||
|
|
56
exports/energy_systems/water_to_water_hp_export.py
Normal file
56
exports/energy_systems/water_to_water_hp_export.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
"""
|
||||||
|
WaterToWaterHPExport exports water to water values after executing insel.
|
||||||
|
Multiple files are generated for the export
|
||||||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
|
Copyright © 2021 Project Author Peter Yefi peteryefi@gmail.com
|
||||||
|
"""
|
||||||
|
from exports.energy_systems.heat_pump_export import HeatPumpExport
|
||||||
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
|
class WaterToWaterHPExport(HeatPumpExport):
|
||||||
|
"""
|
||||||
|
Exports heat pump values as multiple output files
|
||||||
|
after executing insel
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, base_path, city, output_path):
|
||||||
|
template_path = (base_path / 'heat_pumps/water_to_water_tmpl.txt')
|
||||||
|
water_temp = (base_path / 'heat_pumps/wt_hourly3.txt')
|
||||||
|
super().__init__(base_path, city, output_path, template_path, water_temp)
|
||||||
|
|
||||||
|
def _extract_model_coff(self, hp_model: str, data_type='heat') -> Union[Tuple[List, List], None]:
|
||||||
|
"""
|
||||||
|
Extracts heat pump coefficient data for a specific
|
||||||
|
model. e.g 012, 140
|
||||||
|
:param hp_model: the model type
|
||||||
|
:param data_type: indicates whether we're extracting cooling
|
||||||
|
or heating perfarmcn coefficients
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
for energy_system in self._city.energy_systems:
|
||||||
|
if energy_system.water_to_water_hp.model == hp_model:
|
||||||
|
return energy_system.water_to_water_hp.power_demand_coff, \
|
||||||
|
energy_system.water_to_water_hp.heat_output_coff
|
||||||
|
return None
|
||||||
|
|
||||||
|
def execute_insel(self, user_input, hp_model, data_type):
|
||||||
|
"""
|
||||||
|
Runs insel and produces output files
|
||||||
|
Runs insel and write the necessary files
|
||||||
|
:param user_input: a dictionary containing the user
|
||||||
|
values necessary to run insel
|
||||||
|
:param hp_model: a string that indicates the heat
|
||||||
|
pump model to be used e.g. 012, 015
|
||||||
|
:param data_type: a string that indicates whether
|
||||||
|
insel should run for heat or cooling performance
|
||||||
|
:return:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
pow_demand_coeff, heat_output_coeff = self._extract_model_coff(hp_model, data_type)
|
||||||
|
super(WaterToWaterHPExport, self)._run_insel(user_input, pow_demand_coeff, heat_output_coeff)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ Copyright © 2020 Project Author Peter Yefi peteryefi@gmail.com
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from exports.energy_systems.heat_pump_export import HeatPumpExport
|
from exports.energy_systems.heat_pump_export import HeatPumpExport
|
||||||
|
from exports.energy_systems.air_source_hp_export import AirSourceHPExport
|
||||||
|
from exports.energy_systems.water_to_water_hp_export import WaterToWaterHPExport
|
||||||
|
|
||||||
|
|
||||||
class EnergySystemsExportFactory:
|
class EnergySystemsExportFactory:
|
||||||
|
@ -23,18 +25,22 @@ class EnergySystemsExportFactory:
|
||||||
self._data_type = data_type
|
self._data_type = data_type
|
||||||
self._output_path = output_path
|
self._output_path = output_path
|
||||||
|
|
||||||
def _export_heat_pump(self):
|
def _export_heat_pump(self, source):
|
||||||
"""
|
"""
|
||||||
Exports heat pump performance data as coefficients
|
Exports heat pump performance data as coefficients
|
||||||
of some objective function
|
of some objective function
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
HeatPumpExport(self._base_path, self._city, self._output_path)\
|
if source == 'air':
|
||||||
.run_insel(self._user_input, self._hp_model, self._data_type)
|
AirSourceHPExport(self._base_path, self._city, self._output_path)\
|
||||||
|
.execute_insel(self._user_input, self._hp_model, self._data_type)
|
||||||
|
elif source == 'water':
|
||||||
|
WaterToWaterHPExport(self._base_path, self._city, self._output_path)\
|
||||||
|
.execute_insel(self._user_input, self._hp_model, self._data_type)
|
||||||
|
|
||||||
def export(self):
|
def export(self, source='air'):
|
||||||
"""
|
"""
|
||||||
Export the city given to the class using the given export type handler
|
Export the city given to the class using the given export type handler
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
return getattr(self, '_export_heat_pump', lambda: None)()
|
return getattr(self, '_export_heat_pump', lambda: None)(source)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user