Changed how coefficients are generated

This commit is contained in:
Peter Yefi 2022-03-10 12:44:04 -05:00
parent 99a0ac0bce
commit 380c6644a3
5 changed files with 27 additions and 30 deletions

View File

@ -38,8 +38,8 @@ class AirSourceHPExport(HeatPumpExport):
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 energy_system.air_source_hp.heating_capacity_coff
return energy_system.air_source_hp.cooling_capacity_coff
return None
def execute_insel(self, user_input, hp_model, data_type):
@ -55,5 +55,5 @@ class AirSourceHPExport(HeatPumpExport):
: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, 'air_source.insel')
capacity_coeff = self._extract_model_coff(hp_model, data_type)
super(AirSourceHPExport, self)._run_insel(user_input, capacity_coeff, 'air_source.insel')

View File

@ -27,18 +27,17 @@ class HeatPumpExport:
self._base_path = base_path
self._output_path = output_path
def _run_insel(self, user_input: Dict, capacity_coeff: List, power_coeff: List, filename: str) -> None:
def _run_insel(self, user_input: Dict, capacity_coeff: List, filename: str) -> None:
"""
Runs insel and write the necessary files
:param user_input: a dictionary containing the user
values necessary to run insel
:param capacity_coeff: a list containing capacity coefficients
:param power_coeff: a list containing power demand coefficients
:param filename: the name of the insel file to be created
:return:
"""
self._input_data = user_input
self._update_input_data_with_coff(capacity_coeff, power_coeff)
self._update_input_data_with_coff(capacity_coeff)
# update input data with constants
self._update_input_data_with_constants()
# update input data with input and output files for insel
@ -82,7 +81,7 @@ class HeatPumpExport:
'HP Operational Cost (CAD)', 'Auxiliary Heater Operational Cost (CAD)',
'Operational CO2 Emissions of HP (g)',
'Operational CO2 Emissions of Auxiliary Heater (g)',
'Return Temperature', 'Demand (kW)'],
'Return Temperature', 'Demand (kW)', 'Test Column'],
self._input_data['fileOut2']: ['Day', 'Operational Daily Emissions from Heat Pumps (g)',
'Operational Daily Emissions from Auxiliary Heater (g)'],
self._input_data['fileOut3']: ['Month', 'Monthly Operational Costs of Heat Pumps (CAD)',
@ -158,9 +157,18 @@ class HeatPumpExport:
for key, value in constants_dict.items():
self._input_data[key] = value
# compute water to water HP specific values
if self._water_temp is not None:
if 55 <= self._input_data['HPSupTemp'] <= 60:
self._input_data["HPDisactivationTemperature"] = self._input_data["HPSupTemp"] - 5
self._input_data["HPReactivationTemperature"] = self._input_data["HPSupTemp"] - 18
elif 50 <= self._input_data["HPSupTemp"] < 55:
self._input_data["HPDisactivationTemperature"] = self._input_data["HPSupTemp"] - 5
self._input_data["HPReactivationTemperature"] = self._input_data["HPSupTemp"] - 13
elif 45 <= self._input_data["HPSupTemp"] < 50:
self._input_data["HPDisactivationTemperature"] = self._input_data["HPSupTemp"] - 3
self._input_data["HPReactivationTemperature"] = self._input_data["HPSupTemp"] - 8
elif 35 <= self._input_data["HPSupTemp"] < 40:
self._input_data["HPDisactivationTemperature"] = self._input_data["HPSupTemp"] - 2
self._input_data["HPReactivationTemperature"] = self._input_data["HPSupTemp"] - 4
# compute maximum demand. TODO: This should come from catalog in the future
max_demand = self._compute_max_demand()
@ -168,12 +176,11 @@ class HeatPumpExport:
self._input_data["TESCapacity"] = self._input_data["HoursOfStorageAtMaxDemand"] * (max_demand * 3.6) / (
(self._input_data["Cp"] / 1000) * self._input_data["TemperatureDifference"])
def _update_input_data_with_coff(self, a_coeff: List, b_coeff: List):
def _update_input_data_with_coff(self, a_coeff: List):
"""
Updates the user data with coefficients derived from imports
:param a_coeff: insel a coefficient values
:param b_coeff: insel b coefficient values
Meaning of a and b are in the respective models for air source heat pump
Meaning of a is in the models for air source heat pump
and water to water source heat pump
:return:
"""
@ -183,12 +190,6 @@ class HeatPumpExport:
self._input_data["a4"] = a_coeff[3]
self._input_data["a5"] = a_coeff[4]
self._input_data["a6"] = a_coeff[5]
self._input_data["b1"] = b_coeff[0]
self._input_data["b2"] = b_coeff[1]
self._input_data["b3"] = b_coeff[2]
self._input_data["b4"] = b_coeff[3]
self._input_data["b5"] = b_coeff[4]
self._input_data["b6"] = b_coeff[5]
# additional coefficients for water to water source
if self._water_temp is not None:
@ -197,11 +198,6 @@ class HeatPumpExport:
self._input_data["a9"] = a_coeff[8]
self._input_data["a10"] = a_coeff[9]
self._input_data["a11"] = a_coeff[10]
self._input_data["b7"] = b_coeff[6]
self._input_data["b8"] = b_coeff[7]
self._input_data["b9"] = b_coeff[8]
self._input_data["b10"] = b_coeff[9]
self._input_data["b11"] = b_coeff[10]
def _get_user_out_put(self):
"""

View File

@ -76,12 +76,10 @@ class AirSourceHeatPumpParameters:
c_data = self._extract_heat_pump_data(v_cool)
heat_pump.cooling_capacity = c_data[0]
heat_pump.cooling_comp_power = c_data[1]
heat_pump.cooling_capacity_coff = self._compute_coefficients(c_data[0], "cool")
heat_pump.cooling_comp_power_coff = self._compute_coefficients(c_data[1], "cool")
heat_pump.cooling_capacity_coff = self._compute_coefficients(c_data, "cool")
heat_pump.heating_capacity = h_data[0]
heat_pump.heating_comp_power = h_data[1]
heat_pump.heating_capacity_coff = self._compute_coefficients(h_data[0])
heat_pump.heating_comp_power_coff = self._compute_coefficients(h_data[1])
heat_pump.heating_capacity_coff = self._compute_coefficients(h_data)
energy_system = EnergySystem('{} capacity heat pump'.format(heat_pump.model), 0, [], None)
energy_system.air_source_hp = heat_pump
@ -123,10 +121,13 @@ class AirSourceHeatPumpParameters:
x_values = heat_x_values if data_type == "heat" else cool_x_values
x_values = x_values.tolist()
# convert list of lists to one list
heat_pump_data = list(itertools.chain.from_iterable(heat_pump_data))
hp_data = [i/j for i, j in
zip(list(itertools.chain.from_iterable(heat_pump_data[0])),
list(itertools.chain.from_iterable(heat_pump_data[1])))]
# Compute heat output coefficients
popt, _ = curve_fit(self._objective_function, [x_values, out_temp], heat_pump_data)
popt, _ = curve_fit(self._objective_function, [x_values, out_temp], hp_data)
return popt.tolist()
def _objective_function(self, xdata: List, a1: float, a2: float, a3: float, a4: float, a5: float, a6: float) -> float:

View File

@ -52,7 +52,7 @@ class TestEnergySystemsFactory(TestCase):
EnergySystemsExportFactory(self._city, user_input, '012', self._output_path).export()
df = pd.read_csv(self._output_path)
self.assertEqual(df.shape, (13, 3))
self.assertEqual(df.iloc[0, 1], 3045398.0)
self.assertEqual(df.iloc[0, 1], 1867715.88)
def tearDown(self) -> None:
try: