feat: first commit
This commit is contained in:
commit
69097fe7cd
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
8
.idea/flexibility.iml
Normal file
8
.idea/flexibility.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.9 (venv)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
30
.idea/inspectionProfiles/Project_Default.xml
Normal file
30
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ourVersions">
|
||||||
|
<value>
|
||||||
|
<list size="2">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="3.10" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="3.9" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="E111" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="list.__getitem__" />
|
||||||
|
<option value="hub.catalog_factories.data_models.cost.capital_cost.CapitalCost.__getitem__" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (venv)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/flexibility.iml" filepath="$PROJECT_DIR$/.idea/flexibility.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
BIN
Results.xlsx
Normal file
BIN
Results.xlsx
Normal file
Binary file not shown.
1441
new_file.csv
Normal file
1441
new_file.csv
Normal file
File diff suppressed because it is too large
Load Diff
BIN
new_file.xlsx
Normal file
BIN
new_file.xlsx
Normal file
Binary file not shown.
75
optimized.py
Normal file
75
optimized.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
import cvxpy as cp
|
||||||
|
import pandas as pd
|
||||||
|
data = pd.read_csv('new_file.csv')
|
||||||
|
demand = data['Q_tot_mpc'].to_list()
|
||||||
|
demand_watts = [x * 1000 for x in demand]
|
||||||
|
t_out = data['T_out'].to_list()
|
||||||
|
p_electricity = data['Electricity_Price'].to_list()
|
||||||
|
data['Datetime'] = pd.to_datetime(data['Datetime'])
|
||||||
|
cp_water = 4182 # J/kgK
|
||||||
|
# Heat Pump Sizing
|
||||||
|
hp_cap = max(demand_watts) * 0.7
|
||||||
|
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_watts) * 3.6e3 / (1000 * cp_water * 15))
|
||||||
|
height = 2
|
||||||
|
d = math.sqrt((4 * volume) / (math.pi * height))
|
||||||
|
ua = 0.28
|
||||||
|
|
||||||
|
# problem setting
|
||||||
|
time_horizon = 1440 # Number of time steps (15-minute intervals)
|
||||||
|
time_step_size = 900 # Time step size in seconds (15 minutes)
|
||||||
|
initial_temperature = 40
|
||||||
|
lower_limit_TES = 40
|
||||||
|
upper_limit_TES = 55
|
||||||
|
|
||||||
|
# Define problem variables
|
||||||
|
storage_charge = cp.Variable(time_horizon, nonneg=True) # Energy from heat pump to tank
|
||||||
|
storage_discharge = cp.Variable(time_horizon, nonneg=True) # Energy from tank to house
|
||||||
|
heat_pump_energy = cp.Variable(time_horizon, nonneg=True) # Heat pump energy
|
||||||
|
tank_temperature = cp.Variable(time_horizon) # Tank temperature (°C)
|
||||||
|
|
||||||
|
# Define problem parameters
|
||||||
|
thermal_demand = demand_watts # Heating demand
|
||||||
|
|
||||||
|
electricity_price = p_electricity
|
||||||
|
# Calculate the change in tank temperature
|
||||||
|
temperature_change = (time_step_size / (1000 * volume *
|
||||||
|
cp_water)) * (storage_charge[:-1] - storage_discharge[:-1])
|
||||||
|
# Calculate the electricity cost
|
||||||
|
electricity_cost = ((heat_pump_energy[:-1] * time_step_size) / (hp_nominal_efficiency * 3600)) @ electricity_price[:-1]
|
||||||
|
|
||||||
|
# Define the objective function
|
||||||
|
objective = cp.Minimize(cp.sum_squares(thermal_demand - storage_discharge)) + cp.Minimize(cp.sum(electricity_cost)) + cp.Minimize(cp.sum(heat_pump_energy))
|
||||||
|
# Define the constraints
|
||||||
|
constraints = [heat_pump_energy <= hp_cap, tank_temperature >= lower_limit_TES,
|
||||||
|
tank_temperature <= upper_limit_TES, tank_temperature[0] == initial_temperature,
|
||||||
|
storage_charge <= heat_pump_energy]
|
||||||
|
|
||||||
|
# Specify the tank temperature in the next time step
|
||||||
|
constraints.extend([tank_temperature[i+1] == tank_temperature[i] + temperature_change[i] for i in range(time_horizon - 1)])
|
||||||
|
# Create the optimization problem
|
||||||
|
problem = cp.Problem(objective, constraints)
|
||||||
|
# Solve the problem
|
||||||
|
problem.solve(solver=cp.GUROBI)
|
||||||
|
|
||||||
|
# Get the optimized values
|
||||||
|
optimized_storage_charge = storage_charge.value
|
||||||
|
optimized_storage_discharge = storage_discharge.value
|
||||||
|
optimized_heat_pump_energy = heat_pump_energy.value
|
||||||
|
optimized_tank_temperature = tank_temperature.value
|
||||||
|
electricity_consumption = (optimized_heat_pump_energy*time_step_size)/(hp_nominal_efficiency*3600)
|
||||||
|
optimized_cost = electricity_consumption * electricity_price / 1000
|
||||||
|
output = pd.DataFrame(index=data['Datetime'])
|
||||||
|
output["optimized_storage_charge"] = optimized_storage_charge
|
||||||
|
output["optimized_storage_discharge"] = optimized_storage_discharge
|
||||||
|
output["optimized_heat_pump_energy"] = optimized_heat_pump_energy
|
||||||
|
output["demand"] = thermal_demand
|
||||||
|
output["T"] = optimized_tank_temperature
|
||||||
|
output["electricity_consumption"] = electricity_consumption
|
||||||
|
output["electricity_cost"] = optimized_cost
|
||||||
|
out_file = output.to_csv("results_multi_objective.csv")
|
1441
results_multi_objective.csv
Normal file
1441
results_multi_objective.csv
Normal file
File diff suppressed because it is too large
Load Diff
1441
results_rule_based.csv
Normal file
1441
results_rule_based.csv
Normal file
File diff suppressed because it is too large
Load Diff
88
rule_based.py
Normal file
88
rule_based.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user