89 lines
3.2 KiB
Python
89 lines
3.2 KiB
Python
import math
|
|
|
|
import pandas as pd
|
|
data = pd.read_csv('new_file.csv')
|
|
demand = [0] + data['Q_tot_mpc'].to_list()
|
|
t_out = [0] + data['T_out'].to_list()
|
|
data['Datetime'] = pd.to_datetime(data['Datetime'])
|
|
p_electricity = data['Electricity_Price'].to_list()
|
|
cp = 4182 # J/kgK
|
|
# Heat Pump Sizing
|
|
hp_cap = max(demand) * 0.7 * 1000
|
|
hp_cop_curve_coefficients = [1.039924, 0.0146, 6e-06, -0.05026, 0.000635, -0.000154]
|
|
hp_nominal_efficiency = 2.5
|
|
hp_delta_t = 5
|
|
# TES Sizing
|
|
volume = round(max(demand) * 3.6e6 / (1000 * cp * 15))
|
|
height = 2
|
|
d = math.sqrt((4 * volume) / (math.pi * height))
|
|
ua = 0.28
|
|
|
|
variable_names = ["t_sup_hp", "t_tank", "t_ret", "m_ch", "m_dis", "q_hp", "hp_cop", "hp_electricity",
|
|
"electricity_cost"]
|
|
num_hours = len(demand)
|
|
variables = {name: [0] * num_hours for name in variable_names}
|
|
t_sup_hp, t_tank, t_ret, m_ch, m_dis, q_hp, hp_cop, hp_electricity, electricity_cost = [variables[name] for name in variable_names]
|
|
t_tank[0] = 40
|
|
for i in range(len(demand) - 1):
|
|
t_tank[i + 1] = t_tank[i] + ((m_ch[i] * (t_sup_hp[i] - t_tank[i])) + (ua * (t_out[i] - t_tank[i])) / cp - m_dis[i] * (t_tank[i] - t_ret[i])) * (900 / (1000 * volume))
|
|
# hp operation and tank charging
|
|
if t_tank[i + 1] < 40:
|
|
q_hp[i + 1] = hp_cap
|
|
m_ch[i + 1] = q_hp[i + 1] / (cp * hp_delta_t)
|
|
t_sup_hp[i + 1] = (q_hp[i + 1] / (m_ch[i + 1] * cp)) + t_tank[i + 1]
|
|
elif 40 <= t_tank[i + 1] < 55 and q_hp[i] == 0:
|
|
q_hp[i + 1] = 0
|
|
m_ch[i + 1] = 0
|
|
t_sup_hp[i + 1] = t_tank[i + 1]
|
|
elif 40 <= t_tank[i + 1] < 55 and q_hp[i] > 0:
|
|
q_hp[i + 1] = hp_cap
|
|
m_ch[i + 1] = q_hp[i + 1] / (cp * hp_delta_t)
|
|
t_sup_hp[i + 1] = (q_hp[i + 1] / (m_ch[i + 1] * cp)) + t_tank[i + 1]
|
|
else:
|
|
q_hp[i + 1], m_ch[i + 1], t_sup_hp[i + 1] = 0, 0, t_tank[i + 1]
|
|
if q_hp[i + 1] > 0:
|
|
t_out_fahrenheit = 1.8 * t_out[i] + 32
|
|
t_tank_fahrenheit = 1.8 * t_tank[i] + 32
|
|
hp_cop[i + 1] = (1 / (hp_cop_curve_coefficients[0] +
|
|
hp_cop_curve_coefficients[1] * t_tank_fahrenheit +
|
|
hp_cop_curve_coefficients[2] * t_tank_fahrenheit ** 2 +
|
|
hp_cop_curve_coefficients[3] * t_out_fahrenheit +
|
|
hp_cop_curve_coefficients[4] * t_out_fahrenheit ** 2 +
|
|
hp_cop_curve_coefficients[5] * t_tank_fahrenheit * t_out_fahrenheit)) * hp_nominal_efficiency
|
|
hp_electricity[i + 1] = q_hp[i + 1] / hp_cop[i + 1]
|
|
electricity_cost[i + 1] = hp_electricity[i + 1] * p_electricity[i + 1]
|
|
else:
|
|
hp_cop[i + 1] = 0
|
|
hp_electricity[i + 1] = 0
|
|
electricity_cost[i + 1] = 0
|
|
|
|
# storage discharging
|
|
if demand[i + 1] == 0:
|
|
m_dis[i + 1] = 0
|
|
t_ret[i + 1] = t_tank[i + 1]
|
|
else:
|
|
if demand[i + 1] > 0.5 * max(demand):
|
|
factor = 6
|
|
else:
|
|
factor = 4
|
|
m_dis[i + 1] = (max(demand) * 1000) / (cp * factor)
|
|
t_ret[i + 1] = t_tank[i + 1] - (demand[i + 1] * 1000) / (m_dis[i + 1] * cp)
|
|
|
|
output = pd.DataFrame(index=data['Datetime'])
|
|
output["demand"] = [x * 1000 for x in demand][1:]
|
|
output["q_hp"] = q_hp[1:]
|
|
output["hp_cop"] = hp_cop[1:]
|
|
output["hp_electricity_consumption"] = hp_electricity[1:]
|
|
output["m_ch"] = m_ch[1:]
|
|
output["m_dis"] = m_dis[1:]
|
|
output["t_sup_hp"] = t_sup_hp[1:]
|
|
output["t_tank"] = t_tank[1:]
|
|
output["t_return"] = t_ret[1:]
|
|
out_file = output.to_csv("results_rule_based.csv")
|
|
|
|
|
|
|
|
|
|
|
|
|